aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2017-04-12 20:08:29 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2017-04-12 20:08:29 +0200
commitb96a3e11572287992923065def1d64e8a2240f9b (patch)
tree23bd724a0c4faed70f670281fe97486db4f278f8 /gcc/fold-const.c
parent988ed78513a850a6c7eb2b99af93d68668d4a0c7 (diff)
downloadgcc-b96a3e11572287992923065def1d64e8a2240f9b.zip
gcc-b96a3e11572287992923065def1d64e8a2240f9b.tar.gz
gcc-b96a3e11572287992923065def1d64e8a2240f9b.tar.bz2
re PR sanitizer/80403 (UBSAN: compile time crash with "type mismatch in binary expression" message in / and % expr)
PR sanitizer/80403 PR sanitizer/80404 PR sanitizer/80405 * fold-const.c (fold_ternary_loc): Use op1 instead of arg1 as argument to fold_build2_loc. Convert TREE_OPERAND (tem, 0) to type. Use op0 instead of fold_convert_loc (loc, type, arg0). * g++.dg/ubsan/pr80403.C: New test. * g++.dg/ubsan/pr80404.C: New test. * g++.dg/ubsan/pr80405.C: New test. From-SVN: r246881
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 2f2e93a..fb0b1a6 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -11508,10 +11508,12 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
STRIP_NOPS (tem);
if (TREE_CODE (tem) == RSHIFT_EXPR
&& tree_fits_uhwi_p (TREE_OPERAND (tem, 1))
- && (unsigned HOST_WIDE_INT) tree_log2 (arg1) ==
- tree_to_uhwi (TREE_OPERAND (tem, 1)))
+ && (unsigned HOST_WIDE_INT) tree_log2 (arg1)
+ == tree_to_uhwi (TREE_OPERAND (tem, 1)))
return fold_build2_loc (loc, BIT_AND_EXPR, type,
- TREE_OPERAND (tem, 0), arg1);
+ fold_convert_loc (loc, type,
+ TREE_OPERAND (tem, 0)),
+ op1);
}
/* A & N ? N : 0 is simply A & N if N is a power of two. This
@@ -11542,7 +11544,7 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
&& (code == VEC_COND_EXPR || !VECTOR_TYPE_P (type)))
return fold_build2_loc (loc, code == VEC_COND_EXPR ? BIT_AND_EXPR
: TRUTH_ANDIF_EXPR,
- type, fold_convert_loc (loc, type, arg0), arg1);
+ type, op0, op1);
/* Convert A ? B : 1 into !A || B if A and B are truth values. */
if (code == VEC_COND_EXPR ? integer_all_onesp (op2) : integer_onep (op2)
@@ -11558,7 +11560,7 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
? BIT_IOR_EXPR
: TRUTH_ORIF_EXPR,
type, fold_convert_loc (loc, type, tem),
- arg1);
+ op1);
}
/* Convert A ? 0 : B into !A && B if A and B are truth values. */