From: Christian Ehrhardt Date: Mon, 25 Nov 2002 19:04:57 +0000 (+0000) Subject: re PR c/8639 (simple integer arithmetic expression broken) X-Git-Tag: releases/gcc-3.3.0~1644 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b77f37445e014f2423fc2359b426384adec4b89c;p=thirdparty%2Fgcc.git re PR c/8639 (simple integer arithmetic expression broken) 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index dd51dfd8b3c9..967ba8dd811a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2002-11-25 Christian Ehrhardt + + PR c/8639 + * fold-const.c (extract_muldiv): Don't propagate division unless + both arguments are multiples of C. + 2002-11-25 Andrew Haley * libgcc-std.ver (_Unwind_Find_Enclosing_Function): Add. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index c4095e4dd32a..a7556f438e52 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -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 index 000000000000..c4ef460d45af --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/20021119-1.c @@ -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; +}