From a7576e13569b4d6bce28c54ddb139a9119a713d8 Mon Sep 17 00:00:00 2001 From: Justin Squirek Date: Tue, 31 Jul 2018 09:56:04 +0000 Subject: [PATCH] [Ada] Wrong value after assignment of overlain record objects This patch corrects an issue whereby objects of a record type with a representation clause which are overlain by address would fail to get assigned values properly when one or both of said objects were marked volatile. 2018-07-31 Justin Squirek gcc/ada/ * exp_ch5.adb (Make_Field_Assign): Force temporarily generated objects for assignment of overlaid user objects to be renamings instead of constant declarations. gcc/testsuite/ * gnat.dg/addr11.adb: New testcase. From-SVN: r263098 --- gcc/ada/ChangeLog | 6 ++++++ gcc/ada/exp_ch5.adb | 13 ++++++++++++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gnat.dg/addr11.adb | 28 ++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gnat.dg/addr11.adb diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 08fdfcebfca..0d26bb50fda 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2018-07-31 Justin Squirek + + * exp_ch5.adb (Make_Field_Assign): Force temporarily generated + objects for assignment of overlaid user objects to be renamings + instead of constant declarations. + 2018-07-31 Hristian Kirtchev * exp_ch9.adb (Analyze_Pragmas): New routine. diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb index f2a26685dae..7a373ab883b 100644 --- a/gcc/ada/exp_ch5.adb +++ b/gcc/ada/exp_ch5.adb @@ -1531,11 +1531,22 @@ package body Exp_Ch5 is Selector_Name => New_Occurrence_Of (Disc, Loc)); end if; + -- Generate the assignment statement. When the left-hand side + -- is an object with an address clause present, force generated + -- temporaries to be renamings so as to correctly assign to any + -- overlaid objects. + A := Make_Assignment_Statement (Loc, Name => Make_Selected_Component (Loc, - Prefix => Duplicate_Subexpr (Lhs), + Prefix => + Duplicate_Subexpr + (Exp => Lhs, + Name_Req => False, + Renaming_Req => + Is_Entity_Name (Lhs) + and then Present (Address_Clause (Entity (Lhs)))), Selector_Name => New_Occurrence_Of (Find_Component (L_Typ, C), Loc)), Expression => Expr); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 00cf622343e..d7b99081f0d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-07-31 Justin Squirek + + * gnat.dg/addr11.adb: New testcase. + 2018-07-31 Hristian Kirtchev * gnat.dg/global.adb, gnat.dg/global.ads: New testcase. diff --git a/gcc/testsuite/gnat.dg/addr11.adb b/gcc/testsuite/gnat.dg/addr11.adb new file mode 100644 index 00000000000..c7053995f0e --- /dev/null +++ b/gcc/testsuite/gnat.dg/addr11.adb @@ -0,0 +1,28 @@ +-- { dg-do run } + +procedure Addr11 is + + type Rec is record + I : Short_Integer; + C : Character; + end record; + + type Derived is new Rec; + for Derived use record + I at 1 range 0 .. 15; + C at 0 range 0 .. 7; + end record; + + Init : constant Rec := ( 1515, 'A' ); + + D1 : Derived; + D2 : Derived; + pragma Volatile (D2); + for D2'Address use D1'Address; + +begin + D2 := Derived (Init); + if D1 /= Derived (Init) then + raise Program_Error; + end if; +end; -- 2.30.2