diff options
author | Marek Polacek <polacek@redhat.com> | 2013-09-18 13:31:34 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2013-09-18 13:31:34 +0000 |
commit | a24d975caa592f57e0966687ca0340714df9a6a0 (patch) | |
tree | 97eab07355cd3cdcb2aa83c4500a803b8b9678d4 /gcc/c | |
parent | 0547c9b695fcbcd477f7e455c2bf376ce1ec23d1 (diff) | |
download | gcc-a24d975caa592f57e0966687ca0340714df9a6a0.zip gcc-a24d975caa592f57e0966687ca0340714df9a6a0.tar.gz gcc-a24d975caa592f57e0966687ca0340714df9a6a0.tar.bz2 |
re PR sanitizer/58443 (ubsan doesn't properly honor fsanitize= flags)
2013-09-18 Marek Polacek <polacek@redhat.com>
PR sanitize/58443
cp/
* typeck.c (cp_build_binary_op): Properly honor -fsanitize options.
Remove unnecessary check.
c/
* c-typeck.c (build_binary_op): Properly honor -fsanitize options.
Remove unnecessary check.
testsuite/
* g++.dg/ubsan/div-by-zero-1.C: Use the integer-divide-by-zero option
instead of the shift option.
* c-c++-common/ubsan/pr58443-1.c: New test.
* c-c++-common/ubsan/pr58443-3.c: New test.
* c-c++-common/ubsan/pr58443-2.c: New test.
From-SVN: r202701
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 8 |
2 files changed, 10 insertions, 4 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 59b71aa..81b2018 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,5 +1,11 @@ 2013-09-18 Marek Polacek <polacek@redhat.com> + PR sanitize/58443 + * c-typeck.c (build_binary_op): Properly honor -fsanitize options. + Remove unnecessary check. + +2013-09-18 Marek Polacek <polacek@redhat.com> + PR sanitizer/58411 * c-typeck.c (build_binary_op): Don't sanitize function if it has the no_sanitize_undefined attribute. diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 7dc5527..7ecafe4 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -10496,7 +10496,7 @@ build_binary_op (location_t location, enum tree_code code, return error_mark_node; } - if (flag_sanitize & SANITIZE_UNDEFINED + if ((flag_sanitize & (SANITIZE_SHIFT | SANITIZE_DIVIDE)) && current_function_decl != 0 && !lookup_attribute ("no_sanitize_undefined", DECL_ATTRIBUTES (current_function_decl)) @@ -10507,9 +10507,9 @@ build_binary_op (location_t location, enum tree_code code, op1 = c_save_expr (op1); op0 = c_fully_fold (op0, false, NULL); op1 = c_fully_fold (op1, false, NULL); - if (doing_div_or_mod) + if (doing_div_or_mod && (flag_sanitize & SANITIZE_DIVIDE)) instrument_expr = ubsan_instrument_division (location, op0, op1); - else if (doing_shift) + else if (doing_shift && (flag_sanitize & SANITIZE_SHIFT)) instrument_expr = ubsan_instrument_shift (location, code, op0, op1); } @@ -10537,7 +10537,7 @@ build_binary_op (location_t location, enum tree_code code, ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret); protected_set_expr_location (ret, location); - if ((flag_sanitize & SANITIZE_UNDEFINED) && instrument_expr != NULL) + if (instrument_expr != NULL) ret = fold_build2 (COMPOUND_EXPR, TREE_TYPE (ret), instrument_expr, ret); |