From 4b2434da54633662efb8ce31dd6ea15d47bc190f Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sat, 30 May 2009 20:56:46 +0000 Subject: [PATCH] Remove VarDecl from CXXConstructExpr. llvm-svn: 72633 --- clang/include/clang/AST/ExprCXX.h | 14 ++++++-------- clang/lib/AST/ExprCXX.cpp | 18 ++++++++---------- clang/lib/CodeGen/CGExprAgg.cpp | 14 +++----------- clang/lib/Sema/SemaDeclCXX.cpp | 2 +- clang/lib/Sema/SemaExprCXX.cpp | 5 ++--- clang/lib/Sema/SemaInit.cpp | 4 ++-- clang/lib/Sema/SemaTemplateInstantiateExpr.cpp | 10 +--------- 7 files changed, 23 insertions(+), 44 deletions(-) diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 0548a7212d37..05ce4eebbe5c 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -458,7 +458,6 @@ public: /// CXXConstructExpr - Represents a call to a C++ constructor. class CXXConstructExpr : public Expr { - VarDecl *VD; CXXConstructorDecl *Constructor; bool Elidable; @@ -468,19 +467,18 @@ class CXXConstructExpr : public Expr { protected: - CXXConstructExpr(ASTContext &C, StmtClass SC, VarDecl *vd, QualType T, + CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, CXXConstructorDecl *d, bool elidable, Expr **args, unsigned numargs); ~CXXConstructExpr() { } public: - static CXXConstructExpr *Create(ASTContext &C, VarDecl *VD, QualType T, + static CXXConstructExpr *Create(ASTContext &C, QualType T, CXXConstructorDecl *D, bool Elidable, Expr **Args, unsigned NumArgs); void Destroy(ASTContext &C); - VarDecl* getVarDecl() const { return VD; } CXXConstructorDecl* getConstructor() const { return Constructor; } /// \brief Whether this construction is elidable. @@ -558,10 +556,10 @@ class CXXTemporaryObjectExpr : public CXXConstructExpr { SourceLocation RParenLoc; public: - CXXTemporaryObjectExpr(ASTContext &C, VarDecl *vd, - CXXConstructorDecl *Cons, QualType writtenTy, - SourceLocation tyBeginLoc, Expr **Args, - unsigned NumArgs, SourceLocation rParenLoc); + CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, + QualType writtenTy, SourceLocation tyBeginLoc, + Expr **Args,unsigned NumArgs, + SourceLocation rParenLoc); ~CXXTemporaryObjectExpr() { } diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp index f757ac0a8920..4b4360632798 100644 --- a/clang/lib/AST/ExprCXX.cpp +++ b/clang/lib/AST/ExprCXX.cpp @@ -251,35 +251,33 @@ CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C, return new (C) CXXBindTemporaryExpr(Temp, SubExpr); } -CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C, VarDecl *vd, +CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, QualType writtenTy, SourceLocation tyBeginLoc, Expr **Args, unsigned NumArgs, SourceLocation rParenLoc) - : CXXConstructExpr(C, CXXTemporaryObjectExprClass, vd, writtenTy, Cons, + : CXXConstructExpr(C, CXXTemporaryObjectExprClass, writtenTy, Cons, false, Args, NumArgs), TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) { } -CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, VarDecl *VD, - QualType T, CXXConstructorDecl *D, - bool Elidable, +CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T, + CXXConstructorDecl *D, bool Elidable, Expr **Args, unsigned NumArgs) { - return new (C) CXXConstructExpr(C, CXXConstructExprClass, VD, T, D, Elidable, + return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, D, Elidable, Args, NumArgs); } -CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, VarDecl *vd, - QualType T, CXXConstructorDecl *D, - bool elidable, +CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, + CXXConstructorDecl *D, bool elidable, Expr **args, unsigned numargs) : Expr(SC, T, T->isDependentType(), (T->isDependentType() || CallExpr::hasAnyValueDependentArguments(args, numargs))), - VD(vd), Constructor(D), Elidable(elidable), Args(0), NumArgs(numargs) { + Constructor(D), Elidable(elidable), Args(0), NumArgs(numargs) { if (NumArgs > 0) { Args = new (C) Stmt*[NumArgs]; for (unsigned i = 0; i < NumArgs; ++i) diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 9ff8006e8c28..cfb67ade7909 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -292,17 +292,9 @@ void AggExprEmitter::VisitVAArgExpr(VAArgExpr *VE) { void AggExprEmitter::VisitCXXConstructExpr(const CXXConstructExpr *E) { - llvm::Value *V = DestPtr; - - if (!V) { - assert(isa(E->getVarDecl()) && - "Must have a temp var decl when there's no destination!"); - - V = CGF.CreateTempAlloca(CGF.ConvertType(E->getVarDecl()->getType()), - "tmpvar"); - } - - CGF.EmitCXXConstructExpr(V, E); + assert(DestPtr && "Must have somewhere to emit into!"); + + CGF.EmitCXXConstructExpr(DestPtr, E); } void AggExprEmitter::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) { diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 67c6dc3fae49..f13179f0438f 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -1800,7 +1800,7 @@ void Sema::InitializeVarWithConstructor(VarDecl *VD, CXXConstructorDecl *Constructor, QualType DeclInitType, Expr **Exprs, unsigned NumExprs) { - Expr *Temp = CXXConstructExpr::Create(Context, VD, DeclInitType, Constructor, + Expr *Temp = CXXConstructExpr::Create(Context, DeclInitType, Constructor, false, Exprs, NumExprs); VD->setInit(Context, Temp); } diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index b6ccb99d6ba0..e9b68d7a5e08 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -208,7 +208,7 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep, exprs.release(); - Expr *E = new (Context) CXXTemporaryObjectExpr(Context, Temp, Constructor, + Expr *E = new (Context) CXXTemporaryObjectExpr(Context, Constructor, Ty, TyBeginLoc, Exprs, NumExprs, RParenLoc); return MaybeBindToTemporary(E); @@ -883,9 +883,8 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType, // FIXME: When can ToType be a reference type? assert(!ToType->isReferenceType()); - CXXTempVarDecl *Temp = CXXTempVarDecl::Create(Context, CurContext, ToType); // FIXME: Keep track of whether the copy constructor is elidable or not. - From = CXXConstructExpr::Create(Context, Temp, ToType, + From = CXXConstructExpr::Create(Context, ToType, SCS.CopyConstructor, false, &From, 1); return false; } diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 20c712fa2938..4976bd466fcc 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -174,8 +174,8 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType, if (!Constructor) return true; - Init = CXXConstructExpr::Create(Context, 0, DeclType, Constructor, - false, &Init, 1); + Init = CXXConstructExpr::Create(Context, DeclType, Constructor, false, + &Init, 1); return false; } diff --git a/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp b/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp index c37bf2b2c436..a6b9703cee0b 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp @@ -1007,15 +1007,7 @@ TemplateExprInstantiator::VisitCXXConstructExpr(CXXConstructExpr *E) { Args.push_back(ArgInst.takeAs()); } - - VarDecl *Var = cast_or_null(SemaRef.InstantiateDecl(E->getVarDecl(), - SemaRef.CurContext, - TemplateArgs)); - if (!Var) - return SemaRef.ExprError(); - - SemaRef.CurrentInstantiationScope->InstantiatedLocal(E->getVarDecl(), Var); - return SemaRef.Owned(CXXConstructExpr::Create(SemaRef.Context, Var, T, + return SemaRef.Owned(CXXConstructExpr::Create(SemaRef.Context, T, E->getConstructor(), E->isElidable(), Args.takeAs(),