aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2002-01-15 12:00:43 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2002-01-15 12:00:43 +0100
commit7c94ce7f87a1df87f85723833e6a1707e20233c3 (patch)
tree6de273cd90cd66cf20e3c5dc5136b2f813181125 /gcc
parent9631a0e1170f1396448e7b14935a4cf64a9d2424 (diff)
downloadgcc-7c94ce7f87a1df87f85723833e6a1707e20233c3.zip
gcc-7c94ce7f87a1df87f85723833e6a1707e20233c3.tar.gz
gcc-7c94ce7f87a1df87f85723833e6a1707e20233c3.tar.bz2
c-typeck.c (process_init_element): Don't save_expr COMPOUND_LITERAL_EXPR if just its initializer will be used.
* 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. From-SVN: r48868
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-typeck.c9
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/gnu89-init-1.c10
4 files changed, 27 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e95daea..1629ba9 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2002-01-15 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.
+
2002-01-15 David Edelsohn <edelsohn@gnu.org>
* config/rs6000/rs6000.c (rs6000_output_function_epilogue): Do not
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 2c47698..fad00ab 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -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)
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5a8c11d..4ac978a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2002-01-15 Jakub Jelinek <jakub@redhat.com>
+
+ * gcc.dg/gnu89-init-1.c: Add new tests.
+
2002-01-15 Andreas Jaeger <aj@suse.de>
* gcc.dg/i386-mmx-1.c: Also run on x86-64.
diff --git a/gcc/testsuite/gcc.dg/gnu89-init-1.c b/gcc/testsuite/gcc.dg/gnu89-init-1.c
index 3cabeb4..07bf823 100644
--- a/gcc/testsuite/gcc.dg/gnu89-init-1.c
+++ b/gcc/testsuite/gcc.dg/gnu89-init-1.c
@@ -28,6 +28,8 @@ struct C g[3] = { [2] = (struct C) { 13 }, [1] = (const struct C) { 12 } };
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);
}