aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2003-02-28 20:15:34 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>2003-02-28 20:15:34 +0000
commit1cb8292f2ef25a34d7d9efa20ba615514599d900 (patch)
tree3ea59f18a92962b95d5ab1ea899640ed3c1057c9 /gcc
parentf8f0e56649f3f768c10fdada122f616055b3d680 (diff)
downloadgcc-1cb8292f2ef25a34d7d9efa20ba615514599d900.zip
gcc-1cb8292f2ef25a34d7d9efa20ba615514599d900.tar.gz
gcc-1cb8292f2ef25a34d7d9efa20ba615514599d900.tar.bz2
re PR c++/9879 (ICE / endless compile with "new int[2]()")
PR c++/9879 * cp-tree.h (build_zero_init): Add parameter. * decl.c (cp_finish_decl): Adjust call. * init.c (build_zero_init): Add nelts parameter. Adjust recursive calls. (build_default_init): Add nelts parameter. Adjust calls to build_zero_init. (build_new_1): Adjust call to build_default_init. * typeck2.c (process_init_constructor): Adjust call to build_zero_init. PR c++/9879 * testsuite/g++.dg/init/new4.C: New test. From-SVN: r63579
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog12
-rw-r--r--gcc/cp/cp-tree.h2
-rw-r--r--gcc/cp/decl.c1
-rw-r--r--gcc/cp/init.c38
-rw-r--r--gcc/cp/typeck2.c2
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/init/new4.C1
7 files changed, 45 insertions, 16 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b896fb3..8fd10b1 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,15 @@
+2003-02-28 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/9879
+ * cp-tree.h (build_zero_init): Add parameter.
+ * decl.c (cp_finish_decl): Adjust call.
+ * init.c (build_zero_init): Add nelts parameter. Adjust recursive
+ calls.
+ (build_default_init): Add nelts parameter. Adjust calls to
+ build_zero_init.
+ (build_new_1): Adjust call to build_default_init.
+ * typeck2.c (process_init_constructor): Adjust call to build_zero_init.
+
2003-02-26 Devang Patel <dpatel@apple.com>
* decl.c (finish_enum): Merge two 'for' loops. Copy value node if required.
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 8e44bbb..4080248 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -3912,7 +3912,7 @@ extern tree build_init (tree, tree, int);
extern int is_aggr_type (tree, int);
extern tree get_aggr_from_typedef (tree, int);
extern tree get_type_value (tree);
-extern tree build_zero_init (tree, bool);
+extern tree build_zero_init (tree, tree, bool);
extern tree build_member_call (tree, tree, tree);
extern tree build_offset_ref (tree, tree);
extern tree resolve_offset_ref (tree);
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index de63181..cd15f25 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -8209,6 +8209,7 @@ cp_finish_decl (tree decl, tree init, tree asmspec_tree, int flags)
necessary zero-initialization has already been performed. */
if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
+ /*nelts=*/NULL_TREE,
/*static_storage_p=*/true);
/* Remember that the initialization for this variable has
taken place. */
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 7036aa0..1b86513 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -48,7 +48,7 @@ static tree initializing_context PARAMS ((tree));
static void expand_cleanup_for_base PARAMS ((tree, tree));
static tree get_temp_regvar PARAMS ((tree, tree));
static tree dfs_initialize_vtbl_ptrs PARAMS ((tree, void *));
-static tree build_default_init PARAMS ((tree));
+static tree build_default_init PARAMS ((tree, tree));
static tree build_new_1 PARAMS ((tree));
static tree get_cookie_size PARAMS ((tree));
static tree build_dtor_call PARAMS ((tree, special_function_kind, int));
@@ -159,12 +159,14 @@ initialize_vtbl_ptrs (addr)
that T is a scalar), or a CONSTRUCTOR (in the case that T is an
aggregate). In either case, the value can be used as DECL_INITIAL
for a decl of the indicated TYPE; it is a valid static initializer.
- If STATIC_STORAGE_P is TRUE, initializers are only generated for
- entities for which zero-initialization does not simply mean filling
- the storage with zero bytes. */
+ If NELTS is non-NULL, and TYPE is an ARRAY_TYPE, NELTS is the
+ number of elements in the array. If STATIC_STORAGE_P is TRUE,
+ initializers are only generated for entities for which
+ zero-initialization does not simply mean filling the storage with
+ zero bytes. */
tree
-build_zero_init (tree type, bool static_storage_p)
+build_zero_init (tree type, tree nelts, bool static_storage_p)
{
tree init = NULL_TREE;
@@ -217,6 +219,7 @@ build_zero_init (tree type, bool static_storage_p)
if (static_storage_p && !zero_init_p (TREE_TYPE (field)))
inits = tree_cons (field,
build_zero_init (TREE_TYPE (field),
+ /*nelts=*/NULL_TREE,
static_storage_p),
inits);
@@ -236,11 +239,13 @@ build_zero_init (tree type, bool static_storage_p)
init = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
/* Iterate over the array elements, building initializations. */
inits = NULL_TREE;
- for (index = size_zero_node, max_index = array_type_nelts (type);
+ max_index = nelts ? nelts : array_type_nelts (type);
+ for (index = size_zero_node;
!tree_int_cst_lt (max_index, index);
index = size_binop (PLUS_EXPR, index, size_one_node))
inits = tree_cons (index,
- build_zero_init (TREE_TYPE (type),
+ build_zero_init (TREE_TYPE (type),
+ /*nelts=*/NULL_TREE,
static_storage_p),
inits);
CONSTRUCTOR_ELTS (init) = nreverse (inits);
@@ -257,14 +262,17 @@ build_zero_init (tree type, bool static_storage_p)
return init;
}
-/* Build an expression for the default-initialization of an object
- with type T. If initialization T requires calling constructors,
- this function returns NULL_TREE; the caller is responsible for
- arranging for the constructors to be called. */
+/* Build an expression for the default-initialization of an object of
+ the indicated TYPE. If NELTS is non-NULL, and TYPE is an
+ ARRAY_TYPE, NELTS is the number of elements in the array. If
+ initialization of TYPE requires calling constructors, this function
+ returns NULL_TREE; the caller is responsible for arranging for the
+ constructors to be called. */
static tree
-build_default_init (type)
+build_default_init (type, nelts)
tree type;
+ tree nelts;
{
/* [dcl.init]:
@@ -298,7 +306,7 @@ build_default_init (type)
/* At this point, TYPE is either a POD class type, an array of POD
classes, or something even more inoccuous. */
- return build_zero_init (type, /*static_storage_p=*/false);
+ return build_zero_init (type, nelts, /*static_storage_p=*/false);
}
/* Initialize MEMBER, a FIELD_DECL, with INIT, a TREE_LIST of
@@ -364,7 +372,7 @@ perform_member_init (tree member, tree init)
{
if (explicit)
{
- init = build_default_init (type);
+ init = build_default_init (type, /*nelts=*/NULL_TREE);
if (TREE_CODE (type) == REFERENCE_TYPE)
warning
("default-initialization of `%#D', which has reference type",
@@ -2367,7 +2375,7 @@ build_new_1 (exp)
init_expr = build_indirect_ref (alloc_node, NULL);
if (init == void_zero_node)
- init = build_default_init (full_type);
+ init = build_default_init (full_type, nelts);
else if (init && pedantic && has_array)
pedwarn ("ISO C++ forbids initialization in array new");
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 5758bf4..a455879 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -733,6 +733,7 @@ process_init_constructor (type, init, elts)
}
else if (! zero_init_p (TREE_TYPE (type)))
next1 = build_zero_init (TREE_TYPE (type),
+ /*nelts=*/NULL_TREE,
/*static_storage_p=*/false);
else
/* The default zero-initialization is fine for us; don't
@@ -851,6 +852,7 @@ process_init_constructor (type, init, elts)
if (! zero_init_p (TREE_TYPE (field)))
next1 = build_zero_init (TREE_TYPE (field),
+ /*nelts=*/NULL_TREE,
/*static_storage_p=*/false);
else
/* The default zero-initialization is fine for us; don't
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 9c81c63..ac2985c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2003-02-28 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/9879
+ * testsuite/g++.dg/init/new4.C: New test.
+
2003-02-28 Richard Earnshaw <rearnsha@arm.com>
* gcc.dg/arm-asm.c: Enable for StrongARM and XScale targets.
diff --git a/gcc/testsuite/g++.dg/init/new4.C b/gcc/testsuite/g++.dg/init/new4.C
new file mode 100644
index 0000000..ab2fe31
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/new4.C
@@ -0,0 +1 @@
+int *x = new int [2] ();