From c37348963dba9dd4aeaf1b73391bce2f0fe83c89 Mon Sep 17 00:00:00 2001
From: Eric Botcazou <ebotcazou@adacore.com>
Date: Mon, 9 Feb 2009 18:34:20 +0000
Subject: [PATCH] decl.c (gnat_to_gnu_entity): Set TYPE_NONALIASED_COMPONENT on
 the array type only if appropriate.

	* gcc-interface/decl.c (gnat_to_gnu_entity) <E_String_Literal_Subtype>:
	Set TYPE_NONALIASED_COMPONENT on the array type only if appropriate.
	(copy_alias_set): Assert that arrays have the same aliasing settings.
	(substitute_in_type) <ARRAY_TYPE>: Copy TYPE_NONALIASED_COMPONENT.

From-SVN: r144038
---
 gcc/ada/ChangeLog            |  7 +++++++
 gcc/ada/gcc-interface/decl.c | 17 +++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 4da0bbb7222f..6a65f22a135e 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,10 @@
+2009-02-09  Eric Botcazou  <ebotcazou@adacore.com>
+
+	* gcc-interface/decl.c (gnat_to_gnu_entity) <E_String_Literal_Subtype>:
+	Set TYPE_NONALIASED_COMPONENT on the array type only if appropriate.
+	(copy_alias_set): Assert that arrays have the same aliasing settings.
+	(substitute_in_type) <ARRAY_TYPE>: Copy TYPE_NONALIASED_COMPONENT.
+
 2009-02-08  Eric Botcazou  <ebotcazou@adacore.com>
 
 	* gcc-interface/decl.c (gnat_to_gnu_entity) <E_String_Literal_Subtype>:
diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c
index 874b1ccb0353..e86c2f93145f 100644
--- a/gcc/ada/gcc-interface/decl.c
+++ b/gcc/ada/gcc-interface/decl.c
@@ -2615,8 +2615,9 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
 	gnu_type
 	  = build_array_type (gnat_to_gnu_type (Component_Type (gnat_entity)),
 			      gnu_index_type);
-	TYPE_NONALIASED_COMPONENT (gnu_type) = 1;
-	copy_alias_set (gnu_type,  gnu_string_type);
+	if (array_type_has_nonaliased_component (gnat_entity, gnu_type))
+	  TYPE_NONALIASED_COMPONENT (gnu_type) = 1;
+	copy_alias_set (gnu_type, gnu_string_type);
       }
       break;
 
@@ -5184,6 +5185,17 @@ copy_alias_set (tree gnu_new_type, tree gnu_old_type)
       && TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_new_type)))
     copy_alias_set (TREE_TYPE (gnu_new_type), TREE_TYPE (gnu_old_type));
 
+  /* The alias set shouldn't be copied between array types with different
+     aliasing settings because this can break the aliasing relationship
+     between the array type and its element type.  */
+#ifndef ENABLE_CHECKING
+  if (flag_strict_aliasing)
+#endif
+    gcc_assert (!(TREE_CODE (gnu_new_type) == ARRAY_TYPE
+		  && TREE_CODE (gnu_old_type) == ARRAY_TYPE
+		  && TYPE_NONALIASED_COMPONENT (gnu_new_type)
+		     != TYPE_NONALIASED_COMPONENT (gnu_old_type)));
+
   TYPE_ALIAS_SET (gnu_new_type) = get_alias_set (gnu_old_type);
   record_component_aliases (gnu_new_type);
 }
@@ -7510,6 +7522,7 @@ substitute_in_type (tree t, tree f, tree r)
 
 	new = build_array_type (component, domain);
 	TYPE_SIZE (new) = 0;
+	TYPE_NONALIASED_COMPONENT (new) = TYPE_NONALIASED_COMPONENT (t);
 	TYPE_MULTI_ARRAY_P (new) = TYPE_MULTI_ARRAY_P (t);
 	TYPE_CONVENTION_FORTRAN_P (new) = TYPE_CONVENTION_FORTRAN_P (t);
 	layout_type (new);
-- 
GitLab