From b58d017f2b9eeed33f2ab3ede968b89cf5296bf2 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sat, 30 May 2009 23:23:33 +0000 Subject: [PATCH] More temporary support. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72648 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGCXX.cpp | 11 +++++++++++ lib/CodeGen/CGExpr.cpp | 11 ++++++++++- lib/CodeGen/CGExprAgg.cpp | 29 +++++++++++++++++++++++++---- lib/CodeGen/CodeGenFunction.h | 7 ++++++- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index 6ab59e11b6..4b4ed12abb 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -189,6 +189,17 @@ CodeGenFunction::EmitCXXConstructExpr(llvm::Value *Dest, E->arg_begin(), E->arg_end()); } +RValue +CodeGenFunction::EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E, + llvm::Value *AggLoc, + bool isAggLocVolatile) { + RValue RV = EmitAnyExpr(E->getSubExpr(), AggLoc, isAggLocVolatile); + + // FIXME: Handle the temporaries. + + return RV; +} + static bool canGenerateCXXstructor(const CXXRecordDecl *RD, ASTContext &Context) { // The class has base classes - we don't support that right now. diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 12a8002de3..505677bc7d 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -189,7 +189,10 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) { case Expr::CXXConditionDeclExprClass: return EmitCXXConditionDeclLValue(cast(E)); - + case Expr::CXXTemporaryObjectExprClass: + case Expr::CXXConstructExprClass: + return EmitCXXConstructLValue(cast(E)); + case Expr::ObjCMessageExprClass: return EmitObjCMessageExprLValue(cast(E)); case Expr::ObjCIvarRefExprClass: @@ -1198,6 +1201,12 @@ CodeGenFunction::EmitCXXConditionDeclLValue(const CXXConditionDeclExpr *E) { return EmitDeclRefLValue(E); } +LValue CodeGenFunction::EmitCXXConstructLValue(const CXXConstructExpr *E) { + llvm::Value *Temp = CreateTempAlloca(ConvertTypeForMem(E->getType()), "tmp"); + EmitCXXConstructExpr(Temp, E); + return LValue::MakeAddr(Temp, E->getType().getCVRQualifiers()); +} + LValue CodeGenFunction::EmitObjCMessageExprLValue(const ObjCMessageExpr *E) { // Can only get l-value for message expression returning aggregate type RValue RV = EmitObjCMessageExpr(E); diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index cfb67ade79..343163ff2c 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -105,6 +105,7 @@ public: void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) { Visit(DAE->getExpr()); } + void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); void VisitCXXConstructExpr(const CXXConstructExpr *E); void VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E); @@ -290,16 +291,36 @@ void AggExprEmitter::VisitVAArgExpr(VAArgExpr *VE) { EmitFinalDestCopy(VE, LValue::MakeAddr(ArgPtr, 0)); } +void AggExprEmitter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { + llvm::Value *Val = DestPtr; + + if (!Val) { + // Create a temporary variable. + Val = CGF.CreateTempAlloca(CGF.ConvertTypeForMem(E->getType()), "tmp"); + + // FIXME: volatile + CGF.EmitAggExpr(E->getSubExpr(), Val, false); + } else + Visit(E->getSubExpr()); + + // FIXME: Record the value and dest ptr. + Val->dump(); +} + void AggExprEmitter::VisitCXXConstructExpr(const CXXConstructExpr *E) { - assert(DestPtr && "Must have somewhere to emit into!"); + llvm::Value *Val = DestPtr; + + if (!Val) { + // Create a temporary variable. + Val = CGF.CreateTempAlloca(CGF.ConvertTypeForMem(E->getType()), "tmp"); + } - CGF.EmitCXXConstructExpr(DestPtr, E); + CGF.EmitCXXConstructExpr(Val, E); } void AggExprEmitter::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) { - // FIXME: Do something with the temporaries! - Visit(E->getSubExpr()); + CGF.EmitCXXExprWithTemporaries(E, DestPtr, VolatileDest); } void AggExprEmitter::EmitInitializationToLValue(Expr* E, LValue LV) { diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index d7d6c729ad..4411348a58 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -653,7 +653,8 @@ public: LValue EmitBlockDeclRefLValue(const BlockDeclRefExpr *E); LValue EmitCXXConditionDeclLValue(const CXXConditionDeclExpr *E); - + LValue EmitCXXConstructLValue(const CXXConstructExpr *E); + LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E); LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E); LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E); @@ -783,6 +784,10 @@ public: void EmitCXXConstructExpr(llvm::Value *Dest, const CXXConstructExpr *E); + RValue EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E, + llvm::Value *AggLoc = 0, + bool isAggLocVolatile = false); + //===--------------------------------------------------------------------===// // Internal Helpers //===--------------------------------------------------------------------===// -- 2.40.0