• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -std=c++11 -S -emit-llvm -o - %s | FileCheck %s
2 
3 namespace reference {
4   struct A {
5     int i1, i2;
6   };
7 
single_init()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 
31     // CHECK-NEXT: ret
32   }
33 
reference_to_aggregate()34   void reference_to_aggregate() {
35     // CHECK: getelementptr {{.*}}, i32 0, i32 0
36     // CHECK-NEXT: store i32 1
37     // CHECK-NEXT: getelementptr {{.*}}, i32 0, i32 1
38     // CHECK-NEXT: store i32 2
39     // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %{{.*}}, align
40     const A &ra1{1, 2};
41 
42     // CHECK-NEXT: getelementptr inbounds [3 x i32]* %{{.*}}, i{{32|64}} 0, i{{32|64}} 0
43     // CHECK-NEXT: store i32 1
44     // CHECK-NEXT: getelementptr inbounds i32* %{{.*}}, i{{32|64}} 1
45     // CHECK-NEXT: store i32 2
46     // CHECK-NEXT: getelementptr inbounds i32* %{{.*}}, i{{32|64}} 1
47     // CHECK-NEXT: store i32 3
48     // CHECK-NEXT: store [3 x i32]* %{{.*}}, [3 x i32]** %{{.*}}, align
49     const int (&arrayRef)[] = {1, 2, 3};
50 
51     // CHECK-NEXT: ret
52   }
53 
54   struct B {
55     B();
56     ~B();
57   };
58 
single_init_temp_cleanup()59   void single_init_temp_cleanup()
60   {
61     // Ensure lifetime extension.
62 
63     // CHECK: call void @_ZN9reference1BC1Ev
64     // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %
65     const B &rb{ B() };
66     // CHECK: call void @_ZN9reference1BD1Ev
67   }
68 
69 }
70