1 // RUN: %clang_cc1 -std=c++11 -S -triple armv7-none-eabi -fmerge-all-constants -emit-llvm -o - %s | FileCheck %s
2
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 [5 x i8]* @_ZGR19extended_string_ref_,
6 const char (&extended_string_ref)[5] = {"hi"};
7
8 // This binds directly to a string literal object.
9 // CHECK: @nonextended_string_ref = constant [3 x i8]* @.str
10 const char (&nonextended_string_ref)[3] = {"hi"};
11
12 namespace reference {
13 struct A {
14 int i1, i2;
15 };
16
single_init()17 void single_init() {
18 // No superfluous instructions allowed here, they could be
19 // hiding extra temporaries.
20
21 // CHECK: store i32 1, i32*
22 // CHECK-NEXT: store i32* %{{.*}}, i32**
23 const int &cri2a = 1;
24
25 // CHECK-NEXT: store i32 1, i32*
26 // CHECK-NEXT: store i32* %{{.*}}, i32**
27 const int &cri1a = {1};
28
29 // CHECK-NEXT: store i32 1, i32*
30 int i = 1;
31 // CHECK-NEXT: store i32* %{{.*}}, i32**
32 int &ri1a = {i};
33
34 // CHECK-NEXT: bitcast
35 // CHECK-NEXT: memcpy
36 A a{1, 2};
37 // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %
38 A &ra1a = {a};
39
40 using T = A&;
41 // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %
42 A &ra1b = T{a};
43
44 // CHECK-NEXT: ret
45 }
46
reference_to_aggregate(int i)47 void reference_to_aggregate(int i) {
48 // CHECK: getelementptr {{.*}}, i32 0, i32 0
49 // CHECK-NEXT: store i32 1
50 // CHECK-NEXT: getelementptr {{.*}}, i32 0, i32 1
51 // CHECK-NEXT: %[[I1:.*]] = load i32, i32*
52 // CHECK-NEXT: store i32 %[[I1]]
53 // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %{{.*}}, align
54 const A &ra1{1, i};
55
56 // CHECK-NEXT: getelementptr inbounds [3 x i32], [3 x i32]* %{{.*}}, i{{32|64}} 0, i{{32|64}} 0
57 // CHECK-NEXT: store i32 1
58 // CHECK-NEXT: getelementptr inbounds i32, i32* %{{.*}}, i{{32|64}} 1
59 // CHECK-NEXT: store i32 2
60 // CHECK-NEXT: getelementptr inbounds i32, i32* %{{.*}}, i{{32|64}} 1
61 // CHECK-NEXT: %[[I2:.*]] = load i32, i32*
62 // CHECK-NEXT: store i32 %[[I2]]
63 // CHECK-NEXT: store [3 x i32]* %{{.*}}, [3 x i32]** %{{.*}}, align
64 const int (&arrayRef)[] = {1, 2, i};
65
66 // CHECK: store %{{.*}}* @{{.*}}, %{{.*}}** %{{.*}}, align
67 const A &constra1{1, 2};
68
69 // CHECK-NEXT: store [3 x i32]* @{{.*}}, [3 x i32]** %{{.*}}, align
70 const int (&constarrayRef)[] = {1, 2, 3};
71
72 // CHECK-NEXT: ret
73 }
74
75 struct B {
76 B();
77 ~B();
78 };
79
single_init_temp_cleanup()80 void single_init_temp_cleanup()
81 {
82 // Ensure lifetime extension.
83
84 // CHECK: call %"struct.reference::B"* @_ZN9reference1BC1Ev
85 // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %
86 const B &rb{ B() };
87 // CHECK: call %"struct.reference::B"* @_ZN9reference1BD1Ev
88 }
89
90 }
91
92 namespace PR23165 {
93 struct AbstractClass {
94 virtual void foo() const = 0;
95 };
96
97 struct ChildClass : public AbstractClass {
fooPR23165::ChildClass98 virtual void foo() const {}
99 };
100
helper(const AbstractClass & param)101 void helper(const AbstractClass ¶m) {
102 param.foo();
103 }
104
foo()105 void foo() {
106 // CHECK-LABEL: @_ZN7PR231653fooEv
107 // CHECK: call {{.*}} @_ZN7PR2316510ChildClassC1Ev
108 // CHECK: call void @_ZN7PR231656helperERKNS_13AbstractClassE
109 helper(ChildClass());
110 }
111
112 struct S { struct T { int a; } t; mutable int b; };
f()113 void f() {
114 // CHECK-LABEL: _ZN7PR231651fEv
115 // CHECK: alloca
116 // CHECK: alloca
117 // CHECK: store
118 const S::T &r = S().t;
119 }
120 }
121