references.cpp revision 40092972b591646b47037d2b46b695a4014df413
1// RUN: clang-cc -verify -emit-llvm -o - %s | FileCheck %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 c = aggregate_reference_return(); 79} 80 81int& reference_return() { 82 return g; 83} 84 85int reference_decl() { 86 int& a = g; 87 const int& b = 1; 88 return a+b; 89} 90 91struct A { 92 int& b(); 93}; 94 95void f(A* a) { 96 int b = a->b(); 97} 98 99// PR5122 100void *foo = 0; 101void * const & kFoo = foo; 102 103struct D : C { D(); ~D(); }; 104 105void h() { 106 // CHECK: call void @_ZN1DD1Ev 107 const C& c = D(); 108} 109 110namespace T { 111 struct A { 112 A(); 113 ~A(); 114 }; 115 116 struct B { 117 B(); 118 ~B(); 119 A f(); 120 }; 121 122 void f() { 123 // CHECK: call void @_ZN1T1BC1Ev 124 // CHECK: call void @_ZN1T1B1fEv 125 // CHECK: call void @_ZN1T1BD1Ev 126 const A& a = B().f(); 127 // CHECK: call void @_ZN1T1fEv 128 f(); 129 // CHECK: call void @_ZN1T1AD1Ev 130 } 131} 132 133// PR5227. 134namespace PR5227 { 135void f(int &a) { 136 (a = 10) = 20; 137} 138} 139