utils.c (type_for_nonaliased_component_p): Return false for all AGGREGATE_TYPEs.
authorOlivier Hainque <hainque@adacore.com>
Fri, 21 Sep 2007 14:14:45 +0000 (14:14 +0000)
committerOlivier Hainque <hainque@gcc.gnu.org>
Fri, 21 Sep 2007 14:14:45 +0000 (14:14 +0000)
2007-09-21  Olivier Hainque  <hainque@adacore.com>

ada/
        * utils.c (type_for_nonaliased_component_p): Return false for
        all AGGREGATE_TYPEs.

testsuite/
        * gnat.dg/nested_subtype_byref.ad[bs]: Part of new test.
        * gnat.dg/test_nested_subtype_byref.adb: New test.

From-SVN: r128650

gcc/ada/ChangeLog
gcc/ada/utils.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/nested_subtype_byref.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/nested_subtype_byref.ads [new file with mode: 0644]
gcc/testsuite/gnat.dg/test_nested_subtype_byref.adb [new file with mode: 0644]

index 695d4485de3ee92ef4b560b2be25b962d7e22277..bd2560cfcac98c2edb20d6f815072024efdadceb 100644 (file)
@@ -1,3 +1,8 @@
+2007-09-21  Olivier Hainque  <hainque@adacore.com>
+
+       * utils.c (type_for_nonaliased_component_p): Return false for
+       all AGGREGATE_TYPEs.
+
 2007-09-17  Eric Botcazou  <ebotcazou@adacore.com>
 
        * decl.c (gnat_to_gnu_entity) <object>: Make again the type of an
index 0db4e78dc9f1eecb07dca685cdd4d99a3fec086b..e9adfa649a0d81c554e6a396bc2afe2dc1ef775f 100644 (file)
@@ -4005,10 +4005,22 @@ type_for_nonaliased_component_p (tree gnu_type)
   if (must_pass_by_ref (gnu_type) || default_pass_by_ref (gnu_type))
     return false;
 
-  /* We might need the address for any array type, even if normally
-     passed by copy, to construct a fat pointer if the component is
-     used as an actual for an unconstrained formal.  */
-  if (TREE_CODE (gnu_type) == ARRAY_TYPE)
+  /* We used to say that any component of aggregate type is aliased
+     because the front-end may take 'Reference of it.  The front-end
+     has been enhanced in the meantime so as to use a renaming instead
+     in most cases, but the back-end can probably take the address of
+     such a component too so we go for the conservative stance.
+
+     For instance, we might need the address of any array type, even
+     if normally passed by copy, to construct a fat pointer if the
+     component is used as an actual for an unconstrained formal.
+
+     Likewise for record types: even if a specific record subtype is
+     passed by copy, the parent type might be passed by ref (e.g. if
+     it's of variable size) and we might take the address of a child
+     component to pass to a parent formal.  We have no way to check
+     for such conditions here.  */
+  if (AGGREGATE_TYPE_P (gnu_type))
     return false;
 
   return true;
index 70ec4b7805d851c49841dc5efc6c1abfd75d214d..3b95f1d8833b53c376bdc808bb9464f9479d57bb 100644 (file)
@@ -1,3 +1,8 @@
+2007-09-21  Olivier Hainque  <hainque@adacore.com>
+
+       * gnat.dg/nested_subtype_byref.ad[bs]: Part of new test.
+       * gnat.dg/test_nested_subtype_byref.adb: New test.
+
 2007-09-21  Jakub Jelinek  <jakub@redhat.com>
 
        PR fortran/33439
diff --git a/gcc/testsuite/gnat.dg/nested_subtype_byref.adb b/gcc/testsuite/gnat.dg/nested_subtype_byref.adb
new file mode 100644 (file)
index 0000000..b232aa3
--- /dev/null
@@ -0,0 +1,23 @@
+
+package body Nested_Subtype_Byref is
+
+   type Data (Stamped : Boolean) is record
+      case Stamped is
+         when True   => Valid : Boolean;
+         when others => null;
+      end case;
+   end record;
+
+   type Message is record
+      F : Integer := 1;
+      D : Data (Stamped => True);
+   end record;
+
+   procedure Check  is
+      M : Message;
+   begin
+      M.D.Valid := True;
+   end;
+
+end;
+
diff --git a/gcc/testsuite/gnat.dg/nested_subtype_byref.ads b/gcc/testsuite/gnat.dg/nested_subtype_byref.ads
new file mode 100644 (file)
index 0000000..24e3f1e
--- /dev/null
@@ -0,0 +1,4 @@
+
+package Nested_Subtype_Byref is
+   procedure Check;
+end;
diff --git a/gcc/testsuite/gnat.dg/test_nested_subtype_byref.adb b/gcc/testsuite/gnat.dg/test_nested_subtype_byref.adb
new file mode 100644 (file)
index 0000000..282aefd
--- /dev/null
@@ -0,0 +1,8 @@
+-- { dg-do run }
+-- { dg-options "-O2" }
+
+with Nested_Subtype_Byref;
+procedure Test_Nested_Subtype_Byref is
+begin
+   Nested_Subtype_Byref.Check;
+end;