diff options
author | Evan Cheng <evan.cheng@apple.com> | 2008-01-11 23:10:11 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2008-01-11 23:10:11 +0000 |
commit | 3d794786718a62f998639a7061dff24c1e0ebd5e (patch) | |
tree | 9e543efff808c34b90401b0812db6d58d55d7c64 /lib/Target/CBackend/CBackend.cpp | |
parent | 48e1dce486fb7cf5f4ff609cbf3e34cd89694d05 (diff) |
More cbe byval fixes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45891 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/CBackend/CBackend.cpp')
-rw-r--r-- | lib/Target/CBackend/CBackend.cpp | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index bbaf9c1bb8..235e7b7df0 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -1908,18 +1908,24 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) { } else { // Loop over the arguments, printing them. FunctionType::param_iterator I = FT->param_begin(), E = FT->param_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; } - unsigned Idx = 1; for (; I != E; ++I) { if (PrintedArg) FunctionInnards << ", "; - printType(FunctionInnards, *I, + const Type *ArgTy = *I; + if (PAL && PAL->paramHasAttr(Idx, ParamAttr::ByVal)) { + assert(isa<PointerType>(ArgTy)); + ArgTy = cast<PointerType>(ArgTy)->getElementType(); + } + printType(FunctionInnards, ArgTy, /*isSigned=*/PAL && PAL->paramHasAttr(Idx, ParamAttr::SExt)); PrintedArg = true; ++Idx; @@ -2628,9 +2634,11 @@ void CWriter::visitCallInst(CallInst &I) { const ParamAttrsList *PAL = I.getParamAttrs(); bool isStructRet = I.isStructReturn(); if (isStructRet) { - Out << "*("; + bool isByVal = ByValParams.count(I.getOperand(1)); + if (!isByVal) Out << "*("; writeOperand(I.getOperand(1)); - Out << ") = "; + if (!isByVal) Out << ")"; + Out << " = "; } if (I.isTailCall()) Out << " /*tail*/ "; @@ -2685,22 +2693,26 @@ void CWriter::visitCallInst(CallInst &I) { } bool PrintedArg = false; - unsigned Idx = 1; - for (; AI != AE; ++AI, ++ArgNo, ++Idx) { + for (; AI != AE; ++AI, ++ArgNo) { if (PrintedArg) Out << ", "; if (ArgNo < NumDeclaredParams && (*AI)->getType() != FTy->getParamType(ArgNo)) { Out << '('; printType(Out, FTy->getParamType(ArgNo), - /*isSigned=*/PAL && PAL->paramHasAttr(Idx, ParamAttr::SExt)); + /*isSigned=*/PAL && PAL->paramHasAttr(ArgNo+1, ParamAttr::SExt)); Out << ')'; } - // If call is expecting argument to be passed by value, then do not - // take its address. - if (PAL && PAL->paramHasAttr(Idx, ParamAttr::ByVal)) - writeOperandInternal(*AI); - else - writeOperand(*AI); + // Check if the argument is expected to be passed by value. + bool isOutByVal = PAL && PAL->paramHasAttr(ArgNo+1, ParamAttr::ByVal); + // Check if this argument itself is passed in by reference. + bool isInByVal = ByValParams.count(*AI); + if (isOutByVal && !isInByVal) + Out << "*("; + else if (!isOutByVal && isInByVal) + Out << "&("; + writeOperand(*AI); + if (isOutByVal ^ isInByVal) + Out << ")"; PrintedArg = true; } Out << ')'; |