]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/46019 (x / (0x200000000ULL << y) miscompilation with 32-bit HWI)
authorJakub Jelinek <jakub@redhat.com>
Mon, 18 Oct 2010 10:08:47 +0000 (12:08 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 18 Oct 2010 10:08:47 +0000 (12:08 +0200)
PR middle-end/46019
* fold-const.c (fold_binary_loc): If integer_pow2p has
TREE_INT_CST_LOW zero, look at TREE_INT_CST_HIGH.

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

From-SVN: r165621

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr46019.c [new file with mode: 0644]

index 63fdea3f3f261c28d882ced668f24262b1e0535d..aff534d49fde39676bfd55a5639457b0aadcd00a 100644 (file)
@@ -1,3 +1,9 @@
+2010-10-18  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/46019
+       * fold-const.c (fold_binary_loc): If integer_pow2p has
+       TREE_INT_CST_LOW zero, look at TREE_INT_CST_HIGH.
+
 2010-10-07  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
 
        PR target/45820
index 4d5e70d4b2689e0e34171b625298af9e73866bd2..5c549c589bc47ff73fe411c0f9fdd210ac71ee94 100644 (file)
@@ -11658,7 +11658,13 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
          if (integer_pow2p (sval) && tree_int_cst_sgn (sval) > 0)
            {
              tree sh_cnt = TREE_OPERAND (arg1, 1);
-             unsigned long pow2 = exact_log2 (TREE_INT_CST_LOW (sval));
+             unsigned long pow2;
+
+             if (TREE_INT_CST_LOW (sval))
+               pow2 = exact_log2 (TREE_INT_CST_LOW (sval));
+             else
+               pow2 = exact_log2 (TREE_INT_CST_HIGH (sval))
+                      + HOST_BITS_PER_WIDE_INT;
 
              if (strict_overflow_p)
                fold_overflow_warning (("assuming signed overflow does not "
index 0f41aa67bbe6d95546ca18bb458f8e6fdfd1004c..dae7bfcca6557e4bd60d25c9d93e8efcde59a8b9 100644 (file)
@@ -1,3 +1,8 @@
+2010-10-18  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/46019
+       * gcc.c-torture/execute/pr46019.c: New test.
+
 2010-10-16  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
 
        Backport from mainline
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr46019.c b/gcc/testsuite/gcc.c-torture/execute/pr46019.c
new file mode 100644 (file)
index 0000000..b036557
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR middle-end/46019 */
+
+extern void abort (void);
+
+int
+main (void)
+{
+  unsigned long long l = 0x40000000000ULL;
+  int n;
+  for (n = 0; n < 8; n++)
+    if (l / (0x200000000ULL << n) != (0x200 >> n))
+      abort ();
+  return 0;
+}