From 65d5e454e5944531df80d0a9b5dcf2344c146fb8 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 29 Nov 2017 11:33:06 +0100 Subject: [PATCH] re PR middle-end/83185 (ICE with -fsanitize=address in build_simple_mem_ref_loc, at tree.c:4696) PR middle-end/83185 * tree.c (build_simple_mem_ref_loc): Handle get_addr_base_and_unit_offset returning a MEM_REF. * gcc.dg/asan/pr83185.c: New test. From-SVN: r255229 --- gcc/ChangeLog | 4 ++++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.dg/asan/pr83185.c | 14 ++++++++++++++ gcc/tree.c | 8 +++++++- 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/asan/pr83185.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 483c02aa501..51d7009b6ea 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,9 @@ 2017-11-29 Jakub Jelinek + PR middle-end/83185 + * tree.c (build_simple_mem_ref_loc): Handle + get_addr_base_and_unit_offset returning a MEM_REF. + PR middle-end/80929 * rtlanal.c (seq_cost): For non-single_set insns try to use insn_cost. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b8bd264dd33..dbe90640f6b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2017-11-29 Jakub Jelinek + PR middle-end/83185 + * gcc.dg/asan/pr83185.c: New test. + PR target/80819 * gcc.target/i386/pr80819-1.c: New test. * gcc.target/i386/pr80819-2.c: New test. diff --git a/gcc/testsuite/gcc.dg/asan/pr83185.c b/gcc/testsuite/gcc.dg/asan/pr83185.c new file mode 100644 index 00000000000..175d2ce15ff --- /dev/null +++ b/gcc/testsuite/gcc.dg/asan/pr83185.c @@ -0,0 +1,14 @@ +/* PR middle-end/83185 */ +/* { dg-do compile } */ + +#include + +int bar (void); + +void +foo (int i, ...) +{ + va_list aps[bar()]; + va_start (aps[4], i); + va_end (aps[4]); +} diff --git a/gcc/tree.c b/gcc/tree.c index e97654cd0f1..b3902479c32 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -4692,7 +4692,13 @@ build_simple_mem_ref_loc (location_t loc, tree ptr) { ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset); gcc_assert (ptr); - ptr = build_fold_addr_expr (ptr); + if (TREE_CODE (ptr) == MEM_REF) + { + offset += mem_ref_offset (ptr).to_short_addr (); + ptr = TREE_OPERAND (ptr, 0); + } + else + ptr = build_fold_addr_expr (ptr); gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr)); } tem = build2 (MEM_REF, TREE_TYPE (ptype), -- 2.30.2