blob: a825ed8a2e4b4759b2a01b6653795e0a259ad807 [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;
Douglas Gregor0c74e8a2009-04-29 22:16:16 +00006} TU __attribute__((transparent_union));
7
Douglas Gregora41a8c52010-04-22 00:20:18 +00008void f(TU); // expected-note{{passing argument to parameter here}}
Douglas Gregor0c74e8a2009-04-29 22:16:16 +00009
10void g(int *ip, float *fp, char *cp) {
11 f(ip);
12 f(fp);
13 f(cp); // expected-error{{incompatible type}}
14 f(0);
15
16 TU tu_ip = ip; // expected-error{{incompatible type}}
17 TU tu;
18 tu.ip = ip;
19}
20
Peter Collingbourne48466752010-10-24 18:30:18 +000021/* Test ability to redeclare a function taking a transparent_union arg
22 with various compatible and incompatible argument types. */
23
24void fip(TU);
25void fip(int *i) {}
26
27void ffp(TU);
28void ffp(float *f) {}
29
Peter Collingbourneb97c4032010-12-02 20:02:29 +000030void flp(TU);
31void flp(long *l) {}
32
Peter Collingbourne48466752010-10-24 18:30:18 +000033void fvp(TU); // expected-note{{previous declaration is here}}
34void fvp(void *p) {} // expected-error{{conflicting types}}
35
36void fsp(TU); // expected-note{{previous declaration is here}}
37void fsp(short *s) {} // expected-error{{conflicting types}}
38
39void fi(TU); // expected-note{{previous declaration is here}}
40void fi(int i) {} // expected-error{{conflicting types}}
41
Douglas Gregor0c74e8a2009-04-29 22:16:16 +000042/* FIXME: we'd like to just use an "int" here and align it differently
43 from the normal "int", but if we do so we lose the alignment
44 information from the typedef within the compiler. */
45typedef struct { int x, y; } __attribute__((aligned(8))) aligned_struct8;
46
47typedef struct { int x, y; } __attribute__((aligned(4))) aligned_struct4;
48typedef union {
49 aligned_struct4 s4; // expected-note{{alignment of first field}}
50 aligned_struct8 s8; // expected-warning{{alignment of field}}
51} TU1 __attribute__((transparent_union));
52
53typedef union {
54 char c; // expected-note{{size of first field is 8 bits}}
55 int i; // expected-warning{{size of field}}
56} TU2 __attribute__((transparent_union));
57
58typedef union {
59 float f; // expected-warning{{floating}}
60} TU3 __attribute__((transparent_union));
61
62typedef union { } TU4 __attribute__((transparent_union)); // expected-warning{{field}}
Douglas Gregor90cd6722010-06-30 17:24:13 +000063
64typedef int int4 __attribute__((ext_vector_type(4)));
65typedef union {
66 int4 vec; // expected-warning{{first field of a transparent union cannot have vector type 'int4'; transparent_union attribute ignored}}
67} TU5 __attribute__((transparent_union));
68
69