From 165b2f5f5d7fe14ab567e83a4cf2e0a492038a8c Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 4 Aug 2017 10:33:39 +0000 Subject: [PATCH] re PR middle-end/81705 (UBSAN: yet another false positive) 2017-08-04 Richard Biener PR middle-end/81705 * fold-const.c (fold_binary_loc): Properly restrict minus_var0 && minus_var1 case when associating undefined overflow entities. * c-c++-common/ubsan/pr81705.c: New testcase. From-SVN: r250866 --- gcc/ChangeLog | 7 +++++++ gcc/fold-const.c | 9 +++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/c-c++-common/ubsan/pr81705.c | 12 ++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/ubsan/pr81705.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 92143020844..d9c0b0a3579 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2017-08-04 Richard Biener + + PR middle-end/81705 + * fold-const.c (fold_binary_loc): Properly restrict + minus_var0 && minus_var1 case when associating undefined overflow + entities. + 2017-08-04 Tom de Vries * omp-simd-clone.c (simd_clone_adjust): Add missing edge probability. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index ed6c289a64b..53428b89454 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -9592,12 +9592,13 @@ fold_binary_loc (location_t loc, if (POINTER_TYPE_P (atype) || (INTEGRAL_TYPE_P (atype) && !TYPE_OVERFLOW_WRAPS (atype))) { - if (var0 && var1) + if ((var0 && var1) || (minus_var0 && minus_var1)) { /* ??? If split_tree would handle NEGATE_EXPR we could - simplify this down to the var0/minus_var1 cases. */ - tree tmp0 = var0; - tree tmp1 = var1; + simply reject these cases and the allowed cases would + be the var0/minus_var1 ones. */ + tree tmp0 = var0 ? var0 : minus_var0; + tree tmp1 = var1 ? var1 : minus_var1; bool one_neg = false; if (TREE_CODE (tmp0) == NEGATE_EXPR) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1033cc7b1c3..f5ec59d754b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-08-04 Richard Biener + + PR middle-end/81705 + * c-c++-common/ubsan/pr81705.c: New testcase. + 2017-08-03 Bill Schmidt * gcc.target/powerpc/bfp/scalar-cmp-exp-eq-2.c: Adjust for error diff --git a/gcc/testsuite/c-c++-common/ubsan/pr81705.c b/gcc/testsuite/c-c++-common/ubsan/pr81705.c new file mode 100644 index 00000000000..081c741c206 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/pr81705.c @@ -0,0 +1,12 @@ +/* { dg-do run } */ +/* { dg-options "-fsanitize=undefined -fsanitize-undefined-trap-on-error" } */ + +int var_4 = -1716607962; +int var_14 = 943738830; +volatile int a; +int main() +{ + // (-(-1716607962) - 516151698) - -(9403738830) + a = (-var_4 - 516151698) - -var_14; + return 0; +} -- 2.30.2