]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/8639 (simple integer arithmetic expression broken)
authorChristian Ehrhardt <ehrhardt@mathematik.uni-ulm.de>
Mon, 25 Nov 2002 19:04:57 +0000 (19:04 +0000)
committerRichard Henderson <rth@gcc.gnu.org>
Mon, 25 Nov 2002 19:04:57 +0000 (11:04 -0800)
        PR c/8639
        * fold-const.c (extract_muldiv): Don't propagate division unless
        both arguments are multiples of C.
* gcc.c-torture/execute/20021119-1.c: New.

From-SVN: r59466

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

index dd51dfd8b3c93304622a0156a37ebce55177fca2..967ba8dd811a6962c8d1f9589b383afb93e00cef 100644 (file)
@@ -1,3 +1,9 @@
+2002-11-25  Christian Ehrhardt  <ehrhardt@mathematik.uni-ulm.de>
+
+       PR c/8639
+       * fold-const.c (extract_muldiv): Don't propagate division unless
+       both arguments are multiples of C.
+
 2002-11-25  Andrew Haley  <aph@redhat.com>
 
         * libgcc-std.ver (_Unwind_Find_Enclosing_Function): Add.
index c4095e4dd32ac45e0528095a7fe2dfd482999de8..a7556f438e525cf453bd4a71058d6a2eb542dd01 100644 (file)
@@ -4178,10 +4178,10 @@ extract_muldiv (t, c, code, wide_type)
       t2 = extract_muldiv (op1, c, code, wide_type);
       if (t1 != 0 && t2 != 0
          && (code == MULT_EXPR
-             /* If not multiplication, we can only do this if either operand
-                is divisible by c.  */
-             || multiple_of_p (ctype, op0, c)
-             || multiple_of_p (ctype, op1, c)))
+             /* If not multiplication, we can only do this if both operands
+                are divisible by c.  */
+             || (multiple_of_p (ctype, op0, c)
+                 && multiple_of_p (ctype, op1, c))))
        return fold (build (tcode, ctype, convert (ctype, t1),
                            convert (ctype, t2)));
 
diff --git a/gcc/testsuite/gcc.c-torture/execute/20021119-1.c b/gcc/testsuite/gcc.c-torture/execute/20021119-1.c
new file mode 100644 (file)
index 0000000..c4ef460
--- /dev/null
@@ -0,0 +1,17 @@
+/* PR 8639.  */
+
+extern void abort(void);
+
+int foo (int i)
+{
+  int r;
+  r = (80 - 4 * i) / 20;
+  return r;
+}
+    
+int main ()
+{
+  if (foo (1) != 3)
+    abort ();
+  return 0;
+}