diff options
author | Marek Polacek <polacek@redhat.com> | 2014-11-06 11:22:59 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2014-11-06 11:22:59 +0000 |
commit | 34896cd612476e1ee0937ff5bd32f597da944866 (patch) | |
tree | f8c8f0b025057b216716c4e19ffdbaa702d361f6 /gcc/sanopt.c | |
parent | 32dee765689108575338858a16ac5f04b85f88d5 (diff) | |
download | gcc-34896cd612476e1ee0937ff5bd32f597da944866.zip gcc-34896cd612476e1ee0937ff5bd32f597da944866.tar.gz gcc-34896cd612476e1ee0937ff5bd32f597da944866.tar.bz2 |
sanopt.c (sanopt_optimize_walker): Limit removal of the checks.
* sanopt.c (sanopt_optimize_walker): Limit removal of the checks.
Remove vector limit.
testsuite/
* c-c++-common/ubsan/align-2.c: Add dg-output.
* c-c++-common/ubsan/align-4.c: Likewise.
* c-c++-common/ubsan/align-6.c: New test.
* c-c++-common/ubsan/align-7.c: New test.
* c-c++-common/ubsan/align-8.c: New test.
* g++.dg/ubsan/null-1.C: Add dg-output.
* g++.dg/ubsan/null-2.C: Likewise.
* g++.dg/ubsan/null-3.C: New test.
* g++.dg/ubsan/null-4.C: New test.
* g++.dg/ubsan/null-5.C: New test.
From-SVN: r217189
Diffstat (limited to 'gcc/sanopt.c')
-rw-r--r-- | gcc/sanopt.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/gcc/sanopt.c b/gcc/sanopt.c index 4483ff7..0fc032a 100644 --- a/gcc/sanopt.c +++ b/gcc/sanopt.c @@ -130,7 +130,30 @@ sanopt_optimize_walker (basic_block bb, struct sanopt_ctx *ctx) /* At this point we shouldn't have any statements that aren't dominating the current BB. */ tree align = gimple_call_arg (g, 2); - remove = tree_int_cst_le (cur_align, align); + int kind = tree_to_shwi (gimple_call_arg (g, 1)); + /* If this is a NULL pointer check where we had segv + anyway, we can remove it. */ + if (integer_zerop (align) + && (kind == UBSAN_LOAD_OF + || kind == UBSAN_STORE_OF + || kind == UBSAN_MEMBER_ACCESS)) + remove = true; + /* Otherwise remove the check in non-recovering + mode, or if the stmts have same location. */ + else if (integer_zerop (align)) + remove = !(flag_sanitize_recover & SANITIZE_NULL) + || flag_sanitize_undefined_trap_on_error + || gimple_location (g) + == gimple_location (stmt); + else if (tree_int_cst_le (cur_align, align)) + remove = !(flag_sanitize_recover + & SANITIZE_ALIGNMENT) + || flag_sanitize_undefined_trap_on_error + || gimple_location (g) + == gimple_location (stmt); + if (!remove && gimple_bb (g) == gimple_bb (stmt) + && tree_int_cst_compare (cur_align, align) == 0) + v.pop (); break; } } @@ -147,7 +170,7 @@ sanopt_optimize_walker (basic_block bb, struct sanopt_ctx *ctx) } gsi_remove (&gsi, true); } - else if (v.length () < 30) + else v.safe_push (stmt); } } |