diff options
author | Ed Schouten <ed@FreeBSD.org> | 2009-06-02 17:58:47 +0000 |
---|---|---|
committer | Ed Schouten <ed@FreeBSD.org> | 2009-06-02 17:58:47 +0000 |
commit | ec2b103c267a06a66e926f62cd96767b280f5cf5 (patch) | |
tree | ce7d964cbb5e39695b71481698f10cb099c23d4a /test/Sema/transparent-union.c | |
download | src-test2-ec2b103c267a06a66e926f62cd96767b280f5cf5.tar.gz src-test2-ec2b103c267a06a66e926f62cd96767b280f5cf5.zip |
Notes
Diffstat (limited to 'test/Sema/transparent-union.c')
-rw-r--r-- | test/Sema/transparent-union.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/Sema/transparent-union.c b/test/Sema/transparent-union.c new file mode 100644 index 000000000000..90ecaadea6e7 --- /dev/null +++ b/test/Sema/transparent-union.c @@ -0,0 +1,40 @@ +// RUN: clang -fsyntax-only -Xclang -verify %s +typedef union { + int *ip; + float *fp; +} TU __attribute__((transparent_union)); + +void f(TU); + +void g(int *ip, float *fp, char *cp) { + f(ip); + f(fp); + f(cp); // expected-error{{incompatible type}} + f(0); + + TU tu_ip = ip; // expected-error{{incompatible type}} + TU tu; + tu.ip = ip; +} + +/* FIXME: we'd like to just use an "int" here and align it differently + from the normal "int", but if we do so we lose the alignment + information from the typedef within the compiler. */ +typedef struct { int x, y; } __attribute__((aligned(8))) aligned_struct8; + +typedef struct { int x, y; } __attribute__((aligned(4))) aligned_struct4; +typedef union { + aligned_struct4 s4; // expected-note{{alignment of first field}} + aligned_struct8 s8; // expected-warning{{alignment of field}} +} TU1 __attribute__((transparent_union)); + +typedef union { + char c; // expected-note{{size of first field is 8 bits}} + int i; // expected-warning{{size of field}} +} TU2 __attribute__((transparent_union)); + +typedef union { + float f; // expected-warning{{floating}} +} TU3 __attribute__((transparent_union)); + +typedef union { } TU4 __attribute__((transparent_union)); // expected-warning{{field}} |