From: Fariborz Jahanian Date: Tue, 24 Nov 2009 19:27:49 +0000 (+0000) Subject: More cleanup of argument call collection. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4cd1c706c2bfd3533df563c3b7292c85c7143f31;p=clang More cleanup of argument call collection. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89789 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index beaccdac2f..259bf25bed 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -1523,14 +1523,6 @@ public: Expr **Args, unsigned NumArgs, SourceLocation RParenLoc); - bool GatherArgumentsForCall(SourceLocation CallLoc, - FunctionDecl *FDecl, - const FunctionProtoType *Proto, - unsigned FirstProtoArg, - Expr **Args, unsigned NumArgs, - llvm::SmallVector &AllArgs, - Expr *Fn = 0); - void DeconstructCallFunction(Expr *FnExpr, llvm::SmallVectorImpl& Fns, DeclarationName &Name, @@ -3320,9 +3312,21 @@ public: VariadicFunction, VariadicBlock, VariadicMethod, - VariadicConstructor + VariadicConstructor, + VariadicDoesNotApply }; + /// GatherArgumentsForCall - Collector argument expressions for various + /// form of call prototypes. + bool GatherArgumentsForCall(SourceLocation CallLoc, + FunctionDecl *FDecl, + const FunctionProtoType *Proto, + unsigned FirstProtoArg, + Expr **Args, unsigned NumArgs, + llvm::SmallVector &AllArgs, + Expr *Fn = 0, + VariadicCallType CallType = VariadicDoesNotApply); + // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but // will warn if the resulting type is not a POD type. bool DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT); diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 50fd5ec9b1..2a7758a677 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2620,8 +2620,14 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, } } llvm::SmallVector AllArgs; + VariadicCallType CallType = + Proto->isVariadic() ? VariadicFunction : VariadicDoesNotApply; + if (Fn->getType()->isBlockPointerType()) + CallType = VariadicBlock; // Block + else if (isa(Fn)) + CallType = VariadicMethod; Invalid = GatherArgumentsForCall(Call->getSourceRange().getBegin(), FDecl, - Proto, 0, Args, NumArgs, AllArgs, Fn); + Proto, 0, Args, NumArgs, AllArgs, Fn, CallType); if (Invalid) return true; unsigned TotalNumArgs = AllArgs.size(); @@ -2637,7 +2643,8 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc, unsigned FirstProtoArg, Expr **Args, unsigned NumArgs, llvm::SmallVector &AllArgs, - Expr *Fn) { + Expr *Fn, + VariadicCallType CallType) { unsigned NumArgsInProto = Proto->getNumArgs(); unsigned NumArgsToCheck = NumArgs; bool Invalid = false; @@ -2679,14 +2686,7 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc, } // If this is a variadic call, handle args passed through "...". - if (Proto->isVariadic()) { - VariadicCallType CallType = VariadicFunction; - if (Fn) { - if (Fn->getType()->isBlockPointerType()) - CallType = VariadicBlock; // Block - else if (isa(Fn)) - CallType = VariadicMethod; - } + if (CallType != VariadicDoesNotApply) { // Promote the arguments (C99 6.5.2.2p7). for (unsigned i = ArgIx; i < NumArgs; i++) { Expr *Arg = Args[i]; diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 4800a1df4a..4ad62f7311 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -407,9 +407,11 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, // Add default arguments, if any. const FunctionProtoType *Proto = OperatorNew->getType()->getAs(); + VariadicCallType CallType = + Proto->isVariadic() ? VariadicFunction : VariadicDoesNotApply; bool Invalid = GatherArgumentsForCall(PlacementLParen, OperatorNew, Proto, 1, PlaceArgs, NumPlaceArgs, - AllPlaceArgs); + AllPlaceArgs, 0, CallType); if (Invalid) return ExprError();