Bind references to lvalues correctly.

llvm-svn: 72150
This commit is contained in:
Anders Carlsson 2009-05-20 00:36:58 +00:00
parent 7248923a5d
commit 7d4c083c19
2 changed files with 33 additions and 0 deletions

View File

@ -72,6 +72,12 @@ RValue CodeGenFunction::EmitAnyExprToTemp(const Expr *E, llvm::Value *AggLoc,
RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E,
QualType DestType) {
if (E->isLvalue(getContext()) == Expr::LV_Valid) {
// Emit the expr as an lvalue.
LValue LV = EmitLValue(E);
return RValue::get(LV.getAddress());
}
CGM.ErrorUnsupported(E, "reference binding");
return GetUndefRValue(DestType);
}

View File

@ -14,3 +14,30 @@ int& gr = g;
void t3() {
int b = gr;
}
// Test reference binding.
struct C {};
void f(const int&);
void f(const _Complex int&);
void f(const C&);
void test_scalar() {
int a = 10;
f(a);
}
void test_complex() {
_Complex int a = 10i;
f(a);
}
void test_aggregate() {
C c;
f(c);
}