[Ada] Accept renamings of folded string aggregates
authorPiotr Trojanek <trojanek@adacore.com>
Fri, 3 Apr 2020 09:36:55 +0000 (11:36 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 16 Jun 2020 13:07:11 +0000 (09:07 -0400)
2020-06-16  Piotr Trojanek  <trojanek@adacore.com>

gcc/ada/

* sem_ch8.adb (Analyze_Object_Renaming): Remove trivially
useless initialization of Is_Object_Reference.
* sem_util.adb (Is_Object_Reference): Simplify detection of
binary and unary operators; literally implement rules about
aggregates and qualified expressions; recognize string literals
as object references.

gcc/ada/sem_ch8.adb
gcc/ada/sem_util.adb

index b9e5990..069341c 100644 (file)
@@ -754,7 +754,7 @@ package body Sem_Ch8 is
       Id            : constant Entity_Id  := Defining_Identifier (N);
       Loc           : constant Source_Ptr := Sloc (N);
       Nam           : constant Node_Id    := Name (N);
-      Is_Object_Ref : Boolean := False;
+      Is_Object_Ref : Boolean;
       Dec           : Node_Id;
       T             : Entity_Id;
       T2            : Entity_Id;
@@ -1366,7 +1366,7 @@ package body Sem_Ch8 is
       if T = Any_Type or else Etype (Nam) = Any_Type then
          return;
 
-      --  Verify that the renamed entity is an object or function call.
+      --  Verify that the renamed entity is an object or function call
 
       elsif Is_Object_Ref then
          if Comes_From_Source (N) then
index a3dbaaf..dd9ab2e 100644 (file)
@@ -16978,9 +16978,8 @@ package body Sem_Util is
             --  Note that predefined operators are functions as well, and so
             --  are attributes that are (can be renamed as) functions.
 
-            when N_Binary_Op
-               | N_Function_Call
-               | N_Unary_Op
+            when N_Function_Call
+               | N_Op
             =>
                return Etype (N) /= Standard_Void_Type;
 
@@ -17040,12 +17039,21 @@ package body Sem_Util is
             --  of aggregates in more contexts.
 
             when N_Qualified_Expression =>
-               if Ada_Version <  Ada_2012 then
-                  return False;
-               else
-                  return Is_Object_Reference (Expression (N))
-                    or else Nkind (Expression (N)) = N_Aggregate;
-               end if;
+               return Ada_Version >= Ada_2012
+                 and then Is_Object_Reference (Expression (N));
+
+            --  In Ada 95 an aggreate is an object reference
+
+            when N_Aggregate =>
+               return Ada_Version >= Ada_95;
+
+            --  A string literal is not an object reference, but it might come
+            --  from rewriting of an object reference, e.g. from folding of an
+            --  aggregate.
+
+            when N_String_Literal =>
+               return Is_Rewrite_Substitution (N)
+                 and then Is_Object_Reference (Original_Node (N));
 
             when others =>
                return False;