[cfe-commits] r163571 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp test/Analysis/inlining/test-always-inline-size-option.c

Anna Zaks ganna at apple.com
Mon Sep 10 16:35:11 PDT 2012


Author: zaks
Date: Mon Sep 10 18:35:11 2012
New Revision: 163571

URL: http://llvm.org/viewvc/llvm-project?rev=163571&view=rev
Log:
[analyzer] Do not count calls to small functions when computing stack
depth.

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

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

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h?rev=163571&r1=163570&r2=163571&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h Mon Sep 10 18:35:11 2012
@@ -496,6 +496,10 @@
                     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);

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp?rev=163571&r1=163570&r2=163571&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp Mon Sep 10 18:35:11 2012
@@ -247,18 +247,33 @@
   }
 }
 
-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) {

Modified: cfe/trunk/test/Analysis/inlining/test-always-inline-size-option.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/test-always-inline-size-option.c?rev=163571&r1=163570&r2=163571&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/inlining/test-always-inline-size-option.c (original)
+++ cfe/trunk/test/Analysis/inlining/test-always-inline-size-option.c Mon Sep 10 18:35:11 2012
@@ -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 callRecursive() {
   return recursive();
 }
+
+int mutuallyRecursive1();
+
+int mutuallyRecursive2() {
+  return mutuallyRecursive1();
+}
+
+int mutuallyRecursive1() {
+  return mutuallyRecursive2();
+}
+int callMutuallyRecursive() {
+  return mutuallyRecursive1();
+}





More information about the cfe-commits mailing list