decl.c (gnat_to_gnu_entity): Simplify the condition under which a constant renaming...
authorEric Botcazou <ebotcazou@adacore.com>
Sat, 8 Sep 2007 10:30:06 +0000 (10:30 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Sat, 8 Sep 2007 10:30:06 +0000 (10:30 +0000)
* decl.c (gnat_to_gnu_entity) <Object>: Simplify the condition under
which a constant renaming is treated as a normal object declaration.
* trans.c (lvalue_required_p) <N_Slice>: New case, extracted from
the N_Indexed_Component case.
<N_Indexed_Component>: Fall through to above case.
<N_Object_Renaming_Declaration>: Return true for all composite types.

From-SVN: r128268

gcc/ada/ChangeLog
gcc/ada/decl.c
gcc/ada/trans.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/renaming3.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/renaming4.ads [new file with mode: 0644]

index e23d6b813c797b4c949c7091fbd8bfcc538b3cc0..3c5969d96ea3e9f95b63cfb50644988618a47e1a 100644 (file)
@@ -1,3 +1,12 @@
+2007-09-08  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * decl.c (gnat_to_gnu_entity) <Object>: Simplify the condition under
+       which a constant renaming is treated as a normal object declaration.
+       * trans.c (lvalue_required_p) <N_Slice>: New case, extracted from
+       the N_Indexed_Component case.
+       <N_Indexed_Component>: Fall through to above case.
+       <N_Object_Renaming_Declaration>: Return true for all composite types.
+
 2007-09-08  Eric Botcazou  <ebotcazou@adacore.com>
 
        * decl.c (make_packable_type): If the new type has been given BLKmode,
index 7a01327c8652236db68ada20418d9e8619e3bfc9..202cca851ad3d2b13f8e9b5115086448b93b4e59 100644 (file)
@@ -815,10 +815,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
                /* Case 3: If this is a constant renaming and creating a
                   new object is allowed and cheap, treat it as a normal
                   object whose initial value is what is being renamed.  */
-               if (const_flag
-                   && Ekind (Etype (gnat_entity)) != E_Class_Wide_Type
-                   && TREE_CODE (gnu_type) != UNCONSTRAINED_ARRAY_TYPE
-                   && TYPE_MODE (gnu_type) != BLKmode)
+               if (const_flag && Is_Elementary_Type (Etype (gnat_entity)))
                  ;
 
                /* Case 4: Make this into a constant pointer to the object we
index 24797753fd88b1c0bc2ff68b57f4a5715561a89d..1a4067c8639eb2c13ff2c035659f10f7c881764a 100644 (file)
@@ -384,20 +384,28 @@ lvalue_required_p (Node_Id gnat_node, tree operand_type, int aliased)
             gnat_temp = Next (gnat_temp))
          if (Nkind (gnat_temp) != N_Integer_Literal)
            return 1;
-       aliased |= Has_Aliased_Components (Etype (Prefix (gnat_node)));
-       return lvalue_required_p (Parent (gnat_node), operand_type, aliased);
       }
 
+      /* ... fall through ... */
+
+    case N_Slice:
+      aliased |= Has_Aliased_Components (Etype (Prefix (gnat_node)));
+      return lvalue_required_p (Parent (gnat_node), operand_type, aliased);
+
     case N_Selected_Component:
       aliased |= Is_Aliased (Entity (Selector_Name (gnat_node)));
       return lvalue_required_p (Parent (gnat_node), operand_type, aliased);
 
     case N_Object_Renaming_Declaration:
       /* We need to make a real renaming only if the constant object is
-        aliased; otherwise we can optimize and return the rvalue.  We
-        make an exception if the object is an identifier since in this
-        case the rvalue can be propagated attached to the CONST_DECL.  */
-      return aliased || Nkind (Name (gnat_node)) == N_Identifier;
+        aliased or if we may use a renaming pointer; otherwise we can
+        optimize and return the rvalue.  We make an exception if the object
+        is an identifier since in this case the rvalue can be propagated
+        attached to the CONST_DECL.  */
+      return (aliased != 0
+             /* This should match the constant case of the renaming code.  */
+             || Is_Composite_Type (Etype (Name (gnat_node)))
+             || Nkind (Name (gnat_node)) == N_Identifier);
 
     default:
       return 0;
index dd0a5285570879caed5d14ed275c1bc5170173bb..3114824ecc6d5a92cee49cbc132c1c0836dc1891 100644 (file)
@@ -1,3 +1,7 @@
+2007-09-08  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/renaming3.adb, renaming4.ads: New test.
+
 2007-09-08  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/unaligned_rep_clause.adb: New testcase.
diff --git a/gcc/testsuite/gnat.dg/renaming3.adb b/gcc/testsuite/gnat.dg/renaming3.adb
new file mode 100644 (file)
index 0000000..335a212
--- /dev/null
@@ -0,0 +1,12 @@
+-- { dg-do run }
+
+with Renaming4; use Renaming4;
+
+procedure Renaming3 is
+   type A is array(1..16) of Integer;
+   Filler : A := (others => 0);
+begin
+   if B(1) /= 1 then
+      raise Program_Error;
+   end if;
+end;
diff --git a/gcc/testsuite/gnat.dg/renaming4.ads b/gcc/testsuite/gnat.dg/renaming4.ads
new file mode 100644 (file)
index 0000000..4fdc9c1
--- /dev/null
@@ -0,0 +1,15 @@
+package Renaming4 is
+
+   type Big_Array is array (Natural range <>) of Integer;
+
+   subtype Index is Natural range 1..4;
+   subtype My_Array is Big_Array(Index);
+
+   A : constant My_Array := (1, 2, 3, 4);
+
+   subtype Small is Index range 1..2;
+   subtype Small_Array is Big_Array(Small);
+
+   B : Small_Array renames A(Index);
+
+end Renaming4;