tree-ssa-structalias.c (push_fields_onto_fieldstack): Deal with TYPE_NONALIASED_COMPO...
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 11 Sep 2007 19:43:02 +0000 (19:43 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Tue, 11 Sep 2007 19:43:02 +0000 (19:43 +0000)
* tree-ssa-structalias.c (push_fields_onto_fieldstack): Deal with
TYPE_NONALIASED_COMPONENT like with DECL_NONADDRESSABLE_P.

ada/
* decl.c (array_type_has_nonaliased_component): New predicate.
(gnat_to_gnu_field) <E_Array_Type>: Invoke the above predicate to
set the TYPE_NONALIASED_COMPONENT flag on the type.
<E_Array_Subtype>: Likewise.
* gigi.h (type_for_nonaliased_component_p): Declare.
* utils.c (type_for_nonaliased_component_p): New predicate.
(create_field_decl): Invoke the above predicate to set the
DECL_NONADDRESSABLE_P flag on the field.

From-SVN: r128391

gcc/ChangeLog
gcc/ada/ChangeLog
gcc/ada/decl.c
gcc/ada/gigi.h
gcc/ada/utils.c
gcc/tree-ssa-structalias.c

index ac74a0e54c6e019368c4acb9bc9c04e516b2516e..3fff25df9b0466050aff97e309be575c79f30eb7 100644 (file)
@@ -1,3 +1,8 @@
+2007-09-11  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * tree-ssa-structalias.c (push_fields_onto_fieldstack): Deal with
+       TYPE_NONALIASED_COMPONENT like with DECL_NONADDRESSABLE_P.
+
 2007-09-11  Jason Merrill  <jason@redhat.com>
 
        PR middle-end/27945
index 1ad4a404e8e04f76063c939cc355fb14a320e140..6951351c64f0add8c87318f6a721c54c70f5018a 100644 (file)
@@ -1,3 +1,14 @@
+2007-09-11  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * decl.c (array_type_has_nonaliased_component): New predicate.
+       (gnat_to_gnu_field) <E_Array_Type>: Invoke the above predicate to
+       set the TYPE_NONALIASED_COMPONENT flag on the type.
+       <E_Array_Subtype>: Likewise.
+       * gigi.h (type_for_nonaliased_component_p): Declare.
+       * utils.c (type_for_nonaliased_component_p): New predicate.
+       (create_field_decl): Invoke the above predicate to set the
+       DECL_NONADDRESSABLE_P flag on the field.
+
 2007-09-11  Javier Miranda  <miranda@adacore.com>
 
        * einfo.ads, einfo.adb (Dispatch_Table_Wrapper): New attribute. Present
index 5aa4bc8dd3708754f9536ad1d2b56a5b35d29a63..3d7c849fa713b0ff1315ad3538ceb74704397327 100644 (file)
@@ -103,6 +103,7 @@ static tree gnat_to_gnu_field (Entity_Id, tree, int, bool);
 static tree gnat_to_gnu_param (Entity_Id, Mechanism_Type, Entity_Id, bool,
                               bool *);
 static bool same_discriminant_p (Entity_Id, Entity_Id);
+static bool array_type_has_nonaliased_component (Entity_Id, tree);
 static void components_to_record (tree, Node_Id, tree, int, bool, tree *,
                                  bool, bool, bool, bool);
 static Uint annotate_value (tree);
@@ -1788,16 +1789,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
          {
            tem = build_array_type (tem, gnu_index_types[index]);
            TYPE_MULTI_ARRAY_P (tem) = (index > 0);
-
-           /* If the type below this is a multi-array type, then this
-              does not have aliased components.  But we have to make
-              them addressable if it must be passed by reference or
-              if that is the default.  */
-           if ((TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
-                && TYPE_MULTI_ARRAY_P (TREE_TYPE (tem)))
-               || (!Has_Aliased_Components (gnat_entity)
-                   && !must_pass_by_ref (TREE_TYPE (tem))
-                   && !default_pass_by_ref (TREE_TYPE (tem))))
+           if (array_type_has_nonaliased_component (gnat_entity, tem))
              TYPE_NONALIASED_COMPONENT (tem) = 1;
          }
 
@@ -2123,16 +2115,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
            {
              gnu_type = build_array_type (gnu_type, gnu_index_type[index]);
              TYPE_MULTI_ARRAY_P (gnu_type) = (index > 0);
-
-             /* If the type below this is a multi-array type, then this
-                does not have aliased components.  But we have to make
-                them addressable if it must be passed by reference or
-                if that is the default.  */
-             if ((TREE_CODE (TREE_TYPE (gnu_type)) == ARRAY_TYPE
-                  && TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_type)))
-                 || (!Has_Aliased_Components (gnat_entity)
-                     && !must_pass_by_ref (TREE_TYPE (gnu_type))
-                     && !default_pass_by_ref (TREE_TYPE (gnu_type))))
+             if (array_type_has_nonaliased_component (gnat_entity, gnu_type))
                TYPE_NONALIASED_COMPONENT (gnu_type) = 1;
            }
 
@@ -4625,6 +4608,24 @@ same_discriminant_p (Entity_Id discr1, Entity_Id discr2)
   return
     Original_Record_Component (discr1) == Original_Record_Component (discr2);
 }
+
+/* Return true if the array type specified by GNAT_TYPE and GNU_TYPE has
+   a non-aliased component in the back-end sense.  */
+
+static bool
+array_type_has_nonaliased_component (Entity_Id gnat_type, tree gnu_type)
+{
+  /* If the type below this is a multi-array type, then
+     this does not have aliased components.  */
+  if (TREE_CODE (TREE_TYPE (gnu_type)) == ARRAY_TYPE
+      && TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_type)))
+    return true;
+
+  if (Has_Aliased_Components (gnat_type))
+    return false;
+
+  return type_for_nonaliased_component_p (TREE_TYPE (gnu_type));
+}
 \f
 /* Given GNAT_ENTITY, elaborate all expressions that are required to
    be elaborated at the point of its definition, but do nothing else.  */
index 42e923391b5ec212a64a8fa2615dc857fcb0eec0..97a1862a268bc176798d120aec0ee9dd18855284 100644 (file)
@@ -704,6 +704,10 @@ extern tree unchecked_convert (tree type, tree expr, bool notrunc_p);
    the latter being a record type as predicated by Is_Record_Type.  */
 extern enum tree_code tree_code_for_record_type (Entity_Id);
 
+/* Return true if GNU_TYPE is suitable as the type of a non-aliased
+   component of an aggregate type.  */
+extern bool type_for_nonaliased_component_p (tree);
+
 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR or other logical
    operation.
 
index 6a4cc3c7669d0171b011c313560d0dfc17ca2075..56d490073c4870aa76db5a3925c40f8bc761c6bd 100644 (file)
@@ -1625,21 +1625,14 @@ create_field_decl (tree field_name, tree field_type, tree record_type,
     }
 
   /* In addition to what our caller says, claim the field is addressable if we
-     know we might ever attempt to take its address, then mark the decl as
-     nonaddressable accordingly.
+     know that its type is not suitable.
 
      The field may also be "technically" nonaddressable, meaning that even if
      we attempt to take the field's address we will actually get the address
      of a copy.  This is the case for true bitfields, but the DECL_BIT_FIELD
      value we have at this point is not accurate enough, so we don't account
      for this here and let finish_record_type decide.  */
-
-  /* We will take the address in any argument passing sequence if the field
-     type is passed by reference, and we might need the address for any array
-     type, even if normally passed by-copy, to construct a fat pointer if the
-     field is used as an actual for an unconstrained formal.  */
-  if (TREE_CODE (field_type) == ARRAY_TYPE
-      || must_pass_by_ref (field_type) || default_pass_by_ref (field_type))
+  if (!type_for_nonaliased_component_p (field_type))
     addressable = 1;
 
   DECL_NONADDRESSABLE_P (field_decl) = !addressable;
@@ -4004,6 +3997,26 @@ tree_code_for_record_type (Entity_Id gnat_type)
   return UNION_TYPE;
 }
 
+/* Return true if GNU_TYPE is suitable as the type of a non-aliased
+   component of an aggregate type.  */
+
+bool
+type_for_nonaliased_component_p (tree gnu_type)
+{
+  /* If the type is passed by reference, we may have pointers to the
+     component so it cannot be made non-aliased. */
+  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)
+    return false;
+
+  return true;
+}
+
 /* Perform final processing on global variables.  */
 
 void
index a379e7e2a8dfa354631edf575bc455c3df9b5a6b..3e588bdfcdb499ad046a061a08219f200337ba90 100644 (file)
@@ -4114,7 +4114,9 @@ push_fields_onto_fieldstack (tree type, VEC(fieldoff_s,heap) **fieldstack,
          else if (!(pushed = push_fields_onto_fieldstack
                     (TREE_TYPE (type), fieldstack,
                      offset + i * TREE_INT_CST_LOW (elsz), has_union,
-                     TREE_TYPE (type))))
+                     (TYPE_NONALIASED_COMPONENT (type)
+                      ? addressable_type
+                      : TREE_TYPE (type)))))
            /* Empty structures may have actual size, like in C++. So
               see if we didn't push any subfields and the size is
               nonzero, push the field onto the stack */
@@ -4129,7 +4131,10 @@ push_fields_onto_fieldstack (tree type, VEC(fieldoff_s,heap) **fieldstack,
              pair->size = elsz;
              pair->decl = NULL_TREE;
              pair->offset = offset + i * TREE_INT_CST_LOW (elsz);
-             pair->alias_set = -1;
+             if (TYPE_NONALIASED_COMPONENT (type))
+               pair->alias_set = get_alias_set (addressable_type);
+             else
+               pair->alias_set = -1;
              count++;
            }
          else