From: Eli Friedman Date: Wed, 30 Jan 2008 01:32:06 +0000 (+0000) Subject: Make sure to emit all the arguments to a function call. This fixes the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5193b8a3e57c4f696161aeddfe8227c294c0a7fe;p=clang Make sure to emit all the arguments to a function call. This fixes the codegen of calls to functions without a prototype and varargs functions, including printf. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46543 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/CodeGen/CGBuiltin.cpp b/CodeGen/CGBuiltin.cpp index d8fe060eb7..d298b4024f 100644 --- a/CodeGen/CGBuiltin.cpp +++ b/CodeGen/CGBuiltin.cpp @@ -30,7 +30,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) { default: { if (getContext().BuiltinInfo.isLibFunction(BuiltinID)) return EmitCallExpr(CGM.getBuiltinLibFunction(BuiltinID), - E->getCallee()->getType(), E->arg_begin()); + E->getCallee()->getType(), E->arg_begin(), + E->getNumArgs()); // See if we have a target specific intrinsic. Intrinsic::ID IntrinsicID; diff --git a/CodeGen/CGExpr.cpp b/CodeGen/CGExpr.cpp index 04f3f94fad..41eb2756a4 100644 --- a/CodeGen/CGExpr.cpp +++ b/CodeGen/CGExpr.cpp @@ -511,12 +511,14 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E) { return EmitBuiltinExpr(builtinID, E); llvm::Value *Callee = EmitScalarExpr(E->getCallee()); - return EmitCallExpr(Callee, E->getCallee()->getType(), E->arg_begin()); + return EmitCallExpr(Callee, E->getCallee()->getType(), + E->arg_begin(), E->getNumArgs()); } -RValue CodeGenFunction::EmitCallExpr(Expr *FnExpr, Expr *const *Args) { +RValue CodeGenFunction::EmitCallExpr(Expr *FnExpr, Expr *const *Args, + unsigned NumArgs) { llvm::Value *Callee = EmitScalarExpr(FnExpr); - return EmitCallExpr(Callee, FnExpr->getType(), Args); + return EmitCallExpr(Callee, FnExpr->getType(), Args, NumArgs); } LValue CodeGenFunction::EmitCallExprLValue(const CallExpr *E) { @@ -526,17 +528,12 @@ LValue CodeGenFunction::EmitCallExprLValue(const CallExpr *E) { } RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType FnType, - Expr *const *ArgExprs) { + Expr *const *ArgExprs, unsigned NumArgs) { // The callee type will always be a pointer to function type, get the function // type. FnType = cast(FnType.getCanonicalType())->getPointeeType(); QualType ResultType = cast(FnType)->getResultType(); - - // Calling unprototyped functions provides no argument info. - unsigned NumArgs = 0; - if (const FunctionTypeProto *FTP = dyn_cast(FnType)) - NumArgs = FTP->getNumArgs(); - + llvm::SmallVector Args; // Handle struct-return functions by passing a pointer to the location that diff --git a/CodeGen/CGExprScalar.cpp b/CodeGen/CGExprScalar.cpp index 8617a3e340..32a1b5386f 100644 --- a/CodeGen/CGExprScalar.cpp +++ b/CodeGen/CGExprScalar.cpp @@ -1012,7 +1012,7 @@ Value *ScalarExprEmitter::VisitChooseExpr(ChooseExpr *E) { } Value *ScalarExprEmitter::VisitOverloadExpr(OverloadExpr *E) { - return CGF.EmitCallExpr(E->getFn(), E->arg_begin()).getScalarVal(); + return CGF.EmitCallExpr(E->getFn(), E->arg_begin(), E->getNumArgs()).getScalarVal(); } Value *ScalarExprEmitter::VisitVAArgExpr(VAArgExpr *VE) { diff --git a/CodeGen/CodeGenFunction.h b/CodeGen/CodeGenFunction.h index dd91a53326..30dfaabd64 100644 --- a/CodeGen/CodeGenFunction.h +++ b/CodeGen/CodeGenFunction.h @@ -419,8 +419,9 @@ public: //===--------------------------------------------------------------------===// RValue EmitCallExpr(const CallExpr *E); - RValue EmitCallExpr(Expr *FnExpr, Expr *const *Args); - RValue EmitCallExpr(llvm::Value *Callee, QualType FnType, Expr *const *Args); + RValue EmitCallExpr(Expr *FnExpr, Expr *const *Args, unsigned NumArgs); + RValue EmitCallExpr(llvm::Value *Callee, QualType FnType, + Expr *const *Args, unsigned NumArgs); RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E); llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);