This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
fix g++.dg/init/new4.C
- From: Richard Henderson <rth at twiddle dot net>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 30 Jun 2004 12:59:45 -0700
- Subject: fix g++.dg/init/new4.C
This test started failing after
2004-06-29 Richard Henderson <rth@redhat.com>
* gimplify.c (gimplify_modify_expr_rhs): Move immediately before
gimplify_modify_expr.
(gimplify_init_constructor): Likewise. Gimplify the null
CONSTRUCTOR assignment.
(gimplify_modify_expr_to_memcpy): New.
(gimplify_modify_expr_to_memset): New.
(gimplify_modify_expr): Use them.
I had tested only C and Ada, since "obviously" C++ doesn't use VLA
types. :-( Anyway, in this case the bug is in the C++ front end.
It's trying to perform an assignment
*<D123> = { 0, 0, 0 }
where the type across the assignment has unknown (NULL) size. Bzzzt.
My initial reaction was to ignore the "VLA headaches" comment and
generate one anyway. This runs afoul of the middle-end data layout
routines that think they know better and generate an error for building
a VLA type outside of a function context.
Fixing the middle-end seemed like more work than I wanted to do for
the moment, so instead I fill in the relevant fields myself. Blah.
Tested i686-linux.
r~
* init.c (build_new_1): Fill in TYPE_DOMAIN, TYPE_SIZE and
TYPE_SIZE_UNIT of full_type.
Index: init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/init.c,v
retrieving revision 1.380
diff -u -p -r1.380 init.c
--- init.c 29 Jun 2004 14:50:30 -0000 1.380
+++ init.c 30 Jun 2004 19:51:39 -0000
@@ -1815,10 +1815,20 @@ build_new_1 (tree exp)
if (nelts)
{
+ tree index;
+
has_array = 1;
outer_nelts = nelts;
- /* Use an incomplete array type to avoid VLA headaches. */
+
+ /* ??? The middle-end will error on us for building a VLA outside a
+ function context. Methinks that's not it's purvey. So we'll do
+ our own VLA layout later. */
+
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);
}
else
full_type = type;
@@ -1857,7 +1867,20 @@ build_new_1 (tree exp)
size = size_in_bytes (true_type);
if (has_array)
- size = size_binop (MULT_EXPR, size, convert (sizetype, nelts));
+ {
+ tree n, bitsize;
+
+ /* Do our own VLA layout. Setting TYPE_SIZE/_UNIT is necessary in
+ order for the <INIT_EXPR <*foo> <CONSTRUCTOR ...>> to be valid. */
+
+ n = convert (sizetype, nelts);
+ size = size_binop (MULT_EXPR, size, n);
+ TYPE_SIZE_UNIT (full_type) = size;
+
+ n = convert (bitsizetype, nelts);
+ bitsize = size_binop (MULT_EXPR, TYPE_SIZE (true_type), n);
+ TYPE_SIZE (full_type) = bitsize;
+ }
/* Allocate the object. */
if (! placement && TYPE_FOR_JAVA (true_type))