blob: 10586c11a7a720f1613eb18bf9b173a7e8a53d1f [file] [log] [blame]
David Blaikie1b76fbc2012-09-10 23:06:08 +00001// RUN: %clang_cc1 -std=c++11 -S -triple armv7-none-eabi -emit-llvm -o - %s | FileCheck %s
Sebastian Redl13dc8f92011-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 Smith13ec9102012-05-14 21:57:21 +000031 using T = A&;
32 // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %
33 A &ra1b = T{a};
34
Sebastian Redl13dc8f92011-11-27 16:50:07 +000035 // CHECK-NEXT: ret
36 }
37
38 void reference_to_aggregate() {
39 // CHECK: getelementptr {{.*}}, i32 0, i32 0
40 // CHECK-NEXT: store i32 1
41 // CHECK-NEXT: getelementptr {{.*}}, i32 0, i32 1
42 // CHECK-NEXT: store i32 2
43 // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %{{.*}}, align
44 const A &ra1{1, 2};
45
46 // CHECK-NEXT: getelementptr inbounds [3 x i32]* %{{.*}}, i{{32|64}} 0, i{{32|64}} 0
47 // CHECK-NEXT: store i32 1
48 // CHECK-NEXT: getelementptr inbounds i32* %{{.*}}, i{{32|64}} 1
49 // CHECK-NEXT: store i32 2
50 // CHECK-NEXT: getelementptr inbounds i32* %{{.*}}, i{{32|64}} 1
51 // CHECK-NEXT: store i32 3
52 // CHECK-NEXT: store [3 x i32]* %{{.*}}, [3 x i32]** %{{.*}}, align
53 const int (&arrayRef)[] = {1, 2, 3};
54
55 // CHECK-NEXT: ret
56 }
57
58 struct B {
59 B();
60 ~B();
61 };
62
63 void single_init_temp_cleanup()
64 {
65 // Ensure lifetime extension.
66
David Blaikie1b76fbc2012-09-10 23:06:08 +000067 // CHECK: call %"struct.reference::B"* @_ZN9reference1BC1Ev
Sebastian Redl13dc8f92011-11-27 16:50:07 +000068 // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %
69 const B &rb{ B() };
David Blaikie1b76fbc2012-09-10 23:06:08 +000070 // CHECK: call %"struct.reference::B"* @_ZN9reference1BD1Ev
Sebastian Redl13dc8f92011-11-27 16:50:07 +000071 }
72
73}