From: Martin Liska Date: Mon, 10 Apr 2017 07:29:29 +0000 (+0200) Subject: Evaluate a SAVE_EXPR before an UBSAN check (PR sanitizer/80350). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3ee0fb02bb5164817f9ec9e40f9eccde78b6e10b;p=gcc.git Evaluate a SAVE_EXPR before an UBSAN check (PR sanitizer/80350). 2017-04-10 Martin Liska PR sanitizer/80350 * c-ubsan.c (ubsan_instrument_shift): Evaluate RHS before doing an UBSAN check. 2017-04-10 Martin Liska PR sanitizer/80350 * c-c++-common/ubsan/pr80350.c: New test. From-SVN: r246799 --- diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 594aa05a552..ff6edbdbef6 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2017-04-10 Martin Liska + + PR sanitizer/80350 + * c-ubsan.c (ubsan_instrument_shift): Evaluate RHS before + doing an UBSAN check. + 2017-04-03 Jonathan Wakely * c-warn.c (do_warn_double_promotion): Fix typo in comment. diff --git a/gcc/c-family/c-ubsan.c b/gcc/c-family/c-ubsan.c index 91bdef88320..e48841a334c 100644 --- a/gcc/c-family/c-ubsan.c +++ b/gcc/c-family/c-ubsan.c @@ -172,6 +172,7 @@ ubsan_instrument_shift (location_t loc, enum tree_code code, /* In case we have a SAVE_EXPR in a conditional context, we need to make sure it gets evaluated before the condition. */ t = fold_build2 (COMPOUND_EXPR, TREE_TYPE (t), unshare_expr (op0), t); + t = fold_build2 (COMPOUND_EXPR, TREE_TYPE (t), unshare_expr (op1), t); enum sanitize_code recover_kind = SANITIZE_SHIFT_EXPONENT; tree else_t = void_node; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c94c7c475d6..8e6523ac41b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-04-10 Martin Liska + + PR sanitizer/80350 + * c-c++-common/ubsan/pr80350.c: New test. + 2017-04-10 Jakub Jelinek PR target/80324 diff --git a/gcc/testsuite/c-c++-common/ubsan/pr80350.c b/gcc/testsuite/c-c++-common/ubsan/pr80350.c new file mode 100644 index 00000000000..317d2facaf7 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/pr80350.c @@ -0,0 +1,17 @@ +/* PR target/80310 */ +/* { dg-do run } */ +/* { dg-options "-O0 -fsanitize=shift -fno-sanitize-recover=shift" } */ + +unsigned int x = 1; +unsigned int y = 0; + +void foo() { + y = 1 >> (!x * 1111); +} + +int main () { + foo (); + if (y != 1) + __builtin_abort (); + return 0; +}