From 15dbc1a6df73343e769a8e310c1ed89829b61613 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 25 Sep 2015 09:50:29 +0000 Subject: [PATCH] re PR sanitizer/64906 (-fsanitize=integer-divide-by-zero creates false -Wmaybe-uninitialized warning) PR sanitizer/64906 * c-ubsan.c (ubsan_instrument_division): Also pre-evaluate OP1. * c-c++-common/ubsan/pr64906.c: New test. From-SVN: r228112 --- gcc/c-family/ChangeLog | 5 +++++ gcc/c-family/c-ubsan.c | 1 + gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/c-c++-common/ubsan/pr64906.c | 12 ++++++++++++ 4 files changed, 23 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/ubsan/pr64906.c diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index e409150ba61..b9feff6e55c 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2015-09-25 Marek Polacek + + PR sanitizer/64906 + * c-ubsan.c (ubsan_instrument_division): Also pre-evaluate OP1. + 2015-09-24 Patrick Palka * c-indentation.c (should_warn_for_misleading_indentation): diff --git a/gcc/c-family/c-ubsan.c b/gcc/c-family/c-ubsan.c index e0cce8467e4..d2bc264f632 100644 --- a/gcc/c-family/c-ubsan.c +++ b/gcc/c-family/c-ubsan.c @@ -104,6 +104,7 @@ ubsan_instrument_division (location_t loc, tree op0, tree op1) } } t = fold_build2 (COMPOUND_EXPR, TREE_TYPE (t), unshare_expr (op0), t); + t = fold_build2 (COMPOUND_EXPR, TREE_TYPE (t), unshare_expr (op1), t); if (flag_sanitize_undefined_trap_on_error) tt = build_call_expr_loc (loc, builtin_decl_explicit (BUILT_IN_TRAP), 0); else diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 193eb8e99b4..cfa23c659b8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-09-25 Marek Polacek + + PR sanitizer/64906 + * c-c++-common/ubsan/pr64906.c: New test. + 2015-09-24 H.J. Lu * gcc.target/i386/pr66749.c (dg-options): Replace -mtune=iamcu diff --git a/gcc/testsuite/c-c++-common/ubsan/pr64906.c b/gcc/testsuite/c-c++-common/ubsan/pr64906.c new file mode 100644 index 00000000000..e0ac0eefd5e --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/pr64906.c @@ -0,0 +1,12 @@ +/* PR sanitizer/64906 */ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=integer-divide-by-zero -O -Werror=maybe-uninitialized" } */ + +int +fn1 (int f, int s) +{ + int ret = 0; + if (f) + ret = s / (f ? (unsigned long) 8 : 0); + return ret; +} -- 2.30.2