From: Anna Zaks Date: Tue, 13 Mar 2012 22:15:58 +0000 (+0000) Subject: [analyser] Refactor shouldInline logic into a helper. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6cc0969ab37c614d6cf496f2ed6d2fca397a0133;p=clang [analyser] Refactor shouldInline logic into a helper. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152677 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp b/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp index bb4ea99b16..8c9154cf4c 100644 --- a/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp @@ -127,13 +127,29 @@ static unsigned getNumberStackFrames(const LocationContext *LCtx) { return count; } +// Determine if we should inline the call. +static bool shouldInline(const FunctionDecl *FD, ExplodedNode *Pred, + AnalysisManager &AMgr) { + AnalysisDeclContext *CalleeADC = AMgr.getAnalysisDeclContext(FD); + const CFG *CalleeCFG = CalleeADC->getCFG(); + + if (getNumberStackFrames(Pred->getLocationContext()) + == AMgr.InlineMaxStackDepth) + return false; + + if (CalleeCFG->getNumBlockIDs() > AMgr.InlineMaxFunctionSize) + return false; + + return true; +} + bool ExprEngine::InlineCall(ExplodedNodeSet &Dst, const CallExpr *CE, ExplodedNode *Pred) { ProgramStateRef state = Pred->getState(); const Expr *Callee = CE->getCallee(); const FunctionDecl *FD = - state->getSVal(Callee, Pred->getLocationContext()).getAsFunctionDecl(); + state->getSVal(Callee, Pred->getLocationContext()).getAsFunctionDecl(); if (!FD || !FD->hasBody(FD)) return false; @@ -142,16 +158,11 @@ bool ExprEngine::InlineCall(ExplodedNodeSet &Dst, // FIXME: Handle C++. break; case Stmt::CallExprClass: { - if (getNumberStackFrames(Pred->getLocationContext()) - == AMgr.InlineMaxStackDepth) - return false; - - AnalysisDeclContext *CalleeADC = AMgr.getAnalysisDeclContext(FD); - const CFG *CalleeCFG = CalleeADC->getCFG(); - if (CalleeCFG->getNumBlockIDs() > AMgr.InlineMaxFunctionSize) + if (!shouldInline(FD, Pred, AMgr)) return false; // Construct a new stack frame for the callee. + AnalysisDeclContext *CalleeADC = AMgr.getAnalysisDeclContext(FD); const StackFrameContext *CallerSFC = Pred->getLocationContext()->getCurrentStackFrame(); const StackFrameContext *CalleeSFC =