1 // RUN: %clang_cc1 -fsyntax-only -verify %s
7 } TU __attribute__((transparent_union));
9 void f(TU); // expected-note{{passing argument to parameter here}}
11 void g(int *ip, float *fp, char *cp) {
14 f(cp); // expected-error{{incompatible type}}
17 TU tu_ip = ip; // expected-error{{incompatible type}}
22 /* Test ability to redeclare a function taking a transparent_union arg
23 with various compatible and incompatible argument types. */
34 void fvp(TU); // expected-note{{previous declaration is here}}
35 void fvp(void *p) {} // expected-error{{conflicting types}}
37 void fsp(TU); // expected-note{{previous declaration is here}}
38 void fsp(short *s) {} // expected-error{{conflicting types}}
40 void fi(TU); // expected-note{{previous declaration is here}}
41 void fi(int i) {} // expected-error{{conflicting types}}
43 void fvpp(TU); // expected-note{{previous declaration is here}}
44 void fvpp(void **v) {} // expected-error{{conflicting types}}
46 /* FIXME: we'd like to just use an "int" here and align it differently
47 from the normal "int", but if we do so we lose the alignment
48 information from the typedef within the compiler. */
49 typedef struct { int x, y; } __attribute__((aligned(8))) aligned_struct8;
51 typedef struct { int x, y; } __attribute__((aligned(4))) aligned_struct4;
53 aligned_struct4 s4; // expected-note{{alignment of first field}}
54 aligned_struct8 s8; // expected-warning{{alignment of field}}
55 } TU1 __attribute__((transparent_union));
58 char c; // expected-note{{size of first field is 8 bits}}
59 int i; // expected-warning{{size of field}}
60 } TU2 __attribute__((transparent_union));
63 float f; // expected-warning{{floating}}
64 } TU3 __attribute__((transparent_union));
66 typedef union { } TU4 __attribute__((transparent_union)); // expected-warning{{field}}
68 typedef int int4 __attribute__((ext_vector_type(4)));
70 int4 vec; // expected-warning{{first field of a transparent union cannot have vector type 'int4' (vector of 4 'int' values); transparent_union attribute ignored}}
71 } TU5 __attribute__((transparent_union));
78 } __attribute__((packed));
79 // The packed attribute is acceptable because it defines a less strict
80 // alignment than required by the first field of the transparent union.
81 } __attribute__((transparent_union));
84 struct { // expected-note {{alignment of first field is 32 bits}}
88 struct { // expected-warning {{alignment of field '' (64 bits) does not match the alignment of the first field in transparent union; transparent_union attribute ignored}}
90 } __attribute__((aligned(8)));
91 } __attribute__((transparent_union));
93 union pr30520v { void b; } __attribute__((transparent_union)); // expected-error {{field has incomplete type 'void'}}
95 union pr30520a { int b[]; } __attribute__((transparent_union)); // expected-error {{field has incomplete type 'int []'}}
97 // expected-note@+1 2 {{forward declaration of 'struct stb'}}
98 union pr30520s { struct stb b; } __attribute__((transparent_union)); // expected-error {{field has incomplete type 'struct stb'}}
100 union pr30520s2 { int *v; struct stb b; } __attribute__((transparent_union)); // expected-error {{field has incomplete type 'struct stb'}}