xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/2005-02-11-AnonymousUnion.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -emit-llvm -o -
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // Test anonymous union with members of the same size.
test1(float F)4*f4a2713aSLionel Sambuc int test1(float F) {
5*f4a2713aSLionel Sambuc   union {
6*f4a2713aSLionel Sambuc      float G;
7*f4a2713aSLionel Sambuc      int i;
8*f4a2713aSLionel Sambuc   };
9*f4a2713aSLionel Sambuc   G = F;
10*f4a2713aSLionel Sambuc   return i;
11*f4a2713aSLionel Sambuc }
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc // test anonymous union with members of differing size.
test2(short F)14*f4a2713aSLionel Sambuc int test2(short F) {
15*f4a2713aSLionel Sambuc   volatile union {
16*f4a2713aSLionel Sambuc      short G;
17*f4a2713aSLionel Sambuc      int i;
18*f4a2713aSLionel Sambuc   };
19*f4a2713aSLionel Sambuc   G = F;
20*f4a2713aSLionel Sambuc   return i;
21*f4a2713aSLionel Sambuc }
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc // Make sure that normal unions work.  duh :)
24*f4a2713aSLionel Sambuc volatile union U_t {
25*f4a2713aSLionel Sambuc   short S;
26*f4a2713aSLionel Sambuc   int i;
27*f4a2713aSLionel Sambuc } U;
28*f4a2713aSLionel Sambuc 
test3(short s)29*f4a2713aSLionel Sambuc int test3(short s) {
30*f4a2713aSLionel Sambuc   U.S = s;
31*f4a2713aSLionel Sambuc   return U.i;
32*f4a2713aSLionel Sambuc }
33