Revert the new reference binding code; I came up with a way simpler solution for the reference binding bug that is preventing self-hosting.

llvm-svn: 95223
This commit is contained in:
Anders Carlsson 2010-02-03 16:38:03 +00:00
parent 5bb4efdf3c
commit 3b227bd629
7 changed files with 8 additions and 58 deletions

View File

@ -802,11 +802,8 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
}
RValue CodeGenFunction::EmitCallArg(const Expr *E, QualType ArgType) {
if (const CXXBindReferenceExpr *BE = dyn_cast<CXXBindReferenceExpr>(E))
return RValue::get(EmitCXXBindReferenceExpr(BE));
if (ArgType->isReferenceType())
return EmitReferenceBindingToExpr(E, ArgType);
return EmitReferenceBindingToExpr(E);
return EmitAnyExprToTemp(E);
}

View File

@ -838,7 +838,7 @@ static void EmitMemberInitializer(CodeGenFunction &CGF,
// was implicitly generated, we shouldn't be zeroing memory.
RValue RHS;
if (FieldType->isReferenceType()) {
RHS = CGF.EmitReferenceBindingToExpr(MemberInit->getInit(), FieldType,
RHS = CGF.EmitReferenceBindingToExpr(MemberInit->getInit(),
/*IsInitializer=*/true);
CGF.EmitStoreThroughLValue(RHS, LHS, FieldType);
} else if (FieldType->isArrayType() && !MemberInit->getInit()) {

View File

@ -507,12 +507,8 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
Builder.CreateCall4(CGM.getMemCpyFn(), Loc, SrcPtr, SizeVal, AlignVal);
}
} else if (const CXXBindReferenceExpr *BE =
dyn_cast<CXXBindReferenceExpr>(Init)) {
llvm::Value *V = EmitCXXBindReferenceExpr(BE);
EmitStoreOfScalar(V, Loc, /*Volatile=*/false, Ty);
} else if (Ty->isReferenceType()) {
RValue RV = EmitReferenceBindingToExpr(Init, Ty, /*IsInitializer=*/true);
RValue RV = EmitReferenceBindingToExpr(Init, /*IsInitializer=*/true);
EmitStoreOfScalar(RV.getScalarVal(), Loc, false, Ty);
} else if (!hasAggregateLLVMType(Init->getType())) {
llvm::Value *V = EmitScalarExpr(Init);

View File

@ -81,7 +81,7 @@ void CodeGenFunction::EmitCXXGlobalVarDeclInit(const VarDecl &D,
return;
}
if (Init->isLvalue(getContext()) == Expr::LV_Valid) {
RValue RV = EmitReferenceBindingToExpr(Init, T, /*IsInitializer=*/true);
RValue RV = EmitReferenceBindingToExpr(Init, /*IsInitializer=*/true);
EmitStoreOfScalar(RV.getScalarVal(), DeclPtr, false, T);
return;
}
@ -225,7 +225,7 @@ CodeGenFunction::EmitStaticCXXBlockVarDeclInit(const VarDecl &D,
QualType T = D.getType();
// We don't want to pass true for IsInitializer here, because a static
// reference to a temporary does not extend its lifetime.
RValue RV = EmitReferenceBindingToExpr(D.getInit(), T,
RValue RV = EmitReferenceBindingToExpr(D.getInit(),
/*IsInitializer=*/false);
EmitStoreOfScalar(RV.getScalarVal(), GV, /*Volatile=*/false, T);

View File

@ -92,31 +92,8 @@ RValue CodeGenFunction::EmitAnyExprToTemp(const Expr *E,
IsInitializer);
}
llvm::Value *
CodeGenFunction::EmitCXXBindReferenceExpr(const CXXBindReferenceExpr *E) {
QualType T = E->getType();
assert(T->isAnyComplexType() && "FIXME: Unhandled bind expression!");
const Expr *SubExpr = E->getSubExpr();
if (!E->requiresTemporaryCopy())
return EmitLValue(SubExpr).getAddress();
llvm::Value *Value = CreateTempAlloca(ConvertTypeForMem(T), "reftmp");
if (T->isAnyComplexType())
EmitComplexExprIntoAddr(SubExpr, Value, /*DestIsVolatile=*/false);
else
assert(false && "Unhandled bind expression");
return Value;
}
RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E,
QualType DestType,
bool IsInitializer) {
assert(!E->getType()->isAnyComplexType() &&
"Should not use this function for complex types!");
bool ShouldDestroyTemporaries = false;
unsigned OldNumLiveTemporaries = 0;
@ -478,8 +455,6 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) {
return EmitCXXConstructLValue(cast<CXXConstructExpr>(E));
case Expr::CXXBindTemporaryExprClass:
return EmitCXXBindTemporaryLValue(cast<CXXBindTemporaryExpr>(E));
case Expr::CXXBindReferenceExprClass:
return EmitLValue(cast<CXXBindReferenceExpr>(E)->getSubExpr());
case Expr::CXXExprWithTemporariesClass:
return EmitCXXExprWithTemporariesLValue(cast<CXXExprWithTemporaries>(E));
case Expr::CXXZeroInitValueExprClass:

View File

@ -1111,10 +1111,7 @@ public:
/// EmitReferenceBindingToExpr - Emits a reference binding to the passed in
/// expression. Will emit a temporary variable if E is not an LValue.
RValue EmitReferenceBindingToExpr(const Expr* E, QualType DestType,
bool IsInitializer = false);
llvm::Value *EmitCXXBindReferenceExpr(const CXXBindReferenceExpr *E);
RValue EmitReferenceBindingToExpr(const Expr* E, bool IsInitializer = false);
//===--------------------------------------------------------------------===//
// Expression Emission

View File

@ -3304,31 +3304,16 @@ InitializationSequence::Perform(Sema &S,
// Check exception specifications
if (S.CheckExceptionSpecCompatibility(CurInitExpr, DestType))
return S.ExprError();
// FIXME: We should do this for all types.
if (DestType->isAnyComplexType()) {
CurInit =
S.Owned(CXXBindReferenceExpr::Create(S.Context,
CurInit.takeAs<Expr>(),
/*ExtendsLifetime=*/false,
/*RequiresTemporaryCopy=*/false));
}
break;
case SK_BindReferenceToTemporary:
// Reference binding does not have any corresponding ASTs.
// Check exception specifications
if (S.CheckExceptionSpecCompatibility(CurInitExpr, DestType))
return S.ExprError();
// FIXME: We should do this for all types.
if (DestType->isAnyComplexType()) {
CurInit =
S.Owned(CXXBindReferenceExpr::Create(S.Context,
CurInit.takeAs<Expr>(),
/*ExtendsLifetime=*/false,
/*RequiresTemporaryCopy=*/true));
}
break;
case SK_UserConversion: {