This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hello, Ada allows view conversions to appear on the left hand side of an assignment and this requires special care in various places in the compiler. In particular, VIEW_CONVERT_EXPR may appear as an assignment lhs and this is apparently overlooked in tree-nested: convert_local_reference (tree *tp, int *walk_subtrees, void *data) { ... switch (TREE_CODE (t)) { ... default: if (!IS_TYPE_OR_DECL_P (t)) { *walk_subtrees = 1; wi->val_only = true; wi->is_lhs = false; } ... likewise in convert_nonlocal_reference. This leads to wrong code generation for the Ada testcase below: procedure Lhs_View_Convert is type Root is tagged record RV : Natural; end record; type Derived is new Root with null record; Root_Instance : Root := (RV => 1); Derived_Instance : Derived; procedure Process is X : Natural := Derived_Instance.RV; begin null; end; begin Derived_Instance.RV := 2; Root (Derived_Instance) := Root (Root_Instance); if Derived_Instance.RV /= Root_Instance.RV then raise Program_Error; end if; end; The gimple output for "Root (Derived_Instance) := Root (Root_Instance);" reads A843b = VIEW_CONVERT_EXPR<struct lhs_view_convert__root>(derived_instance)._tag; VIEW_CONVERT_EXPR<struct lhs_view_convert__root>(derived_instance) = root_instance; VIEW_CONVERT_EXPR<struct lhs_view_convert__root>(derived_instance)._tag = A843b; The reference to "Derived_Instance" in the nested "Process" subprogram triggers various reference conversions, and the code excerpt quoted above forces an intermediate temporary for the second gimple assignment: [.005t.nested] ... D.1916 = FRAME.264.derived_instance; VIEW_CONVERT_EXPR<struct lhs_view_convert__root>(D.1916) = root_instance; The bulk of the assignment thus eventually doesn't affect the actual target object and the test unexpectedly raises Program_Error. The attached patch fixes this by handling VIEW_CONVERT_EXPR explicitly in convert_[non]local_reference, to request walking the subtrees only and not touch the current is_lhs/val_only indications. Bootstrapped and regtested succesfully on i686-pc-linux-gnu. Thanks in advance, With Kind Regards, Olivier 2006-12-12 Olivier Hainque <hainque@adacore.com> * tree-nested.c (convert_local_reference): Handle VIEW_CONVERT_EXPR. Request walking the subtrees only, leaving the current is_lhs/val_only untouched. (convert_non_local_reference): Likewise. testsuite/ * gnat.dg/lhs_view_convert.adb: New test.
Attachment:
lhs_view_convert.dif
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |