-
Notifications
You must be signed in to change notification settings - Fork 184
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
base: master
Are you sure you want to change the base?
Conversation
gcc/rust/rust-gcc.cc
Outdated
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); |
There was a problem hiding this comment.
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 ())
There was a problem hiding this comment.
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!
7e2064c
to
34a1709
Compare
gcc/rust/rust-gcc.cc
Outdated
@@ -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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]>
Fixes #3947
gcc/rust/ChangeLog:
gcc/testsuite/ChangeLog: