diff mbox series

[Ada] Fix internal error on bit-packed array in Volatile_Full_Access record

Message ID 20201214155603.GA4096@adacore.com
State New
Headers show
Series [Ada] Fix internal error on bit-packed array in Volatile_Full_Access record | expand

Commit Message

Pierre-Marie de Rodat Dec. 14, 2020, 3:56 p.m. UTC
This fixes an issue in Remove_Side_Effects, which insists that a renaming
be handled by the back-end whereas Evaluation_Required says that it should
be handled by the front-end (renamings involving Volatile_Full_Access must
be fully expanded by the front-end).

This also reinstates an earlier fix in Expand_Bit_Packed_Element_Set which
was dropped and is again necessary because of the previous change.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* exp_pakd.adb (Expand_Bit_Packed_Element_Set): Fix again packed
	array type in complex cases where array is Volatile.
	* exp_util.adb (Remove_Side_Effects): Do not force a renaming to
	be handled by the back-end.
diff mbox series

Patch

diff --git a/gcc/ada/exp_pakd.adb b/gcc/ada/exp_pakd.adb
--- a/gcc/ada/exp_pakd.adb
+++ b/gcc/ada/exp_pakd.adb
@@ -1256,8 +1256,15 @@  package body Exp_Pakd is
          --  array type on Obj to get lost. So we save the type of Obj, and
          --  make sure it is reset properly.
 
-         New_Lhs := Duplicate_Subexpr (Obj, Name_Req => True);
-         New_Rhs := Duplicate_Subexpr_No_Checks (Obj);
+         declare
+            T : constant Entity_Id := Etype (Obj);
+         begin
+            New_Lhs := Duplicate_Subexpr (Obj, Name_Req => True);
+            New_Rhs := Duplicate_Subexpr_No_Checks (Obj);
+            Set_Etype (Obj, T);
+            Set_Etype (New_Lhs, T);
+            Set_Etype (New_Rhs, T);
+         end;
 
          --  First we deal with the "and"
 


diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -11798,8 +11798,8 @@  package body Exp_Util is
       --  If this is a packed array component or a selected component with a
       --  nonstandard representation, we cannot generate a reference because
       --  the component may be unaligned, so we must use a renaming and this
-      --  renaming must be handled by the front end, as the back end may balk
-      --  at the nonstandard representation (see Exp_Ch2.Expand_Renaming).
+      --  renaming is handled by the front end, as the back end may balk at
+      --  the nonstandard representation (see Evaluation_Required in Exp_Ch8).
 
       elsif Nkind (Exp) in N_Indexed_Component | N_Selected_Component
         and then Has_Non_Standard_Rep (Etype (Prefix (Exp)))
@@ -11813,8 +11813,7 @@  package body Exp_Util is
              Subtype_Mark        => New_Occurrence_Of (Exp_Type, Loc),
              Name                => Relocate_Node (Exp)));
 
-      --  For an expression that denotes a name, we can use a renaming scheme
-      --  that is handled by the back end, instead of the front end as above.
+      --  For an expression that denotes a name, we can use a renaming scheme.
       --  This is needed for correctness in the case of a volatile object of
       --  a nonvolatile type because the Make_Reference call of the "default"
       --  approach would generate an illegal access value (an access value
@@ -11837,8 +11836,6 @@  package body Exp_Util is
              Subtype_Mark        => New_Occurrence_Of (Exp_Type, Loc),
              Name                => Relocate_Node (Exp)));
 
-         Set_Is_Renaming_Of_Object (Def_Id, False);
-
       --  Avoid generating a variable-sized temporary, by generating the
       --  reference just for the function call. The transformation could be
       --  refined to apply only when the array component is constrained by a