summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2012-01-18 21:24:45 +0000
committerDan Gohman <gohman@apple.com>2012-01-18 21:24:45 +0000
commit8f12faeb145b120cd84b7b6168554068366ddcb2 (patch)
tree8621b5a4eb2bd3d832b99933adee141ac7aae8b1
parent8715c517d5f2db048c7ab583a8650faa55ea676d (diff)
downloadbcm5719-llvm-8f12faeb145b120cd84b7b6168554068366ddcb2.tar.gz
bcm5719-llvm-8f12faeb145b120cd84b7b6168554068366ddcb2.zip
Add a depth limit to avoid runaway recursion.
llvm-svn: 148419
-rw-r--r--llvm/lib/Transforms/Scalar/ObjCARC.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/ObjCARC.cpp b/llvm/lib/Transforms/Scalar/ObjCARC.cpp
index a01676ab65b..410f6bcd42f 100644
--- a/llvm/lib/Transforms/Scalar/ObjCARC.cpp
+++ b/llvm/lib/Transforms/Scalar/ObjCARC.cpp
@@ -895,7 +895,7 @@ namespace {
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
virtual bool runOnModule(Module &M);
- bool MayAutorelease(CallSite CS);
+ bool MayAutorelease(CallSite CS, unsigned Depth = 0);
bool OptimizeBB(BasicBlock *BB);
public:
@@ -922,7 +922,7 @@ void ObjCARCAPElim::getAnalysisUsage(AnalysisUsage &AU) const {
/// MayAutorelease - Interprocedurally determine if calls made by the
/// given call site can possibly produce autoreleases.
-bool ObjCARCAPElim::MayAutorelease(CallSite CS) {
+bool ObjCARCAPElim::MayAutorelease(CallSite CS, unsigned Depth) {
if (Function *Callee = CS.getCalledFunction()) {
if (Callee->isDeclaration() || Callee->mayBeOverridden())
return true;
@@ -931,7 +931,11 @@ bool ObjCARCAPElim::MayAutorelease(CallSite CS) {
BasicBlock *BB = I;
for (BasicBlock::iterator J = BB->begin(), F = BB->end(); J != F; ++J)
if (CallSite JCS = CallSite(J))
- if (!JCS.onlyReadsMemory() && MayAutorelease(JCS))
+ // This recursion depth limit is arbitrary. It's just great
+ // enough to cover known interesting testcases.
+ if (Depth < 3 &&
+ !JCS.onlyReadsMemory() &&
+ MayAutorelease(JCS, Depth + 1))
return true;
}
return false;
OpenPOWER on IntegriCloud