This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR C++/28906, fallout from the fix for PR 27184
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 31 Aug 2006 21:44:55 -0700
- Subject: [PATCH] Fix PR C++/28906, fallout from the fix for PR 27184
The problem here is that after the fix for PR 27184, build_array_type
with a NULL_TREE as the index is now shared and the C++ front-end was
not taking that into account when using that to build the type for
operator new. This patch fixes the problem by copying
(build_distinct_type_copy) the type for the expression. Note this does
not increase the memory usage more than what was being used before the
patch for PR 27184 as build_array_type before that patch would always
create a new type rather than being shared.
OK? Bootstrapped and tested on i686-linux-gnu with no regressions.
Thanks,
Andrew Pinski
cp/ChangeLog:
* init.c (build_new_1): Build a distinct type copy
for the array type that was returned from
build_cplus_array_type.
testsuite/ChangeLog:
* g++.dg/other/array3.C: New test.
* g++.dg/other/array4.C: New test.
* g++.dg/other/array5.C: New test.
Index: testsuite/g++.dg/other/array4.C
===================================================================
--- testsuite/g++.dg/other/array4.C (revision 0)
+++ testsuite/g++.dg/other/array4.C (revision 0)
@@ -0,0 +1,19 @@
+// PR C++/28906: new on an array causes incomplete arrays to
+// become complete with the wrong size.
+// The sizeof machineMain should be 5 and not 100.
+// { dg-do run }
+
+
+extern char machineMain[];
+void sort (long len)
+{
+ new char[100];
+}
+char machineMain[] = "main";
+int main(void)
+{
+ if (sizeof(machineMain)!=sizeof("main"))
+ __builtin_abort();
+}
+
+
Index: testsuite/g++.dg/other/array5.C
===================================================================
--- testsuite/g++.dg/other/array5.C (revision 0)
+++ testsuite/g++.dg/other/array5.C (revision 0)
@@ -0,0 +1,9 @@
+// Check to make sure changing from an incomplete
+// array type to a complete one does not change other
+// incomplete array type's bounds.
+// { dg-do compile }
+
+extern unsigned char xvalue_store[];
+extern unsigned char xvalue_store1[];
+unsigned char xvalue_store[7];
+unsigned char xvalue_store1[9];
Index: testsuite/g++.dg/other/array3.C
===================================================================
--- testsuite/g++.dg/other/array3.C (revision 0)
+++ testsuite/g++.dg/other/array3.C (revision 0)
@@ -0,0 +1,14 @@
+// PR C++/28906: new on an array causes incomplete arrays to
+// become complete with the wrong size.
+
+// the bounds of xvalue_store was being set to include want
+// which was incorrect.
+
+// { dg-do compile }
+
+extern unsigned char xvalue_store[];
+bool reserve (int want)
+{
+ new unsigned char[want];
+}
+unsigned char xvalue_store[257];
Index: cp/init.c
===================================================================
--- cp/init.c (revision 116601)
+++ cp/init.c (working copy)
@@ -1628,10 +1628,14 @@ build_new_1 (tree placement, tree type,
function context. Methinks that's not it's purvey. So we'll do
our own VLA layout later. */
vla_p = true;
- full_type = build_cplus_array_type (type, NULL_TREE);
index = convert (sizetype, nelts);
index = size_binop (MINUS_EXPR, index, size_one_node);
- TYPE_DOMAIN (full_type) = build_index_type (index);
+ index = build_index_type (index);
+ full_type = build_cplus_array_type (type, NULL_TREE);
+ /* We need a copy of the type as build_array_type will return a shared copy
+ of the incomplete array type. */
+ full_type = build_distinct_type_copy (full_type);
+ TYPE_DOMAIN (full_type) = index;
}
else
{