From: Douglas Gregor Date: Tue, 22 Dec 2009 16:09:06 +0000 (+0000) Subject: Switch parameter-passing for calls via function pointers (where we X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a188ff2d8a18140541fcd5884deda4552dac71a7;p=clang Switch parameter-passing for calls via function pointers (where we don't have a FunctionDecl) over to InitializationSequence. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91906 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index d01516c77f..09e1d6f455 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3181,21 +3181,22 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc, << Arg->getSourceRange())) return true; - // Pass the argument. - if (FDecl && i < FDecl->getNumParams()) { - ParmVarDecl *Param = FDecl->getParamDecl(i); - InitializedEntity Entity =InitializedEntity::InitializeParameter(Param); - OwningExprResult ArgE = PerformCopyInitialization(Entity, - SourceLocation(), - Owned(Arg)); - if (ArgE.isInvalid()) - return true; - - Arg = ArgE.takeAs(); - } else { - if (PerformCopyInitialization(Arg, ProtoArgType, AA_Passing)) - return true; - } + // Pass the argument + ParmVarDecl *Param = 0; + if (FDecl && i < FDecl->getNumParams()) + Param = FDecl->getParamDecl(i); + + + InitializedEntity Entity = + Param? InitializedEntity::InitializeParameter(Param) + : InitializedEntity::InitializeParameter(ProtoArgType); + OwningExprResult ArgE = PerformCopyInitialization(Entity, + SourceLocation(), + Owned(Arg)); + if (ArgE.isInvalid()) + return true; + + Arg = ArgE.takeAs(); if (!ProtoArgType->isReferenceType()) Arg = MaybeBindToTemporary(Arg).takeAs(); diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index b72fede8bb..9c85ceca74 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -1807,8 +1807,12 @@ InitializedEntity InitializedEntity::InitializeBase(ASTContext &Context, DeclarationName InitializedEntity::getName() const { switch (getKind()) { - case EK_Variable: case EK_Parameter: + if (!VariableOrMember) + return DeclarationName(); + // Fall through + + case EK_Variable: case EK_Member: return VariableOrMember->getDeclName(); diff --git a/lib/Sema/SemaInit.h b/lib/Sema/SemaInit.h index c5ba57c726..959c55e3d3 100644 --- a/lib/Sema/SemaInit.h +++ b/lib/Sema/SemaInit.h @@ -105,8 +105,9 @@ private: : Kind(EK_Parameter), Parent(0), Type(Parm->getType()), VariableOrMember(reinterpret_cast(Parm)) { } - /// \brief Create the initialization entity for the result of a function, - /// throwing an object, or performing an explicit cast. + /// \brief Create the initialization entity for the result of a + /// function, throwing an object, performing an explicit cast, or + /// initializing a parameter for which there is no declaration. InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type) : Kind(Kind), Parent(0), Type(Type), Location(Loc.getRawEncoding()) { } @@ -130,6 +131,12 @@ public: return InitializedEntity(Parm); } + /// \brief Create the initialization entity for a parameter that is + /// only known by its type. + static InitializedEntity InitializeParameter(QualType Type) { + return InitializedEntity(EK_Parameter, SourceLocation(), Type); + } + /// \brief Create the initialization entity for the result of a function. static InitializedEntity InitializeResult(SourceLocation ReturnLoc, QualType Type) {