Skip to content

gccrs: fix ICE for empty enum variant #4081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Lishin1215
Copy link
Contributor

Fixes #3947
gcc/rust/ChangeLog:

* rust-gcc.cc (constructor_expression): 
Ensure vec_alloc reserves at least one element.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3947.rs: New test.

Comment on lines 1261 to 1264
vec_alloc (init, vals.size ());
size_t reserve = vals.size ();
if (is_variant && union_index != -1)
reserve = reserve < 1 ? 1 : reserve;
vec_reserve (init, reserve);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this should really be vec_alloc (init, union_index != -1 ? 1 : vals.size ())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@powerboat9
Thanks so much! I just updated it!

@Lishin1215 Lishin1215 force-pushed the 3947 branch 2 times, most recently from 7e2064c to 34a1709 Compare August 15, 2025 10:34
@@ -1258,7 +1258,10 @@ constructor_expression (tree type_tree, bool is_variant,
return error_mark_node;

vec<constructor_elt, va_gc> *init;
vec_alloc (init, vals.size ());
size_t reserve = vals.size ();
if (is_variant && union_index != -1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this condition should trigger even if is_variant is false, to handle unions properly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@powerboat9
Thanks for pointing that out, I hadn’t considered the non-variant union case!
I’ve updated the patch accordingly. Thanks a lot!

gcc/rust/ChangeLog:

	* rust-gcc.cc (constructor_expression):
	Ensure vec_alloc reserves at least one element.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-3947.rs: New test.

Signed-off-by: lishin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE in Compile, at rust/backend/rust-compile-pattern.h:36 type switcheroo
2 participants