xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/lvalue-bitcasts.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s | FileCheck %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc struct X { int i; float f; };
4*f4a2713aSLionel Sambuc struct Y { X x; };
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_Z21reinterpret_cast_testRiRfR1X
reinterpret_cast_test(int & ir,float & fr,X & xr)7*f4a2713aSLionel Sambuc void reinterpret_cast_test(int &ir, float &fr, X &xr) {
8*f4a2713aSLionel Sambuc   // CHECK: load float**
9*f4a2713aSLionel Sambuc   // CHECK: bitcast float*
10*f4a2713aSLionel Sambuc   // CHECK: load i32*
11*f4a2713aSLionel Sambuc   ir = reinterpret_cast<int&>(fr);
12*f4a2713aSLionel Sambuc   // CHECK: load
13*f4a2713aSLionel Sambuc   // CHECK: {{bitcast.*to i32\*}}
14*f4a2713aSLionel Sambuc   // CHECK: load i32*
15*f4a2713aSLionel Sambuc   ir = reinterpret_cast<int&>(xr);
16*f4a2713aSLionel Sambuc   // CHECK: load i32
17*f4a2713aSLionel Sambuc   // CHECK: {{bitcast.*to float\*}}
18*f4a2713aSLionel Sambuc   // CHECK: load float*
19*f4a2713aSLionel Sambuc   fr = reinterpret_cast<float&>(ir);
20*f4a2713aSLionel Sambuc   // CHECK: load
21*f4a2713aSLionel Sambuc   // CHECK: {{bitcast.*to float\*}}
22*f4a2713aSLionel Sambuc   // CHECK: load float*
23*f4a2713aSLionel Sambuc   fr = reinterpret_cast<float&>(xr);
24*f4a2713aSLionel Sambuc   // CHECK: load i32**
25*f4a2713aSLionel Sambuc   // CHECK: bitcast i32*
26*f4a2713aSLionel Sambuc   // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
27*f4a2713aSLionel Sambuc   xr = reinterpret_cast<X&>(ir);
28*f4a2713aSLionel Sambuc   // CHECK: load float**
29*f4a2713aSLionel Sambuc   // CHECK: bitcast float*
30*f4a2713aSLionel Sambuc   // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
31*f4a2713aSLionel Sambuc   xr = reinterpret_cast<X&>(fr);
32*f4a2713aSLionel Sambuc   _Complex float cf;
33*f4a2713aSLionel Sambuc   _Complex float &cfr = cf;
34*f4a2713aSLionel Sambuc   // CHECK: load i32**
35*f4a2713aSLionel Sambuc   // CHECK: bitcast i32*
36*f4a2713aSLionel Sambuc   // CHECK: load float*
37*f4a2713aSLionel Sambuc   // CHECK: load float*
38*f4a2713aSLionel Sambuc   cfr = reinterpret_cast<_Complex float&>(ir);
39*f4a2713aSLionel Sambuc   // CHECK: load float**
40*f4a2713aSLionel Sambuc   // CHECK: bitcast float*
41*f4a2713aSLionel Sambuc   // CHECK: load float*
42*f4a2713aSLionel Sambuc   // CHECK: load float*
43*f4a2713aSLionel Sambuc   cfr = reinterpret_cast<_Complex float&>(fr);
44*f4a2713aSLionel Sambuc   // CHECK: bitcast
45*f4a2713aSLionel Sambuc   // CHECK: load float*
46*f4a2713aSLionel Sambuc   // CHECK: load float*
47*f4a2713aSLionel Sambuc   cfr = reinterpret_cast<_Complex float&>(xr);
48*f4a2713aSLionel Sambuc   // CHECK: ret void
49*f4a2713aSLionel Sambuc }
50*f4a2713aSLionel Sambuc 
51*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_Z6c_castRiRfR1X
c_cast(int & ir,float & fr,X & xr)52*f4a2713aSLionel Sambuc void c_cast(int &ir, float &fr, X &xr) {
53*f4a2713aSLionel Sambuc   // CHECK: load float**
54*f4a2713aSLionel Sambuc   // CHECK: bitcast float*
55*f4a2713aSLionel Sambuc   // CHECK: load i32*
56*f4a2713aSLionel Sambuc   ir = (int&)fr;
57*f4a2713aSLionel Sambuc   // CHECK: load
58*f4a2713aSLionel Sambuc   // CHECK: {{bitcast.*to i32\*}}
59*f4a2713aSLionel Sambuc   // CHECK: load i32*
60*f4a2713aSLionel Sambuc   ir = (int&)xr;
61*f4a2713aSLionel Sambuc   // CHECK: load i32
62*f4a2713aSLionel Sambuc   // CHECK: {{bitcast.*to float\*}}
63*f4a2713aSLionel Sambuc   // CHECK: load float*
64*f4a2713aSLionel Sambuc   fr = (float&)ir;
65*f4a2713aSLionel Sambuc   // CHECK: load
66*f4a2713aSLionel Sambuc   // CHECK: {{bitcast.*to float\*}}
67*f4a2713aSLionel Sambuc   // CHECK: load float*
68*f4a2713aSLionel Sambuc   fr = (float&)xr;
69*f4a2713aSLionel Sambuc   // CHECK: load i32**
70*f4a2713aSLionel Sambuc   // CHECK: bitcast i32*
71*f4a2713aSLionel Sambuc   // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
72*f4a2713aSLionel Sambuc   xr = (X&)ir;
73*f4a2713aSLionel Sambuc   // CHECK: load float**
74*f4a2713aSLionel Sambuc   // CHECK: bitcast float*
75*f4a2713aSLionel Sambuc   // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
76*f4a2713aSLionel Sambuc   xr = (X&)fr;
77*f4a2713aSLionel Sambuc   _Complex float cf;
78*f4a2713aSLionel Sambuc   _Complex float &cfr = cf;
79*f4a2713aSLionel Sambuc   // CHECK: load i32**
80*f4a2713aSLionel Sambuc   // CHECK: bitcast i32*
81*f4a2713aSLionel Sambuc   // CHECK: load float*
82*f4a2713aSLionel Sambuc   // CHECK: load float*
83*f4a2713aSLionel Sambuc   cfr = (_Complex float&)ir;
84*f4a2713aSLionel Sambuc   // CHECK: load float**
85*f4a2713aSLionel Sambuc   // CHECK: bitcast float*
86*f4a2713aSLionel Sambuc   // CHECK: load float*
87*f4a2713aSLionel Sambuc   // CHECK: load float*
88*f4a2713aSLionel Sambuc   cfr = (_Complex float&)fr;
89*f4a2713aSLionel Sambuc   // CHECK: bitcast
90*f4a2713aSLionel Sambuc   // CHECK: load float*
91*f4a2713aSLionel Sambuc   // CHECK: load float*
92*f4a2713aSLionel Sambuc   cfr = (_Complex float&)xr;
93*f4a2713aSLionel Sambuc   // CHECK: ret void
94*f4a2713aSLionel Sambuc }
95*f4a2713aSLionel Sambuc 
96*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_Z15functional_castRiRfR1X
functional_cast(int & ir,float & fr,X & xr)97*f4a2713aSLionel Sambuc void functional_cast(int &ir, float &fr, X &xr) {
98*f4a2713aSLionel Sambuc   typedef int &intref;
99*f4a2713aSLionel Sambuc   typedef float &floatref;
100*f4a2713aSLionel Sambuc   typedef X &Xref;
101*f4a2713aSLionel Sambuc   // CHECK: load float**
102*f4a2713aSLionel Sambuc   // CHECK: bitcast float*
103*f4a2713aSLionel Sambuc   // CHECK: load i32*
104*f4a2713aSLionel Sambuc   ir = intref(fr);
105*f4a2713aSLionel Sambuc   // CHECK: load
106*f4a2713aSLionel Sambuc   // CHECK: {{bitcast.*to i32\*}}
107*f4a2713aSLionel Sambuc   // CHECK: load i32*
108*f4a2713aSLionel Sambuc   ir = intref(xr);
109*f4a2713aSLionel Sambuc   // CHECK: load i32
110*f4a2713aSLionel Sambuc   // CHECK: {{bitcast.*to float\*}}
111*f4a2713aSLionel Sambuc   // CHECK: load float*
112*f4a2713aSLionel Sambuc   fr = floatref(ir);
113*f4a2713aSLionel Sambuc   // CHECK: load
114*f4a2713aSLionel Sambuc   // CHECK: {{bitcast.*to float\*}}
115*f4a2713aSLionel Sambuc   // CHECK: load float*
116*f4a2713aSLionel Sambuc   fr = floatref(xr);
117*f4a2713aSLionel Sambuc   // CHECK: load i32**
118*f4a2713aSLionel Sambuc   // CHECK: bitcast i32*
119*f4a2713aSLionel Sambuc   // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
120*f4a2713aSLionel Sambuc   xr = Xref(ir);
121*f4a2713aSLionel Sambuc   // CHECK: load float**
122*f4a2713aSLionel Sambuc   // CHECK: bitcast float*
123*f4a2713aSLionel Sambuc   // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
124*f4a2713aSLionel Sambuc   xr = Xref(fr);
125*f4a2713aSLionel Sambuc   typedef _Complex float &complex_float_ref;
126*f4a2713aSLionel Sambuc   _Complex float cf;
127*f4a2713aSLionel Sambuc   _Complex float &cfr = cf;
128*f4a2713aSLionel Sambuc   // CHECK: load i32**
129*f4a2713aSLionel Sambuc   // CHECK: bitcast i32*
130*f4a2713aSLionel Sambuc   // CHECK: load float*
131*f4a2713aSLionel Sambuc   // CHECK: load float*
132*f4a2713aSLionel Sambuc   cfr = complex_float_ref(ir);
133*f4a2713aSLionel Sambuc   // CHECK: load float**
134*f4a2713aSLionel Sambuc   // CHECK: bitcast float*
135*f4a2713aSLionel Sambuc   // CHECK: load float*
136*f4a2713aSLionel Sambuc   // CHECK: load float*
137*f4a2713aSLionel Sambuc   cfr = complex_float_ref(fr);
138*f4a2713aSLionel Sambuc   // CHECK: bitcast
139*f4a2713aSLionel Sambuc   // CHECK: load float*
140*f4a2713aSLionel Sambuc   // CHECK: load float*
141*f4a2713aSLionel Sambuc   cfr = complex_float_ref(xr);
142*f4a2713aSLionel Sambuc   // CHECK: ret void
143*f4a2713aSLionel Sambuc }
144*f4a2713aSLionel Sambuc 
145*f4a2713aSLionel Sambuc namespace PR6437 {
146*f4a2713aSLionel Sambuc   struct in_addr {};
copy(const struct in_addr & new_addr)147*f4a2713aSLionel Sambuc   void copy( const struct in_addr &new_addr ) {
148*f4a2713aSLionel Sambuc     int addr = (int&)new_addr;
149*f4a2713aSLionel Sambuc   }
150*f4a2713aSLionel Sambuc }
151*f4a2713aSLionel Sambuc 
152*f4a2713aSLionel Sambuc namespace PR7593 {
foo(double & X,char * A)153*f4a2713aSLionel Sambuc   void foo(double &X, char *A) {
154*f4a2713aSLionel Sambuc     X = reinterpret_cast<double&>(A[4]);
155*f4a2713aSLionel Sambuc   }
156*f4a2713aSLionel Sambuc }
157*f4a2713aSLionel Sambuc 
158*f4a2713aSLionel Sambuc namespace PR7344 {
serialize_annotatable_id(void * & id)159*f4a2713aSLionel Sambuc   void serialize_annotatable_id( void*& id )
160*f4a2713aSLionel Sambuc   {
161*f4a2713aSLionel Sambuc     unsigned long l_id = (unsigned long&)id;
162*f4a2713aSLionel Sambuc   }
163*f4a2713aSLionel Sambuc }
164