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 PR30212, ICE in VRP on the 4.1 branch


This fixes PR30212 a case where we try to fall through to using
TYPE_MIN/MAX_VALUE of a pointer type as we try to compensate
an invalid range in adjust_range_with_scev.  Fixed by backporting
a part of

      PR tree-optimization/27865
       * tree-vrp.c (adjust_range_with_scev): Do not use TYPE_{MIN,MAX}_VALUE
       for pointer types.
       * tree-scalar-evolution.c (fold_used_pointer_cast, pointer_offset_p,
       fold_used_pointer, pointer_used_p): New functions.
       (analyze_scalar_evolution_1): Use fold_used_pointer.
       * tree-chrec.c (convert_affine_scev): Convert no-op casts correctly.
       * tree-ssa-loop-ivopts.c (generic_type_for): Return integral type
       for pointers.

namely just punting in this case.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to the
4.1 branch.

Richard.

2007-01-05 Richard Guenther <rguenther@suse.de>

       PR tree-optimization/30212
       * tree-vrp.c (adjust_range_with_scev): Do not adjust invalid
       ranges by using TYPE_MIN_VALUE or TYPE_MAX_VALUE.

* gcc.dg/torture/pr30212.c: New testcase.
2007-01-05  Richard Guenther  <rguenther@suse.de>

        PR tree-optimization/30212
        * tree-vrp.c (adjust_range_with_scev): Do not adjust invalid
	ranges by using TYPE_MIN_VALUE or TYPE_MAX_VALUE.

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

Index: tree-vrp.c
===================================================================
*** tree-vrp.c	(revision 120496)
--- tree-vrp.c	(working copy)
*************** adjust_range_with_scev (value_range_t *v
*** 1816,1825 ****
  	      max = init;
  
  	      /* If we just created an invalid range with the minimum
! 		 greater than the maximum, take the minimum all the
! 		 way to -INF.  */
  	      if (compare_values (min, max) == 1)
! 		min = TYPE_MIN_VALUE (TREE_TYPE (min));
  	    }
  	}
        else
--- 1816,1826 ----
  	      max = init;
  
  	      /* If we just created an invalid range with the minimum
! 		 greater than the maximum, we fail conservatively.
! 		 This should happen only in unreachable
! 		 parts of code, or for invalid programs.  */
  	      if (compare_values (min, max) == 1)
! 		return;
  	    }
  	}
        else
*************** adjust_range_with_scev (value_range_t *v
*** 1829,1839 ****
  	    {
  	      min = init;
  
! 	      /* If we just created an invalid range with the minimum
! 		 greater than the maximum, take the maximum all the
! 		 way to +INF.  */
  	      if (compare_values (min, max) == 1)
! 		max = TYPE_MAX_VALUE (TREE_TYPE (max));
  	    }
  	}
  
--- 1830,1838 ----
  	    {
  	      min = init;
  
! 	      /* Again, avoid creating invalid range by failing.  */
  	      if (compare_values (min, max) == 1)
! 		return;
  	    }
  	}
  
Index: testsuite/gcc.dg/torture/pr30212.c
===================================================================
*** testsuite/gcc.dg/torture/pr30212.c	(revision 0)
--- testsuite/gcc.dg/torture/pr30212.c	(revision 0)
***************
*** 0 ****
--- 1,27 ----
+ /* { dg-do compile } */
+ 
+ void test_crash (short *wb, int *dst)
+ {
+   int is;
+   int i;
+ 
+   short *wBufSrc = wb;
+   int *iBufDst = dst;
+ 
+   for (i = 0; i < 2; i++)
+   {  
+     is =  (wBufSrc[ 0 > (i-1) ? 0 : (i -1 )]);
+ 
+     iBufDst[i] =  is;
+   }
+ }
+ 
+ int main(int argc, char** argv)
+ {
+   short wb [] = { 1, 2, 3 };
+   int   in [] = { 4, 5, 6 };
+ 
+   test_crash(wb, in);
+ 
+   return 0;
+ }

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