forked from OSchip/llvm-project
Start creating CXXBindReferenceExpr nodes when binding complex types to references.
llvm-svn: 94964
This commit is contained in:
parent
8abde4b447
commit
ab0ddb57b1
|
@ -802,6 +802,9 @@ 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);
|
||||
|
||||
|
|
|
@ -507,6 +507,10 @@ 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);
|
||||
EmitStoreOfScalar(RV.getScalarVal(), Loc, false, Ty);
|
||||
|
|
|
@ -92,9 +92,31 @@ 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;
|
||||
|
||||
|
|
|
@ -1116,6 +1116,8 @@ public:
|
|||
RValue EmitReferenceBindingToExpr(const Expr* E, QualType DestType,
|
||||
bool IsInitializer = false);
|
||||
|
||||
llvm::Value *EmitCXXBindReferenceExpr(const CXXBindReferenceExpr *E);
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Expression Emission
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
|
|
@ -3297,15 +3297,31 @@ 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:
|
||||
// Check exception specifications
|
||||
if (S.CheckExceptionSpecCompatibility(CurInitExpr, DestType))
|
||||
return S.ExprError();
|
||||
|
||||
// FIXME: At present, we have no AST to describe when we need to make a
|
||||
// temporary to bind a reference to. We should.
|
||||
// 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: {
|
||||
|
|
Loading…
Reference in New Issue