From aaef8ce85655cd3a8d51161aecd2278e9a670443 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Fri, 11 Jan 2008 03:07:46 +0000 Subject: [PATCH] A couple of obvious off-by-one bugs. llvm-svn: 45852 --- llvm/lib/Target/CBackend/CBackend.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Target/CBackend/CBackend.cpp b/llvm/lib/Target/CBackend/CBackend.cpp index f4e9e3415283..23e9b275d810 100644 --- a/llvm/lib/Target/CBackend/CBackend.cpp +++ b/llvm/lib/Target/CBackend/CBackend.cpp @@ -366,10 +366,11 @@ void CWriter::printStructReturnPointerFunctionType(std::ostream &Out, FunctionType::param_iterator I = FTy->param_begin(), E = FTy->param_end(); const Type *RetTy = cast(I->get())->getElementType(); unsigned Idx = 1; - for (++I; I != E; ++I) { + for (++I, ++Idx; I != E; ++I, ++Idx) { if (PrintedType) FunctionInnards << ", "; - printType(FunctionInnards, *I, + const Type *ArgTy = *I; + printType(FunctionInnards, ArgTy, /*isSigned=*/PAL && PAL->paramHasAttr(Idx, ParamAttr::SExt), ""); PrintedType = true; } @@ -1866,23 +1867,25 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) { if (!F->isDeclaration()) { if (!F->arg_empty()) { Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end(); + unsigned Idx = 1; // If this is a struct-return function, don't print the hidden // struct-return argument. if (isStructReturn) { assert(I != E && "Invalid struct return function!"); ++I; + ++Idx; } std::string ArgName; - unsigned Idx = 1; for (; I != E; ++I) { if (PrintedArg) FunctionInnards << ", "; if (I->hasName() || !Prototype) ArgName = GetValueName(I); else ArgName = ""; - printType(FunctionInnards, I->getType(), + const Type *ArgTy = I->getType(); + printType(FunctionInnards, ArgTy, /*isSigned=*/PAL && PAL->paramHasAttr(Idx, ParamAttr::SExt), ArgName); PrintedArg = true;