public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix internal error on bit-aligned component of function call
@ 2020-10-20  7:23 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2020-10-20  7:23 UTC (permalink / raw)
  To: gcc-patches; +Cc: Eric Botcazou

[-- Attachment #1: Type: text/plain, Size: 659 bytes --]

This fixes an internal error in the code generator triggered by a
reference generated by the front-end to a bit-aligned component of
the result of a function call.  Such a reference cannot be handled
by the code generator because the object is not aligned on a byte
boundary, so it is replaced by a renaming that is fully handled by
the front-end because of the potential nonstandard representation.

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

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.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2727 bytes --]

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
@@ -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



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-10-20  7:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-20  7:23 [Ada] Fix internal error on bit-aligned component of function call Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).