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/CGExpr.cpp b/CodeGen/CGExpr.cpp
index 04f3f94..41eb275 100644
--- a/CodeGen/CGExpr.cpp
+++ b/CodeGen/CGExpr.cpp
@@ -511,12 +511,14 @@
           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 @@
 }
 
 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<PointerType>(FnType.getCanonicalType())->getPointeeType();
   QualType ResultType = cast<FunctionType>(FnType)->getResultType();
-  
-  // Calling unprototyped functions provides no argument info.
-  unsigned NumArgs = 0;
-  if (const FunctionTypeProto *FTP = dyn_cast<FunctionTypeProto>(FnType))
-    NumArgs = FTP->getNumArgs();
-  
+
   llvm::SmallVector<llvm::Value*, 16> Args;
   
   // Handle struct-return functions by passing a pointer to the location that