Hi. Following patch checks that we do not call operand_equal_p with the first argument equals to NULL.
Patch survives regression tests and bootstraps on x86_64-linux-gnu. Ready for trunk? Thanks, Martin
>From 46c4b641778d42a5567f2e12cf987bb25f501ce7 Mon Sep 17 00:00:00 2001 From: marxin <mli...@suse.cz> Date: Mon, 23 May 2016 16:43:34 +0200 Subject: [PATCH] Fix PR tree-optimization/71239. gcc/testsuite/ChangeLog: 2016-05-23 Martin Liska <mli...@suse.cz> * g++.dg/pr71239.C: New test. gcc/ChangeLog: 2016-05-23 Martin Liska <mli...@suse.cz> PR tree-optimization/71239 * tree.c (array_at_struct_end_p): Do not call operand_equal_p if DECL_SIZE is NULL. --- gcc/testsuite/g++.dg/pr71239.C | 26 ++++++++++++++++++++++++++ gcc/tree.c | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/pr71239.C diff --git a/gcc/testsuite/g++.dg/pr71239.C b/gcc/testsuite/g++.dg/pr71239.C new file mode 100644 index 0000000..cb42d9c --- /dev/null +++ b/gcc/testsuite/g++.dg/pr71239.C @@ -0,0 +1,26 @@ +// PR c++/70590 +// { dg-do compile } +// { dg-options "-Wall -Os" } + +class A; +template <long Length> class B { + A mArr[Length]; + +public: + A &operator[](long aIndex) { + return mArr[aIndex]; + } +}; +class A { +public: + operator int *() { + int *a = mRawPtr; + return a; + } + int *mRawPtr; +}; +extern B<0> b; +void fn1() { + if (b[long(fn1)]) + new int; +} diff --git a/gcc/tree.c b/gcc/tree.c index 83dc7d8..f4b470b 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -13097,7 +13097,8 @@ array_at_struct_end_p (tree ref) is valid because BUF allocate enough space. */ - && (!size || operand_equal_p (DECL_SIZE (ref), size, 0)) + && (!size || (DECL_SIZE (ref) != NULL + && operand_equal_p (DECL_SIZE (ref), size, 0))) && !(flag_unconstrained_commons && TREE_CODE (ref) == VAR_DECL && DECL_COMMON (ref))) return false; -- 2.8.2