references.cpp revision 50c39ea4858265f3f5f42a0c624557ce2281936b
1// RUN: clang-cc -verify -emit-llvm -o %t %s
2
3void t1() {
4  extern int& a;
5  int b = a;
6}
7
8void t2(int& a) {
9  int b = a;
10}
11
12int g;
13int& gr = g;
14int& grr = gr;
15void t3() {
16  int b = gr;
17}
18
19// Test reference binding.
20
21struct C { int a; };
22
23void f(const bool&);
24void f(const int&);
25void f(const _Complex int&);
26void f(const C&);
27
28C aggregate_return();
29
30bool& bool_reference_return();
31int& int_reference_return();
32_Complex int& complex_int_reference_return();
33C& aggregate_reference_return();
34
35void test_bool() {
36  bool a = true;
37  f(a);
38
39  f(true);
40
41  bool_reference_return() = true;
42  a = bool_reference_return();
43}
44
45void 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
61void test_complex() {
62  _Complex int a = 10i;
63  f(a);
64
65  f(10i);
66
67  complex_int_reference_return() = 10i;
68  a = complex_int_reference_return();
69}
70
71void test_aggregate() {
72  C c;
73  f(c);
74
75  f(aggregate_return());
76  aggregate_reference_return().a = 10;
77}
78
79int& reference_return() {
80  return g;
81}
82
83int reference_decl() {
84  int& a = g;
85  const int& b = 1;
86  return a+b;
87}
88