c-typeck.c (store_init_value): Don't require constant initializer elements with -pedantic -std=c99.
* c-typeck.c (store_init_value): Don't require constant initializer elements with -pedantic -std=c99. (digest_init): Change error about non-constant initializer elements into pedwarn. (constructor_range_end): Remove. (constructor_incremental, designator_depth, designator_errorneous): New variables. (struct constructor_stack): Remove range_end, add incremental. (struct constructor_range_stack, constructor_range_stack): New. (struct initializer_stack): Add constructor_range_stack. (finish_init): Set it. (start_init): Likewise. require_constant_elements for non-static trees only if not flag_isoc99. (really_start_incremental_init): Remove constructor_range_end, add constructor_incremental. (pop_init_level): Likewise. (push_init_level): Likewise. If implicit and the subobject had some value set already, preinitialize the level with it. Warn about missing braces only if not pushing due to designators. (set_designator, push_range_stack): New functions. (set_init_label): Use them. (set_init_index): Likewise. Remove constructor_range_end. Error if designator index is outside of array bounds. (add_pending_init): Compare values of purpose index trees, not the trees themselves. Allow overwriting of already initialized element. Issue a warning if it had side-effects. (set_nonincremental_init, set_nonincremental_init_from_string): New functions. (pending_init_member): Rename to... (find_init_member): ...this function. Call set_nonincremental_init if necessary. Compare values of purpose index trees, not the trees themselves. Return the actual value, not just non-zero if something is found. (output_init_element): Remove checks for duplicates. If field has zero size, only check the initializer for correctness. Call set_nonincremental_init if necessary. Push RECORD/ARRAY into AVL if constructor_incremental is zero. Change error about initializers not computable at load time into pedwarn. (output_pending_init_elements): Compare bit positions, not FIELD_DECLs to take into account zero-sized fields. (process_init_element): Use constructor_range_stack to fill all ranges in the designator lists from current level up. * extend.texi: Update documentation for labeled elements. * gcc.c-torture/execute/20000801-3.x: Remove. * gcc.dg/c90-init-1.c: New test. * gcc.dg/c99-init-1.c: New test. * gcc.dg/c99-init-2.c: New test. * gcc.dg/gnu99-init-1.c: New test. From-SVN: r38968
This commit is contained in:
parent
fafc249b1b
commit
8b6a5902b5
@ -1,3 +1,49 @@
|
||||
2001-01-12 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
* c-typeck.c (store_init_value): Don't require constant initializer
|
||||
elements with -pedantic -std=c99.
|
||||
(digest_init): Change error about non-constant initializer elements
|
||||
into pedwarn.
|
||||
(constructor_range_end): Remove.
|
||||
(constructor_incremental, designator_depth,
|
||||
designator_errorneous): New variables.
|
||||
(struct constructor_stack): Remove range_end, add incremental.
|
||||
(struct constructor_range_stack, constructor_range_stack): New.
|
||||
(struct initializer_stack): Add constructor_range_stack.
|
||||
(finish_init): Set it.
|
||||
(start_init): Likewise. require_constant_elements for non-static
|
||||
trees only if not flag_isoc99.
|
||||
(really_start_incremental_init): Remove constructor_range_end, add
|
||||
constructor_incremental.
|
||||
(pop_init_level): Likewise.
|
||||
(push_init_level): Likewise. If implicit and the subobject had some
|
||||
value set already, preinitialize the level with it.
|
||||
Warn about missing braces only if not pushing due to designators.
|
||||
(set_designator, push_range_stack): New functions.
|
||||
(set_init_label): Use them.
|
||||
(set_init_index): Likewise. Remove constructor_range_end.
|
||||
Error if designator index is outside of array bounds.
|
||||
(add_pending_init): Compare values of purpose index trees, not the
|
||||
trees themselves. Allow overwriting of already initialized element.
|
||||
Issue a warning if it had side-effects.
|
||||
(set_nonincremental_init, set_nonincremental_init_from_string): New
|
||||
functions.
|
||||
(pending_init_member): Rename to...
|
||||
(find_init_member): ...this function. Call set_nonincremental_init
|
||||
if necessary. Compare values of purpose index trees, not the trees
|
||||
themselves. Return the actual value, not just non-zero if something
|
||||
is found.
|
||||
(output_init_element): Remove checks for duplicates.
|
||||
If field has zero size, only check the initializer for correctness.
|
||||
Call set_nonincremental_init if necessary. Push RECORD/ARRAY into AVL
|
||||
if constructor_incremental is zero. Change error about initializers
|
||||
not computable at load time into pedwarn.
|
||||
(output_pending_init_elements): Compare bit positions, not
|
||||
FIELD_DECLs to take into account zero-sized fields.
|
||||
(process_init_element): Use constructor_range_stack to fill all
|
||||
ranges in the designator lists from current level up.
|
||||
* extend.texi: Update documentation for labeled elements.
|
||||
|
||||
2001-01-12 Alexandre Oliva <aoliva@redhat.com>
|
||||
|
||||
* calls.c (emit_library_call_value_1): Add USEs and CLOBBERs
|
||||
|
804
gcc/c-typeck.c
804
gcc/c-typeck.c
File diff suppressed because it is too large
Load Diff
@ -1260,6 +1260,10 @@ extension. For example,
|
||||
int widths[] = @{ [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 @};
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
If the value in it has side-effects, the side-effects will happen only once,
|
||||
not for each initialized field by the range initializer.
|
||||
|
||||
@noindent
|
||||
Note that the length of the array is the highest value specified
|
||||
plus one.
|
||||
@ -1345,6 +1349,12 @@ example, with the @samp{struct point} declaration above:
|
||||
struct point ptarray[10] = @{ [2].y = yv2, [2].x = xv2, [0].x = xv0 @};
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
If the same field is initialized multiple times, it will have value from
|
||||
the last initialization. If any such overridden initialization has
|
||||
side-effect, it is unspecified whether the side-effect happens or not.
|
||||
Currently, gcc will discard them and issue a warning.
|
||||
|
||||
@node Case Ranges
|
||||
@section Case Ranges
|
||||
@cindex case ranges
|
||||
|
@ -1,3 +1,11 @@
|
||||
2001-01-12 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
* gcc.c-torture/execute/20000801-3.x: Remove.
|
||||
* gcc.dg/c90-init-1.c: New test.
|
||||
* gcc.dg/c99-init-1.c: New test.
|
||||
* gcc.dg/c99-init-2.c: New test.
|
||||
* gcc.dg/gnu99-init-1.c: New test.
|
||||
|
||||
2001-01-12 Richard Earnshaw <rearnsha@arm.com>
|
||||
|
||||
* lib/f-torture.exp (f_torture_compile): Prune the warnings before
|
||||
|
@ -1,2 +0,0 @@
|
||||
set torture_execute_xfail "*-*-*"
|
||||
return 0
|
25
gcc/testsuite/gcc.dg/c90-init-1.c
Normal file
25
gcc/testsuite/gcc.dg/c90-init-1.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* Test for C99 designated initializers */
|
||||
/* Origin: Jakub Jelinek <jakub@redhat.com> */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-std=iso9899:1990 -pedantic-errors" } */
|
||||
|
||||
struct A {
|
||||
int B;
|
||||
short C[2];
|
||||
};
|
||||
int a[10] = { 10, [4] = 15 }; /* { dg-error "ISO C89 forbids specifying subobject to initialize" } */
|
||||
struct A b = { .B = 2 }; /* { dg-error "ISO C89 forbids specifying subobject to initialize" } */
|
||||
struct A c[] = { [3].C[1] = 1 }; /* { dg-error "ISO C89 forbids specifying subobject to initialize" } */
|
||||
struct A d[] = { [4 ... 6].C[0 ... 1] = 2 }; /* { dg-error "(forbids specifying range of elements to initialize)|(ISO C89 forbids specifying subobject to initialize)" } */
|
||||
int e[] = { [2] 2 }; /* { dg-error "use of designated initializer without" } */
|
||||
struct A f = { C: { 0, 1 } }; /* { dg-error "use of designated initializer with " } */
|
||||
int g;
|
||||
|
||||
void foo (int *);
|
||||
|
||||
void bar (void)
|
||||
{
|
||||
int x[] = { g++, 2 }; /* { dg-error "is not computable at load time" } */
|
||||
|
||||
foo (x);
|
||||
}
|
78
gcc/testsuite/gcc.dg/c99-init-1.c
Normal file
78
gcc/testsuite/gcc.dg/c99-init-1.c
Normal file
@ -0,0 +1,78 @@
|
||||
/* Test for C99 designated initializers */
|
||||
/* Origin: Jakub Jelinek <jakub@redhat.com> */
|
||||
/* { dg-do run } */
|
||||
/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
|
||||
|
||||
typedef __SIZE_TYPE__ size_t;
|
||||
typedef __WCHAR_TYPE__ wchar_t;
|
||||
extern int memcmp (const void *, const void *, size_t);
|
||||
extern void abort (void);
|
||||
extern void exit (int);
|
||||
|
||||
int a[10] = { 10, 0, 12, 13, 14, 0, 0, 17, 0, 0 };
|
||||
int b[10] = { 10, [4] = 15, [2] = 12, [4] = 14, [7] = 17 };
|
||||
int c[10] = { 10, [4] = 15, [2] = 12, [3] = 13, 14, [7] = 17 };
|
||||
struct A {
|
||||
int B;
|
||||
short C[2];
|
||||
};
|
||||
struct A d[] = { { 0, { 1, 2 } }, { 0, { 0, 0 } }, { 10, { 11, 12 } } };
|
||||
struct A e[] = { 0, 1, 2, [2] = 10, 11, 12 };
|
||||
struct A f[] = { 0, 1, 2, [2].C = 11, 12, 13 };
|
||||
struct A g[] = { 0, 1, 2, [2].C[1] = 12, 13, 14 };
|
||||
struct A h[] = { 0, 1, 2, [2] = { .C[1] = 12 }, 13, 14 };
|
||||
struct A i[] = { 0, 1, 2, [2] = { .C = { [1] = 12 } }, 13, 14 };
|
||||
union D {
|
||||
int E;
|
||||
double F;
|
||||
struct A G;
|
||||
};
|
||||
union D j[] = { [4] = 1, [4].F = 1.0, [1].G.C[1] = 4 };
|
||||
struct H {
|
||||
char I[6];
|
||||
int J;
|
||||
} k[] = { { { "foo" }, 1 }, [0].I[0] = 'b' };
|
||||
struct K {
|
||||
wchar_t L[6];
|
||||
int M;
|
||||
} l[] = { { { L"foo" }, 1 }, [0].L[2] = L'x', [0].L[4] = L'y' };
|
||||
struct H m[] = { { { "foo" }, 1 }, [0] = { .I[0] = 'b' } };
|
||||
struct H n[] = { { { "foo" }, 1 }, [0].I = { "a" }, [0].J = 2 };
|
||||
int o = { 22 };
|
||||
|
||||
int main (void)
|
||||
{
|
||||
if (b[3])
|
||||
abort ();
|
||||
b[3] = 13;
|
||||
if (memcmp (a, b, sizeof (a)) || memcmp (a, c, sizeof (a)))
|
||||
abort ();
|
||||
if (memcmp (d, e, sizeof (d)) || sizeof (d) != sizeof (e))
|
||||
abort ();
|
||||
if (f[2].B != 0 || g[2].B != 0 || g[2].C[0] != 0)
|
||||
abort ();
|
||||
if (memcmp (g, h, sizeof (g)) || memcmp (g, i, sizeof (g)))
|
||||
abort ();
|
||||
f[2].B = 10;
|
||||
g[2].B = 10;
|
||||
g[2].C[0] = 11;
|
||||
if (memcmp (d, f, sizeof (d)) || memcmp (d, g, sizeof (d)))
|
||||
abort ();
|
||||
if (f[3].B != 13 || g[3].B != 13 || g[3].C[0] != 14)
|
||||
abort ();
|
||||
if (j[0].E || j[1].G.B || j[1].G.C[0] || j[1].G.C[1] != 4)
|
||||
abort ();
|
||||
if (j[2].E || j[3].E || j[4].F != 1.0)
|
||||
abort ();
|
||||
if (memcmp (k[0].I, "boo\0\0", 6) || k[0].J != 1)
|
||||
abort ();
|
||||
if (memcmp (l[0].L, L"fox\0y", 6 * sizeof(wchar_t)) || l[0].M != 1)
|
||||
abort ();
|
||||
if (memcmp (m[0].I, "b\0\0\0\0", 6) || m[0].J)
|
||||
abort ();
|
||||
if (memcmp (n[0].I, "a\0\0\0\0", 6) || n[0].J != 2)
|
||||
abort ();
|
||||
if (o != 22)
|
||||
abort ();
|
||||
exit (0);
|
||||
}
|
30
gcc/testsuite/gcc.dg/c99-init-2.c
Normal file
30
gcc/testsuite/gcc.dg/c99-init-2.c
Normal file
@ -0,0 +1,30 @@
|
||||
/* Test for C99 designated initializer warnings and errors */
|
||||
/* Origin: Jakub Jelinek <jakub@redhat.com> */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-std=iso9899:1999 -Wall -pedantic-errors" } */
|
||||
|
||||
typedef struct {
|
||||
int B;
|
||||
short C[2];
|
||||
} A;
|
||||
A a = { [2] = 1 }; /* { dg-error "(array index in non-array)|(near initialization)" } */
|
||||
int b[] = { .B = 1 }; /* { dg-error "(field name not in record)|(near initialization)" } */
|
||||
A c[] = { [0].D = 1 }; /* { dg-error "unknown field" } */
|
||||
int d;
|
||||
int e = { d++ }; /* { dg-error "(is not constant)|(near initialization)" } */
|
||||
A f[2] = { [0].C[0] = 1, [2] = { 2, { 1, 2 } } };/* { dg-error "(array index in initializer exceeds array bounds)|(near initialization)" } */
|
||||
int g[4] = { [1] = 1, 2, [6] = 5 }; /* { dg-error "(array index in initializer exceeds array bounds)|(near initialization)" } */
|
||||
int h[] = { [0 ... 3] = 5 }; /* { dg-error "forbids specifying range of elements" } */
|
||||
int i[] = { [2] 4 }; /* { dg-error "use of designated initializer without" } */
|
||||
A j = { B: 2 }; /* { dg-error "use of designated initializer with " } */
|
||||
|
||||
void foo (int *, A *);
|
||||
|
||||
void bar (void)
|
||||
{
|
||||
int a[] = { d++, [0] = 1 }; /* { dg-warning "(initialized field with side-effects overwritten)|(near initialization)" } */
|
||||
A b = { 1, { d++, 2 }, .C[0] = 3 };/* { dg-warning "(initialized field with side-effects overwritten)|(near initialization)" } */
|
||||
A c = { d++, { 2, 3 }, .B = 4 }; /* { dg-warning "(initialized field with side-effects overwritten)|(near initialization)" } */
|
||||
|
||||
foo (a, d ? &b : &c);
|
||||
}
|
62
gcc/testsuite/gcc.dg/gnu99-init-1.c
Normal file
62
gcc/testsuite/gcc.dg/gnu99-init-1.c
Normal file
@ -0,0 +1,62 @@
|
||||
/* Test for GNU extensions to C99 designated initializers */
|
||||
/* Origin: Jakub Jelinek <jakub@redhat.com> */
|
||||
/* { dg-do run } */
|
||||
/* { dg-options "-std=gnu99" } */
|
||||
|
||||
typedef __SIZE_TYPE__ size_t;
|
||||
extern int memcmp (const void *, const void *, size_t);
|
||||
extern void abort (void);
|
||||
extern void exit (int);
|
||||
|
||||
int a[][2][4] = { [2 ... 4][0 ... 1][2 ... 3] = 1, [2] = 2, [2][0][2] = 3 };
|
||||
struct E {};
|
||||
struct F { struct E H; };
|
||||
struct G { int I; struct E J; int K; };
|
||||
struct H { int I; struct F J; int K; };
|
||||
struct G k = { .J = {}, 1 };
|
||||
struct H l = { .J.H = {}, 2 };
|
||||
struct H m = { .J = {}, 3 };
|
||||
struct I { int J; int K[3]; int L; };
|
||||
struct M { int N; struct I O[3]; int P; };
|
||||
struct M n[] = { [0 ... 5].O[1 ... 2].K[0 ... 1] = 4, 5, 6, 7 };
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int x, y, z;
|
||||
|
||||
if (a[2][0][0] != 2 || a[2][0][2] != 3)
|
||||
abort ();
|
||||
a[2][0][0] = 0;
|
||||
a[2][0][2] = 1;
|
||||
for (x = 0; x <= 4; x++)
|
||||
for (y = 0; y <= 1; y++)
|
||||
for (z = 0; z <= 3; z++)
|
||||
if (a[x][y][z] != (x >= 2 && z >= 2))
|
||||
abort ();
|
||||
if (k.I || l.I || m.I || k.K != 1 || l.K != 2 || m.K != 3)
|
||||
abort ();
|
||||
for (x = 0; x <= 5; x++)
|
||||
{
|
||||
if (n[x].N || n[x].O[0].J || n[x].O[0].L)
|
||||
abort ();
|
||||
for (y = 0; y <= 2; y++)
|
||||
if (n[x].O[0].K[y])
|
||||
abort ();
|
||||
for (y = 1; y <= 2; y++)
|
||||
{
|
||||
if (n[x].O[y].J)
|
||||
abort ();
|
||||
if (n[x].O[y].K[0] != 4)
|
||||
abort ();
|
||||
if (n[x].O[y].K[1] != 4)
|
||||
abort ();
|
||||
if ((x < 5 || y < 2) && (n[x].O[y].K[2] || n[x].O[y].L))
|
||||
abort ();
|
||||
}
|
||||
if (x < 5 && n[x].P)
|
||||
abort ();
|
||||
}
|
||||
if (n[5].O[2].K[2] != 5 || n[5].O[2].L != 6 || n[5].P != 7)
|
||||
abort ();
|
||||
exit (0);
|
||||
}
|
Loading…
Reference in New Issue
Block a user