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 distribute_bit_expr (PR middle-end/37931)


Hi!

distribute_bit_expr is called by fold_binary with arg{0,1}, not op{0,1},
where arg{0,1} are STRIP_NOPed from op{0,1}, so the might have different
types.  This means distribute_bit_expr needs to fold_convert all the args
to type before using them, otherwise we trigger gimple type verification.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2008-10-28  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/37931
	* fold-const.c (distribute_bit_expr): Convert common, left and
	right arguments to type.

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

--- gcc/fold-const.c.jj	2008-10-24 15:56:02.000000000 +0200
+++ gcc/fold-const.c	2008-10-28 09:22:16.000000000 +0100
@@ -3806,6 +3806,9 @@ distribute_bit_expr (enum tree_code code
   else
     return 0;
 
+  common = fold_convert (type, common);
+  left = fold_convert (type, left);
+  right = fold_convert (type, right);
   return fold_build2 (TREE_CODE (arg0), type, common,
 		      fold_build2 (code, type, left, right));
 }
--- gcc/testsuite/gcc.c-torture/execute/pr37931.c.jj	2008-10-28 09:21:28.000000000 +0100
+++ gcc/testsuite/gcc.c-torture/execute/pr37931.c	2008-10-28 09:24:52.000000000 +0100
@@ -0,0 +1,23 @@
+/* PR middle-end/37931 */
+
+extern void abort (void);
+
+int
+foo (int a, unsigned int b)
+{
+  return (a | 1) & (b | 1);
+}
+
+int
+main (void)
+{
+  if (foo (6, 0xc6) != 7)
+    abort ();
+  if (foo (0x80, 0xc1) != 0x81)
+    abort ();
+  if (foo (4, 4) != 5)
+    abort ();
+  if (foo (5, 4) != 5)
+    abort ();
+  return 0;
+}

	Jakub


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