blob: 318c8ea0d77039fdffcd230e852fdb87a5c7c80e [file] [log] [blame]
David Blaikie60761492012-09-10 23:06:08 +00001// RUN: %clang_cc1 -std=c++11 -S -triple armv7-none-eabi -emit-llvm -o - %s | FileCheck %s
Sebastian Redl29526f02011-11-27 16:50:07 +00002
3namespace reference {
4 struct A {
5 int i1, i2;
6 };
7
8 void single_init() {
9 // No superfluous instructions allowed here, they could be
10 // hiding extra temporaries.
11
12 // CHECK: store i32 1, i32*
13 // CHECK-NEXT: store i32* %{{.*}}, i32**
14 const int &cri2a = 1;
15
16 // CHECK-NEXT: store i32 1, i32*
17 // CHECK-NEXT: store i32* %{{.*}}, i32**
18 const int &cri1a = {1};
19
20 // CHECK-NEXT: store i32 1, i32*
21 int i = 1;
22 // CHECK-NEXT: store i32* %{{.*}}, i32**
23 int &ri1a = {i};
24
25 // CHECK-NEXT: bitcast
26 // CHECK-NEXT: memcpy
27 A a{1, 2};
28 // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %
29 A &ra1a = {a};
30
Richard Smithbb653bd2012-05-14 21:57:21 +000031 using T = A&;
32 // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %
33 A &ra1b = T{a};
34
Sebastian Redl29526f02011-11-27 16:50:07 +000035 // CHECK-NEXT: ret
36 }
37
Benjamin Kramerf8b86962015-03-07 13:37:13 +000038 void reference_to_aggregate(int i) {
Sebastian Redl29526f02011-11-27 16:50:07 +000039 // CHECK: getelementptr {{.*}}, i32 0, i32 0
40 // CHECK-NEXT: store i32 1
41 // CHECK-NEXT: getelementptr {{.*}}, i32 0, i32 1
Benjamin Kramerf8b86962015-03-07 13:37:13 +000042 // CHECK-NEXT: %[[I1:.*]] = load i32, i32*
43 // CHECK-NEXT: store i32 %[[I1]]
Sebastian Redl29526f02011-11-27 16:50:07 +000044 // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %{{.*}}, align
Benjamin Kramerf8b86962015-03-07 13:37:13 +000045 const A &ra1{1, i};
Sebastian Redl29526f02011-11-27 16:50:07 +000046
David Blaikie218b7832015-02-27 19:18:17 +000047 // CHECK-NEXT: getelementptr inbounds [3 x i32], [3 x i32]* %{{.*}}, i{{32|64}} 0, i{{32|64}} 0
Sebastian Redl29526f02011-11-27 16:50:07 +000048 // CHECK-NEXT: store i32 1
David Blaikie218b7832015-02-27 19:18:17 +000049 // CHECK-NEXT: getelementptr inbounds i32, i32* %{{.*}}, i{{32|64}} 1
Sebastian Redl29526f02011-11-27 16:50:07 +000050 // CHECK-NEXT: store i32 2
David Blaikie218b7832015-02-27 19:18:17 +000051 // CHECK-NEXT: getelementptr inbounds i32, i32* %{{.*}}, i{{32|64}} 1
Benjamin Kramerf8b86962015-03-07 13:37:13 +000052 // CHECK-NEXT: %[[I2:.*]] = load i32, i32*
53 // CHECK-NEXT: store i32 %[[I2]]
Sebastian Redl29526f02011-11-27 16:50:07 +000054 // CHECK-NEXT: store [3 x i32]* %{{.*}}, [3 x i32]** %{{.*}}, align
Benjamin Kramerf8b86962015-03-07 13:37:13 +000055 const int (&arrayRef)[] = {1, 2, i};
56
57 // CHECK: store %{{.*}}* @{{.*}}, %{{.*}}** %{{.*}}, align
58 const A &constra1{1, 2};
59
60 // CHECK-NEXT: store [3 x i32]* @{{.*}}, [3 x i32]** %{{.*}}, align
61 const int (&constarrayRef)[] = {1, 2, 3};
Sebastian Redl29526f02011-11-27 16:50:07 +000062
63 // CHECK-NEXT: ret
64 }
65
66 struct B {
67 B();
68 ~B();
69 };
70
71 void single_init_temp_cleanup()
72 {
73 // Ensure lifetime extension.
74
David Blaikie60761492012-09-10 23:06:08 +000075 // CHECK: call %"struct.reference::B"* @_ZN9reference1BC1Ev
Sebastian Redl29526f02011-11-27 16:50:07 +000076 // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %
77 const B &rb{ B() };
David Blaikie60761492012-09-10 23:06:08 +000078 // CHECK: call %"struct.reference::B"* @_ZN9reference1BD1Ev
Sebastian Redl29526f02011-11-27 16:50:07 +000079 }
80
81}
Benjamin Kramerb2b81432015-04-09 16:09:29 +000082
83namespace PR23165 {
84struct AbstractClass {
85 virtual void foo() const = 0;
86};
87
88struct ChildClass : public AbstractClass {
89 virtual void foo() const {}
90};
91
92void helper(const AbstractClass &param) {
93 param.foo();
94}
95
96void foo() {
Benjamin Kramerf3e67de2015-04-09 22:50:07 +000097// CHECK-LABEL: @_ZN7PR231653fooEv
98// CHECK: call {{.*}} @_ZN7PR2316510ChildClassC1Ev
99// CHECK: call void @_ZN7PR231656helperERKNS_13AbstractClassE
Benjamin Kramerb2b81432015-04-09 16:09:29 +0000100 helper(ChildClass());
101}
Benjamin Kramerf3e67de2015-04-09 22:50:07 +0000102
103struct S { struct T { int a; } t; mutable int b; };
104void f() {
105// CHECK-LABEL: _ZN7PR231651fEv
106// CHECK: alloca
107// CHECK: alloca
108// CHECK: store
109 const S::T &r = S().t;
110}
Benjamin Kramerb2b81432015-04-09 16:09:29 +0000111}