aboutsummaryrefslogtreecommitdiff
path: root/gcc/ubsan.c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2017-05-18 07:18:24 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2017-05-18 07:18:24 +0000
commit243c288370fe51ba55c3a9ee61eb2a1a62cb1279 (patch)
tree61c04324127c01037d585d966283e4575d024204 /gcc/ubsan.c
parenta7ab66385376da4f0d9cbe48f191ddb8928fd06d (diff)
downloadgcc-243c288370fe51ba55c3a9ee61eb2a1a62cb1279.zip
gcc-243c288370fe51ba55c3a9ee61eb2a1a62cb1279.tar.gz
gcc-243c288370fe51ba55c3a9ee61eb2a1a62cb1279.tar.bz2
re PR sanitizer/80797 (-fsanitize=null doesn't instrument &s->x)
PR sanitizer/80797 * ubsan.c (instrument_null): Unwrap ADDR_EXPRs. (pass_ubsan::execute): Call gimple_assign_single_p instead of gimple_assign_load_p. * c-c++-common/ubsan/null-12.c: New test. From-SVN: r248179
Diffstat (limited to 'gcc/ubsan.c')
-rw-r--r--gcc/ubsan.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/gcc/ubsan.c b/gcc/ubsan.c
index 4159cc5..a4808d2 100644
--- a/gcc/ubsan.c
+++ b/gcc/ubsan.c
@@ -1208,6 +1208,9 @@ instrument_null (gimple_stmt_iterator gsi, bool is_lhs)
{
gimple *stmt = gsi_stmt (gsi);
tree t = is_lhs ? gimple_get_lhs (stmt) : gimple_assign_rhs1 (stmt);
+ /* Handle also e.g. &s->i. */
+ if (TREE_CODE (t) == ADDR_EXPR)
+ t = TREE_OPERAND (t, 0);
tree base = get_base_address (t);
const enum tree_code code = TREE_CODE (base);
if (code == MEM_REF
@@ -1998,7 +2001,7 @@ pass_ubsan::execute (function *fun)
{
if (gimple_store_p (stmt))
instrument_null (gsi, true);
- if (gimple_assign_load_p (stmt))
+ if (gimple_assign_single_p (stmt))
instrument_null (gsi, false);
}