From 2f77bbd1bffcc4715033fc6509a2b9f111432085 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 18 Jan 2012 21:24:45 +0000 Subject: [PATCH] Add a depth limit to avoid runaway recursion. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148419 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/ObjCARC.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/Scalar/ObjCARC.cpp b/lib/Transforms/Scalar/ObjCARC.cpp index a01676ab65b..410f6bcd42f 100644 --- a/lib/Transforms/Scalar/ObjCARC.cpp +++ b/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; -- 2.34.1