re PR sanitizer/80875 (UBSAN: compile time crash in fold_binary_loc at fold-const.c:9817)

PR sanitizer/80875
	* fold-const.c (fold_binary_loc) <case MULT_EXPR>: Check if OP1
	can be negated.

	* c-c++-common/ubsan/pr80875.c: New test.

From-SVN: r248490
This commit is contained in:
Marek Polacek 2017-05-26 11:15:37 +00:00 committed by Marek Polacek
parent 9f67f1462d
commit 9e2248e6d3
4 changed files with 27 additions and 0 deletions

View File

@ -1,3 +1,12 @@
2017-05-26 Marek Polacek <polacek@redhat.com>
Backported from mainline
2017-05-26 Marek Polacek <polacek@redhat.com>
PR sanitizer/80875
* fold-const.c (fold_binary_loc) <case MULT_EXPR>: Check if OP1
can be negated.
2017-05-26 Jakub Jelinek <jakub@redhat.com>
Backported from mainline

View File

@ -9808,6 +9808,7 @@ fold_binary_loc (location_t loc,
if (TREE_CODE (op1) == INTEGER_CST
&& tree_int_cst_sgn (op1) == -1
&& negate_expr_p (op0)
&& negate_expr_p (op1)
&& (tem = negate_expr (op1)) != op1
&& ! TREE_OVERFLOW (tem))
return fold_build2_loc (loc, MULT_EXPR, type,

View File

@ -1,3 +1,11 @@
2017-05-26 Marek Polacek <polacek@redhat.com>
Backported from mainline
2017-05-26 Marek Polacek <polacek@redhat.com>
PR sanitizer/80875
* c-c++-common/ubsan/pr80875.c: New test.
2017-05-25 Michael Meissner <meissner@linux.vnet.ibm.com>
Backport from trunk

View File

@ -0,0 +1,9 @@
/* PR sanitizer/80875 */
/* { dg-do compile } */
/* { dg-options "-fsanitize=undefined" } */
int
foo (void)
{
return ~__INT_MAX__ * (0 / 0); /* { dg-warning "division by zero" } */
}