blob: 27d5c2403b43c808b7f8e2af0cc91df575126ad9 [file] [log] [blame]
Daniel Dunbar80737ad2009-12-15 22:01:24 +00001// RUN: %clang -fsyntax-only -Xclang -verify %s
Douglas Gregor0c74e8a2009-04-29 22:16:16 +00002typedef union {
3 int *ip;
4 float *fp;
5} TU __attribute__((transparent_union));
6
Douglas Gregora41a8c52010-04-22 00:20:18 +00007void f(TU); // expected-note{{passing argument to parameter here}}
Douglas Gregor0c74e8a2009-04-29 22:16:16 +00008
9void 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. */
23typedef struct { int x, y; } __attribute__((aligned(8))) aligned_struct8;
24
25typedef struct { int x, y; } __attribute__((aligned(4))) aligned_struct4;
26typedef 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
31typedef 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
36typedef union {
37 float f; // expected-warning{{floating}}
38} TU3 __attribute__((transparent_union));
39
40typedef union { } TU4 __attribute__((transparent_union)); // expected-warning{{field}}
Douglas Gregor90cd6722010-06-30 17:24:13 +000041
42typedef int int4 __attribute__((ext_vector_type(4)));
43typedef 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