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][4.1] Fix PR26763


This fixes PR26763, not considering overflow in folding of
PTR + CST CMP PTR + CST.

Bootstrapped and regtested on x86_64-unknown-linux-gnu for 4.1 branch.

Ok for branch?

Thanks,
Richard.

:ADDPATCH middle-end:


2006-04-03  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/26763
	* fold-const.c (fold_binary): Fold PTR + CST CMP PTR + CST
	only for EQ_EXPR and NE_EXPR.

	* gcc.dg/torture/pr26763-1.c: New testcase.
	* gcc.dg/torture/pr26763-2.c: Likewise.

Index: fold-const.c
===================================================================
*** fold-const.c	(revision 112634)
--- fold-const.c	(working copy)
*************** fold_binary (enum tree_code code, tree t
*** 8897,8904 ****
  
        /* If this is a comparison of two exprs that look like an
  	 ARRAY_REF of the same object, then we can fold this to a
! 	 comparison of the two offsets.  */
!       if (TREE_CODE_CLASS (code) == tcc_comparison)
  	{
  	  tree base0, offset0, base1, offset1;
  
--- 8897,8905 ----
  
        /* If this is a comparison of two exprs that look like an
  	 ARRAY_REF of the same object, then we can fold this to a
! 	 comparison of the two offsets.  This is only safe for
! 	 EQ_EXPR and NE_EXPR because of overflow issues.  */
!       if (code == EQ_EXPR || code == NE_EXPR)
  	{
  	  tree base0, offset0, base1, offset1;
  
Index: testsuite/gcc.dg/torture/pr26763-1.c
===================================================================
*** testsuite/gcc.dg/torture/pr26763-1.c	(revision 0)
--- testsuite/gcc.dg/torture/pr26763-1.c	(revision 0)
***************
*** 0 ****
--- 1,18 ----
+ /* { dg-do run } */
+ 
+ extern void abort(void);
+ 
+ int try (int *a)
+ {
+   return a + -1 > a;
+ }
+ 
+ int main(void)
+ {
+   int bla[100];
+ 
+   if (try (bla + 50))
+     abort ();
+ 
+   return 0;
+ }
Index: testsuite/gcc.dg/torture/pr26763-2.c
===================================================================
*** testsuite/gcc.dg/torture/pr26763-2.c	(revision 0)
--- testsuite/gcc.dg/torture/pr26763-2.c	(revision 0)
***************
*** 0 ****
--- 1,18 ----
+ /* { dg-do run } */
+ 
+ extern void abort(void);
+ 
+ int try (char *a, int d)
+ {
+   return a + d > a;
+ }
+ 
+ int main(void)
+ {
+   char bla[100];
+ 
+   if (try (bla + 50, -1))
+     abort ();
+ 
+   return 0;
+ }


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