aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2014-10-17 21:02:54 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2014-10-17 21:02:54 +0000
commit7278465e24b3d5a399ae2474f12870a91ba6af62 (patch)
treee31df103a9c2a703683c07fab2d8a2abd2dc0a27
parentd83fa499b9895618ae8f63c004f3090b71d488ae (diff)
downloadgcc-7278465e24b3d5a399ae2474f12870a91ba6af62.zip
gcc-7278465e24b3d5a399ae2474f12870a91ba6af62.tar.gz
gcc-7278465e24b3d5a399ae2474f12870a91ba6af62.tar.bz2
re PR c/63567 (Linux kernel build error due to non-static initializers)
PR c/63567 * c-typeck.c (digest_init): Allow initializing objects with static storage duration with compound literals even in C99 and add pedwarn for it. * gcc.dg/pr61096-1.c: Change dg-error into dg-warning. * gcc.dg/pr63567-1.c: New test. * gcc.dg/pr63567-2.c: New test. From-SVN: r216416
-rw-r--r--gcc/c/ChangeLog7
-rw-r--r--gcc/c/c-typeck.c4
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.dg/pr61096-1.c2
-rw-r--r--gcc/testsuite/gcc.dg/pr63567-1.c10
-rw-r--r--gcc/testsuite/gcc.dg/pr63567-2.c10
6 files changed, 38 insertions, 2 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 294b4ef..35b8dcd 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,5 +1,12 @@
2014-10-17 Marek Polacek <polacek@redhat.com>
+ PR c/63567
+ * c-typeck.c (digest_init): Allow initializing objects with static
+ storage duration with compound literals even in C99 and add pedwarn
+ for it.
+
+2014-10-17 Marek Polacek <polacek@redhat.com>
+
PR c/63543
* c-tree.h (C_TYPE_ERROR_REPORTED): Define.
* c-typeck.c (build_indirect_ref): Don't print the "dereferencing..."
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 324736a..0dd3366 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -6683,13 +6683,15 @@ digest_init (location_t init_loc, tree type, tree init, tree origtype,
inside_init = convert (type, inside_init);
if (require_constant
- && (code == VECTOR_TYPE || !flag_isoc99)
&& TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
{
/* As an extension, allow initializing objects with static storage
duration with compound literals (which are then treated just as
the brace enclosed list they contain). Also allow this for
vectors, as we can only assign them with compound literals. */
+ if (flag_isoc99 && code != VECTOR_TYPE)
+ pedwarn_init (init_loc, OPT_Wpedantic, "initializer element "
+ "is not constant");
tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
inside_init = DECL_INITIAL (decl);
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 29ed3e6..ea14847 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,12 @@
2014-10-17 Marek Polacek <polacek@redhat.com>
+ PR c/63567
+ * gcc.dg/pr61096-1.c: Change dg-error into dg-warning.
+ * gcc.dg/pr63567-1.c: New test.
+ * gcc.dg/pr63567-2.c: New test.
+
+2014-10-17 Marek Polacek <polacek@redhat.com>
+
PR c/63543
* gcc.dg/pr63543.c: New test.
* gcc.dg/array-8.c: Remove dg-error.
diff --git a/gcc/testsuite/gcc.dg/pr61096-1.c b/gcc/testsuite/gcc.dg/pr61096-1.c
index 3f7d60c..fa8932f 100644
--- a/gcc/testsuite/gcc.dg/pr61096-1.c
+++ b/gcc/testsuite/gcc.dg/pr61096-1.c
@@ -23,7 +23,7 @@ char w1[] = L"foo"; /* { dg-error "13:char-array initialized from wide string" }
__WCHAR_TYPE__ w2[] = "foo"; /* { dg-error "23:wide character array initialized from non-wide string" } */
__WCHAR_TYPE__ w3[] = U"foo"; /* { dg-error "23:wide character array initialized from incompatible wide string" } */
schar a1[] = "foo"; /* { dg-error "14:array of inappropriate type initialized from string constant" } */
-int a2[] = (int[]) { 1 }; /* { dg-error "12:array initialized from non-constant array expression" } */
+int a2[] = (int[]) { 1 }; /* { dg-warning "12:initializer element is not constant" } */
int a3 = e; /* { dg-error "10:initializer element is not constant" } */
int a4 = (e, 1); /* { dg-error "10:initializer element is not constant" } */
diff --git a/gcc/testsuite/gcc.dg/pr63567-1.c b/gcc/testsuite/gcc.dg/pr63567-1.c
new file mode 100644
index 0000000..97da171
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr63567-1.c
@@ -0,0 +1,10 @@
+/* PR c/63567 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+/* Allow initializing objects with static storage duration with
+ compound literals even. This is being used in Linux kernel. */
+
+struct T { int i; };
+struct S { struct T t; };
+static struct S s = (struct S) { .t = { 42 } };
diff --git a/gcc/testsuite/gcc.dg/pr63567-2.c b/gcc/testsuite/gcc.dg/pr63567-2.c
new file mode 100644
index 0000000..5ea2b37
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr63567-2.c
@@ -0,0 +1,10 @@
+/* PR c/63567 */
+/* { dg-do compile } */
+/* { dg-options "-pedantic" } */
+
+/* Allow initializing objects with static storage duration with
+ compound literals. This is being used in Linux kernel. */
+
+struct T { int i; };
+struct S { struct T t; };
+static struct S s = (struct S) { .t = { 42 } }; /* { dg-warning "initializer element is not constant" } */