diff options
author | Matthew Curtis <mcurtis@codeaurora.org> | 2013-10-03 12:14:24 +0000 |
---|---|---|
committer | Matthew Curtis <mcurtis@codeaurora.org> | 2013-10-03 12:14:24 +0000 |
commit | 274a9cc84bcfaec3f3a3ef99a4c55587edbf8645 (patch) | |
tree | 0e7cf30387293bd7faa500989f505d88e6050c73 /clang/test/Sema/designated-initializers.c | |
parent | 85aeffaf5c20a068dbadcfa22f6c3ae922a0085e (diff) | |
download | bcm5719-llvm-274a9cc84bcfaec3f3a3ef99a4c55587edbf8645.tar.gz bcm5719-llvm-274a9cc84bcfaec3f3a3ef99a4c55587edbf8645.zip |
Gracefully (and correctly) handle init of multiple union members
We now emit warnings when doing so and code generation is consistent
with GCC. Note that the C99 spec is unclear as to the precise
behavior.
See also ...
Bug:
http://llvm.org/bugs/show_bug.cgi?id=16644 and
cfe-dev discussion:
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-September/031918.html
llvm-svn: 191890
Diffstat (limited to 'clang/test/Sema/designated-initializers.c')
-rw-r--r-- | clang/test/Sema/designated-initializers.c | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/clang/test/Sema/designated-initializers.c b/clang/test/Sema/designated-initializers.c index 36fa559f6f3..6630da67c5b 100644 --- a/clang/test/Sema/designated-initializers.c +++ b/clang/test/Sema/designated-initializers.c @@ -137,7 +137,6 @@ void test() { }; } -// FIXME: How do we test that this initializes the long properly? union { char c; long l; } u1 = { .l = 0xFFFF }; extern float global_float; @@ -223,6 +222,55 @@ struct Enigma enigma = { }; +/// PR16644 +typedef union { + struct { + int zero; + int one; + int two; + int three; + } a; + int b[4]; +} union_16644_t; + +union_16644_t union_16644_instance_0 = +{ + .b[0] = 0, // expected-note{{previous}} + .a.one = 1, // expected-warning{{overrides}} expected-note{{previous}} + .b[2] = 2, // expected-warning{{overrides}} expected-note{{previous}} + .a.three = 3, // expected-warning{{overrides}} +}; + +union_16644_t union_16644_instance_1 = +{ + .a.three = 13, // expected-note{{previous}} + .b[2] = 12, // expected-warning{{overrides}} expected-note{{previous}} + .a.one = 11, // expected-warning{{overrides}} expected-note{{previous}} + .b[0] = 10, // expected-warning{{overrides}} +}; + +union_16644_t union_16644_instance_2 = +{ + .a.one = 21, // expected-note{{previous}} + .b[1] = 20, // expected-warning{{overrides}} +}; + +union_16644_t union_16644_instance_3 = +{ + .b[1] = 30, // expected-note{{previous}} + .a = { // expected-warning{{overrides}} + .one = 31 + } +}; + +union_16644_t union_16644_instance_4[2] = +{ + [0].a.one = 2, + [1].a.zero = 3,// expected-note{{previous}} + [0].a.zero = 5, + [1].b[1] = 4 // expected-warning{{overrides}} +}; + /// PR4073 /// Should use evaluate to fold aggressively and emit a warning if not an ice. extern int crazy_x; |