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 build_range_check (PR tree-optimization/58385)


Hi!

If exp has side effects, for [-,-] ranges we would optimize them away.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk/4.8?

2013-09-10  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/58385
	* fold-const.c (build_range_check): If both low and high are NULL,
	use omit_one_operand_loc to preserve exp side-effects.

	* gcc.c-torture/execute/pr58385.c: New test.

--- gcc/fold-const.c.jj	2013-09-09 11:32:39.000000000 +0200
+++ gcc/fold-const.c	2013-09-10 20:48:12.018170411 +0200
@@ -4299,7 +4299,7 @@ build_range_check (location_t loc, tree
     }
 
   if (low == 0 && high == 0)
-    return build_int_cst (type, 1);
+    return omit_one_operand_loc (loc, type, build_int_cst (type, 1), exp);
 
   if (low == 0)
     return fold_build2_loc (loc, LE_EXPR, type, exp,
--- gcc/testsuite/gcc.c-torture/execute/pr58385.c.jj	2013-09-10 20:50:02.909589473 +0200
+++ gcc/testsuite/gcc.c-torture/execute/pr58385.c	2013-09-10 20:48:38.000000000 +0200
@@ -0,0 +1,21 @@
+/* PR tree-optimization/58385 */
+
+extern void abort (void);
+
+int a, b = 1;
+
+int
+foo ()
+{
+  b = 0;
+  return 0;
+}
+
+int
+main ()
+{
+  ((0 || a) & foo () >= 0) <= 1 && 1;
+  if (b)
+    abort ();
+  return 0;
+}

	Jakub


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