1 // RUN: not %clang_cc1 -triple x86_64-apple-darwin -verify -emit-llvm -o - %s | FileCheck %s
3 // CHECK-LABEL: define{{.*}} void @_Z2t1v
4 // CHECK: [[REFLOAD:%.*]] = load ptr, ptr @a, align 8
5 // CHECK: load i32, ptr [[REFLOAD]], align 4
11 // CHECK-LABEL: define{{.*}} void @_Z2t2Ri
12 // CHECK: [[REFLOAD2:%.*]] = load ptr, ptr {{.*}}, align 8
13 // CHECK: load i32, ptr [[REFLOAD2]], align 4
24 // Test reference binding.
29 void f(const _Complex
int&);
34 bool& bool_reference_return();
35 int& int_reference_return();
36 _Complex
int& complex_int_reference_return();
37 C
& aggregate_reference_return();
45 bool_reference_return() = true;
46 a
= bool_reference_return();
48 struct { const bool& b
; } b
= { true };
55 struct { int bitfield
: 3; } s
= { 3 };
60 __attribute((vector_size(16))) typedef int vec4
;
61 f((vec4
){1,2,3,4}[0]);
63 int_reference_return() = 10;
64 a
= int_reference_return();
66 struct { const int& a
; } agg
= { 10 };
75 complex_int_reference_return() = 10i
;
76 a
= complex_int_reference_return();
78 struct { const _Complex
int &a
; } agg
= { 10i
};
81 void test_aggregate() {
85 f(aggregate_return());
86 aggregate_reference_return().a
= 10;
88 c
= aggregate_reference_return();
90 struct { const C
& a
; } agg
= { C() };
93 int& reference_return() {
97 int reference_decl() {
113 void * const & kFoo
= foo
;
115 struct D
: C
{ D(); ~D(); };
118 // CHECK: call void @_ZN1DD1Ev
135 // CHECK: call void @_ZN1T1BC1Ev
136 // CHECK: call void @_ZN1T1B1fEv
137 // CHECK: call void @_ZN1T1BD1Ev
138 const A
& a
= B().f();
139 // CHECK: call void @_ZN1T1fEv
141 // CHECK: call void @_ZN1T1AD1Ev
154 struct s1
{ struct s0
&s0
; };
155 void f0(s1 a
) { s1 b
= a
; }
159 // CHECK: alloca i32,
162 const int &f2() { return 0; }
164 // Don't constant fold const reference parameters with default arguments to
165 // their default arguments.
168 // CHECK: @_ZN2N14test
169 void test(const int& arg
= foo
) {
170 // Ensure this array is on the stack where we can set values instead of
171 // being a global constant.
172 // CHECK: %args_array = alloca
173 const int* const args_array
[] = { &arg
};
177 // Bind to subobjects while extending the life of the complete object.
182 X
&operator=(const X
&);
192 // CHECK-LABEL: define{{.*}} void @_ZN2N21fEi
193 // CHECK: call void @_ZN2N24getPEv
194 // CHECK: getelementptr inbounds
195 // CHECK: store i32 17
196 // CHECK: call void @_ZN2N21PD1Ev
198 const X
& xr
= getP().first
;
210 struct HasX
: ReallyHasX
{ };
212 struct HasXContainer
{
216 struct Y
: SpaceWaster
, HasXContainer
{ };
217 struct Z
: SpaceWaster
, Y
{ };
221 // CHECK-LABEL: define{{.*}} void @_ZN2N21gEi
222 // CHECK: call void @_ZN2N24getZEv
223 // CHECK: {{getelementptr inbounds.*i32 0, i32 0}}
224 // CHECK: {{getelementptr inbounds.*i32 0, i32 0}}
225 // CHECK: store i32 19
226 // CHECK: call void @_ZN2N21ZD1Ev
229 const X
&xr
= getZ().has
.x
;
243 // CHECK-LABEL: define internal void @__cxx_global_var_init
244 // CHECK: call void @_ZN2N31AC1Ei(ptr {{[^,]*}} @_ZGRN2N35sA123E_, i32 noundef 123)
245 // CHECK: call i32 @__cxa_atexit
247 const A
&sA123
= A(123);
258 // CHECK-LABEL: define{{.*}} void @_ZN2N41fEv
259 // CHECK: call void @_ZN2N41AC1Ev(ptr {{[^,]*}} @_ZGRZN2N41fEvE2ar_)
260 // CHECK: call i32 @__cxa_atexit
262 static const A
& ar
= A();
269 struct AnyS
{ bool b
; };
273 // CHECK: call i8 @_ZN2N51gEv()
274 // CHECK: call void @_ZN2N51fERKb(ptr
281 struct a
{ int a
: 10, b
: 10; };
282 // CHECK-LABEL: define{{.*}} void @_ZN6PR95651fEv()
284 // CHECK: call void @llvm.memcpy
286 // CHECK: [[WITH_SEVENTEEN:%[.a-zA-Z0-9]+]] = or i32 [[WITHOUT_SEVENTEEN:%[.a-zA-Z0-9]+]], 17
287 // CHECK: store i32 [[WITH_SEVENTEEN]], ptr [[XA:%[.a-zA-Z0-9]+]]
292 // CHECK-NEXT: store i32
293 // CHECK-NEXT: store ptr
297 // CHECK-NEXT: or i32 {{.*}}, 19456
298 // CHECK-NEXT: store i32
300 // CHECK-NEXT: ret void
305 extern struct x
{char& x
;}y
;
306 int a() { return y
.x
; }
307 // CHECK-LABEL: define{{.*}} i32 @_ZN2N61aEv
308 // CHECK: [[REFLOAD3:%.*]] = load ptr, ptr @_ZN2N61yE, align 8
309 // CHECK: load i8, ptr [[REFLOAD3]], align 1