Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 1 | // RUN: %clang -fsyntax-only -Xclang -verify %s |
Douglas Gregor | 0c74e8a | 2009-04-29 22:16:16 +0000 | [diff] [blame] | 2 | typedef union { |
| 3 | int *ip; |
| 4 | float *fp; |
| 5 | } TU __attribute__((transparent_union)); |
| 6 | |
Douglas Gregor | a41a8c5 | 2010-04-22 00:20:18 +0000 | [diff] [blame] | 7 | void f(TU); // expected-note{{passing argument to parameter here}} |
Douglas Gregor | 0c74e8a | 2009-04-29 22:16:16 +0000 | [diff] [blame] | 8 | |
| 9 | void g(int *ip, float *fp, char *cp) { |
| 10 | f(ip); |
| 11 | f(fp); |
| 12 | f(cp); // expected-error{{incompatible type}} |
| 13 | f(0); |
| 14 | |
| 15 | TU tu_ip = ip; // expected-error{{incompatible type}} |
| 16 | TU tu; |
| 17 | tu.ip = ip; |
| 18 | } |
| 19 | |
| 20 | /* FIXME: we'd like to just use an "int" here and align it differently |
| 21 | from the normal "int", but if we do so we lose the alignment |
| 22 | information from the typedef within the compiler. */ |
| 23 | typedef struct { int x, y; } __attribute__((aligned(8))) aligned_struct8; |
| 24 | |
| 25 | typedef struct { int x, y; } __attribute__((aligned(4))) aligned_struct4; |
| 26 | typedef union { |
| 27 | aligned_struct4 s4; // expected-note{{alignment of first field}} |
| 28 | aligned_struct8 s8; // expected-warning{{alignment of field}} |
| 29 | } TU1 __attribute__((transparent_union)); |
| 30 | |
| 31 | typedef union { |
| 32 | char c; // expected-note{{size of first field is 8 bits}} |
| 33 | int i; // expected-warning{{size of field}} |
| 34 | } TU2 __attribute__((transparent_union)); |
| 35 | |
| 36 | typedef union { |
| 37 | float f; // expected-warning{{floating}} |
| 38 | } TU3 __attribute__((transparent_union)); |
| 39 | |
| 40 | typedef union { } TU4 __attribute__((transparent_union)); // expected-warning{{field}} |
Douglas Gregor | 90cd672 | 2010-06-30 17:24:13 +0000 | [diff] [blame] | 41 | |
| 42 | typedef int int4 __attribute__((ext_vector_type(4))); |
| 43 | typedef union { |
| 44 | int4 vec; // expected-warning{{first field of a transparent union cannot have vector type 'int4'; transparent_union attribute ignored}} |
| 45 | } TU5 __attribute__((transparent_union)); |
| 46 | |
| 47 | |