diff mbox series

[Ada] Fix bogus CE raised on elaboration of multidimensional array

Message ID 2816075.FCe4BPizGZ@polaris
State New
Headers show
Series [Ada] Fix bogus CE raised on elaboration of multidimensional array | expand

Commit Message

Eric Botcazou Jan. 27, 2019, 6:16 p.m. UTC
This is a regression present on all active branches: the compiler may generate 
elaboration code that wrongly raises a Constraint_Error for a multidimensional 
array whose component type is controlled if the unit is compiled at -O3.

Tested on x86_64-suse-linux, applied on all active branches.


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-27  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/opt75.adb: New test.
	* gnat.dg/opt75_pkg.ad[sb]: New helper.
diff mbox series

Patch

Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 268309)
+++ gcc-interface/decl.c	(working copy)
@@ -6237,12 +6237,6 @@  same_discriminant_p (Entity_Id discr1, E
 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))
@@ -6253,15 +6247,17 @@  array_type_has_nonaliased_component (tre
   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);
+
   /* Consider that an array of pointers has an aliased component, which is
      sort of logical and helps with Taft Amendment types in LTO mode.  */
   if (POINTER_TYPE_P (TREE_TYPE (gnu_type)))