1 // RUN: %clang_cc1 -std=c++11 -triple armv7-none-eabi -fmerge-all-constants -emit-llvm -o - %s | FileCheck %s
3 // This creates and lifetime-extends a 'const char[5]' temporary.
4 // CHECK: @_ZGR19extended_string_ref_ = internal constant [5 x i8] c"hi\00\00\00",
5 // CHECK: @extended_string_ref ={{.*}} constant ptr @_ZGR19extended_string_ref_,
6 const char (&extended_string_ref
)[5] = {"hi"};
8 // This binds directly to a string literal object.
9 // CHECK: @nonextended_string_ref ={{.*}} constant ptr @.str
10 const char (&nonextended_string_ref
)[3] = {"hi"};
18 // No superfluous instructions allowed here, they could be
19 // hiding extra temporaries.
21 // CHECK: store i32 1, ptr
22 // CHECK-NEXT: store ptr %{{.*}}, ptr
25 // CHECK-NEXT: store i32 1, ptr
26 // CHECK-NEXT: store ptr %{{.*}}, ptr
27 const int &cri1a
= {1};
29 // CHECK-NEXT: store i32 1, ptr
31 // CHECK-NEXT: store ptr %{{.*}}, ptr
36 // CHECK-NEXT: store ptr %{{.*}}, ptr %
40 // CHECK-NEXT: store ptr %{{.*}}, ptr %
46 void reference_to_aggregate(int i
) {
47 // CHECK: getelementptr {{.*}}, i32 0, i32 0
48 // CHECK-NEXT: store i32 1
49 // CHECK-NEXT: getelementptr {{.*}}, i32 0, i32 1
50 // CHECK-NEXT: %[[I1:.*]] = load i32, ptr
51 // CHECK-NEXT: store i32 %[[I1]]
52 // CHECK-NEXT: store ptr %{{.*}}, ptr %{{.*}}, align
55 // CHECK-NEXT: store i32 1
56 // CHECK-NEXT: getelementptr inbounds i32, ptr %{{.*}}, i{{32|64}} 1
57 // CHECK-NEXT: store i32 2
58 // CHECK-NEXT: getelementptr inbounds i32, ptr %{{.*}}, i{{32|64}} 2
59 // CHECK-NEXT: %[[I2:.*]] = load i32, ptr
60 // CHECK-NEXT: store i32 %[[I2]]
61 // CHECK-NEXT: store ptr %{{.*}}, ptr %{{.*}}, align
62 const int (&arrayRef
)[] = {1, 2, i
};
64 // CHECK: store ptr @{{.*}}, ptr %{{.*}}, align
65 const A
&constra1
{1, 2};
67 // CHECK-NEXT: store ptr @{{.*}}, ptr %{{.*}}, align
68 const int (&constarrayRef
)[] = {1, 2, 3};
78 void single_init_temp_cleanup()
80 // Ensure lifetime extension.
82 // CHECK: call noundef ptr @_ZN9reference1BC1Ev
83 // CHECK-NEXT: store ptr %{{.*}}, ptr %
85 // CHECK: call noundef ptr @_ZN9reference1BD1Ev
91 struct AbstractClass
{
92 virtual void foo() const = 0;
95 struct ChildClass
: public AbstractClass
{
96 virtual void foo() const {}
99 void helper(const AbstractClass
¶m
) {
104 // CHECK-LABEL: @_ZN7PR231653fooEv
105 // CHECK: call {{.*}} @_ZN7PR2316510ChildClassC1Ev
106 // CHECK: call void @_ZN7PR231656helperERKNS_13AbstractClassE
107 helper(ChildClass());
110 struct S
{ struct T
{ int a
; } t
; mutable int b
; };
112 // CHECK-LABEL: _ZN7PR231651fEv
116 const S::T
&r
= S().t
;