From 531f0b3879b09b53d738b5bf84790c49bdd60977 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 20 Jun 2017 12:46:46 +0000 Subject: [PATCH] re PR sanitizer/81097 (UBSAN: false positive for not existing negation operator and a bogus message) 2017-06-20 Richard Biener PR middle-end/81097 * fold-const.c (split_tree): Fold to type before negating. * c-c++-common/ubsan/pr81097.c: New testcase. From-SVN: r249407 --- gcc/ChangeLog | 5 +++++ gcc/fold-const.c | 6 +++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/c-c++-common/ubsan/pr81097.c | 12 ++++++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/ubsan/pr81097.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4293a05242d..8210d273a5a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-06-20 Richard Biener + + PR middle-end/81097 + * fold-const.c (split_tree): Fold to type before negating. + 2017-06-20 David Malcolm * diagnostic-show-locus.c diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 8559b1d0731..379a30ea285 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -853,9 +853,9 @@ split_tree (location_t loc, tree in, tree type, enum tree_code code, && code == PLUS_EXPR) { /* -X - 1 is folded to ~X, undo that here. Do _not_ do this - when IN is constant. */ - *minus_litp = build_one_cst (TREE_TYPE (in)); - var = negate_expr (TREE_OPERAND (in, 0)); + when IN is constant. Convert to TYPE before negating. */ + *minus_litp = build_one_cst (type); + var = negate_expr (fold_convert_loc (loc, type, TREE_OPERAND (in, 0))); } else var = in; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9077fe17a9e..28c97de8f3b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-06-20 Richard Biener + + PR middle-end/81097 + * c-c++-common/ubsan/pr81097.c: New testcase. + 2017-06-20 Richard Biener * gcc.dg/vect/pr65947-9.c: Adjust. diff --git a/gcc/testsuite/c-c++-common/ubsan/pr81097.c b/gcc/testsuite/c-c++-common/ubsan/pr81097.c new file mode 100644 index 00000000000..cd323ea2acb --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/pr81097.c @@ -0,0 +1,12 @@ +/* { dg-do run } */ +/* { dg-options "-fsanitize=undefined -fsanitize-undefined-trap-on-error" } */ + +unsigned int a = 3309568; +unsigned int b = -1204857327; +short c = -10871; +short x; +int main() +{ + x = ((short)(~a) | ~c) + ((short)(~b) | ~c); + return 0; +} -- 2.30.2