Add support for binding references to scalar rvalues.

llvm-svn: 72153
This commit is contained in:
Anders Carlsson 2009-05-20 01:03:17 +00:00
parent 9cbf850506
commit 145eae5224
2 changed files with 18 additions and 3 deletions

View File

@ -78,6 +78,14 @@ RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E,
return RValue::get(LV.getAddress());
}
if (!hasAggregateLLVMType(E->getType())) {
// Make a temporary variable that we can bind the reference to.
llvm::Value *Temp = CreateTempAlloca(ConvertTypeForMem(E->getType()),
"reftmp");
EmitStoreOfScalar(EmitScalarExpr(E), Temp, false, E->getType());
return RValue::get(Temp);
}
CGM.ErrorUnsupported(E, "reference binding");
return GetUndefRValue(DestType);
}

View File

@ -19,25 +19,32 @@ void t3() {
struct C {};
void f(const bool&);
void f(const int&);
void f(const _Complex int&);
void f(const C&);
void test_bool() {
bool a = true;
f(a);
f(true);
}
void test_scalar() {
int a = 10;
f(a);
f(10);
}
void test_complex() {
_Complex int a = 10i;
f(a);
}
void test_aggregate() {
C c;
f(c);
}