blob: ab1ba1867f47b00ad962c65d5cc3e67ef7ecd227 [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;
Peter Collingbourneb97c4032010-12-02 20:02:29 +00005 long *__restrict rlp;
Peter Collingbournef91d7572010-12-02 21:00:06 +00006 void *vpa[1];
Douglas Gregor0c74e8a2009-04-29 22:16:16 +00007} TU __attribute__((transparent_union));
8
Douglas Gregora41a8c52010-04-22 00:20:18 +00009void f(TU); // expected-note{{passing argument to parameter here}}
Douglas Gregor0c74e8a2009-04-29 22:16:16 +000010
11void g(int *ip, float *fp, char *cp) {
12 f(ip);
13 f(fp);
14 f(cp); // expected-error{{incompatible type}}
15 f(0);
16
17 TU tu_ip = ip; // expected-error{{incompatible type}}
18 TU tu;
19 tu.ip = ip;
20}
21
Peter Collingbourne48466752010-10-24 18:30:18 +000022/* Test ability to redeclare a function taking a transparent_union arg
23 with various compatible and incompatible argument types. */
24
25void fip(TU);
26void fip(int *i) {}
27
28void ffp(TU);
29void ffp(float *f) {}
30
Peter Collingbourneb97c4032010-12-02 20:02:29 +000031void flp(TU);
32void flp(long *l) {}
33
Peter Collingbourne48466752010-10-24 18:30:18 +000034void fvp(TU); // expected-note{{previous declaration is here}}
35void fvp(void *p) {} // expected-error{{conflicting types}}
36
37void fsp(TU); // expected-note{{previous declaration is here}}
38void fsp(short *s) {} // expected-error{{conflicting types}}
39
40void fi(TU); // expected-note{{previous declaration is here}}
41void fi(int i) {} // expected-error{{conflicting types}}
42
Peter Collingbournef91d7572010-12-02 21:00:06 +000043void fvpp(TU); // expected-note{{previous declaration is here}}
44void fvpp(void **v) {} // expected-error{{conflicting types}}
45
Douglas Gregor0c74e8a2009-04-29 22:16:16 +000046/* 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. */
49typedef struct { int x, y; } __attribute__((aligned(8))) aligned_struct8;
50
51typedef struct { int x, y; } __attribute__((aligned(4))) aligned_struct4;
52typedef union {
53 aligned_struct4 s4; // expected-note{{alignment of first field}}
54 aligned_struct8 s8; // expected-warning{{alignment of field}}
55} TU1 __attribute__((transparent_union));
56
57typedef 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));
61
62typedef union {
63 float f; // expected-warning{{floating}}
64} TU3 __attribute__((transparent_union));
65
66typedef union { } TU4 __attribute__((transparent_union)); // expected-warning{{field}}
Douglas Gregor90cd6722010-06-30 17:24:13 +000067
68typedef int int4 __attribute__((ext_vector_type(4)));
69typedef union {
70 int4 vec; // expected-warning{{first field of a transparent union cannot have vector type 'int4'; transparent_union attribute ignored}}
71} TU5 __attribute__((transparent_union));
72
73