From c71a55f88d2d4fc29f9009aea2d833ac340ea38b Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 19 Nov 2014 14:32:02 +0000 Subject: [PATCH] re PR sanitizer/63690 (ICE: tree check: expected class 'expression', have 'constant' (string_cst) with -fsanitize=undefined) PR sanitizer/63690 * ubsan.c (instrument_object_size): Check for MEM_REF. * gcc.dg/ubsan/pr63690.c: New test. From-SVN: r217778 --- gcc/ChangeLog | 5 +++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/ubsan/pr63690.c | 18 ++++++++++++++++++ gcc/ubsan.c | 8 +++++++- 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/ubsan/pr63690.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6e1f93069c1..2c13f13e4a2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2014-11-19 Marek Polacek + + PR sanitizer/63690 + * ubsan.c (instrument_object_size): Check for MEM_REF. + 2014-11-19 Ilya Verbin PR regression/63868 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 93d00115079..1f25b0ba5a3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-11-19 Marek Polacek + + PR sanitizer/63690 + * gcc.dg/ubsan/pr63690.c: New test. + 2014-11-19 Francois-Xavier Coudert PR sanitizer/62132 diff --git a/gcc/testsuite/gcc.dg/ubsan/pr63690.c b/gcc/testsuite/gcc.dg/ubsan/pr63690.c new file mode 100644 index 00000000000..be8600f3fae --- /dev/null +++ b/gcc/testsuite/gcc.dg/ubsan/pr63690.c @@ -0,0 +1,18 @@ +/* PR sanitizer/63690 */ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=undefined" } */ + +void +foo (void) +{ + (*"c")++; +} +/* PR sanitizer/63690 */ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=undefined" } */ + +void +foo (void) +{ + (*"c")++; +} diff --git a/gcc/ubsan.c b/gcc/ubsan.c index 7d1e341812c..ad5665ff047 100644 --- a/gcc/ubsan.c +++ b/gcc/ubsan.c @@ -1539,7 +1539,13 @@ instrument_object_size (gimple_stmt_iterator *gsi, bool is_lhs) return; bool decl_p = DECL_P (inner); - tree base = decl_p ? inner : TREE_OPERAND (inner, 0); + tree base; + if (decl_p) + base = inner; + else if (TREE_CODE (inner) == MEM_REF) + base = TREE_OPERAND (inner, 0); + else + return; tree ptr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (t)), t); while (TREE_CODE (base) == SSA_NAME) -- 2.30.2