diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-01-28 21:54:33 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-01-28 21:54:33 +0000 |
commit | 347f7eabb9ae43482f04855cde43f9d164b7b6f0 (patch) | |
tree | b167e4bf7fc08a2d9c09efd46cb7775daed2b521 /clang/test/Sema/designated-initializers.c | |
parent | c78320960513fe9f193104cbb07b0a5711c81ee0 (diff) | |
download | bcm5719-llvm-347f7eabb9ae43482f04855cde43f9d164b7b6f0.tar.gz bcm5719-llvm-347f7eabb9ae43482f04855cde43f9d164b7b6f0.zip |
Code generation support for C99 designated initializers.
The approach I've taken in this patch is relatively straightforward,
although the code itself is non-trivial. Essentially, as we process
an initializer list we build up a fully-explicit representation of the
initializer list, where each of the subobject initializations occurs
in order. Designators serve to "fill in" subobject initializations in
a non-linear way. The fully-explicit representation makes initializer
lists (both with and without designators) easy to grok for codegen and
later semantic analyses. We keep the syntactic form of the initializer
list linked into the AST for those clients interested in exactly what
the user wrote.
Known limitations:
- Designating a member of a union that isn't the first member may
result in bogus initialization (we warn about this)
- GNU array-range designators are not supported (we warn about this)
llvm-svn: 63242
Diffstat (limited to 'clang/test/Sema/designated-initializers.c')
-rw-r--r-- | clang/test/Sema/designated-initializers.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/clang/test/Sema/designated-initializers.c b/clang/test/Sema/designated-initializers.c index fd4873193cf..c9a0aa7f05b 100644 --- a/clang/test/Sema/designated-initializers.c +++ b/clang/test/Sema/designated-initializers.c @@ -18,7 +18,8 @@ int iarray2[10] = { }; int iarray3[10] = { - [5 ... 12] = 2 // expected-error{{array designator index (12) exceeds array bounds (10)}} + [5 ... 12] = 2 // expected-error{{array designator index (12) exceeds array bounds (10)}}\ + // expected-warning{{GNU array-range designator extension is unsupported}} }; struct point { @@ -44,8 +45,8 @@ struct point array[10] = { struct point array2[10] = { [10].x = 2.0, // expected-error{{array designator index (10) exceeds array bounds (10)}} - [4 ... 5].y = 2.0, - [4 ... 6] = { .x = 3, .y = 4.0 } + [4 ... 5].y = 2.0, // expected-warning{{GNU array-range designator extension is unsupported}} + [4 ... 6] = { .x = 3, .y = 4.0 } // expected-warning{{GNU array-range designator extension is unsupported}} }; struct point array3[10] = { @@ -116,4 +117,25 @@ struct disklabel_ops disklabel64_ops = { // PR clang/3378 int bitwidth[] = { [(long long int)1] = 5, [(short int)2] = 2 }; int a[]= { [sizeof(int)] = 0 }; -int a2[]= { [0 ... sizeof(int)] = 0 }; +int a2[]= { [0 ... sizeof(int)] = 0 }; // expected-warning{{GNU array-range designator extension is unsupported}} + +// Test warnings about initializers overriding previous initializers +struct X { + int a, b, c; +}; + +int counter = 0; +int get8() { ++counter; return 8; } + +void test() { + struct X xs[] = { + [0] = (struct X){1, 2}, // expected-note{{previous initialization is here}} + [0].c = 3, // expected-warning{{subobject initialization overrides initialization of other fields within its enclosing subobject}} + (struct X) {4, 5, 6}, // expected-note{{previous initialization is here}} + [1].b = get8(), // expected-warning{{subobject initialization overrides initialization of other fields within its enclosing subobject}} + [0].b = 8 + }; +} + +// FIXME: we need to +union { char c; long l; } u1 = { .l = 0xFFFF }; // expected-warning{{designated initialization of union member is broken}} |