]> granicus.if.org Git - clang/commitdiff
[analyzer] NFC: Eliminate ParentMap lookup in mayInlineCallKind().
authorArtem Dergachev <artem.dergachev@gmail.com>
Thu, 15 Feb 2018 19:01:55 +0000 (19:01 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Thu, 15 Feb 2018 19:01:55 +0000 (19:01 +0000)
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.

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

include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp

index a9423d4f029db99dac413505f13ff1cfa93dbc4e..ea81313a8757088a8df03a97b9b9f23ab4a78667 100644 (file)
@@ -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,
index bdf5555b2e596a833d8454bef1a2355bf7597f0d..107debdd4c445fc96eb566a9469c01ead3bbe312 100644 (file)
@@ -109,10 +109,7 @@ ExprEngine::getRegionForConstructedObject(const CXXConstructExpr *CE,
 
   // 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()) {
index 9f61861ae4fb156c7a7ff3cfbb29eab5988b000a..d89d8f5bba7fd9cc869d913289eb09f78e11201d 100644 (file)
@@ -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 CallEvent &Call, const ExplodedNode *Pred,
 
     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())