diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8198e0c88d6..fa94c6fa46a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-06-07 Marek Polacek + + PR sanitizer/80932 + * fold-const.c (extract_muldiv_1) : Add + TYPE_OVERFLOW_WRAPS check. + 2017-06-07 Bin Cheng * tree-vect-loop-manip.c (vect_do_peeling): Don't skip vector loop diff --git a/gcc/fold-const.c b/gcc/fold-const.c index b0d03c9aaa3..f3975c7391f 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6178,6 +6178,7 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type, t1 = extract_muldiv (op0, c, code, wide_type, &sub_strict_overflow_p); t2 = extract_muldiv (op1, c, code, wide_type, &sub_strict_overflow_p); if (t1 != 0 && t2 != 0 + && TYPE_OVERFLOW_WRAPS (ctype) && (code == MULT_EXPR /* If not multiplication, we can only do this if both operands are divisible by c. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 38b22ee3dc0..990e10ac327 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-06-07 Marek Polacek + + PR sanitizer/80932 + * c-c++-common/ubsan/pr80932.c: New test. + 2017-06-07 Bin Cheng * gcc.target/i386/l_fma_double_1.c: Adjust test strings. diff --git a/gcc/testsuite/c-c++-common/ubsan/pr80932.c b/gcc/testsuite/c-c++-common/ubsan/pr80932.c new file mode 100644 index 00000000000..a833712d383 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/pr80932.c @@ -0,0 +1,17 @@ +/* PR sanitizer/80932 */ +/* { dg-do run } */ +/* { dg-options "-fsanitize=undefined -fsanitize-undefined-trap-on-error" } */ + +int x = 1; + +long int +foo (void) +{ + return ((long) (13801962912760474560ULL * x) - (long) (15334142073106273231ULL * x)) * -6; +} + +int +main () +{ + foo (); +}