Repository navigation
Fix evaluation order in struct field expressions - #4448
elshorbagyx wants to merge 1 commit into
Conversation
188de4d to
d1fd377
Compare
|
the tests are failing: but also i am pretty sure we update the ordering within the typecheck pass to sort this out. |
I am working on that. |
|
Make sure to double-check that the generated GIMPLE doesn't have unspecified evaluation order (I'm not sure about |
d1fd377 to
b4a862e
Compare
|
@philberty @powerboat9 |
|
you need to fix your change log here to match gcc style |
Fixes Rust-GCC#4445 gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Get the struct field type by field name instead of relying on declaration order, and only reorder fields for struct ADTs. * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve): Cancel reordering of struct field expressions. Signed-off-by: Mohamed El Shorbagy <mohrizq895@gmail.com>
7470ba2 to
088b863
Compare
|
I believe it is now ready |
| auto _adt = static_cast<TyTy::ADTType *> (adt->clone ()); | ||
| _adt->get_variants ()[0]->get_fields () = ordered_variant_fields; | ||
| tyty = _adt; |
There was a problem hiding this comment.
I'm not sure creating a new type with reordered fields and treating trees constructed with that type the same as trees constructed with the old type will work.
There was a problem hiding this comment.
I am not sure I understand your concern -- could you elaborate ?
|
|
||
| // it must be an ADT | ||
| rust_assert (tyty->get_kind () == TyTy::TypeKind::ADT); | ||
| TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (tyty); |
There was a problem hiding this comment.
and adt, while used after tyty is updated, is not itself updated
|
It'd probably be better to create temporary variables, initialize them in order, then use them in the constructor expression |
Fixes #4445
gcc/rust/ChangeLog:
gccrs evaluates struct field expressions in the order they are declared inside the struct definition. The current logic reorders the struct field expressions to match the struct field types, which results in incorrect behavior compared to the Rust reference (as mentioned in #4445). Instead, we could fetch the struct field type by field name through
lookup_field.