From 2ef42cf92408dadf44b5418b1c369bf0aa36d657 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Tue, 25 Apr 2017 16:39:57 +0000 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-2.C: New test. From-SVN: r247257 --- gcc/ChangeLog | 6 ++++++ gcc/fold-const.c | 6 ++++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/ubsan/pr80349-2.C | 11 +++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ubsan/pr80349-2.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 56da6914880..1d35b3c9c2c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-04-25 Marek Polacek + + PR sanitizer/80349 + * fold-const.c (fold_binary_loc) : Convert arg0's + first argument to type. + 2017-04-25 Bill Seurer PR target/80482 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index f0b8e7a3f1b..ce4b2df8cd2 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -9898,8 +9898,10 @@ fold_binary_loc (location_t loc, /* If (C1|C2) == ~0 then (X&C1)|C2 becomes X|C2. */ if (msk.and_not (c1 | c2) == 0) - return fold_build2_loc (loc, BIT_IOR_EXPR, type, - TREE_OPERAND (arg0, 0), arg1); + { + tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)); + return fold_build2_loc (loc, BIT_IOR_EXPR, type, tem, arg1); + } /* Minimize the number of bits set in C1, i.e. C1 := C1 & ~C2, unless (C1 & ~C2) | (C2 & C3) for some C3 is a mask of some diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6b1feffebe8..0b2e2085612 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-04-25 Marek Polacek + + PR sanitizer/80349 + * g++.dg/ubsan/pr80349-2.C: New test. + 2017-04-25 Volker Reichelt * g++.dg/cpp0x/enum34.C: New test. diff --git a/gcc/testsuite/g++.dg/ubsan/pr80349-2.C b/gcc/testsuite/g++.dg/ubsan/pr80349-2.C new file mode 100644 index 00000000000..ca5ea4a0dbe --- /dev/null +++ b/gcc/testsuite/g++.dg/ubsan/pr80349-2.C @@ -0,0 +1,11 @@ +// PR sanitizer/80349 +// { dg-do compile } +// { dg-options "-fsanitize=undefined" } + +unsigned long int ll; + +int +foo () +{ + return (2036854775807 >> ll & char(207648476159223) | 502810590243120797UL) << 0; +} -- 2.30.2