Hi,

Attached is a patch to fix codegen of function calls to varargs functions.
e.g.: printf("size=%d\n",sizeof(long));

Nuno
Index: CGExprScalar.cpp
===================================================================
--- CGExprScalar.cpp    (revision 46352)
+++ CGExprScalar.cpp    (working copy)
@@ -993,7 +993,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) {
Index: CodeGenFunction.h
===================================================================
--- CodeGenFunction.h   (revision 46352)
+++ CodeGenFunction.h   (working copy)
@@ -419,8 +419,8 @@
  //===--------------------------------------------------------------------===//

  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);
Index: CGBuiltin.cpp
===================================================================
--- CGBuiltin.cpp       (revision 46352)
+++ CGBuiltin.cpp       (working copy)
@@ -30,7 +30,7 @@
  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;
Index: CGExpr.cpp
===================================================================
--- CGExpr.cpp  (revision 46352)
+++ CGExpr.cpp  (working copy)
@@ -511,12 +511,12 @@
          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 +526,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
_______________________________________________
cfe-dev mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

Reply via email to