]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CodeGenCXX/references.cpp
Update clang to r100181.
[FreeBSD/FreeBSD.git] / test / CodeGenCXX / references.cpp
1 // RUN: %clang_cc1 -verify -emit-llvm -o - %s | FileCheck %s
2 void t1() {
3   extern int& a;
4   int b = a; 
5 }
6
7 void t2(int& a) {
8   int b = a;
9 }
10
11 int g;
12 int& gr = g;
13 int& grr = gr;
14 void t3() {
15   int b = gr;
16 }
17
18 // Test reference binding.
19
20 struct C { int a; };
21 void f(const bool&);
22 void f(const int&);
23 void f(const _Complex int&);
24 void f(const C&);
25
26 C aggregate_return();
27
28 bool& bool_reference_return();
29 int& int_reference_return();
30 _Complex int& complex_int_reference_return();
31 C& aggregate_reference_return();
32
33 void test_bool() {
34   bool a = true;
35   f(a);
36
37   f(true);
38   
39   bool_reference_return() = true;
40   a = bool_reference_return();
41   
42   struct { const bool& b; } b = { true };
43 }
44
45 void test_scalar() {
46   int a = 10;
47   f(a);
48   
49   struct { int bitfield : 3; } s = { 3 };
50   f(s.bitfield);
51   
52   f(10);
53
54   __attribute((vector_size(16))) typedef int vec4;
55   f((vec4){1,2,3,4}[0]);
56   
57   int_reference_return() = 10;
58   a = int_reference_return();
59   
60   struct { const int& a; } agg = { 10 };
61 }
62
63 void test_complex() {
64   _Complex int a = 10i;
65   f(a);
66   
67   f(10i);
68   
69   complex_int_reference_return() = 10i;
70   a = complex_int_reference_return();
71   
72   struct { const _Complex int &a; } agg = { 10i };
73 }
74
75 void test_aggregate() {
76   C c;
77   f(c);
78
79   f(aggregate_return());
80   aggregate_reference_return().a = 10;
81
82   c = aggregate_reference_return();
83   
84   struct { const C& a; } agg = { C() };
85 }
86
87 int& reference_return() {
88   return g;
89 }
90
91 int reference_decl() {
92   int& a = g;
93   const int& b = 1;
94   return a+b;
95 }
96
97 struct A {
98   int& b();
99 };
100
101 void f(A* a) {
102   int b = a->b();
103 }
104
105 // PR5122
106 void *foo = 0;
107 void * const & kFoo = foo;
108
109 struct D : C { D(); ~D(); };
110
111 void h() {
112   // CHECK: call void @_ZN1DD1Ev
113   const C& c = D();
114 }
115
116 namespace T {
117   struct A {
118     A();
119     ~A();
120   };
121
122   struct B {
123     B();
124     ~B();
125     A f();
126   };
127
128   void f() {
129     // CHECK: call void @_ZN1T1BC1Ev
130     // CHECK: call void @_ZN1T1B1fEv
131     // CHECK: call void @_ZN1T1BD1Ev
132     const A& a = B().f();
133     // CHECK: call void @_ZN1T1fEv
134     f();
135     // CHECK: call void @_ZN1T1AD1Ev
136   }
137 }
138
139 // PR5227.
140 namespace PR5227 {
141 void f(int &a) {
142   (a = 10) = 20;
143 }
144 }
145
146 // PR5590
147 struct s0;
148 struct s1 { struct s0 &s0; };
149 void f0(s1 a) { s1 b = a; }
150
151 // PR6024
152 // CHECK: @_Z2f2v()
153 // CHECK: alloca
154 // CHECK: store
155 // CHECK: load
156 // CHECK: ret
157 const int &f2() { return 0; }