diff options
author | Marek Polacek <polacek@redhat.com> | 2017-04-27 21:12:29 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2017-04-27 21:12:29 +0000 |
commit | 3777eda2eddbc7d5d54bdc0cddaa7f8f44c5ffe9 (patch) | |
tree | 76d8381120643982630eae02550e5044ba926547 /gcc/fold-const.c | |
parent | f49215b10cb70ee28f041c6b5088b55b3f33afb9 (diff) | |
download | gcc-3777eda2eddbc7d5d54bdc0cddaa7f8f44c5ffe9.zip gcc-3777eda2eddbc7d5d54bdc0cddaa7f8f44c5ffe9.tar.gz gcc-3777eda2eddbc7d5d54bdc0cddaa7f8f44c5ffe9.tar.bz2 |
re PR sanitizer/80349 (UBSAN: compile time crash with "type mismatch in binary expression" message)
PR sanitizer/80349
* fold-const.c (fold_binary_loc) <case EQ_EXPR, NE_EXPR>: Convert
arg10 and arg11 to itype.
* c-c++-common/ubsan/pr80349.c: New test.
From-SVN: r247352
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index ce4b2df..f6d5af4 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -10797,40 +10797,37 @@ fold_binary_loc (location_t loc, tree itype = TREE_TYPE (arg0); if (operand_equal_p (arg01, arg11, 0)) - return fold_build2_loc (loc, code, type, - fold_build2_loc (loc, BIT_AND_EXPR, itype, - fold_build2_loc (loc, - BIT_XOR_EXPR, itype, - arg00, arg10), - arg01), - build_zero_cst (itype)); - + { + tem = fold_convert_loc (loc, itype, arg10); + tem = fold_build2_loc (loc, BIT_XOR_EXPR, itype, arg00, tem); + tem = fold_build2_loc (loc, BIT_AND_EXPR, itype, tem, arg01); + return fold_build2_loc (loc, code, type, tem, + build_zero_cst (itype)); + } if (operand_equal_p (arg01, arg10, 0)) - return fold_build2_loc (loc, code, type, - fold_build2_loc (loc, BIT_AND_EXPR, itype, - fold_build2_loc (loc, - BIT_XOR_EXPR, itype, - arg00, arg11), - arg01), - build_zero_cst (itype)); - + { + tem = fold_convert_loc (loc, itype, arg11); + tem = fold_build2_loc (loc, BIT_XOR_EXPR, itype, arg00, tem); + tem = fold_build2_loc (loc, BIT_AND_EXPR, itype, tem, arg01); + return fold_build2_loc (loc, code, type, tem, + build_zero_cst (itype)); + } if (operand_equal_p (arg00, arg11, 0)) - return fold_build2_loc (loc, code, type, - fold_build2_loc (loc, BIT_AND_EXPR, itype, - fold_build2_loc (loc, - BIT_XOR_EXPR, itype, - arg01, arg10), - arg00), - build_zero_cst (itype)); - + { + tem = fold_convert_loc (loc, itype, arg10); + tem = fold_build2_loc (loc, BIT_XOR_EXPR, itype, arg01, tem); + tem = fold_build2_loc (loc, BIT_AND_EXPR, itype, tem, arg00); + return fold_build2_loc (loc, code, type, tem, + build_zero_cst (itype)); + } if (operand_equal_p (arg00, arg10, 0)) - return fold_build2_loc (loc, code, type, - fold_build2_loc (loc, BIT_AND_EXPR, itype, - fold_build2_loc (loc, - BIT_XOR_EXPR, itype, - arg01, arg11), - arg00), - build_zero_cst (itype)); + { + tem = fold_convert_loc (loc, itype, arg11); + tem = fold_build2_loc (loc, BIT_XOR_EXPR, itype, arg01, tem); + tem = fold_build2_loc (loc, BIT_AND_EXPR, itype, tem, arg00); + return fold_build2_loc (loc, code, type, tem, + build_zero_cst (itype)); + } } if (TREE_CODE (arg0) == BIT_XOR_EXPR |