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]

[PATCH] Fix DECL_BASED_ON_RESTRICT_P handling (PR middle-end/36013)


Hi!

I've bootstrapped/regtested and committed this patch from Ian, approved in
bugzilla.

2008-05-07  Ian Lance Taylor  <iant@google.com>

	PR middle-end/36013
	* gimplify.c (find_single_pointer_decl_1): Don't look through
	indirections.
	(find_single_pointer_decl): Adjust comments.

	* gcc.c-torture/execute/20080506-2.c: New test.

--- gcc/gimplify.c.jj	2008-04-28 11:35:55.000000000 +0200
+++ gcc/gimplify.c	2008-05-06 22:45:12.000000000 +0200
@@ -391,6 +391,13 @@ find_single_pointer_decl_1 (tree *tp, in
 {
   tree *pdecl = (tree *) data;
 
+  /* We are only looking for pointers at the same level as the
+     original tree; we must not look through any indirections.
+     Returning anything other than NULL_TREE will cause the caller to
+     not find a base.  */
+  if (REFERENCE_CLASS_P (*tp))
+    return *tp;
+
   if (DECL_P (*tp) && POINTER_TYPE_P (TREE_TYPE (*tp)))
     {
       if (*pdecl)
@@ -406,8 +413,9 @@ find_single_pointer_decl_1 (tree *tp, in
   return NULL_TREE;
 }
 
-/* Find the single DECL of pointer type in the tree T and return it.
-   If there are zero or more than one such DECLs, return NULL.  */
+/* Find the single DECL of pointer type in the tree T, used directly
+   rather than via an indirection, and return it.  If there are zero
+   or more than one such DECLs, return NULL.  */
 
 static tree
 find_single_pointer_decl (tree t)
@@ -418,7 +426,8 @@ find_single_pointer_decl (tree t)
     {
       /* find_single_pointer_decl_1 returns a nonzero value, causing
 	 walk_tree to return a nonzero value, to indicate that it
-	 found more than one pointer DECL.  */
+	 found more than one pointer DECL or that it found an
+	 indirection.  */
       return NULL_TREE;
     }
 
--- gcc/testsuite/gcc.c-torture/execute/20080506-2.c.jj	2008-05-06 22:50:46.000000000 +0200
+++ gcc/testsuite/gcc.c-torture/execute/20080506-2.c	2008-05-06 22:50:17.000000000 +0200
@@ -0,0 +1,21 @@
+/* PR middle-end/36013 */
+
+extern void abort (void);
+
+void __attribute__((noinline))
+foo (int **__restrict p, int **__restrict q)
+{
+  *p[0] = 1;
+  *q[0] = 2;
+  if (*p[0] != 2)
+    abort ();
+}
+
+int
+main (void)
+{
+  int a;
+  int *p1 = &a, *p2 = &a;
+  foo (&p1, &p2);
+  return 0;
+}

	Jakub


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