This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR c/9799
- From: Eric Botcazou <ebotcazou at libertysurf dot fr>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 22 Feb 2003 22:09:57 +0100
- Subject: [PATCH] Fix PR c/9799
Hi,
I don't know if this is technically a regression, because gcc 2.95.3 doesn't
support flexible array members, but at least it doesn't SIGSEGV on the
testcase like all versions since 3.0 .
The sanity check is sufficient to let the compiler emits proper warnings
without crashing:
pr9799.c:11: warning: excess elements in struct initializer
pr9799.c:11: warning: (near initialization for `s2_array[0]')
pr9799.c:12: warning: excess elements in struct initializer
pr9799.c:12: warning: (near initialization for `s2_array[1]')
pr9799.c:13: warning: excess elements in struct initializer
pr9799.c:13: warning: (near initialization for `s2_array[2]')
Compiled on i586-redhat-linux-gnu. Ok everywhere?
--
Eric Botcazou
2003-02-22 Eric Botcazou <ebotcazou at libertysurf dot fr>
PR c/9799
* c-typeck.c (push_init_level): Add sanity check.
2003-02-22 Eric Botcazou <ebotcazou at libertysurf dot fr>
* gcc.c-torture/compile/20030222-1.c
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.213.2.2
diff -u -p -r1.213.2.2 c-typeck.c
--- c-typeck.c 9 Jan 2003 12:11:34 -0000 1.213.2.2
+++ c-typeck.c 22 Feb 2003 20:57:23 -0000
@@ -5266,6 +5266,7 @@ push_init_level (implicit)
&& constructor_fields == 0)
process_init_element (pop_init_level (1));
else if (TREE_CODE (constructor_type) == ARRAY_TYPE
+ && constructor_max_index
&& tree_int_cst_lt (constructor_max_index, constructor_index))
process_init_element (pop_init_level (1));
else
typedef struct {
int aaa;
} s1_t;
typedef struct {
int bbb;
s1_t s1_array[];
} s2_t;
static s2_t s2_array[]= {
{ 1, 4 },
{ 2, 5 },
{ 3, 6 }
};