This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Make the static init with compound literal extension work with [x...y] designators
- From: Jakub Jelinek <jakub at redhat dot com>
- To: rth at redhat dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 14 Jan 2002 19:30:12 +0100
- Subject: [PATCH] Make the static init with compound literal extension work with [x...y] designators
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
Looks like Linux kernel initializes with compound literals in a lot of
different constructs.
The following patch is hopefully a last one:
if save_expr is called on the compound literal, pending_element will not
recognize it as initialization by compound literal.
Bootstrap pending, ok to commit?
2002-01-14 Jakub Jelinek <jakub@redhat.com>
* c-typeck.c (process_init_element): Don't save_expr
COMPOUND_LITERAL_EXPR if just its initializer will be used.
* gcc.dg/gnu89-init-1.c: Add new tests.
--- gcc/testsuite/gcc.dg/gnu89-init-1.c.jj Wed Jan 2 16:46:12 2002
+++ gcc/testsuite/gcc.dg/gnu89-init-1.c Mon Jan 14 20:36:41 2002
@@ -28,6 +28,8 @@ struct C g[3] = { [2] = (struct C) { 13
struct D h = { .j = (struct C) { 15 }, .i = 14 };
struct D i[2] = { [1].j = (const struct C) { 17 },
[0] = { 0, (struct C) { 16 } } };
+struct C j[2][3] = { [0 ... 1] = { [0 ... 2] = (struct C) { 26 } } };
+struct C k[3][2] = { [0 ... 2][0 ... 1] = (const struct C) { 27 } };
int main (void)
{
@@ -55,5 +57,13 @@ int main (void)
abort ();
if (i[0].i || i[0].j.i != 16 || i[1].i || i[1].j.i != 17)
abort ();
+ if (j[0][0].i != 26 || j[0][1].i != 26 || j[0][2].i != 26)
+ abort ();
+ if (j[1][0].i != 26 || j[1][1].i != 26 || j[1][2].i != 26)
+ abort ();
+ if (k[0][0].i != 27 || k[0][1].i != 27 || k[1][0].i != 27)
+ abort ();
+ if (k[1][1].i != 27 || k[2][0].i != 27 || k[2][1].i != 27)
+ abort ();
exit (0);
}
--- gcc/c-typeck.c.jj Fri Jan 11 14:01:06 2002
+++ gcc/c-typeck.c Mon Jan 14 20:29:40 2002
@@ -6618,7 +6618,14 @@ process_init_element (value)
/* In the case of [LO ... HI] = VALUE, only evaluate VALUE once. */
if (constructor_range_stack)
- value = save_expr (value);
+ {
+ /* If value is a compound literal and we'll be just using its
+ content, don't put it into a SAVE_EXPR. */
+ if (TREE_CODE (value) != COMPOUND_LITERAL_EXPR
+ || !require_constant_value
+ || flag_isoc99)
+ value = save_expr (value);
+ }
while (1)
{
Jakub