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][RFC] Fix PR30364, reassociation not allowed for undefined overflow


This patch addresses PR30364 by not reassociating in fold for types that
do not wrap on overflow.  This unfortunately causes some testsuite 
failures:

FAIL: gcc.dg/Warray-bounds.c (test for excess errors)
FAIL: gcc.dg/pr15785-1.c (test for excess errors)
FAIL: gcc.dg/strict-overflow-5.c scan-tree-dump-times r = 3 1
FAIL: gcc.dg/tree-ssa/loop-15.c scan-tree-dump-times \\+ 0
FAIL: gcc.dg/tree-ssa/loop-15.c scan-tree-dump-times n \\* n 1
FAIL: gcc.dg/vect/vect-62.c execution test
FAIL: gcc.dg/vect/vect-64.c execution test
FAIL: gcc.dg/vect/vect-67.c execution test
FAIL: gcc.dg/vect/vect-70.c execution test
FAIL: gcc.dg/vect/no-section-anchors-vect-69.c execution test

FAIL: gfortran.dg/single_char_string.f90 scan-tree-dump-times 
_gfortran_compare_ string 0

I didn't cross-check that these are all caused by the patch (I hope
the vect execution failures are not), but at least I don't remember those
from previous testings.

Now I don't see a way around the following patch really, but maybe someone
else does.  I'll work on analyzing the failures and fixing them either
by changing the testcases or fixing fallout from the patch as soon as
time permits.

Richard.


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

	PR middle-end/30364
	* fold-const.c (fold_binary): Do not assoicate expressions
	for integer type that do not wrap.

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

Index: testsuite/gcc.dg/torture/pr30364-1.c
===================================================================
*** testsuite/gcc.dg/torture/pr30364-1.c	(revision 0)
--- testsuite/gcc.dg/torture/pr30364-1.c	(revision 0)
***************
*** 0 ****
--- 1,19 ----
+ /* { dg-do run } */
+ 
+ extern void abort (void);
+ 
+ int f(int a, int b)
+ {
+   if (a > 0x7FFFFFF0) return 0;
+   if (b > 0x7FFFFFF0) return 0;
+ 
+   int c = (a - 20) + (b - 20);
+   return c > 0x7FFFFFF0;
+ }
+ 
+ int main()
+ {
+   if (f (0x7FFFFFF0, 41) != 1)
+     abort ();
+   return 0;
+ }
Index: testsuite/gcc.dg/torture/pr30364-2.c
===================================================================
*** testsuite/gcc.dg/torture/pr30364-2.c	(revision 0)
--- testsuite/gcc.dg/torture/pr30364-2.c	(revision 0)
***************
*** 0 ****
--- 1,19 ----
+ /* { dg-do run } */
+ 
+ extern void abort (void);
+ 
+ int f(unsigned int a, unsigned int b)
+ {
+   if (a > 0x7FFFFFF0) return 0;
+   if (b > 0x7FFFFFF0) return 0;
+ 
+   int c = (a - 20) + (b - 20);
+   return c > 0x7FFFFFF0;
+ }
+ 
+ int main()
+ {
+   if (f (0x7FFFFFF0, 41) != 1)
+     abort ();
+   return 0;
+ }
Index: testsuite/gcc.dg/torture/pr30364-3.c
===================================================================
*** testsuite/gcc.dg/torture/pr30364-3.c	(revision 0)
--- testsuite/gcc.dg/torture/pr30364-3.c	(revision 0)
***************
*** 0 ****
--- 1,20 ----
+ /* { dg-do run } */
+ /* { dg-options "-fwrapv" } */
+ 
+ extern void abort (void);
+ 
+ int f(int a, int b)
+ {
+   if (a > 0x7FFFFFF0) return 0;
+   if (b > 0x7FFFFFF0) return 0;
+ 
+   int c = (a - 20) + (b - 20);
+   return c > 0x7FFFFFF0;
+ }
+ 
+ int main()
+ {
+   if (f (0x7FFFFFF0, 41) != 1)
+     abort ();
+   return 0;
+ }
Index: fold-const.c
===================================================================
*** fold-const.c	(revision 122196)
--- fold-const.c	(working copy)
*************** fold_binary (enum tree_code code, tree t
*** 9420,9426 ****
  	 don't associate floats at all, unless the user has specified
  	 -funsafe-math-optimizations.  */
  
!       if (! FLOAT_TYPE_P (type) || flag_unsafe_math_optimizations)
  	{
  	  tree var0, con0, lit0, minus_lit0;
  	  tree var1, con1, lit1, minus_lit1;
--- 9420,9427 ----
  	 don't associate floats at all, unless the user has specified
  	 -funsafe-math-optimizations.  */
  
!       if ((FLOAT_TYPE_P (type) && flag_unsafe_math_optimizations)
! 	  || (INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_WRAPS (type)))
  	{
  	  tree var0, con0, lit0, minus_lit0;
  	  tree var1, con1, lit1, minus_lit1;


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