]> granicus.if.org Git - clang/commitdiff
[analyzer] Do not count calls to small functions when computing stack
authorAnna Zaks <ganna@apple.com>
Mon, 10 Sep 2012 23:35:11 +0000 (23:35 +0000)
committerAnna Zaks <ganna@apple.com>
Mon, 10 Sep 2012 23:35:11 +0000 (23:35 +0000)
depth.

We only want to count how many substantial functions we inlined. This
is an improvement to r163558.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163571 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
test/Analysis/inlining/test-always-inline-size-option.c

index ffc169889183a025b61ac135375e1ebb6a580126..690ead02a00850bbddd945a8996f3e2714d64c15 100644 (file)
@@ -496,6 +496,10 @@ private:
                     ProgramStateRef St, SVal location,
                     const ProgramPointTag *tag, bool isLoad);
 
+  /// Count the stack depth and determine if the call is recursive.
+  void examineStackFrames(const Decl *D, const LocationContext *LCtx,
+                          bool &IsRecursive, unsigned &StackDepth);
+
   bool shouldInlineDecl(const Decl *D, ExplodedNode *Pred);
   bool inlineCall(const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
                   ExplodedNode *Pred, ProgramStateRef State);
index 54c66d37ba7f229af3edaada8beab66a7548dbb2..eb5395e93c7785fad3f33fb1cefdc70cdab2b04f 100644 (file)
@@ -247,18 +247,33 @@ void ExprEngine::processCallExit(ExplodedNode *CEBNode) {
   }
 }
 
-static void examineStackFrames(const Decl *D, const LocationContext *LCtx,
+void ExprEngine::examineStackFrames(const Decl *D, const LocationContext *LCtx,
                                bool &IsRecursive, unsigned &StackDepth) {
   IsRecursive = false;
   StackDepth = 0;
+
   while (LCtx) {
     if (const StackFrameContext *SFC = dyn_cast<StackFrameContext>(LCtx)) {
-      ++StackDepth;
-      if (SFC->getDecl() == D)
+      const Decl *DI = SFC->getDecl();
+
+      // Mark recursive (and mutually recursive) functions and always count
+      // them when measuring the stack depth.
+      if (DI == D) {
         IsRecursive = true;
+        ++StackDepth;
+        LCtx = LCtx->getParent();
+        continue;
+      }
+
+      // Do not count the small functions when determining the stack depth.
+      AnalysisDeclContext *CalleeADC = AMgr.getAnalysisDeclContext(DI);
+      const CFG *CalleeCFG = CalleeADC->getCFG();
+      if (CalleeCFG->getNumBlockIDs() > AMgr.options.getAlwaysInlineSize())
+        ++StackDepth;
     }
     LCtx = LCtx->getParent();
   }
+
 }
 
 static bool IsInStdNamespace(const FunctionDecl *FD) {
index ef604c2128ce3bcae8a13b74862ef35f8c2f0173..6b3c13d2b6722a3b9ad89b952b066b20635406d0 100644 (file)
@@ -2,6 +2,11 @@
 
 void clang_analyzer_eval(int);
 int nested5() {
+  if (5 < 3)
+    return 0;
+  else
+    if (3 == 3)
+      return 0;
   return 0;
 }
 int nested4() {
@@ -28,3 +33,16 @@ int recursive() {
 int callRecursive() {
   return recursive();
 }
+
+int mutuallyRecursive1();
+
+int mutuallyRecursive2() {
+  return mutuallyRecursive1();
+}
+
+int mutuallyRecursive1() {
+  return mutuallyRecursive2();
+}
+int callMutuallyRecursive() {
+  return mutuallyRecursive1();
+}