aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2002-07-22 12:11:16 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2002-07-22 12:11:16 +0200
commitcf3c4f5609b982b1e640f5ac5a51b07711ec29de (patch)
tree3ea4f8ebfcd8cea35de19665d6ffa3cbdf453ef4
parent9f8da5fad69532eca570bb5420c23fbe41e4dc4d (diff)
downloadgcc-cf3c4f5609b982b1e640f5ac5a51b07711ec29de.zip
gcc-cf3c4f5609b982b1e640f5ac5a51b07711ec29de.tar.gz
gcc-cf3c4f5609b982b1e640f5ac5a51b07711ec29de.tar.bz2
c-decl.c (build_compound_literal): Defer compound literal decls until until file end to emit them only if...
* c-decl.c (build_compound_literal): Defer compound literal decls until until file end to emit them only if they are actually used. * gcc.dg/gnu89-init-2.c: New test. From-SVN: r55645
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-decl.c16
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/gnu89-init-2.c25
4 files changed, 45 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index cfd9e50..44bf4e1 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2002-07-22 Jakub Jelinek <jakub@redhat.com>
+
+ * c-decl.c (build_compound_literal): Defer compound literal decls
+ until until file end to emit them only if they are actually used.
+
2002-07-21 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* ra-build.c (check_conflict_numbers): Hide unused function.
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index c6e592a..57af611 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -3669,12 +3669,18 @@ build_compound_literal (type, init)
if (TREE_STATIC (decl))
{
/* This decl needs a name for the assembler output. We also need
- a unique suffix to be added to the name, for which DECL_CONTEXT
- must be set. */
- DECL_NAME (decl) = get_identifier ("__compound_literal");
- DECL_CONTEXT (decl) = complit;
+ a unique suffix to be added to the name. */
+ char *name;
+ extern int var_labelno;
+
+ ASM_FORMAT_PRIVATE_NAME (name, "__compound_literal", var_labelno);
+ var_labelno++;
+ DECL_NAME (decl) = get_identifier (name);
+ DECL_DEFER_OUTPUT (decl) = 1;
+ DECL_COMDAT (decl) = 1;
+ DECL_ARTIFICIAL (decl) = 1;
+ pushdecl (decl);
rest_of_decl_compilation (decl, NULL, 1, 0);
- DECL_CONTEXT (decl) = NULL_TREE;
}
return complit;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index bf8976f..37d9e47 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2002-07-22 Jakub Jelinek <jakub@redhat.com>
+
+ * gcc.dg/gnu89-init-2.c: New test.
+
2002-07-21 Gabriel Dos Reis <gdr@nerim.net>
* gcc.dg/c90-arraydecl-1.c: Change C89 too C90.
diff --git a/gcc/testsuite/gcc.dg/gnu89-init-2.c b/gcc/testsuite/gcc.dg/gnu89-init-2.c
new file mode 100644
index 0000000..ce966ec
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gnu89-init-2.c
@@ -0,0 +1,25 @@
+/* Test whether __compound_literal.* objects are not emitted unless
+ they are actually needed. */
+/* Origin: Jakub Jelinek <jakub@redhat.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu89 -O2" } */
+/* { dg-final { scan-assembler-not "__compound_literal" } } */
+
+struct A { int i; int j; int k[4]; };
+struct B { };
+struct C { int i; };
+struct D { int i; struct C j; };
+
+struct A a = (struct A) { .j = 6, .k[2] = 12 };
+struct B b = (struct B) { };
+int c[] = (int []) { [2] = 6, 7, 8 };
+int d[] = (int [3]) { 1 };
+int e[2] = (int []) { 1, 2 };
+int f[2] = (int [2]) { 1 };
+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 } } };
+static const int *j = 1 ? (const int *) 0 : & (const int) { 26 };
+int k = (int) sizeof ((int [6]) { 1, 2, 3, 4, 5, 6 }) + 4;
+int l = (int) sizeof ((struct C) { 16 });