aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/InstCombine/InstCombineCalls.cpp
diff options
context:
space:
mode:
authorEric Christopher <echristo@apple.com>2010-03-11 19:24:34 +0000
committerEric Christopher <echristo@apple.com>2010-03-11 19:24:34 +0000
commit76ce2055c858caa96d28a3dc49369d4aadf2764f (patch)
treeb127a398aab6319e15ac2beedcaa9d0a61e5751e /lib/Transforms/InstCombine/InstCombineCalls.cpp
parente092374f6e511c73b65b198dabe7bdcd23591363 (diff)
downloadexternal_llvm-76ce2055c858caa96d28a3dc49369d4aadf2764f.zip
external_llvm-76ce2055c858caa96d28a3dc49369d4aadf2764f.tar.gz
external_llvm-76ce2055c858caa96d28a3dc49369d4aadf2764f.tar.bz2
Lower stpcpy_chk when possible.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98274 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineCalls.cpp')
-rw-r--r--lib/Transforms/InstCombine/InstCombineCalls.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp
index c62155e..43ff58d 100644
--- a/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -838,6 +838,19 @@ Instruction *InstCombiner::tryOptimizeCall(CallInst *CI, const TargetData *TD) {
// Should be similar to strcpy.
if (Name == "__stpcpy_chk") {
+ ConstantInt *SizeCI = dyn_cast<ConstantInt>(CI->getOperand(3));
+ if (!SizeCI)
+ return 0;
+ // If a) we don't have any length information, or b) we know this will
+ // fit then just lower to a plain stpcpy. Otherwise we'll keep our
+ // stpcpy_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 (SizeCI->isAllOnesValue() ||
+ SizeCI->getZExtValue() >= GetStringLength(CI->getOperand(2))) {
+ Value *Ret = EmitStpCpy(CI->getOperand(1), CI->getOperand(2), B, TD);
+ return ReplaceInstUsesWith(*CI, Ret);
+ }
return 0;
}