summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
diff options
context:
space:
mode:
authorErik Pilkington <erik.pilkington@gmail.com>2019-05-31 22:41:31 +0000
committerErik Pilkington <erik.pilkington@gmail.com>2019-05-31 22:41:31 +0000
commit5234921119f95138e2a0802369b7b092ddb7cc4a (patch)
tree08f658c7376ee451c9dcdbf961d228e03be680c2 /llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
parentfa6bcd0b966ee67696d40256971d5325117875d5 (diff)
downloadbcm5719-llvm-5234921119f95138e2a0802369b7b092ddb7cc4a.tar.gz
bcm5719-llvm-5234921119f95138e2a0802369b7b092ddb7cc4a.zip
NFC: Pull out a function to reduce some duplication
Part of https://reviews.llvm.org/D62358 llvm-svn: 362271
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index cc0b6e0f469..f5e3d76faa0 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -2887,8 +2887,6 @@ Value *FortifiedLibCallSimplifier::optimizeMemSetChk(CallInst *CI,
Value *FortifiedLibCallSimplifier::optimizeStrpCpyChk(CallInst *CI,
IRBuilder<> &B,
LibFunc Func) {
- Function *Callee = CI->getCalledFunction();
- StringRef Name = Callee->getName();
const DataLayout &DL = CI->getModule()->getDataLayout();
Value *Dst = CI->getArgOperand(0), *Src = CI->getArgOperand(1),
*ObjSize = CI->getArgOperand(2);
@@ -2904,8 +2902,12 @@ Value *FortifiedLibCallSimplifier::optimizeStrpCpyChk(CallInst *CI,
// st[rp]cpy_chk call which may fail at runtime if the size is too long.
// TODO: It might be nice to get a maximum length out of the possible
// string lengths for varying.
- if (isFortifiedCallFoldable(CI, 2, 1, true))
- return emitStrCpy(Dst, Src, B, TLI, Name.substr(2, 6));
+ if (isFortifiedCallFoldable(CI, 2, 1, true)) {
+ if (Func == LibFunc_strcpy_chk)
+ return emitStrCpy(Dst, Src, B, TLI);
+ else
+ return emitStpCpy(Dst, Src, B, TLI);
+ }
if (OnlyLowerUnknownSize)
return nullptr;
@@ -2928,13 +2930,15 @@ Value *FortifiedLibCallSimplifier::optimizeStrpCpyChk(CallInst *CI,
Value *FortifiedLibCallSimplifier::optimizeStrpNCpyChk(CallInst *CI,
IRBuilder<> &B,
LibFunc Func) {
- Function *Callee = CI->getCalledFunction();
- StringRef Name = Callee->getName();
if (isFortifiedCallFoldable(CI, 3, 2, false)) {
- Value *Ret = emitStrNCpy(CI->getArgOperand(0), CI->getArgOperand(1),
- CI->getArgOperand(2), B, TLI, Name.substr(2, 7));
- return Ret;
+ if (Func == LibFunc_strncpy_chk)
+ return emitStrNCpy(CI->getArgOperand(0), CI->getArgOperand(1),
+ CI->getArgOperand(2), B, TLI);
+ else
+ return emitStpNCpy(CI->getArgOperand(0), CI->getArgOperand(1),
+ CI->getArgOperand(2), B, TLI);
}
+
return nullptr;
}
OpenPOWER on IntegriCloud