From d62e6f1078dd62f6e8937d1f48f1f77f0a78e19e Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 12 Apr 2017 08:12:26 +0200 Subject: [PATCH] re PR sanitizer/80349 (UBSAN: compile time crash with "type mismatch in binary expression" message) PR sanitizer/80349 * fold-const.c (fold_binary_loc) : Convert arg0's first argument to type. * g++.dg/ubsan/pr80349.C: New test. From-SVN: r246865 --- gcc/ChangeLog | 6 ++++++ gcc/fold-const.c | 12 ++++++------ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/ubsan/pr80349.C | 11 +++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ubsan/pr80349.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 388db6d7ab2..f96256bfac9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-04-12 Jakub Jelinek + + PR sanitizer/80349 + * fold-const.c (fold_binary_loc) : Convert arg0's + first argument to type. + 2017-04-11 Bill Schmidt PR target/80376 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 524bb0fe3fb..2f2e93afb55 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -9916,12 +9916,12 @@ fold_binary_loc (location_t loc, } if (c3 != c1) - return fold_build2_loc (loc, BIT_IOR_EXPR, type, - fold_build2_loc (loc, BIT_AND_EXPR, type, - TREE_OPERAND (arg0, 0), - wide_int_to_tree (type, - c3)), - arg1); + { + tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)); + tem = fold_build2_loc (loc, BIT_AND_EXPR, type, tem, + wide_int_to_tree (type, c3)); + return fold_build2_loc (loc, BIT_IOR_EXPR, type, tem, arg1); + } } /* See if this can be simplified into a rotate first. If that diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 354adb04314..bf315d3696e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-04-12 Jakub Jelinek + + PR sanitizer/80349 + * g++.dg/ubsan/pr80349.C: New test. + 2017-04-11 Jakub Jelinek PR c++/80370 diff --git a/gcc/testsuite/g++.dg/ubsan/pr80349.C b/gcc/testsuite/g++.dg/ubsan/pr80349.C new file mode 100644 index 00000000000..f705b92caff --- /dev/null +++ b/gcc/testsuite/g++.dg/ubsan/pr80349.C @@ -0,0 +1,11 @@ +// PR sanitizer/80349 +// { dg-do compile } +// { dg-options "-fsanitize=undefined" } + +extern const long long int v; + +void +foo () +{ + (int)((v & 50 | 051UL) << 0) << 0; +} -- 2.30.2