From 46c4b641778d42a5567f2e12cf987bb25f501ce7 Mon Sep 17 00:00:00 2001
From: marxin <mliska@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 <mliska@suse.cz>
* g++.dg/pr71239.C: New test.
gcc/ChangeLog:
2016-05-23 Martin Liska <mliska@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
new file mode 100644
@@ -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;
+}
@@ -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