]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
decl.c (array_type_has_nonaliased_component): Return the same value for every dimensi...
authorEric Botcazou <ebotcazou@adacore.com>
Sun, 27 Jan 2019 18:16:23 +0000 (18:16 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Sun, 27 Jan 2019 18:16:23 +0000 (18:16 +0000)
* gcc-interface/decl.c (array_type_has_nonaliased_component): Return
the same value for every dimension of a multidimensional array type.

From-SVN: r268316

gcc/ada/ChangeLog
gcc/ada/gcc-interface/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/opt75.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/opt75_pkg.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/opt75_pkg.ads [new file with mode: 0644]

index 27719e69558278714b7f14859ea38a90c232faa4..e5adc7f53e0eeb9710c361b0d9810e69ee5dd787 100644 (file)
@@ -1,3 +1,8 @@
+2019-01-27  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/decl.c (array_type_has_nonaliased_component): Return
+       the same value for every dimension of a multidimensional array type.
+
 2019-01-26  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc-interface/trans.c (gnat_to_gnu) <N_Assignment_Statement>: Use
index bf3269af5345b7390270a4ed315fb7969cad4743..acd7fc5ddc88057b76a5e2ceb994822f42ef5394 100644 (file)
@@ -6341,12 +6341,6 @@ same_discriminant_p (Entity_Id discr1, Entity_Id discr2)
 static bool
 array_type_has_nonaliased_component (tree gnu_type, Entity_Id gnat_type)
 {
-  /* If the array type is not the innermost dimension of the GNAT type,
-     then it has a non-aliased component.  */
-  if (TREE_CODE (TREE_TYPE (gnu_type)) == ARRAY_TYPE
-      && TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_type)))
-    return true;
-
   /* If the array type has an aliased component in the front-end sense,
      then it also has an aliased component in the back-end sense.  */
   if (Has_Aliased_Components (gnat_type))
@@ -6357,15 +6351,17 @@ array_type_has_nonaliased_component (tree gnu_type, Entity_Id gnat_type)
   if (Is_Derived_Type (gnat_type))
     {
       tree gnu_parent_type = gnat_to_gnu_type (Etype (gnat_type));
-      int index;
       if (TREE_CODE (gnu_parent_type) == UNCONSTRAINED_ARRAY_TYPE)
        gnu_parent_type
          = TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_parent_type))));
-      for (index = Number_Dimensions (gnat_type) - 1; index > 0; index--)
-       gnu_parent_type = TREE_TYPE (gnu_parent_type);
       return TYPE_NONALIASED_COMPONENT (gnu_parent_type);
     }
 
+  /* For a multi-dimensional array type, find the component type.  */
+  while (TREE_CODE (TREE_TYPE (gnu_type)) == ARRAY_TYPE
+        && TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_type)))
+    gnu_type = TREE_TYPE (gnu_type);
+
   /* Otherwise, rely exclusively on properties of the element type.  */
   return type_for_nonaliased_component_p (TREE_TYPE (gnu_type));
 }
index ac19a5ebc6846e507b3893653580b10e5b099009..9102652934368b5cd9f77efdcdbe0ee137f6c763 100644 (file)
@@ -1,3 +1,8 @@
+2019-01-27  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/opt75.adb: New test.
+       * gnat.dg/opt75_pkg.ad[sb]: New helper.
+
 2019-01-27  Uroš Bizjak  <ubizjak@gmail.com>
 
        PR target/88948
diff --git a/gcc/testsuite/gnat.dg/opt75.adb b/gcc/testsuite/gnat.dg/opt75.adb
new file mode 100644 (file)
index 0000000..080a518
--- /dev/null
@@ -0,0 +1,9 @@
+-- { dg-do run }
+-- { dg-options "-O3" }
+
+with Opt75_Pkg; use Opt75_Pkg;
+
+procedure Opt75 is
+begin
+  null;
+end;
diff --git a/gcc/testsuite/gnat.dg/opt75_pkg.adb b/gcc/testsuite/gnat.dg/opt75_pkg.adb
new file mode 100644 (file)
index 0000000..4424e70
--- /dev/null
@@ -0,0 +1,12 @@
+package body Opt75_Pkg is
+
+  overriding procedure Adjust (Object : in out T) is
+  begin
+    if Object.Ref /= Empty_Rec'Access then
+      System.Atomic_Counters.Increment (Object.Ref.Counter);
+    end if;
+  end;
+
+  A : constant Arr := (others => (others => Empty));
+
+end Opt75_Pkg;
diff --git a/gcc/testsuite/gnat.dg/opt75_pkg.ads b/gcc/testsuite/gnat.dg/opt75_pkg.ads
new file mode 100644 (file)
index 0000000..4fae165
--- /dev/null
@@ -0,0 +1,27 @@
+pragma Restrictions (No_Abort_Statements);
+pragma Restrictions (Max_Asynchronous_Select_Nesting => 0);
+
+with Ada.Finalization;
+with System.Atomic_Counters;
+
+package Opt75_Pkg is
+
+  type Rec is record
+    Counter : System.Atomic_Counters.Atomic_Counter;
+  end record;
+
+  type Rec_Ptr is access all Rec;
+
+  Empty_Rec : aliased Rec;
+
+  type T is new Ada.Finalization.Controlled with record
+    Ref : Rec_Ptr := Empty_Rec'Access;
+  end record;
+
+  overriding procedure Adjust (Object : in out T);
+
+  Empty : constant T := (Ada.Finalization.Controlled with Ref => Empty_Rec'Access);
+
+  type Arr is array (Integer range 1 .. 8, Integer range 1 .. 4) of T;
+
+end Opt75_Pkg;