summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp
diff options
context:
space:
mode:
authorEric Christopher <echristo@apple.com>2010-01-29 01:37:11 +0000
committerEric Christopher <echristo@apple.com>2010-01-29 01:37:11 +0000
commit9b3c02b7da767c62ae21f9a27544484527643d64 (patch)
tree78ed91af1a4a58f60ed2b20e105cecd5a42c9e17 /llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp
parentd5fd0fac3801a43b2e232f3f6ac2fcecbedbd53b (diff)
downloadbcm5719-llvm-9b3c02b7da767c62ae21f9a27544484527643d64.tar.gz
bcm5719-llvm-9b3c02b7da767c62ae21f9a27544484527643d64.zip
Make strcpy_chk lower to strcpy if we have a safe size.
llvm-svn: 94783
Diffstat (limited to 'llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp
index a49da9ce9e5..fc23c420cc8 100644
--- a/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp
@@ -1203,9 +1203,6 @@ struct MemMoveChkOpt : public LibCallOptimization {
struct StrCpyChkOpt : public LibCallOptimization {
virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
- // These optimizations require TargetData.
- if (!TD) return 0;
-
const FunctionType *FT = Callee->getFunctionType();
if (FT->getNumParams() != 3 || FT->getReturnType() != FT->getParamType(0) ||
!isa<PointerType>(FT->getParamType(0)) ||
@@ -1217,8 +1214,13 @@ struct StrCpyChkOpt : public LibCallOptimization {
if (!SizeCI)
return 0;
- // We don't have any length information, just lower to a plain strcpy.
- if (SizeCI->isAllOnesValue())
+ // If a) we don't have any length information, or b) we know this will
+ // fit then just lower to a plain strcpy. Otherwise we'll keep our
+ // strcpy_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)))
return EmitStrCpy(CI->getOperand(1), CI->getOperand(2), B);
return 0;
OpenPOWER on IntegriCloud