mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-22 21:51:36 +08:00
re PR sanitizer/59306 (ICE with -fsanitize=null: gimple check: expected gimple_call(error_mark), have gimple_assign(addr_expr) in gimple_call_arg)
PR sanitizer/59306 * ubsan.c (instrument_null): Use gimple_store_p/gimple_assign_load_p instead of walk_gimple_op. (ubsan_pass): Adjust. Call instrument_null only if SANITIZE_NULL. testsuite/ * g++.dg/ubsan/pr59306.C: New test. From-SVN: r205443
This commit is contained in:
parent
0136f8f03a
commit
536da97c4e
@ -1,3 +1,10 @@
|
||||
2013-11-27 Marek Polacek <polacek@redhat.com>
|
||||
|
||||
PR sanitizer/59306
|
||||
* ubsan.c (instrument_null): Use gimple_store_p/gimple_assign_load_p
|
||||
instead of walk_gimple_op.
|
||||
(ubsan_pass): Adjust. Call instrument_null only if SANITIZE_NULL.
|
||||
|
||||
2013-11-27 Aldy Hernandez <aldyh@redhat.com>
|
||||
Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
2013-11-27 Marek Polacek <polacek@redhat.com>
|
||||
|
||||
PR sanitizer/59306
|
||||
* g++.dg/ubsan/pr59306.C: New test.
|
||||
|
||||
2013-11-27 Aldy Hernandez <aldyh@redhat.com>
|
||||
Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
|
14
gcc/testsuite/g++.dg/ubsan/pr59306.C
Normal file
14
gcc/testsuite/g++.dg/ubsan/pr59306.C
Normal file
@ -0,0 +1,14 @@
|
||||
// { dg-do compile }
|
||||
// { dg-options "-fsanitize=undefined" }
|
||||
// { dg-skip-if "" { *-*-* } { "-flto" } { "" } }
|
||||
|
||||
class A {
|
||||
void bar (void (A::*) (int));
|
||||
void foo (int);
|
||||
void B ();
|
||||
};
|
||||
|
||||
void A::B()
|
||||
{
|
||||
bar (&A::foo);
|
||||
}
|
30
gcc/ubsan.c
30
gcc/ubsan.c
@ -614,24 +614,22 @@ instrument_mem_ref (tree t, gimple_stmt_iterator *iter, bool is_lhs)
|
||||
gsi_insert_before (iter, g, GSI_SAME_STMT);
|
||||
}
|
||||
|
||||
/* Callback function for the pointer instrumentation. */
|
||||
/* Perform the pointer instrumentation. */
|
||||
|
||||
static tree
|
||||
instrument_null (tree *tp, int * /*walk_subtree*/, void *data)
|
||||
static void
|
||||
instrument_null (gimple_stmt_iterator gsi, bool is_lhs)
|
||||
{
|
||||
tree t = *tp;
|
||||
gimple stmt = gsi_stmt (gsi);
|
||||
tree t = is_lhs ? gimple_get_lhs (stmt) : gimple_assign_rhs1 (stmt);
|
||||
t = get_base_address (t);
|
||||
const enum tree_code code = TREE_CODE (t);
|
||||
struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
|
||||
|
||||
if (code == MEM_REF
|
||||
&& TREE_CODE (TREE_OPERAND (t, 0)) == SSA_NAME)
|
||||
instrument_mem_ref (TREE_OPERAND (t, 0), &wi->gsi, wi->is_lhs);
|
||||
instrument_mem_ref (TREE_OPERAND (t, 0), &gsi, is_lhs);
|
||||
else if (code == ADDR_EXPR
|
||||
&& POINTER_TYPE_P (TREE_TYPE (t))
|
||||
&& TREE_CODE (TREE_TYPE (TREE_TYPE (t))) == METHOD_TYPE)
|
||||
instrument_member_call (&wi->gsi);
|
||||
|
||||
return NULL_TREE;
|
||||
instrument_member_call (&gsi);
|
||||
}
|
||||
|
||||
/* Gate and execute functions for ubsan pass. */
|
||||
@ -646,7 +644,6 @@ ubsan_pass (void)
|
||||
{
|
||||
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
|
||||
{
|
||||
struct walk_stmt_info wi;
|
||||
gimple stmt = gsi_stmt (gsi);
|
||||
if (is_gimple_debug (stmt) || gimple_clobber_p (stmt))
|
||||
{
|
||||
@ -654,9 +651,14 @@ ubsan_pass (void)
|
||||
continue;
|
||||
}
|
||||
|
||||
memset (&wi, 0, sizeof (wi));
|
||||
wi.gsi = gsi;
|
||||
walk_gimple_op (stmt, instrument_null, &wi);
|
||||
if (flag_sanitize & SANITIZE_NULL)
|
||||
{
|
||||
if (gimple_store_p (stmt))
|
||||
instrument_null (gsi, true);
|
||||
if (gimple_assign_load_p (stmt))
|
||||
instrument_null (gsi, false);
|
||||
}
|
||||
|
||||
gsi_next (&gsi);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user