]> gcc.gnu.org Git - gcc.git/commitdiff
[Ada] Fix internal error on bit-aligned component of function call
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 16 Jul 2020 09:07:32 +0000 (11:07 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 20 Oct 2020 07:21:34 +0000 (03:21 -0400)
gcc/ada/

* exp_util.adb (Remove_Side_Effects): Always generate a renaming
that is handled by the front-end in the case of an indexed or a
selected component whose prefix has a nonstandard representation.

gcc/ada/exp_util.adb

index 508381763d338972377dbaca20e2d533651af17c..2c08ea9077137804fcb547f807e7803314bd88c1 100644 (file)
@@ -11530,7 +11530,26 @@ package body Exp_Util is
             Insert_Action (Exp, E);
          end if;
 
-      --  For expressions that denote names, we can use a renaming scheme.
+      --  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).
+
+      elsif Nkind (Exp) in N_Indexed_Component | N_Selected_Component
+        and then Has_Non_Standard_Rep (Etype (Prefix (Exp)))
+      then
+         Def_Id := Build_Temporary (Loc, 'R', Exp);
+         Res := New_Occurrence_Of (Def_Id, Loc);
+
+         Insert_Action (Exp,
+           Make_Object_Renaming_Declaration (Loc,
+             Defining_Identifier => Def_Id,
+             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.
       --  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
@@ -11553,21 +11572,7 @@ package body Exp_Util is
              Subtype_Mark        => New_Occurrence_Of (Exp_Type, Loc),
              Name                => Relocate_Node (Exp)));
 
-         --  If this is a packed reference, or a selected component with
-         --  a nonstandard representation, a reference to the temporary
-         --  will be replaced by a copy of the original expression (see
-         --  Exp_Ch2.Expand_Renaming). Otherwise the temporary must be
-         --  elaborated by gigi, and is of course not to be replaced in-line
-         --  by the expression it renames, which would defeat the purpose of
-         --  removing the side effect.
-
-         if Nkind (Exp) in N_Selected_Component | N_Indexed_Component
-           and then Has_Non_Standard_Rep (Etype (Prefix (Exp)))
-         then
-            null;
-         else
-            Set_Is_Renaming_Of_Object (Def_Id, False);
-         end if;
+         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
This page took 0.074188 seconds and 5 git commands to generate.