This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Remove unnecessary VLA restriction in copy_forbidden (PR middle-end/42874)


> As mentioned in the PR, this check has been added many years ago when
> tree-inline.c didn't handle VL type remapping properly.
> GCC until 4.4 has been ignoring this restriction for always_inline
> functions, and inlining them successfully, and OpenMP code remaps such
> types for years as well.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2010-01-27  Jakub Jelinek  <jakub@redhat.com>
>
> 	PR middle-end/42874
> 	* tree-inline.c (cannot_copy_type_1): Removed.
> 	(copy_forbidden): Don't forbid copying of functions containing
> 	records/unions with variable length fields.
>
> 	* gcc.dg/vla-22.c: New test.

This has introduced a regression in Ada (all platforms):

FAIL: gnat.dg/test_nested_subtype_byref.adb execution test


Richard, fixing this requires extending the provision in tree-ssa-alias.c:

2009-10-24  Eric Botcazou  <ebotcazou@adacore.com>

	* tree-ssa-alias.c (nonaliasing_component_refs_p): Rename into...
	(aliasing_component_refs_p): ...this.  Return true if there is no
	common base and the base access types have the same alias set.

Something like the attached patch, currently only regtested C/C++/Ada.  What 
do you think?


	* tree-ssa-alias.c (same_type_for_tbaa): Return 1 if the types have
	the same alias set and their sizes different constantness.
	(aliasing_component_refs_p): Revert 2009-10-24 change.


-- 
Eric Botcazou
Index: tree-ssa-alias.c
===================================================================
--- tree-ssa-alias.c	(revision 156298)
+++ tree-ssa-alias.c	(working copy)
@@ -544,6 +544,16 @@ same_type_for_tbaa (tree type1, tree typ
       && TREE_CODE (type2) == ARRAY_TYPE)
     return -1;
 
+  /* In Ada, an lvalue of unconstrained type can be used to access an object
+     of one of its constrained subtypes, for example when a function with an
+     unconstrained parameter passed by reference is called on a constrained
+     object and inlined.  In this case, the types have the same alias set but
+     aren't equivalent.  */
+  if (TYPE_SIZE (type1) && TYPE_SIZE (type2)
+      && TREE_CONSTANT (TYPE_SIZE (type1)) != TREE_CONSTANT (TYPE_SIZE (type2))
+      && get_alias_set (type1) == get_alias_set (type2))
+    return 1;
+
   /* The types are known to be not equal.  */
   return 0;
 }
@@ -600,19 +610,9 @@ aliasing_component_refs_p (tree ref1, tr
       offset1 -= offadj;
       return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
     }
-
-  /* We haven't found any common base to apply offset-based disambiguation.
-     There are two cases:
-       1. The base access types have the same alias set.  This can happen
-	  in Ada when a function with an unconstrained parameter passed by
-	  reference is called on a constrained object and inlined: the types
-	  have the same alias set but aren't equivalent.  The references may
-	  alias in this case.
-       2. The base access types don't have the same alias set, i.e. one set
-	  is a subset of the other.  We have proved that B1 is not in the
-	  access path B2.path and that B2 is not in the access path B1.path
-	  so the references may not alias.  */
-  return get_alias_set (type1) == get_alias_set (type2);
+  /* If we have two type access paths B1.path1 and B2.path2 they may
+     only alias if either B1 is in B2.path2 or B2 is in B1.path1.  */
+  return false;
 }
 
 /* Return true if two memory references based on the variables BASE1

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]