[cfe-commits] r46543 - in /cfe/trunk/CodeGen: CGBuiltin.cpp CGExpr.cpp CGExprScalar.cpp CodeGenFunction.h

Eli Friedman eli.friedman at gmail.com
Tue Jan 29 17:32:06 PST 2008


Author: efriedma
Date: Tue Jan 29 19:32:06 2008
New Revision: 46543

URL: http://llvm.org/viewvc/llvm-project?rev=46543&view=rev
Log:
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.

Modified:
    cfe/trunk/CodeGen/CGBuiltin.cpp
    cfe/trunk/CodeGen/CGExpr.cpp
    cfe/trunk/CodeGen/CGExprScalar.cpp
    cfe/trunk/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGBuiltin.cpp?rev=46543&r1=46542&r2=46543&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/CodeGen/CGBuiltin.cpp Tue Jan 29 19:32:06 2008
@@ -30,7 +30,8 @@
   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;

Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=46543&r1=46542&r2=46543&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Tue Jan 29 19:32:06 2008
@@ -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

Modified: cfe/trunk/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprScalar.cpp?rev=46543&r1=46542&r2=46543&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/CodeGen/CGExprScalar.cpp Tue Jan 29 19:32:06 2008
@@ -1012,7 +1012,7 @@
 }
 
 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) {

Modified: cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenFunction.h?rev=46543&r1=46542&r2=46543&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.h Tue Jan 29 19:32:06 2008
@@ -419,8 +419,9 @@
   //===--------------------------------------------------------------------===//
 
   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);





More information about the cfe-commits mailing list