Commit 7a1d37e9 by Matt Austern Committed by Matt Austern

Fix for PR c++/11228, infinite loop for new int[n]().

From-SVN: r68235
parent 3a95fe8f
2003-06-19 Matt Austern <austern@apple.com>
PR c++/11228
* init.c (build_zero_init): Assert that number of array elements
is an integer constant.
(build_default_init) Don't use build_zero_init for arrays with
variable number of elements.
2003-06-19 Andreas Jaeger <aj@suse.de>
* cp-tree.h: Remove duplicated declarations.
......
......@@ -180,6 +180,9 @@ build_zero_init (tree type, tree nelts, bool static_storage_p)
-- if T is a reference type, no initialization is performed. */
my_friendly_assert (nelts == NULL_TREE || TREE_CODE (nelts) == INTEGER_CST,
20030618);
if (type == error_mark_node)
;
else if (static_storage_p && zero_init_p (type))
......@@ -232,6 +235,8 @@ build_zero_init (tree type, tree nelts, bool static_storage_p)
/* Iterate over the array elements, building initializations. */
inits = NULL_TREE;
max_index = nelts ? nelts : array_type_nelts (type);
my_friendly_assert (TREE_CODE (max_index) == INTEGER_CST, 20030618);
for (index = size_zero_node;
!tree_int_cst_lt (max_index, index);
index = size_binop (PLUS_EXPR, index, size_one_node))
......@@ -291,7 +296,8 @@ build_default_init (tree type, tree nelts)
standard says we should have generated would be precisely the
same as that obtained by calling build_zero_init below, so things
work out OK. */
if (TYPE_NEEDS_CONSTRUCTING (type))
if (TYPE_NEEDS_CONSTRUCTING (type)
|| (nelts && TREE_CODE (nelts) != INTEGER_CST))
return NULL_TREE;
/* At this point, TYPE is either a POD class type, an array of POD
......
2003-06-19 Matt Austern <austern@apple.com>
PR c++/11228
* g++.dg/anew1.C: New test.
* g++.dg/anew2.C: New test.
* g++.dg/anew3.C: New test.
* g++.dg/anew4.C: New test.
2003-06-19 Kazu Hirata <kazu@cs.umass.edu>
* gcc.c-torture/compile/simd-5.c: Don't XFAIL on H8.
......
// { dg-do run }
// PR 11228: array operator new, with zero-initialization and a variable sized array.
// Regression test for PR
// Author: Matt Austern <austern@apple.com>
int* allocate(int n)
{
return new int[n]();
}
int main()
{
const int n = 17;
int* p = allocate(n);
for (int i = 0; i < n; ++i)
if (p[i] != 0)
return 1;
return 0;
}
// { dg-do run }
// PR 11228: array operator new, with zero-initialization and a variable sized array.
// Regression test for PR
// Author: Matt Austern <austern@apple.com>
double* allocate(int n)
{
return new double[n]();
}
int main()
{
const int n = 17;
double* p = allocate(n);
for (int i = 0; i < n; ++i)
if (p[i] != 0.0)
return 1;
return 0;
}
// { dg-do run }
// PR 11228: array operator new, with zero-initialization and a variable sized array.
// Regression test for PR
// Author: Matt Austern <austern@apple.com>
struct X
{
int a;
double b;
};
X* allocate(int n)
{
return new X[n]();
}
int main()
{
const int n = 17;
X* p = allocate(n);
for (int i = 0; i < n; ++i)
if (p[i].a != 0 || p[i].b != 0.0)
return 1;
return 0;
}
// { dg-do run }
// PR 11228: array operator new, with zero-initialization and a variable sized array.
// Regression test for PR
// Author: Matt Austern <austern@apple.com>
struct B
{
B();
int n;
};
B::B()
{
n = 137;
}
struct D : public B
{
double x;
};
D* allocate(int n)
{
return new D[n]();
}
int main()
{
const int n = 17;
D* p = allocate(n);
for (int i = 0; i < n; ++i)
if (p[i].n != 137 || p[i].x != 0)
return 1;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment