r325278 - [analyzer] NFC: Eliminate ParentMap lookup in mayInlineCallKind().

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 15 11:01:55 PST 2018


Author: dergachev
Date: Thu Feb 15 11:01:55 2018
New Revision: 325278

URL: http://llvm.org/viewvc/llvm-project?rev=325278&view=rev
Log:
[analyzer] NFC: Eliminate ParentMap lookup in mayInlineCallKind().

Don't look at the parent statement to figure out if the cxx-allocator-inlining
flag should kick in and prevent us from inlining the constructor within
a new-expression. We now have construction contexts for that purpose.

Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp

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=325278&r1=325277&r2=325278&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h Thu Feb 15 11:01:55 2018
@@ -577,6 +577,12 @@ public:
                  ExplodedNode *Pred, ProgramStateRef St, SVal TargetLV, SVal Val,
                  const ProgramPointTag *tag = nullptr);
 
+  /// Return the CFG element corresponding to the worklist element
+  /// that is currently being processed by ExprEngine.
+  CFGElement getCurrentCFGElement() {
+    return (*currBldrCtx->getBlock())[currStmtIdx];
+  }
+
   /// \brief Create a new state in which the call return value is binded to the
   /// call origin expression.
   ProgramStateRef bindReturnValue(const CallEvent &Call,

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp?rev=325278&r1=325277&r2=325278&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp Thu Feb 15 11:01:55 2018
@@ -109,10 +109,7 @@ ExprEngine::getRegionForConstructedObjec
 
   // See if we're constructing an existing region by looking at the
   // current construction context.
-  const NodeBuilderContext &CurrBldrCtx = getBuilderContext();
-  const CFGBlock *B = CurrBldrCtx.getBlock();
-  const CFGElement &E = (*B)[currStmtIdx];
-  if (auto CC = E.getAs<CFGConstructor>()) {
+  if (auto CC = getCurrentCFGElement().getAs<CFGConstructor>()) {
     if (const Stmt *TriggerStmt = CC->getTriggerStmt()) {
       if (const CXXNewExpr *CNE = dyn_cast<CXXNewExpr>(TriggerStmt)) {
         if (AMgr.getAnalyzerOptions().mayInlineCXXAllocator()) {

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp?rev=325278&r1=325277&r2=325278&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp Thu Feb 15 11:01:55 2018
@@ -15,7 +15,6 @@
 #include "PrettyStackTraceLocationContext.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/DeclCXX.h"
-#include "clang/AST/ParentMap.h"
 #include "clang/Analysis/Analyses/LiveVariables.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
@@ -639,10 +638,8 @@ ExprEngine::mayInlineCallKind(const Call
 
     const CXXConstructExpr *CtorExpr = Ctor.getOriginExpr();
 
-    // FIXME: ParentMap is slow and ugly. The callee should provide the
-    // necessary context. Ideally as part of the call event, or maybe as part of
-    // location context.
-    const Stmt *ParentExpr = CurLC->getParentMap().getParent(CtorExpr);
+    auto CC = getCurrentCFGElement().getAs<CFGConstructor>();
+    const Stmt *ParentExpr = CC ? CC->getTriggerStmt() : nullptr;
 
     if (ParentExpr && isa<CXXNewExpr>(ParentExpr) &&
         !Opts.mayInlineCXXAllocator())




More information about the cfe-commits mailing list