From 786c6d10af3386f348d676a27b3d7f195dff9700 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Tue, 27 Jun 2017 11:38:31 +0000 Subject: [PATCH] re PR sanitizer/81223 (ICE in instrument_null at gcc/ubsan.c:1230) PR sanitizer/81223 * ubsan.c (instrument_null): Check get_base_address's result for null. * gcc.dg/ubsan/pr81223.c: New test. From-SVN: r249687 --- gcc/ChangeLog | 5 +++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/ubsan/pr81223.c | 12 ++++++++++++ gcc/ubsan.c | 3 ++- 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/ubsan/pr81223.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 665e0b5b085..f9e00198bbf 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-06-27 Marek Polacek + + PR sanitizer/81223 + * ubsan.c (instrument_null): Check get_base_address's result for null. + 2017-06-27 Marc Glisse * match.pd ((A+-B)+(C-A), (A+B)-(A-C)): New transformations. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7364606164c..98faa118078 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-06-27 Marek Polacek + + PR sanitizer/81223 + * gcc.dg/ubsan/pr81223.c: New test. + 2017-06-27 Marc Glisse * gcc.dg/tree-ssa/assoc-1.c: New file. diff --git a/gcc/testsuite/gcc.dg/ubsan/pr81223.c b/gcc/testsuite/gcc.dg/ubsan/pr81223.c new file mode 100644 index 00000000000..e7aff5243e6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ubsan/pr81223.c @@ -0,0 +1,12 @@ +/* PR sanitizer/81223 */ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=undefined" } */ + +void bar (); + +void +foo (int x) +{ + struct S { char a[x]; } v; + bar (v); +} diff --git a/gcc/ubsan.c b/gcc/ubsan.c index c7a06ef0e8d..bd0588b89ba 100644 --- a/gcc/ubsan.c +++ b/gcc/ubsan.c @@ -1228,7 +1228,8 @@ instrument_null (gimple_stmt_iterator gsi, tree t, bool is_lhs) if (TREE_CODE (t) == ADDR_EXPR) t = TREE_OPERAND (t, 0); tree base = get_base_address (t); - if (TREE_CODE (base) == MEM_REF + if (base != NULL_TREE + && TREE_CODE (base) == MEM_REF && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME) instrument_mem_ref (t, base, &gsi, is_lhs); } -- 2.30.2