[PATCH][4.2] Fix PRs 33099, 33381 - wrong code with VRP/SCEV

Richard Guenther rguenther@suse.de
Fri Sep 21 15:54:00 GMT 2007


This fixes these two PRs by simply not adjusting value ranges from SCEV
data of pointer type.  This is the least invasive patch I could come up
with to address the problem that SCEV assumes ranges do not wrap when
converting to pointer chrecs.  On the mainline these issues were fixed
by the pointer-plus merge which ripped out the conversion handling from
SCEV (we now create (void *){-1, +, 1}_1 instead of {-1B, +, 1B}_1 on
the branch).  That is, for the mainline VRP will give up in this case
as well, as the resulting CHREC is not polynomial (but a conversion).

Bootstrap and regtest on x86_64-unknown-linux-gnu in progress.  Mark,
do you want this patch before or after the 4.2.2 release?

Thanks,
Richard.

2007-09-21  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/33099
	PR tree-optimization/33381
	* tree-vrp.c (adjust_range_with_scev): Do not adjust ranges
	from pointer typed chrecs.

	* gcc.c-torture/execute/pr33099.c: New testcase.
	* gcc.c-torture/execute/pr33381.c: Likewise.

Index: gcc/tree-vrp.c
===================================================================
*** gcc/tree-vrp.c	(revision 128649)
--- gcc/tree-vrp.c	(working copy)
*************** adjust_range_with_scev (value_range_t *v
*** 2486,2491 ****
--- 2486,2495 ----
    if (TREE_CODE (chrec) != POLYNOMIAL_CHREC)
      return;
  
+   /* Don't adjust ranges from pointer CHRECs.  */
+   if (POINTER_TYPE_P (TREE_TYPE (chrec)))
+     return;
+ 
    init = initial_condition_in_loop_num (chrec, loop->num);
    step = evolution_part_in_loop_num (chrec, loop->num);
  
Index: gcc/testsuite/gcc.c-torture/execute/pr33381.c
===================================================================
*** gcc/testsuite/gcc.c-torture/execute/pr33381.c	(revision 0)
--- gcc/testsuite/gcc.c-torture/execute/pr33381.c	(revision 0)
***************
*** 0 ****
--- 1,15 ----
+ extern void abort(void);
+ void x(void *data)
+ {
+   if ((long)data < 0)
+     abort();
+ }
+ int main()
+ {
+   long i;
+   for (i = 0; i < 5; i++)
+     if (i > 0)
+       x((void *)(i - 1));
+   return 0;
+ }
+ 
Index: gcc/testsuite/gcc.c-torture/execute/pr33099.c
===================================================================
*** gcc/testsuite/gcc.c-torture/execute/pr33099.c	(revision 0)
--- gcc/testsuite/gcc.c-torture/execute/pr33099.c	(revision 0)
***************
*** 0 ****
--- 1,26 ----
+ extern void abort (void);
+ 
+ volatile int N = 5;
+ 
+ void foo (void)
+ {
+   int i;
+   char *p, value[10];
+ 
+   value[0] = 0x42;
+   for (i = 0; i < N; i++)
+     if (i > 0)
+       {
+         p = (char *)i - 1;
+         *(value + (int) p) = (char) i;
+       }
+ 
+   if (value[0] != 1)
+     abort ();
+ }
+ 
+ main()
+ {
+   foo ();
+   return 0;
+ }



More information about the Gcc-patches mailing list