1 // RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-darwin10 -o - %s | FileCheck %s
6 // CHECK: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z16lvalue_noop_castv() [[NUW:#[0-9]+]]
7 const int &lvalue_noop_cast() {
9 // CHECK: store i32 17, ptr
10 return (const int&)17;
12 // CHECK: store i32 17, ptr
13 return static_cast<const int&>(17);
14 // CHECK: store i32 17, ptr
18 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z20lvalue_integral_castv()
19 const short &lvalue_integral_cast() {
21 // CHECK: store i16 17, ptr
22 return (const short&)17;
24 // CHECK: store i16 17, ptr
25 return static_cast<const short&>(17);
26 // CHECK: store i16 17, ptr
30 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z29lvalue_floating_integral_castv()
31 const short &lvalue_floating_integral_cast() {
33 // CHECK: store i16 17, ptr
34 return (const short&)17.5;
36 // CHECK: store i16 17, ptr
37 return static_cast<const short&>(17.5);
38 // CHECK: store i16 17, ptr
42 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z29lvalue_integral_floating_castv()
43 const float &lvalue_integral_floating_cast() {
45 // CHECK: store float 1.700000e+{{0*}}1, ptr
46 return (const float&)17;
48 // CHECK: store float 1.700000e+{{0*}}1, ptr
49 return static_cast<const float&>(17);
50 // CHECK: store float 1.700000e+{{0*}}1, ptr
54 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z20lvalue_floating_castv()
55 const float &lvalue_floating_cast() {
57 // CHECK: store float 1.700000e+{{0*}}1, ptr
58 return (const float&)17.0;
60 // CHECK: store float 1.700000e+{{0*}}1, ptr
61 return static_cast<const float&>(17.0);
62 // CHECK: store float 1.700000e+{{0*}}1, ptr
68 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z24lvalue_integer_bool_castv()
69 const bool &lvalue_integer_bool_cast() {
71 // CHECK: call noundef i32 @_Z7get_intv()
73 return (const bool&)get_int();
75 // CHECK: call noundef i32 @_Z7get_intv()
77 return static_cast<const bool&>(get_int());
78 // CHECK: call noundef i32 @_Z7get_intv()
85 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z25lvalue_floating_bool_castv()
86 const bool &lvalue_floating_bool_cast() {
88 // CHECK: call noundef float @_Z9get_floatv()
89 // CHECK: fcmp une float
91 return (const bool&)get_float();
93 // CHECK: call noundef float @_Z9get_floatv()
94 // CHECK: fcmp une float
96 return static_cast<const bool&>(get_float());
97 // CHECK: call noundef float @_Z9get_floatv()
98 // CHECK: fcmp une float
105 typedef int (X::*pmf
)(int);
107 pm
get_pointer_to_member_data();
108 pmf
get_pointer_to_member_function();
110 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z26lvalue_ptrmem_to_bool_castv()
111 const bool &lvalue_ptrmem_to_bool_cast() {
113 // CHECK: call i64 @_Z26get_pointer_to_member_datav()
116 return (const bool&)get_pointer_to_member_data();
118 // CHECK: call i64 @_Z26get_pointer_to_member_datav()
121 return static_cast<const bool&>(get_pointer_to_member_data());
122 // CHECK: call i64 @_Z26get_pointer_to_member_datav()
125 return get_pointer_to_member_data();
128 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z27lvalue_ptrmem_to_bool_cast2v
129 const bool &lvalue_ptrmem_to_bool_cast2() {
131 // CHECK: {{call.*_Z30get_pointer_to_member_functionv}}
134 return (const bool&)get_pointer_to_member_function();
136 // CHECK: {{call.*_Z30get_pointer_to_member_functionv}}
139 return static_cast<const bool&>(get_pointer_to_member_function());
140 // CHECK: {{call.*_Z30get_pointer_to_member_functionv}}
143 return get_pointer_to_member_function();
146 _Complex
double get_complex_double();
148 // CHECK: {{define.*_Z2f1v}}
149 const _Complex
float &f1() {
151 // CHECK: {{call.*_Z18get_complex_doublev}}
154 // CHECK: store float
155 // CHECK: store float
156 return (const _Complex
float&)get_complex_double();
158 // CHECK: {{call.*_Z18get_complex_doublev}}
161 // CHECK: store float
162 // CHECK: store float
163 return static_cast<const _Complex
float&>(get_complex_double());
164 // CHECK: {{call.*_Z18get_complex_doublev}}
167 // CHECK: store float
168 // CHECK: store float
169 return get_complex_double();
172 // CHECK-LABEL: define{{.*}} i32 @_Z7pr10592RKi(ptr
173 unsigned pr10592(const int &v
) {
174 // CHECK: [[VADDR:%[a-zA-Z0-9.]+]] = alloca ptr
175 // CHECK-NEXT: [[REFTMP:%[a-zA-Z0-9.]+]] = alloca i32
176 // CHECK-NEXT: store ptr [[V:%[a-zA-Z0-9.]+]], ptr [[VADDR]]
177 // CHECK-NEXT: [[VADDR_1:%[a-zA-Z0-9.]+]] = load ptr, ptr [[VADDR]]
178 // CHECK-NEXT: [[VVAL:%[a-zA-Z0-9.]+]] = load i32, ptr [[VADDR_1]]
179 // CHECK-NEXT: store i32 [[VVAL]], ptr [[REFTMP]]
180 // CHECK-NEXT: [[VVAL_I:%[a-zA-Z0-9.]+]] = load i32, ptr [[REFTMP]]
181 // CHECK-NEXT: ret i32 [[VVAL_I]]
182 return static_cast<const unsigned &>(v
);
187 unsigned long long id();
189 unsigned long long test(Helper
*obj
) {
190 return static_cast<const unsigned long long&>(obj
->id());
192 // CHECK-LABEL: define{{.*}} i64 @_ZN7PR106504testEPNS_6HelperE
196 // CHECK: attributes [[NUW]] = { mustprogress noinline nounwind{{.*}} }