diff options
author | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
---|---|---|
committer | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
commit | be1de4be954c80875ad4108e0a33e8e131b2f2c0 (patch) | |
tree | 1fbbecf276bf7c7bdcbb4dd446099d6d90eaa516 /clang/test/Sema/transparent-union.c | |
parent | c4626a62754862d20b41e8a46a3574264ea80e6d (diff) | |
parent | f1bd2e48c5324d3f7cda4090c87f8a5b6f463ce2 (diff) |
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Diffstat (limited to 'clang/test/Sema/transparent-union.c')
-rw-r--r-- | clang/test/Sema/transparent-union.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/clang/test/Sema/transparent-union.c b/clang/test/Sema/transparent-union.c new file mode 100644 index 0000000..ab1ba18 --- /dev/null +++ b/clang/test/Sema/transparent-union.c @@ -0,0 +1,73 @@ +// RUN: %clang -fsyntax-only -Xclang -verify %s +typedef union { + int *ip; + float *fp; + long *__restrict rlp; + void *vpa[1]; +} TU __attribute__((transparent_union)); + +void f(TU); // expected-note{{passing argument to parameter here}} + +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; +} + +/* Test ability to redeclare a function taking a transparent_union arg + with various compatible and incompatible argument types. */ + +void fip(TU); +void fip(int *i) {} + +void ffp(TU); +void ffp(float *f) {} + +void flp(TU); +void flp(long *l) {} + +void fvp(TU); // expected-note{{previous declaration is here}} +void fvp(void *p) {} // expected-error{{conflicting types}} + +void fsp(TU); // expected-note{{previous declaration is here}} +void fsp(short *s) {} // expected-error{{conflicting types}} + +void fi(TU); // expected-note{{previous declaration is here}} +void fi(int i) {} // expected-error{{conflicting types}} + +void fvpp(TU); // expected-note{{previous declaration is here}} +void fvpp(void **v) {} // expected-error{{conflicting types}} + +/* 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}} + +typedef int int4 __attribute__((ext_vector_type(4))); +typedef union { + int4 vec; // expected-warning{{first field of a transparent union cannot have vector type 'int4'; transparent_union attribute ignored}} +} TU5 __attribute__((transparent_union)); + + |