aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2015-01-07 08:19:48 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2015-01-07 08:19:48 +0000
commit2cc901dcb29e15e06bfeab82a9834b6254b4ae0f (patch)
treeac7198bcaff351ddad9f6145ef4bf9118f191c97 /gcc/c
parent0e905f0f4656514d9a6f9112581e463ed64fd74b (diff)
downloadgcc-2cc901dcb29e15e06bfeab82a9834b6254b4ae0f.zip
gcc-2cc901dcb29e15e06bfeab82a9834b6254b4ae0f.tar.gz
gcc-2cc901dcb29e15e06bfeab82a9834b6254b4ae0f.tar.bz2
re PR c/64417 ([SH] FAIL: gcc.c-torture/compile/pr28865.c -O0 (test for excess errors))
PR c/64417 c/ * c-typeck.c (process_init_element): Disallow initialization of a flexible array member with a string constant if the structure is in an array. testsuite/ * gcc.c-torture/compile/pr28865.c: Add dg-errors. * gcc.dg/pr64417.c: New test. From-SVN: r219278
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog7
-rw-r--r--gcc/c/c-typeck.c27
2 files changed, 34 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index d6b2289..357d2c4 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,10 @@
+2015-01-07 Marek Polacek <polacek@redhat.com>
+
+ PR c/64417
+ * c-typeck.c (process_init_element): Disallow initialization of
+ a flexible array member with a string constant if the structure
+ is in an array.
+
2015-01-05 Jakub Jelinek <jakub@redhat.com>
PR sanitizer/64344
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 0db43cc..38ba9b8 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -8809,6 +8809,33 @@ process_init_element (location_t loc, struct c_expr value, bool implicit,
break;
}
+ /* Error for initialization of a flexible array member with
+ a string constant if the structure is in an array. E.g.:
+ struct S { int x; char y[]; };
+ struct S s[] = { { 1, "foo" } };
+ is invalid. */
+ if (string_flag
+ && fieldcode == ARRAY_TYPE
+ && constructor_depth > 1
+ && TYPE_SIZE (fieldtype) == NULL_TREE
+ && DECL_CHAIN (constructor_fields) == NULL_TREE)
+ {
+ bool in_array_p = false;
+ for (struct constructor_stack *p = constructor_stack;
+ p && p->type; p = p->next)
+ if (TREE_CODE (p->type) == ARRAY_TYPE)
+ {
+ in_array_p = true;
+ break;
+ }
+ if (in_array_p)
+ {
+ error_init (loc, "initialization of flexible array "
+ "member in a nested context");
+ break;
+ }
+ }
+
/* Accept a string constant to initialize a subarray. */
if (value.value != 0
&& fieldcode == ARRAY_TYPE