From: Richard Biener Date: Mon, 10 Apr 2017 13:02:12 +0000 (+0000) Subject: re PR middle-end/80362 (gcc miscompiles arithmetic with signed char) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=737237c9b8a6e24949975433a5696d4f12d602db;p=gcc.git re PR middle-end/80362 (gcc miscompiles arithmetic with signed char) 2017-04-10 Richard Biener PR middle-end/80362 * fold-const.c (fold_binary_loc): Look at unstripped ops when looking for NEGATE_EXPR in -A / -B to A / B folding. * gcc.dg/torture/pr80362.c: New testcase. From-SVN: r246805 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1e03c02ad29..4a72cf63294 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-04-10 Richard Biener + + PR middle-end/80362 + * fold-const.c (fold_binary_loc): Look at unstripped ops when + looking for NEGATE_EXPR in -A / -B to A / B folding. + 2017-04-10 Martin Liska PR gcov-profile/80224 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index b4c117c8494..524bb0fe3fb 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -10205,7 +10205,7 @@ fold_binary_loc (location_t loc, /* Convert -A / -B to A / B when the type is signed and overflow is undefined. */ if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type)) - && TREE_CODE (arg0) == NEGATE_EXPR + && TREE_CODE (op0) == NEGATE_EXPR && negate_expr_p (op1)) { if (INTEGRAL_TYPE_P (type)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d579a09067e..f71cb1a30aa 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-04-10 Richard Biener + + PR middle-end/80362 + * gcc.dg/torture/pr80362.c: New testcase. + 2017-04-10 Richard Biener PR tree-optimization/80304 diff --git a/gcc/testsuite/gcc.dg/torture/pr80362.c b/gcc/testsuite/gcc.dg/torture/pr80362.c new file mode 100644 index 00000000000..6d22eb040ad --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr80362.c @@ -0,0 +1,10 @@ +/* { dg-do run } */ +/* { dg-additional-options "-fstrict-overflow" } */ + +int main() +{ + signed char var_0, var_1 = -128; + var_0 = (signed char)(-var_1) / 3; + if (var_0 > 0) + __builtin_abort(); +}