From: Diego Novillo Date: Thu, 5 Apr 2001 02:27:47 +0000 (+0000) Subject: simplify-rtx.c (simplify_binary_operation): Check for overflow when folding integer... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b08355783200651f189f2f057663e12f9755bb92;p=gcc.git simplify-rtx.c (simplify_binary_operation): Check for overflow when folding integer division and modulo operations. 2001-04-04 Diego Novillo * simplify-rtx.c (simplify_binary_operation): Check for overflow when folding integer division and modulo operations. 2001-04-04 Diego Novillo * gcc.c-torture/compile/20010404-1.c: New test. From-SVN: r41105 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e7444c98f67..cfc9306318e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2001-04-04 Diego Novillo + + * simplify-rtx.c (simplify_binary_operation): Check for overflow + when folding integer division and modulo operations. + 2001-04-04 Andrew MacLeod * dwarf2out.c (output_cfi): Add 'for_eh' parameter, use PTR_SIZE diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index dd7d2e1e6b5..af8b708977c 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -1407,25 +1407,33 @@ simplify_binary_operation (code, mode, op0, op1) break; case DIV: - if (arg1s == 0) + if (arg1s == 0 + || (arg0s == (HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT - 1) + && arg1s == -1)) return 0; val = arg0s / arg1s; break; case MOD: - if (arg1s == 0) + if (arg1s == 0 + || (arg0s == (HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT - 1) + && arg1s == -1)) return 0; val = arg0s % arg1s; break; case UDIV: - if (arg1 == 0) + if (arg1 == 0 + || (arg0s == (HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT - 1) + && arg1s == -1)) return 0; val = (unsigned HOST_WIDE_INT) arg0 / arg1; break; case UMOD: - if (arg1 == 0) + if (arg1 == 0 + || (arg0s == (HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT - 1) + && arg1s == -1)) return 0; val = (unsigned HOST_WIDE_INT) arg0 % arg1; break; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 225f9280257..5e4c1552010 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-04-04 Diego Novillo + + * gcc.c-torture/compile/20010404-1.c: New test. + 2001-04-04 Jakub Jelinek * gcc.c-torture/compile/20010326-1.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/compile/20010404-1.c b/gcc/testsuite/gcc.c-torture/compile/20010404-1.c new file mode 100644 index 00000000000..f890118e15d --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/20010404-1.c @@ -0,0 +1,15 @@ +/* This testcase caused a floating point exception in the compiler when + compiled with -O2. The crash occurs when trying to simplify division + and modulo operations. */ + +#include + +extern void bar (int); + +void foo () +{ + int a = INT_MIN; + int b = -1; + bar (a / b); + bar (a % b); +}