Patchwork Fix PR50363

login
register
mail settings
Submitter Richard Guenther
Date Sept. 27, 2011, 8:47 a.m.
Message ID <alpine.LNX.2.00.1109271039450.2130@zhemvz.fhfr.qr>
Download mbox | patch
Permalink /patch/116552/
State New
Headers show

Comments

Richard Guenther - Sept. 27, 2011, 8:47 a.m.
This fixes PR50363.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Richard.

2011-09-27  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/50363
	* tree-ssa-pre.c (create_expression_by_pieces): Handle
	pointer conversions in POINTER_PLUS_EXPRs properly.

	* gcc.dg/torture/pr50363.c: New testcase.

Patch

Index: gcc/tree-ssa-pre.c
===================================================================
--- gcc/tree-ssa-pre.c	(revision 179200)
+++ gcc/tree-ssa-pre.c	(working copy)
@@ -3085,11 +3085,15 @@  create_expression_by_pieces (basic_block
 						    stmts, domstmt);
 	    if (!genop[i])
 	      return NULL_TREE;
-	    /* Ensure genop[1] is a ptrofftype for POINTER_PLUS_EXPR.  It
-	       may be a constant with the wrong type.  */
-	    if (i == 1
-		&& nary->opcode == POINTER_PLUS_EXPR)
-	      genop[i] = convert_to_ptrofftype (genop[i]);
+	    /* Ensure genop[] is properly typed for POINTER_PLUS_EXPR.  It
+	       may have conversions stripped.  */
+	    if (nary->opcode == POINTER_PLUS_EXPR)
+	      {
+		if (i == 0)
+		  genop[i] = fold_convert (nary->type, genop[i]);
+		else if (i == 1)
+		  genop[i] = convert_to_ptrofftype (genop[i]);
+	      }
 	    else
 	      genop[i] = fold_convert (TREE_TYPE (nary->op[i]), genop[i]);
 	  }
Index: gcc/testsuite/gcc.dg/torture/pr50363.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr50363.c	(revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr50363.c	(revision 0)
@@ -0,0 +1,10 @@ 
+/* { dg-do compile } */
+/* { dg-options "-fno-tree-ch -fno-tree-fre" } */
+
+void
+foo (int *__restrict__ * r, int n)
+{
+  int *p;
+  for (p = *r; p < *r + n; p++)
+    ;
+}