blob: d13b4045a918f482232822a4f700b01d1d4de863 [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
Peter Collingbourne48466752010-10-24 18:30:18 +000020/* Test ability to redeclare a function taking a transparent_union arg
21 with various compatible and incompatible argument types. */
22
23void fip(TU);
24void fip(int *i) {}
25
26void ffp(TU);
27void ffp(float *f) {}
28
29void fvp(TU); // expected-note{{previous declaration is here}}
30void fvp(void *p) {} // expected-error{{conflicting types}}
31
32void fsp(TU); // expected-note{{previous declaration is here}}
33void fsp(short *s) {} // expected-error{{conflicting types}}
34
35void fi(TU); // expected-note{{previous declaration is here}}
36void fi(int i) {} // expected-error{{conflicting types}}
37
Douglas Gregor0c74e8a2009-04-29 22:16:16 +000038/* FIXME: we'd like to just use an "int" here and align it differently
39 from the normal "int", but if we do so we lose the alignment
40 information from the typedef within the compiler. */
41typedef struct { int x, y; } __attribute__((aligned(8))) aligned_struct8;
42
43typedef struct { int x, y; } __attribute__((aligned(4))) aligned_struct4;
44typedef union {
45 aligned_struct4 s4; // expected-note{{alignment of first field}}
46 aligned_struct8 s8; // expected-warning{{alignment of field}}
47} TU1 __attribute__((transparent_union));
48
49typedef union {
50 char c; // expected-note{{size of first field is 8 bits}}
51 int i; // expected-warning{{size of field}}
52} TU2 __attribute__((transparent_union));
53
54typedef union {
55 float f; // expected-warning{{floating}}
56} TU3 __attribute__((transparent_union));
57
58typedef union { } TU4 __attribute__((transparent_union)); // expected-warning{{field}}
Douglas Gregor90cd6722010-06-30 17:24:13 +000059
60typedef int int4 __attribute__((ext_vector_type(4)));
61typedef union {
62 int4 vec; // expected-warning{{first field of a transparent union cannot have vector type 'int4'; transparent_union attribute ignored}}
63} TU5 __attribute__((transparent_union));
64
65