diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2005-05-21 00:39:30 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2005-05-21 00:39:30 +0000 |
commit | b82baf04ecc33f450c0102f68f9272c0724610ed (patch) | |
tree | 63d5b9312a7398fe0a621b8afe0a1465fa0d9493 /lib/Transforms | |
parent | 5845623148891ab1a41e55358cbe8393814fed14 (diff) |
Make sure ... arguments are casted to sbyte* where needed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22162 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/IPO/SimplifyLibCalls.cpp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/lib/Transforms/IPO/SimplifyLibCalls.cpp b/lib/Transforms/IPO/SimplifyLibCalls.cpp index cb5194fea1..5c99a025f0 100644 --- a/lib/Transforms/IPO/SimplifyLibCalls.cpp +++ b/lib/Transforms/IPO/SimplifyLibCalls.cpp @@ -1237,6 +1237,16 @@ public: } } PowOptimizer; +/// CastToCStr - Return V if it is an sbyte*, otherwise cast it to sbyte*, +/// inserting the cast before IP, and return the cast. +/// @brief Cast a value to a "C" string. +static Value *CastToCStr(Value *V, Instruction &IP) { + const Type *SBPTy = PointerType::get(Type::SByteTy); + if (V->getType() != SBPTy) + return new CastInst(V, SBPTy, V->getName(), &IP); + return V; +} + /// This LibCallOptimization will simplify calls to the "fprintf" library /// function. It looks for cases where the result of fprintf is not used and the /// operation can be reduced to something simpler. @@ -1292,7 +1302,7 @@ public: return false; } - // fprintf(file,fmt) -> fwrite(fmt,strlen(fmt),1file) + // fprintf(file,fmt) -> fwrite(fmt,strlen(fmt),file) const Type* FILEptr_type = ci->getOperand(1)->getType(); Function* fwrite_func = SLC.get_fwrite(FILEptr_type); if (!fwrite_func) @@ -1335,7 +1345,7 @@ public: if (!fwrite_func) return false; std::vector<Value*> args; - args.push_back(ci->getOperand(3)); + args.push_back(CastToCStr(ci->getOperand(3), *ci)); args.push_back(ConstantUInt::get(SLC.getIntPtrType(),len)); args.push_back(ConstantUInt::get(SLC.getIntPtrType(),1)); args.push_back(ci->getOperand(1)); @@ -1366,17 +1376,6 @@ public: } } FPrintFOptimizer; -/// CastToCStr - Return V if it is an sbyte*, otherwise cast it to sbyte*, -/// inserting the cast before IP, and return the cast. -/// @brief Cast a value to a "C" string. -static Value *CastToCStr(Value *V, Instruction &IP) { - const Type *SBPTy = PointerType::get(Type::SByteTy); - if (V->getType() != SBPTy) - return new CastInst(V, SBPTy, V->getName(), &IP); - return V; -} - - /// This LibCallOptimization will simplify calls to the "sprintf" library /// function. It looks for cases where the result of sprintf is not used and the /// operation can be reduced to something simpler. |