diff options
author | Jakub Jelinek <jakub@redhat.com> | 2017-06-08 20:53:16 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2017-06-08 20:53:16 +0200 |
commit | 0d05f68547fb7478f3a210a6240d3a05465daad9 (patch) | |
tree | 84461529e5d68a05a471ad1b9597446211aa204e /gcc/ubsan.c | |
parent | 3159d897bda6798885f34eaaba916b46ebe2382f (diff) | |
download | gcc-0d05f68547fb7478f3a210a6240d3a05465daad9.zip gcc-0d05f68547fb7478f3a210a6240d3a05465daad9.tar.gz gcc-0d05f68547fb7478f3a210a6240d3a05465daad9.tar.bz2 |
re PR middle-end/81005 (-fsanitize=null and -fsanitize=alignment doesn't check aggregate arguments of calls)
PR middle-end/81005
* ubsan.c (instrument_null): Avoid pointless code temporary.
(pass_ubsan::execute): Instrument aggregate arguments of calls.
* c-c++-common/ubsan/align-10.c: New test.
* c-c++-common/ubsan/null-13.c: New test.
From-SVN: r249030
Diffstat (limited to 'gcc/ubsan.c')
-rw-r--r-- | gcc/ubsan.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/gcc/ubsan.c b/gcc/ubsan.c index a4808d2..133409a 100644 --- a/gcc/ubsan.c +++ b/gcc/ubsan.c @@ -1212,8 +1212,7 @@ instrument_null (gimple_stmt_iterator gsi, bool is_lhs) 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 + if (TREE_CODE (base) == MEM_REF && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME) instrument_mem_ref (t, base, &gsi, is_lhs); } @@ -2003,6 +2002,20 @@ pass_ubsan::execute (function *fun) instrument_null (gsi, true); if (gimple_assign_single_p (stmt)) instrument_null (gsi, false); + if (is_gimple_call (stmt)) + { + unsigned args_num = gimple_call_num_args (stmt); + for (unsigned i = 0; i < args_num; ++i) + { + tree arg = gimple_call_arg (stmt, i); + if (is_gimple_reg (arg) || is_gimple_min_invariant (arg)) + continue; + tree base = get_base_address (arg); + if (TREE_CODE (base) == MEM_REF + && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME) + instrument_mem_ref (arg, base, &gsi, false); + } + } } if (flag_sanitize & (SANITIZE_BOOL | SANITIZE_ENUM) |