r327258 - [analyzer] Add scope information to CFG

Maxim Ostapenko via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 12 05:26:15 PDT 2018


Author: chefmax
Date: Mon Mar 12 05:26:15 2018
New Revision: 327258

URL: http://llvm.org/viewvc/llvm-project?rev=327258&view=rev
Log:
[analyzer] Add scope information to CFG

This patch adds two new CFG elements CFGScopeBegin and CFGScopeEnd that indicate
when a local scope begins and ends respectively. We use first VarDecl declared
in a scope to uniquely identify it and add CFGScopeBegin and CFGScopeEnd elements
into corresponding basic blocks.

Differential Revision: https://reviews.llvm.org/D16403

Added:
    cfe/trunk/test/Analysis/scopes-cfg-output.cpp
Modified:
    cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h
    cfe/trunk/include/clang/Analysis/CFG.h
    cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
    cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
    cfe/trunk/lib/Analysis/CFG.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
    cfe/trunk/test/Analysis/analyzer-config.c
    cfe/trunk/test/Analysis/analyzer-config.cpp

Modified: cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h?rev=327258&r1=327257&r2=327258&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h (original)
+++ cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h Mon Mar 12 05:26:15 2018
@@ -435,7 +435,9 @@ public:
                              bool addImplicitDtors = false,
                              bool addInitializers = false,
                              bool addTemporaryDtors = false,
-                             bool addLifetime = false, bool addLoopExit = false,
+                             bool addLifetime = false,
+                             bool addLoopExit = false,
+                             bool addScopes = false,
                              bool synthesizeBodies = false,
                              bool addStaticInitBranches = false,
                              bool addCXXNewAllocator = true,

Modified: cfe/trunk/include/clang/Analysis/CFG.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CFG.h?rev=327258&r1=327257&r2=327258&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/CFG.h (original)
+++ cfe/trunk/include/clang/Analysis/CFG.h Mon Mar 12 05:26:15 2018
@@ -57,6 +57,8 @@ public:
   enum Kind {
     // main kind
     Initializer,
+    ScopeBegin,
+    ScopeEnd,
     NewAllocator,
     LifetimeEnds,
     LoopExit,
@@ -260,6 +262,55 @@ private:
   }
 };
 
+/// Represents beginning of a scope implicitly generated
+/// by the compiler on encountering a CompoundStmt
+class CFGScopeBegin : public CFGElement {
+public:
+  CFGScopeBegin() {}
+  CFGScopeBegin(const VarDecl *VD, const Stmt *S)
+      : CFGElement(ScopeBegin, VD, S) {}
+
+  // Get statement that triggered a new scope.
+  const Stmt *getTriggerStmt() const {
+    return static_cast<Stmt*>(Data2.getPointer());
+  }
+
+  // Get VD that triggered a new scope.
+  const VarDecl *getVarDecl() const {
+    return static_cast<VarDecl *>(Data1.getPointer());
+  }
+
+private:
+  friend class CFGElement;
+  static bool isKind(const CFGElement &E) {
+    Kind kind = E.getKind();
+    return kind == ScopeBegin;
+  }
+};
+
+/// Represents end of a scope implicitly generated by
+/// the compiler after the last Stmt in a CompoundStmt's body
+class CFGScopeEnd : public CFGElement {
+public:
+  CFGScopeEnd() {}
+  CFGScopeEnd(const VarDecl *VD, const Stmt *S) : CFGElement(ScopeEnd, VD, S) {}
+
+  const VarDecl *getVarDecl() const {
+    return static_cast<VarDecl *>(Data1.getPointer());
+  }
+
+  const Stmt *getTriggerStmt() const {
+    return static_cast<Stmt *>(Data2.getPointer());
+  }
+
+private:
+  friend class CFGElement;
+  static bool isKind(const CFGElement &E) {
+    Kind kind = E.getKind();
+    return kind == ScopeEnd;
+  }
+};
+
 /// CFGImplicitDtor - Represents C++ object destructor implicitly generated
 /// by compiler on various occasions.
 class CFGImplicitDtor : public CFGElement {
@@ -799,6 +850,24 @@ public:
     Elements.push_back(CFGNewAllocator(NE), C);
   }
 
+  void appendScopeBegin(const VarDecl *VD, const Stmt *S,
+                        BumpVectorContext &C) {
+    Elements.push_back(CFGScopeBegin(VD, S), C);
+  }
+
+  void prependScopeBegin(const VarDecl *VD, const Stmt *S,
+                         BumpVectorContext &C) {
+    Elements.insert(Elements.rbegin(), 1, CFGScopeBegin(VD, S), C);
+  }
+
+  void appendScopeEnd(const VarDecl *VD, const Stmt *S, BumpVectorContext &C) {
+    Elements.push_back(CFGScopeEnd(VD, S), C);
+  }
+
+  void prependScopeEnd(const VarDecl *VD, const Stmt *S, BumpVectorContext &C) {
+    Elements.insert(Elements.rbegin(), 1, CFGScopeEnd(VD, S), C);
+  }
+
   void appendBaseDtor(const CXXBaseSpecifier *BS, BumpVectorContext &C) {
     Elements.push_back(CFGBaseDtor(BS), C);
   }
@@ -852,6 +921,19 @@ public:
     *I = CFGLifetimeEnds(VD, S);
     return ++I;
   }
+
+  // Scope leaving must be performed in reversed order. So insertion is in two
+  // steps. First we prepare space for some number of elements, then we insert
+  // the elements beginning at the last position in prepared space.
+  iterator beginScopeEndInsert(iterator I, size_t Cnt, BumpVectorContext &C) {
+    return iterator(
+        Elements.insert(I.base(), Cnt, CFGScopeEnd(nullptr, nullptr), C));
+  }
+  iterator insertScopeEnd(iterator I, VarDecl *VD, Stmt *S) {
+    *I = CFGScopeEnd(VD, S);
+    return ++I;
+  }
+
 };
 
 /// \brief CFGCallback defines methods that should be called when a logical
@@ -894,6 +976,7 @@ public:
     bool AddLifetime = false;
     bool AddLoopExit = false;
     bool AddTemporaryDtors = false;
+    bool AddScopes = false;
     bool AddStaticInitBranches = false;
     bool AddCXXNewAllocator = false;
     bool AddCXXDefaultInitExprInCtors = false;

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h?rev=327258&r1=327257&r2=327258&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Mon Mar 12 05:26:15 2018
@@ -240,6 +240,9 @@ private:
   /// \sa mayInlineCXXStandardLibrary
   Optional<bool> InlineCXXStandardLibrary;
   
+  /// \sa includeScopesInCFG
+  Optional<bool> IncludeScopesInCFG;
+
   /// \sa mayInlineTemplateFunctions
   Optional<bool> InlineTemplateFunctions;
 
@@ -481,6 +484,12 @@ public:
   /// which accepts the values "true" and "false".
   bool includeRichConstructorsInCFG();
 
+  /// Returns whether or not scope information should be included in the CFG.
+  ///
+  /// This is controlled by the 'cfg-scope-info' config option, which accepts
+  /// the values "true" and "false".
+  bool includeScopesInCFG();
+
   /// Returns whether or not C++ standard library functions may be considered
   /// for inlining.
   ///

Modified: cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp?rev=327258&r1=327257&r2=327258&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp (original)
+++ cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp Mon Mar 12 05:26:15 2018
@@ -66,9 +66,9 @@ AnalysisDeclContext::AnalysisDeclContext
 AnalysisDeclContextManager::AnalysisDeclContextManager(
     ASTContext &ASTCtx, bool useUnoptimizedCFG, bool addImplicitDtors,
     bool addInitializers, bool addTemporaryDtors, bool addLifetime,
-    bool addLoopExit, bool synthesizeBodies, bool addStaticInitBranch,
-    bool addCXXNewAllocator, bool addRichCXXConstructors,
-    CodeInjector *injector)
+    bool addLoopExit, bool addScopes, bool synthesizeBodies,
+    bool addStaticInitBranch, bool addCXXNewAllocator,
+    bool addRichCXXConstructors, CodeInjector *injector)
     : Injector(injector), FunctionBodyFarm(ASTCtx, injector),
       SynthesizeBodies(synthesizeBodies) {
   cfgBuildOptions.PruneTriviallyFalseEdges = !useUnoptimizedCFG;
@@ -77,6 +77,7 @@ AnalysisDeclContextManager::AnalysisDecl
   cfgBuildOptions.AddTemporaryDtors = addTemporaryDtors;
   cfgBuildOptions.AddLifetime = addLifetime;
   cfgBuildOptions.AddLoopExit = addLoopExit;
+  cfgBuildOptions.AddScopes = addScopes;
   cfgBuildOptions.AddStaticInitBranches = addStaticInitBranch;
   cfgBuildOptions.AddCXXNewAllocator = addCXXNewAllocator;
   cfgBuildOptions.AddRichCXXConstructors = addRichCXXConstructors;

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=327258&r1=327257&r2=327258&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Mon Mar 12 05:26:15 2018
@@ -234,6 +234,13 @@ public:
       assert(VarIter != 0 && "Iterator has invalid value of VarIter member");
       return &Scope->Vars[VarIter - 1];
     }
+
+    const VarDecl *getFirstVarInScope() const {
+      assert(Scope && "Dereferencing invalid iterator is not allowed");
+      assert(VarIter != 0 && "Iterator has invalid value of VarIter member");
+      return Scope->Vars[0];
+    }
+
     VarDecl *operator*() const {
       return *this->operator->();
     }
@@ -267,6 +274,7 @@ public:
 
     int distance(const_iterator L);
     const_iterator shared_parent(const_iterator L);
+    bool pointsToFirstDeclaredVar() { return VarIter == 1; }
   };
 
 private:
@@ -479,6 +487,9 @@ class CFGBuilder {
   llvm::DenseMap<CXXConstructExpr *, const ConstructionContextLayer *>
       ConstructionContextMap;
 
+  using DeclsWithEndedScopeSetTy = llvm::SmallSetVector<VarDecl *, 16>;
+  DeclsWithEndedScopeSetTy DeclsWithEndedScope;
+
   bool badCFG = false;
   const CFG::BuildOptions &BuildOpts;
   
@@ -576,6 +587,12 @@ private:
   CFGBlock *VisitChildren(Stmt *S);
   CFGBlock *VisitNoRecurse(Expr *E, AddStmtChoice asc);
 
+  void maybeAddScopeBeginForVarDecl(CFGBlock *B, const VarDecl *VD,
+                                    const Stmt *S) {
+    if (ScopePos && (VD == ScopePos.getFirstVarInScope()))
+      appendScopeBegin(B, VD, S);
+  }
+
   /// When creating the CFG for temporary destructors, we want to mirror the
   /// branch structure of the corresponding constructor calls.
   /// Thus, while visiting a statement for temporary destructors, we keep a
@@ -688,6 +705,11 @@ private:
   void addAutomaticObjHandling(LocalScope::const_iterator B,
                                LocalScope::const_iterator E, Stmt *S);
   void addImplicitDtorsForDestructor(const CXXDestructorDecl *DD);
+  void addScopesEnd(LocalScope::const_iterator B, LocalScope::const_iterator E,
+                    Stmt *S);
+
+  void getDeclsWithEndedScope(LocalScope::const_iterator B,
+                              LocalScope::const_iterator E, Stmt *S);
 
   // Local scopes creation.
   LocalScope* createOrReuseLocalScope(LocalScope* Scope);
@@ -770,6 +792,11 @@ private:
                                                  LocalScope::const_iterator B,
                                                  LocalScope::const_iterator E);
 
+  const VarDecl *
+  prependAutomaticObjScopeEndWithTerminator(CFGBlock *Blk,
+                                            LocalScope::const_iterator B,
+                                            LocalScope::const_iterator E);
+
   void addSuccessor(CFGBlock *B, CFGBlock *S, bool IsReachable = true) {
     B->addSuccessor(CFGBlock::AdjacentBlock(S, IsReachable),
                     cfg->getBumpVectorContext());
@@ -782,6 +809,26 @@ private:
                     cfg->getBumpVectorContext());
   }
 
+  void appendScopeBegin(CFGBlock *B, const VarDecl *VD, const Stmt *S) {
+    if (BuildOpts.AddScopes)
+      B->appendScopeBegin(VD, S, cfg->getBumpVectorContext());
+  }
+
+  void prependScopeBegin(CFGBlock *B, const VarDecl *VD, const Stmt *S) {
+    if (BuildOpts.AddScopes)
+      B->prependScopeBegin(VD, S, cfg->getBumpVectorContext());
+  }
+
+  void appendScopeEnd(CFGBlock *B, const VarDecl *VD, const Stmt *S) {
+    if (BuildOpts.AddScopes)
+      B->appendScopeEnd(VD, S, cfg->getBumpVectorContext());
+  }
+
+  void prependScopeEnd(CFGBlock *B, const VarDecl *VD, const Stmt *S) {
+    if (BuildOpts.AddScopes)
+      B->prependScopeEnd(VD, S, cfg->getBumpVectorContext());
+  }
+
   /// \brief Find a relational comparison with an expression evaluating to a
   /// boolean and a constant other than 0 and 1.
   /// e.g. if ((x < y) == 10)
@@ -1299,6 +1346,9 @@ std::unique_ptr<CFG> CFGBuilder::buildCF
                                               JT.scopePosition);
     prependAutomaticObjDtorsWithTerminator(B, I->scopePosition,
                                            JT.scopePosition);
+    const VarDecl *VD = prependAutomaticObjScopeEndWithTerminator(
+        B, I->scopePosition, JT.scopePosition);
+    appendScopeBegin(JT.block, VD, G);
     addSuccessor(B, JT.block);
   }
 
@@ -1456,9 +1506,34 @@ void CFGBuilder::addLoopExit(const Stmt
   appendLoopExit(Block, LoopStmt);
 }
 
+void CFGBuilder::getDeclsWithEndedScope(LocalScope::const_iterator B,
+                                        LocalScope::const_iterator E, Stmt *S) {
+  if (!BuildOpts.AddScopes)
+    return;
+
+  if (B == E)
+    return;
+
+  // To go from B to E, one first goes up the scopes from B to P
+  // then sideways in one scope from P to P' and then down
+  // the scopes from P' to E.
+  // The lifetime of all objects between B and P end.
+  LocalScope::const_iterator P = B.shared_parent(E);
+  int Dist = B.distance(P);
+  if (Dist <= 0)
+    return;
+
+  for (LocalScope::const_iterator I = B; I != P; ++I)
+    if (I.pointsToFirstDeclaredVar())
+      DeclsWithEndedScope.insert(*I);
+}
+
 void CFGBuilder::addAutomaticObjHandling(LocalScope::const_iterator B,
                                          LocalScope::const_iterator E,
                                          Stmt *S) {
+  getDeclsWithEndedScope(B, E, S);
+  if (BuildOpts.AddScopes)
+    addScopesEnd(B, E, S);
   if (BuildOpts.AddImplicitDtors)
     addAutomaticObjDtors(B, E, S);
   if (BuildOpts.AddLifetime)
@@ -1510,6 +1585,23 @@ void CFGBuilder::addLifetimeEnds(LocalSc
     appendLifetimeEnds(Block, *I, S);
 }
 
+/// Add to current block markers for ending scopes.
+void CFGBuilder::addScopesEnd(LocalScope::const_iterator B,
+                              LocalScope::const_iterator E, Stmt *S) {
+  // If implicit destructors are enabled, we'll add scope ends in
+  // addAutomaticObjDtors.
+  if (BuildOpts.AddImplicitDtors)
+    return;
+
+  autoCreateBlock();
+
+  for (auto I = DeclsWithEndedScope.rbegin(), E = DeclsWithEndedScope.rend();
+       I != E; ++I)
+    appendScopeEnd(Block, *I, S);
+
+  return;
+}
+
 /// addAutomaticObjDtors - Add to current block automatic objects destructors
 /// for objects in range of local scope positions. Use S as trigger statement
 /// for destructors.
@@ -1533,6 +1625,15 @@ void CFGBuilder::addAutomaticObjDtors(Lo
   for (SmallVectorImpl<VarDecl*>::reverse_iterator I = Decls.rbegin(),
                                                    E = Decls.rend();
        I != E; ++I) {
+    if (hasTrivialDestructor(*I)) {
+      // If AddScopes is enabled and *I is a first variable in a scope, add a
+      // ScopeEnd marker in a Block.
+      if (BuildOpts.AddScopes && DeclsWithEndedScope.count(*I)) {
+        autoCreateBlock();
+        appendScopeEnd(Block, *I, S);
+      }
+      continue;
+    }
     // If this destructor is marked as a no-return destructor, we need to
     // create a new block for the destructor which does not have as a successor
     // anything built thus far: control won't flow out of this block.
@@ -1547,6 +1648,9 @@ void CFGBuilder::addAutomaticObjDtors(Lo
     else
       autoCreateBlock();
 
+    // Add ScopeEnd just after automatic obj destructor.
+    if (BuildOpts.AddScopes && DeclsWithEndedScope.count(*I))
+      appendScopeEnd(Block, *I, S);
     appendAutomaticObjDtor(Block, *I, S);
   }
 }
@@ -1609,7 +1713,8 @@ LocalScope* CFGBuilder::createOrReuseLoc
 /// addLocalScopeForStmt - Add LocalScope to local scopes tree for statement
 /// that should create implicit scope (e.g. if/else substatements). 
 void CFGBuilder::addLocalScopeForStmt(Stmt *S) {
-  if (!BuildOpts.AddImplicitDtors && !BuildOpts.AddLifetime)
+  if (!BuildOpts.AddImplicitDtors && !BuildOpts.AddLifetime &&
+      !BuildOpts.AddScopes)
     return;
 
   LocalScope *Scope = nullptr;
@@ -1634,7 +1739,8 @@ void CFGBuilder::addLocalScopeForStmt(St
 /// reuse Scope if not NULL.
 LocalScope* CFGBuilder::addLocalScopeForDeclStmt(DeclStmt *DS,
                                                  LocalScope* Scope) {
-  if (!BuildOpts.AddImplicitDtors && !BuildOpts.AddLifetime)
+  if (!BuildOpts.AddImplicitDtors && !BuildOpts.AddLifetime &&
+      !BuildOpts.AddScopes)
     return Scope;
 
   for (auto *DI : DS->decls())
@@ -1686,7 +1792,8 @@ LocalScope* CFGBuilder::addLocalScopeFor
                                                 LocalScope* Scope) {
   assert(!(BuildOpts.AddImplicitDtors && BuildOpts.AddLifetime) &&
          "AddImplicitDtors and AddLifetime cannot be used at the same time");
-  if (!BuildOpts.AddImplicitDtors && !BuildOpts.AddLifetime)
+  if (!BuildOpts.AddImplicitDtors && !BuildOpts.AddLifetime &&
+      !BuildOpts.AddScopes)
     return Scope;
 
   // Check if variable is local.
@@ -1699,7 +1806,7 @@ LocalScope* CFGBuilder::addLocalScopeFor
   }
 
   if (BuildOpts.AddImplicitDtors) {
-    if (!hasTrivialDestructor(VD)) {
+    if (!hasTrivialDestructor(VD) || BuildOpts.AddScopes) {
       // Add the variable to scope
       Scope = createOrReuseLocalScope(Scope);
       Scope->addVar(VD);
@@ -1759,6 +1866,26 @@ void CFGBuilder::prependAutomaticObjLife
     InsertPos = Blk->insertLifetimeEnds(InsertPos, *I, Blk->getTerminator());
 }
 
+/// prependAutomaticObjScopeEndWithTerminator - Prepend scope end CFGElements for
+/// variables with automatic storage duration to CFGBlock's elements vector.
+/// Elements will be prepended to physical beginning of the vector which
+/// happens to be logical end. Use blocks terminator as statement that specifies
+/// where scope ends.
+const VarDecl *
+CFGBuilder::prependAutomaticObjScopeEndWithTerminator(
+    CFGBlock *Blk, LocalScope::const_iterator B, LocalScope::const_iterator E) {
+  if (!BuildOpts.AddScopes)
+    return nullptr;
+  BumpVectorContext &C = cfg->getBumpVectorContext();
+  CFGBlock::iterator InsertPos =
+      Blk->beginScopeEndInsert(Blk->end(), 1, C);
+  LocalScope::const_iterator PlaceToInsert = B;
+  for (LocalScope::const_iterator I = B; I != E; ++I)
+    PlaceToInsert = I;
+  Blk->insertScopeEnd(InsertPos, *PlaceToInsert, Blk->getTerminator());
+  return *PlaceToInsert;
+}
+
 /// Visit - Walk the subtree of a statement and add extra
 ///   blocks for ternary operators, &&, and ||.  We also process "," and
 ///   DeclStmts (which may contain nested control-flow).
@@ -2492,6 +2619,8 @@ CFGBlock *CFGBuilder::VisitDeclSubExpr(D
       LastBlock = newBlock;
   }
 
+  maybeAddScopeBeginForVarDecl(Block, VD, DS);
+
   // Remove variable from local scope.
   if (ScopePos && VD == *ScopePos)
     ++ScopePos;
@@ -2956,6 +3085,7 @@ CFGBlock *CFGBuilder::VisitForStmt(ForSt
 
   do {
     Expr *C = F->getCond();
+    SaveAndRestore<LocalScope::const_iterator> save_scope_pos(ScopePos);
 
     // Specially handle logical operators, which have a slightly
     // more optimal CFG representation.
@@ -2989,6 +3119,7 @@ CFGBlock *CFGBuilder::VisitForStmt(ForSt
           appendStmt(Block, F->getConditionVariableDeclStmt());
           EntryConditionBlock = addStmt(Init);
           assert(Block == EntryConditionBlock);
+          maybeAddScopeBeginForVarDecl(EntryConditionBlock, VD, C);
         }
       }
 
@@ -3015,6 +3146,8 @@ CFGBlock *CFGBuilder::VisitForStmt(ForSt
   // If the loop contains initialization, create a new block for those
   // statements.  This block can also contain statements that precede the loop.
   if (Stmt *I = F->getInit()) {
+    SaveAndRestore<LocalScope::const_iterator> save_scope_pos(ScopePos);
+    ScopePos = LoopBeginScopePos;
     Block = createBlock();
     return addStmt(I);
   }
@@ -3311,6 +3444,7 @@ CFGBlock *CFGBuilder::VisitWhileStmt(Whi
         appendStmt(Block, W->getConditionVariableDeclStmt());
         EntryConditionBlock = addStmt(Init);
         assert(Block == EntryConditionBlock);
+        maybeAddScopeBeginForVarDecl(EntryConditionBlock, VD, C);
       }
     }
 
@@ -3636,6 +3770,7 @@ CFGBlock *CFGBuilder::VisitSwitchStmt(Sw
       autoCreateBlock();
       appendStmt(Block, Terminator->getConditionVariableDeclStmt());
       LastBlock = addStmt(Init);
+      maybeAddScopeBeginForVarDecl(LastBlock, VD, Init);
     }
   }
 
@@ -4381,6 +4516,8 @@ CFGImplicitDtor::getDestructorDecl(ASTCo
     case CFGElement::LifetimeEnds:
     case CFGElement::Statement:
     case CFGElement::Constructor:
+    case CFGElement::ScopeBegin:
+    case CFGElement::ScopeEnd:
       llvm_unreachable("getDestructorDecl should only be used with "
                        "ImplicitDtors");
     case CFGElement::AutomaticObjectDtor: {
@@ -4841,6 +4978,16 @@ static void print_elem(raw_ostream &OS,
   } else if (Optional<CFGLoopExit> LE = E.getAs<CFGLoopExit>()) {
     const Stmt *LoopStmt = LE->getLoopStmt();
     OS << LoopStmt->getStmtClassName() << " (LoopExit)\n";
+  } else if (Optional<CFGScopeBegin> SB = E.getAs<CFGScopeBegin>()) {
+    OS << "CFGScopeBegin(";
+    if (const VarDecl *VD = SB->getVarDecl())
+      OS << VD->getQualifiedNameAsString();
+    OS << ")\n";
+  } else if (Optional<CFGScopeEnd> SE = E.getAs<CFGScopeEnd>()) {
+    OS << "CFGScopeEnd(";
+    if (const VarDecl *VD = SE->getVarDecl())
+      OS << VD->getQualifiedNameAsString();
+    OS << ")\n";
   } else if (Optional<CFGNewAllocator> NE = E.getAs<CFGNewAllocator>()) {
     OS << "CFGNewAllocator(";
     if (const CXXNewExpr *AllocExpr = NE->getAllocatorExpr())

Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp?rev=327258&r1=327257&r2=327258&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp Mon Mar 12 05:26:15 2018
@@ -26,6 +26,7 @@ AnalysisManager::AnalysisManager(
                 // Adding LoopExit elements to the CFG is a requirement for loop
                 // unrolling.
                 Options.includeLoopExitInCFG() || Options.shouldUnrollLoops(),
+                Options.includeScopesInCFG(),
                 Options.shouldSynthesizeBodies(),
                 Options.shouldConditionalizeStaticInitializers(),
                 /*addCXXNewAllocator=*/true,

Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp?rev=327258&r1=327257&r2=327258&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp Mon Mar 12 05:26:15 2018
@@ -224,6 +224,12 @@ bool AnalyzerOptions::includeRichConstru
                           /* Default = */ true);
 }
 
+bool AnalyzerOptions::includeScopesInCFG() {
+  return getBooleanOption(IncludeScopesInCFG,
+                          "cfg-scopes",
+                          /* Default = */ false);
+}
+
 bool AnalyzerOptions::mayInlineCXXStandardLibrary() {
   return getBooleanOption(InlineCXXStandardLibrary,
                           "c++-stdlib-inlining",

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=327258&r1=327257&r2=327258&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Mon Mar 12 05:26:15 2018
@@ -632,6 +632,8 @@ void ExprEngine::processCFGElement(const
       ProcessLoopExit(E.castAs<CFGLoopExit>().getLoopStmt(), Pred);
       return;
     case CFGElement::LifetimeEnds:
+    case CFGElement::ScopeBegin:
+    case CFGElement::ScopeEnd:
       return;
   }
 }

Modified: cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp?rev=327258&r1=327257&r2=327258&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp Mon Mar 12 05:26:15 2018
@@ -614,6 +614,9 @@ getLocationForCaller(const StackFrameCon
     return PathDiagnosticLocation::createEnd(Dtor.getBindTemporaryExpr(), SM,
                                              CallerCtx);
   }
+  case CFGElement::ScopeBegin:
+  case CFGElement::ScopeEnd:
+    llvm_unreachable("not yet implemented!");
   case CFGElement::LifetimeEnds:
   case CFGElement::LoopExit:
     llvm_unreachable("CFGElement kind should not be on callsite!");

Modified: cfe/trunk/test/Analysis/analyzer-config.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer-config.c?rev=327258&r1=327257&r2=327258&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/analyzer-config.c (original)
+++ cfe/trunk/test/Analysis/analyzer-config.c Mon Mar 12 05:26:15 2018
@@ -16,6 +16,7 @@ void foo() {
 // CHECK-NEXT: cfg-lifetime = false
 // CHECK-NEXT: cfg-loopexit = false
 // CHECK-NEXT: cfg-rich-constructors = true
+// CHECK-NEXT: cfg-scopes = false
 // CHECK-NEXT: cfg-temporary-dtors = true
 // CHECK-NEXT: exploration_strategy = unexplored_first_queue
 // CHECK-NEXT: faux-bodies = true
@@ -34,4 +35,4 @@ void foo() {
 // CHECK-NEXT: unroll-loops = false
 // CHECK-NEXT: widen-loops = false
 // CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 22
+// CHECK-NEXT: num-entries = 23

Modified: cfe/trunk/test/Analysis/analyzer-config.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer-config.cpp?rev=327258&r1=327257&r2=327258&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/analyzer-config.cpp (original)
+++ cfe/trunk/test/Analysis/analyzer-config.cpp Mon Mar 12 05:26:15 2018
@@ -30,6 +30,7 @@ public:
 // CHECK-NEXT: cfg-lifetime = false
 // CHECK-NEXT: cfg-loopexit = false
 // CHECK-NEXT: cfg-rich-constructors = true
+// CHECK-NEXT: cfg-scopes = false
 // CHECK-NEXT: cfg-temporary-dtors = true
 // CHECK-NEXT: experimental-enable-naive-ctu-analysis = false
 // CHECK-NEXT: exploration_strategy = unexplored_first_queue
@@ -49,4 +50,4 @@ public:
 // CHECK-NEXT: unroll-loops = false
 // CHECK-NEXT: widen-loops = false
 // CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 29
+// CHECK-NEXT: num-entries = 30

Added: cfe/trunk/test/Analysis/scopes-cfg-output.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/scopes-cfg-output.cpp?rev=327258&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/scopes-cfg-output.cpp (added)
+++ cfe/trunk/test/Analysis/scopes-cfg-output.cpp Mon Mar 12 05:26:15 2018
@@ -0,0 +1,1171 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -analyze -analyzer-checker=debug.DumpCFG -analyzer-config cfg-scopes=true %s > %t 2>&1
+// RUN: FileCheck --input-file=%t %s
+
+class A {
+public:
+// CHECK:      [B1 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+  A() {}
+
+// CHECK:      [B1 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+  ~A() {}
+
+// CHECK:      [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B1]
+// CHECK-NEXT:   1: 1
+// CHECK-NEXT:   2: return [B1.1];
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+  operator int() const { return 1; }
+};
+
+int getX();
+extern const bool UV;
+
+// CHECK:      [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B1]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B1.3], class A [2])
+// CHECK-NEXT:   3: A a[2];
+// CHECK-NEXT:   4:  (CXXConstructExpr, [B1.5], class A [0])
+// CHECK-NEXT:   5: A b[0];
+// CHECK-NEXT:   6: [B1.3].~A() (Implicit destructor)
+// CHECK-NEXT:   7: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_array() {
+  A a[2];
+  A b[0];
+}
+
+// CHECK:      [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B1]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B1.3], class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   4: CFGScopeBegin(c)
+// CHECK-NEXT:   5:  (CXXConstructExpr, [B1.6], class A)
+// CHECK-NEXT:   6: A c;
+// CHECK-NEXT:   7:  (CXXConstructExpr, [B1.8], class A)
+// CHECK-NEXT:   8: A d;
+// CHECK-NEXT:   9: [B1.8].~A() (Implicit destructor)
+// CHECK-NEXT:  10: [B1.6].~A() (Implicit destructor)
+// CHECK-NEXT:  11: CFGScopeEnd(c)
+// CHECK-NEXT:  12:  (CXXConstructExpr, [B1.13], class A)
+// CHECK-NEXT:  13: A b;
+// CHECK-NEXT:  14: [B1.13].~A() (Implicit destructor)
+// CHECK-NEXT:  15: [B1.3].~A() (Implicit destructor)
+// CHECK-NEXT:  16: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_scope() {
+  A a;
+  { A c;
+    A d;
+  }
+  A b;
+}
+
+// CHECK:      [B4 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B3
+// CHECK:      [B1]
+// CHECK-NEXT:   1:  (CXXConstructExpr, [B1.2], class A)
+// CHECK-NEXT:   2: A c;
+// CHECK-NEXT:   3: [B1.2].~A() (Implicit destructor)
+// CHECK-NEXT:   4: [B3.5].~A() (Implicit destructor)
+// CHECK-NEXT:   5: [B3.3].~A() (Implicit destructor)
+// CHECK-NEXT:   6: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B3
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B2]
+// CHECK-NEXT:   1: return;
+// CHECK-NEXT:   2: [B3.5].~A() (Implicit destructor)
+// CHECK-NEXT:   3: [B3.3].~A() (Implicit destructor)
+// CHECK-NEXT:   4: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B3
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B3]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B3.3], class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   4:  (CXXConstructExpr, [B3.5], class A)
+// CHECK-NEXT:   5: A b;
+// CHECK-NEXT:   6: UV
+// CHECK-NEXT:   7: [B3.6] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: if [B3.7]
+// CHECK-NEXT:   Preds (1): B4
+// CHECK-NEXT:   Succs (2): B2 B1
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (2): B1 B2
+void test_return() {
+  A a;
+  A b;
+  if (UV) return;
+  A c;
+}
+
+// CHECK:      [B5 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B4
+// CHECK:      [B1]
+// CHECK-NEXT:   1: [B4.8].~A() (Implicit destructor)
+// CHECK-NEXT:   2: CFGScopeEnd(b)
+// CHECK-NEXT:   3: [B4.3].~A() (Implicit destructor)
+// CHECK-NEXT:   4: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (2): B2 B3
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B2]
+// CHECK-NEXT:   1: CFGScopeBegin(c)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B2.3], class A)
+// CHECK-NEXT:   3: A c;
+// CHECK-NEXT:   4: [B2.3].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(c)
+// CHECK-NEXT:   Preds (1): B4
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B3]
+// CHECK-NEXT:   1: CFGScopeBegin(c)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B3.3], class A)
+// CHECK-NEXT:   3: A c;
+// CHECK-NEXT:   4: [B3.3].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(c)
+// CHECK-NEXT:   Preds (1): B4
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B4]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B4.3], class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   4: CFGScopeBegin(b)
+// CHECK-NEXT:   5: a
+// CHECK-NEXT:   6: [B4.5] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:   7: [B4.6] (CXXConstructExpr, [B4.8], class A)
+// CHECK-NEXT:   8: A b = a;
+// CHECK-NEXT:   9: b
+// CHECK-NEXT:  10: [B4.9] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:  11: [B4.10].operator int
+// CHECK-NEXT:  12: [B4.10]
+// CHECK-NEXT:  13: [B4.12] (ImplicitCastExpr, UserDefinedConversion, int)
+// CHECK-NEXT:  14: [B4.13] (ImplicitCastExpr, IntegralToBoolean, _Bool)
+// CHECK-NEXT:   T: if [B4.14]
+// CHECK-NEXT:   Preds (1): B5
+// CHECK-NEXT:   Succs (2): B3 B2
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_if_implicit_scope() {
+  A a;
+  if (A b = a)
+    A c;
+  else A c;
+}
+
+// CHECK:      [B9 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B8
+// CHECK:      [B1]
+// CHECK-NEXT:   1: [B8.8].~A() (Implicit destructor)
+// CHECK-NEXT:   2: CFGScopeEnd(b)
+// CHECK-NEXT:   3:  (CXXConstructExpr, [B1.4], class A)
+// CHECK-NEXT:   4: A e;
+// CHECK-NEXT:   5: [B1.4].~A() (Implicit destructor)
+// CHECK-NEXT:   6: [B8.3].~A() (Implicit destructor)
+// CHECK-NEXT:   7: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (2): B2 B5
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B2]
+// CHECK-NEXT:   1:  (CXXConstructExpr, [B2.2], class A)
+// CHECK-NEXT:   2: A d;
+// CHECK-NEXT:   3: [B2.2].~A() (Implicit destructor)
+// CHECK-NEXT:   4: [B4.3].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(c)
+// CHECK-NEXT:   Preds (1): B4
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B3]
+// CHECK-NEXT:   1: return;
+// CHECK-NEXT:   2: [B4.3].~A() (Implicit destructor)
+// CHECK-NEXT:   3: CFGScopeEnd(c)
+// CHECK-NEXT:   4: [B8.8].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(b)
+// CHECK-NEXT:   6: [B8.3].~A() (Implicit destructor)
+// CHECK-NEXT:   7: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B4
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B4]
+// CHECK-NEXT:   1: CFGScopeBegin(c)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B4.3], class A)
+// CHECK-NEXT:   3: A c;
+// CHECK-NEXT:   4: UV
+// CHECK-NEXT:   5: [B4.4] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: if [B4.5]
+// CHECK-NEXT:   Preds (1): B8
+// CHECK-NEXT:   Succs (2): B3 B2
+// CHECK:      [B5]
+// CHECK-NEXT:   1:  (CXXConstructExpr, [B5.2], class A)
+// CHECK-NEXT:   2: A d;
+// CHECK-NEXT:   3: [B5.2].~A() (Implicit destructor)
+// CHECK-NEXT:   4: [B7.3].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(c)
+// CHECK-NEXT:   Preds (1): B7
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B6]
+// CHECK-NEXT:   1: return;
+// CHECK-NEXT:   2: [B7.3].~A() (Implicit destructor)
+// CHECK-NEXT:   3: CFGScopeEnd(c)
+// CHECK-NEXT:   4: [B8.8].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(b)
+// CHECK-NEXT:   6: [B8.3].~A() (Implicit destructor)
+// CHECK-NEXT:   7: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B7
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B7]
+// CHECK-NEXT:   1: CFGScopeBegin(c)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B7.3], class A)
+// CHECK-NEXT:   3: A c;
+// CHECK-NEXT:   4: UV
+// CHECK-NEXT:   5: [B7.4] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: if [B7.5]
+// CHECK-NEXT:   Preds (1): B8
+// CHECK-NEXT:   Succs (2): B6 B5
+// CHECK:      [B8]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B8.3], class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   4: CFGScopeBegin(b)
+// CHECK-NEXT:   5: a
+// CHECK-NEXT:   6: [B8.5] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:   7: [B8.6] (CXXConstructExpr, [B8.8], class A)
+// CHECK-NEXT:   8: A b = a;
+// CHECK-NEXT:   9: b
+// CHECK-NEXT:  10: [B8.9] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:  11: [B8.10].operator int
+// CHECK-NEXT:  12: [B8.10]
+// CHECK-NEXT:  13: [B8.12] (ImplicitCastExpr, UserDefinedConversion, int)
+// CHECK-NEXT:  14: [B8.13] (ImplicitCastExpr, IntegralToBoolean, _Bool)
+// CHECK-NEXT:   T: if [B8.14]
+// CHECK-NEXT:   Preds (1): B9
+// CHECK-NEXT:   Succs (2): B7 B4
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (3): B1 B3 B6
+void test_if_jumps() {
+  A a;
+  if (A b = a) {
+    A c;
+    if (UV) return;
+    A d;
+  } else {
+    A c;
+    if (UV) return;
+    A d;
+  }
+  A e;
+}
+
+// CHECK:      [B6 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B5
+// CHECK:      [B1]
+// CHECK-NEXT:   1: [B4.5].~A() (Implicit destructor)
+// CHECK-NEXT:   2: CFGScopeEnd(b)
+// CHECK-NEXT:   3: [B5.3].~A() (Implicit destructor)
+// CHECK-NEXT:   4: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B4
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B2]
+// CHECK-NEXT:   Preds (1): B3
+// CHECK-NEXT:   Succs (1): B4
+// CHECK:      [B3]
+// CHECK-NEXT:   1: CFGScopeBegin(c)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B3.3], class A)
+// CHECK-NEXT:   3: A c;
+// CHECK-NEXT:   4: [B3.3].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(c)
+// CHECK-NEXT:   6: [B4.5].~A() (Implicit destructor)
+// CHECK-NEXT:   7: CFGScopeEnd(b)
+// CHECK-NEXT:   Preds (1): B4
+// CHECK-NEXT:   Succs (1): B2
+// CHECK:      [B4]
+// CHECK-NEXT:   1: CFGScopeBegin(b)
+// CHECK-NEXT:   2: a
+// CHECK-NEXT:   3: [B4.2] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:   4: [B4.3] (CXXConstructExpr, class A)
+// CHECK-NEXT:   5: A b = a;
+// CHECK-NEXT:   6: b
+// CHECK-NEXT:   7: [B4.6] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:   8: [B4.7].operator int
+// CHECK-NEXT:   9: [B4.7]
+// CHECK-NEXT:  10: [B4.9] (ImplicitCastExpr, UserDefinedConversion, int)
+// CHECK-NEXT:  11: [B4.10] (ImplicitCastExpr, IntegralToBoolean, _Bool)
+// CHECK-NEXT:   T: while [B4.11]
+// CHECK-NEXT:   Preds (2): B2 B5
+// CHECK-NEXT:   Succs (2): B3 B1
+// CHECK:      [B5]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B5.3], class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   Preds (1): B6
+// CHECK-NEXT:   Succs (1): B4
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_while_implicit_scope() {
+  A a;
+  while (A b = a)
+    A c;
+}
+
+// CHECK:      [B12 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B11
+// CHECK:      [B1]
+// CHECK-NEXT:   1: [B10.5].~A() (Implicit destructor)
+// CHECK-NEXT:   2: CFGScopeEnd(b)
+// CHECK-NEXT:   3:  (CXXConstructExpr, [B1.4], class A)
+// CHECK-NEXT:   4: A e;
+// CHECK-NEXT:   5: [B1.4].~A() (Implicit destructor)
+// CHECK-NEXT:   6: [B11.3].~A() (Implicit destructor)
+// CHECK-NEXT:   7: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (2): B8 B10
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B2]
+// CHECK-NEXT:   Preds (2): B3 B6
+// CHECK-NEXT:   Succs (1): B10
+// CHECK:      [B3]
+// CHECK-NEXT:   1:  (CXXConstructExpr, [B3.2], class A)
+// CHECK-NEXT:   2: A d;
+// CHECK-NEXT:   3: [B3.2].~A() (Implicit destructor)
+// CHECK-NEXT:   4: [B9.3].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(c)
+// CHECK-NEXT:   6: [B10.5].~A() (Implicit destructor)
+// CHECK-NEXT:   7: CFGScopeEnd(b)
+// CHECK-NEXT:   Preds (1): B5
+// CHECK-NEXT:   Succs (1): B2
+// CHECK:      [B4]
+// CHECK-NEXT:   1: return;
+// CHECK-NEXT:   2: [B9.3].~A() (Implicit destructor)
+// CHECK-NEXT:   3: CFGScopeEnd(c)
+// CHECK-NEXT:   4: [B10.5].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(b)
+// CHECK-NEXT:   6: [B11.3].~A() (Implicit destructor)
+// CHECK-NEXT:   7: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B5
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B5]
+// CHECK-NEXT:   1: UV
+// CHECK-NEXT:   2: [B5.1] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: if [B5.2]
+// CHECK-NEXT:   Preds (1): B7
+// CHECK-NEXT:   Succs (2): B4 B3
+// CHECK:      [B6]
+// CHECK-NEXT:   1: [B9.3].~A() (Implicit destructor)
+// CHECK-NEXT:   2: CFGScopeEnd(c)
+// CHECK-NEXT:   3: [B10.5].~A() (Implicit destructor)
+// CHECK-NEXT:   4: CFGScopeEnd(b)
+// CHECK-NEXT:   T: continue;
+// CHECK-NEXT:   Preds (1): B7
+// CHECK-NEXT:   Succs (1): B2
+// CHECK:      [B7]
+// CHECK-NEXT:   1: UV
+// CHECK-NEXT:   2: [B7.1] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: if [B7.2]
+// CHECK-NEXT:   Preds (1): B9
+// CHECK-NEXT:   Succs (2): B6 B5
+// CHECK:      [B8]
+// CHECK-NEXT:   1: [B9.3].~A() (Implicit destructor)
+// CHECK-NEXT:   2: CFGScopeEnd(c)
+// CHECK-NEXT:   T: break;
+// CHECK-NEXT:   Preds (1): B9
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B9]
+// CHECK-NEXT:   1: CFGScopeBegin(c)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B9.3], class A)
+// CHECK-NEXT:   3: A c;
+// CHECK-NEXT:   4: UV
+// CHECK-NEXT:   5: [B9.4] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: if [B9.5]
+// CHECK-NEXT:   Preds (1): B10
+// CHECK-NEXT:   Succs (2): B8 B7
+// CHECK:      [B10]
+// CHECK-NEXT:   1: CFGScopeBegin(b)
+// CHECK-NEXT:   2: a
+// CHECK-NEXT:   3: [B10.2] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:   4: [B10.3] (CXXConstructExpr, class A)
+// CHECK-NEXT:   5: A b = a;
+// CHECK-NEXT:   6: b
+// CHECK-NEXT:   7: [B10.6] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:   8: [B10.7].operator int
+// CHECK-NEXT:   9: [B10.7]
+// CHECK-NEXT:  10: [B10.9] (ImplicitCastExpr, UserDefinedConversion, int)
+// CHECK-NEXT:  11: [B10.10] (ImplicitCastExpr, IntegralToBoolean, _Bool)
+// CHECK-NEXT:   T: while [B10.11]
+// CHECK-NEXT:   Preds (2): B2 B11
+// CHECK-NEXT:   Succs (2): B9 B1
+// CHECK:      [B11]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B11.3], class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   Preds (1): B12
+// CHECK-NEXT:   Succs (1): B10
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (2): B1 B4
+void test_while_jumps() {
+  A a;
+  while (A b = a) {
+    A c;
+    if (UV) break;
+    if (UV) continue;
+    if (UV) return;
+    A d;
+  }
+  A e;
+}
+
+// CHECK:      [B12 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B11
+// CHECK:      [B1]
+// CHECK-NEXT:   1:  (CXXConstructExpr, [B1.2], class A)
+// CHECK-NEXT:   2: A d;
+// CHECK-NEXT:   3: [B1.2].~A() (Implicit destructor)
+// CHECK-NEXT:   4: [B11.3].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (2): B8 B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B2]
+// CHECK-NEXT:   1: UV
+// CHECK-NEXT:   2: [B2.1] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: do ... while [B2.2]
+// CHECK-NEXT:   Preds (2): B3 B6
+// CHECK-NEXT:   Succs (2): B10 B1
+// CHECK:      [B3]
+// CHECK-NEXT:   1:  (CXXConstructExpr, [B3.2], class A)
+// CHECK-NEXT:   2: A c;
+// CHECK-NEXT:   3: [B3.2].~A() (Implicit destructor)
+// CHECK-NEXT:   4: [B9.3].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(b)
+// CHECK-NEXT:   Preds (1): B5
+// CHECK-NEXT:   Succs (1): B2
+// CHECK:      [B4]
+// CHECK-NEXT:   1: return;
+// CHECK-NEXT:   2: [B9.3].~A() (Implicit destructor)
+// CHECK-NEXT:   3: CFGScopeEnd(b)
+// CHECK-NEXT:   4: [B11.3].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B5
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B5]
+// CHECK-NEXT:   1: UV
+// CHECK-NEXT:   2: [B5.1] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: if [B5.2]
+// CHECK-NEXT:   Preds (1): B7
+// CHECK-NEXT:   Succs (2): B4 B3
+// CHECK:      [B6]
+// CHECK-NEXT:   1: [B9.3].~A() (Implicit destructor)
+// CHECK-NEXT:   2: CFGScopeEnd(b)
+// CHECK-NEXT:   T: continue;
+// CHECK-NEXT:   Preds (1): B7
+// CHECK-NEXT:   Succs (1): B2
+// CHECK:      [B7]
+// CHECK-NEXT:   1: UV
+// CHECK-NEXT:   2: [B7.1] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: if [B7.2]
+// CHECK-NEXT:   Preds (1): B9
+// CHECK-NEXT:   Succs (2): B6 B5
+// CHECK:      [B8]
+// CHECK-NEXT:   1: [B9.3].~A() (Implicit destructor)
+// CHECK-NEXT:   2: CFGScopeEnd(b)
+// CHECK-NEXT:   T: break;
+// CHECK-NEXT:   Preds (1): B9
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B9]
+// CHECK-NEXT:   1: CFGScopeBegin(b)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B9.3], class A)
+// CHECK-NEXT:   3: A b;
+// CHECK-NEXT:   4: UV
+// CHECK-NEXT:   5: [B9.4] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: if [B9.5]
+// CHECK-NEXT:   Preds (2): B10 B11
+// CHECK-NEXT:   Succs (2): B8 B7
+// CHECK:      [B10]
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B9
+// CHECK:      [B11]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B11.3], class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   Preds (1): B12
+// CHECK-NEXT:   Succs (1): B9
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (2): B1 B4
+void test_do_jumps() {
+  A a;
+  do {
+    A b;
+    if (UV) break;
+    if (UV) continue;
+    if (UV) return;
+    A c;
+  } while (UV);
+  A d;
+}
+
+// CHECK:      [B6 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B5
+// CHECK:      [B1]
+// CHECK-NEXT:   1: [B4.5].~A() (Implicit destructor)
+// CHECK-NEXT:   2: CFGScopeEnd(b)
+// CHECK-NEXT:   3: [B5.3].~A() (Implicit destructor)
+// CHECK-NEXT:   4: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B4
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B2]
+// CHECK-NEXT:   Preds (1): B3
+// CHECK-NEXT:   Succs (1): B4
+// CHECK:      [B3]
+// CHECK-NEXT:   1: CFGScopeBegin(c)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B3.3], class A)
+// CHECK-NEXT:   3: A c;
+// CHECK-NEXT:   4: [B3.3].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(c)
+// CHECK-NEXT:   6: [B4.5].~A() (Implicit destructor)
+// CHECK-NEXT:   7: CFGScopeEnd(b)
+// CHECK-NEXT:   Preds (1): B4
+// CHECK-NEXT:   Succs (1): B2
+// CHECK:      [B4]
+// CHECK-NEXT:   1: CFGScopeBegin(b)
+// CHECK-NEXT:   2: a
+// CHECK-NEXT:   3: [B4.2] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:   4: [B4.3] (CXXConstructExpr, class A)
+// CHECK-NEXT:   5: A b = a;
+// CHECK-NEXT:   6: b
+// CHECK-NEXT:   7: [B4.6] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:   8: [B4.7].operator int
+// CHECK-NEXT:   9: [B4.7]
+// CHECK-NEXT:  10: [B4.9] (ImplicitCastExpr, UserDefinedConversion, int)
+// CHECK-NEXT:  11: [B4.10] (ImplicitCastExpr, IntegralToBoolean, _Bool)
+// CHECK-NEXT:   T: for (...; [B4.11]; )
+// CHECK-NEXT:   Preds (2): B2 B5
+// CHECK-NEXT:   Succs (2): B3 B1
+// CHECK:      [B5]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B5.3], class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   Preds (1): B6
+// CHECK-NEXT:   Succs (1): B4
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_for_implicit_scope() {
+  for (A a; A b = a; )
+    A c;
+}
+
+// CHECK:      [B12 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B11
+// CHECK:      [B1]
+// CHECK-NEXT:   1: [B10.5].~A() (Implicit destructor)
+// CHECK-NEXT:   2: CFGScopeEnd(c)
+// CHECK-NEXT:   3: [B11.6].~A() (Implicit destructor)
+// CHECK-NEXT:   4: CFGScopeEnd(b)
+// CHECK-NEXT:   5:  (CXXConstructExpr, [B1.6], class A)
+// CHECK-NEXT:   6: A f;
+// CHECK-NEXT:   7: [B1.6].~A() (Implicit destructor)
+// CHECK-NEXT:   8: [B11.3].~A() (Implicit destructor)
+// CHECK-NEXT:   9: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (2): B8 B10
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B2]
+// CHECK-NEXT:   Preds (2): B3 B6
+// CHECK-NEXT:   Succs (1): B10
+// CHECK:      [B3]
+// CHECK-NEXT:   1:  (CXXConstructExpr, [B3.2], class A)
+// CHECK-NEXT:   2: A e;
+// CHECK-NEXT:   3: [B3.2].~A() (Implicit destructor)
+// CHECK-NEXT:   4: [B9.3].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(d)
+// CHECK-NEXT:   6: [B10.5].~A() (Implicit destructor)
+// CHECK-NEXT:   7: CFGScopeEnd(c)
+// CHECK-NEXT:   Preds (1): B5
+// CHECK-NEXT:   Succs (1): B2
+// CHECK:      [B4]
+// CHECK-NEXT:   1: return;
+// CHECK-NEXT:   2: [B9.3].~A() (Implicit destructor)
+// CHECK-NEXT:   3: CFGScopeEnd(d)
+// CHECK-NEXT:   4: [B10.5].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(c)
+// CHECK-NEXT:   6: [B11.6].~A() (Implicit destructor)
+// CHECK-NEXT:   7: CFGScopeEnd(b)
+// CHECK-NEXT:   8: [B11.3].~A() (Implicit destructor)
+// CHECK-NEXT:   9: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B5
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B5]
+// CHECK-NEXT:   1: UV
+// CHECK-NEXT:   2: [B5.1] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: if [B5.2]
+// CHECK-NEXT:   Preds (1): B7
+// CHECK-NEXT:   Succs (2): B4 B3
+// CHECK:      [B6]
+// CHECK-NEXT:   1: [B9.3].~A() (Implicit destructor)
+// CHECK-NEXT:   2: CFGScopeEnd(d)
+// CHECK-NEXT:   T: continue;
+// CHECK-NEXT:   Preds (1): B7
+// CHECK-NEXT:   Succs (1): B2
+// CHECK:      [B7]
+// CHECK-NEXT:   1: UV
+// CHECK-NEXT:   2: [B7.1] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: if [B7.2]
+// CHECK-NEXT:   Preds (1): B9
+// CHECK-NEXT:   Succs (2): B6 B5
+// CHECK:      [B8]
+// CHECK-NEXT:   1: [B9.3].~A() (Implicit destructor)
+// CHECK-NEXT:   2: CFGScopeEnd(d)
+// CHECK-NEXT:   T: break;
+// CHECK-NEXT:   Preds (1): B9
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B9]
+// CHECK-NEXT:   1: CFGScopeBegin(d)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B9.3], class A)
+// CHECK-NEXT:   3: A d;
+// CHECK-NEXT:   4: UV
+// CHECK-NEXT:   5: [B9.4] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: if [B9.5]
+// CHECK-NEXT:   Preds (1): B10
+// CHECK-NEXT:   Succs (2): B8 B7
+// CHECK:      [B10]
+// CHECK-NEXT:   1: CFGScopeBegin(c)
+// CHECK-NEXT:   2: b
+// CHECK-NEXT:   3: [B10.2] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:   4: [B10.3] (CXXConstructExpr, class A)
+// CHECK-NEXT:   5: A c = b;
+// CHECK-NEXT:   6: c
+// CHECK-NEXT:   7: [B10.6] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:   8: [B10.7].operator int
+// CHECK-NEXT:   9: [B10.7]
+// CHECK-NEXT:  10: [B10.9] (ImplicitCastExpr, UserDefinedConversion, int)
+// CHECK-NEXT:  11: [B10.10] (ImplicitCastExpr, IntegralToBoolean, _Bool)
+// CHECK-NEXT:   T: for (...; [B10.11]; )
+// CHECK-NEXT:   Preds (2): B2 B11
+// CHECK-NEXT:   Succs (2): B9 B1
+// CHECK:      [B11]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B11.3], class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   4: CFGScopeBegin(b)
+// CHECK-NEXT:   5:  (CXXConstructExpr, [B11.6], class A)
+// CHECK-NEXT:   6: A b;
+// CHECK-NEXT:   Preds (1): B12
+// CHECK-NEXT:   Succs (1): B10
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (2): B1 B4
+void test_for_jumps() {
+  A a;
+  for (A b; A c = b; ) {
+    A d;
+    if (UV) break;
+    if (UV) continue;
+    if (UV) return;
+    A e;
+  }
+  A f;
+}
+
+// CHECK:      [B8 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B7
+// CHECK:      [B1]
+// CHECK-NEXT:  l1:
+// CHECK-NEXT:   1:  (CXXConstructExpr, [B1.2], class A)
+// CHECK-NEXT:   2: A c;
+// CHECK-NEXT:   3: [B1.2].~A() (Implicit destructor)
+// CHECK-NEXT:   4: [B6.5].~A() (Implicit destructor)
+// CHECK-NEXT:   5: [B6.3].~A() (Implicit destructor)
+// CHECK-NEXT:   6: [B7.3].~A() (Implicit destructor)
+// CHECK-NEXT:   7: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (2): B2 B3
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B2]
+// CHECK-NEXT:   1:  (CXXConstructExpr, [B2.2], class A)
+// CHECK-NEXT:   2: A b;
+// CHECK-NEXT:   3: [B2.2].~A() (Implicit destructor)
+// CHECK-NEXT:   4: [B6.8].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B4
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B3]
+// CHECK-NEXT:   1: [B6.8].~A() (Implicit destructor)
+// CHECK-NEXT:   2: CFGScopeEnd(a)
+// CHECK-NEXT:   T: goto l1;
+// CHECK-NEXT:   Preds (1): B4
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B4]
+// CHECK-NEXT:   1: UV
+// CHECK-NEXT:   2: [B4.1] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: if [B4.2]
+// CHECK-NEXT:   Preds (1): B6
+// CHECK-NEXT:   Succs (2): B3 B2
+// CHECK:      [B5]
+// CHECK-NEXT:   1: [B6.8].~A() (Implicit destructor)
+// CHECK-NEXT:   2: [B6.5].~A() (Implicit destructor)
+// CHECK-NEXT:   3: [B6.3].~A() (Implicit destructor)
+// CHECK-NEXT:   4: CFGScopeEnd(cb)
+// CHECK-NEXT:   T: goto l0;
+// CHECK-NEXT:   Preds (1): B6
+// CHECK-NEXT:   Succs (1): B6
+// CHECK:      [B6]
+// CHECK-NEXT:  l0:
+// CHECK-NEXT:   1: CFGScopeBegin(cb)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B6.3], class A)
+// CHECK-NEXT:   3: A cb;
+// CHECK-NEXT:   4:  (CXXConstructExpr, [B6.5], class A)
+// CHECK-NEXT:   5: A b;
+// CHECK-NEXT:   6: CFGScopeBegin(a)
+// CHECK-NEXT:   7:  (CXXConstructExpr, [B6.8], class A)
+// CHECK-NEXT:   8: A a;
+// CHECK-NEXT:   9: UV
+// CHECK-NEXT:  10: [B6.9] (ImplicitCastExpr, LValueToRValue, _Bool)
+// CHECK-NEXT:   T: if [B6.10]
+// CHECK-NEXT:   Preds (2): B7 B5
+// CHECK-NEXT:   Succs (2): B5 B4
+// CHECK:      [B7]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B7.3], class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   Preds (1): B8
+// CHECK-NEXT:   Succs (1): B6
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_goto() {
+  A a;
+l0:
+  A cb;
+  A b;
+  { A a;
+    if (UV) goto l0;
+    if (UV) goto l1;
+    A b;
+  }
+l1:
+  A c;
+}
+
+// CHECK:      [B7 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B6
+// CHECK:      [B1]
+// CHECK-NEXT:   1: CFGScopeEnd(i)
+// CHECK-NEXT:   2: CFGScopeBegin(unused2)
+// CHECK-NEXT:   3: int unused2;
+// CHECK-NEXT:   4: CFGScopeEnd(unused2)
+// CHECK-NEXT:   Preds (2): B4 B5
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B2]
+// CHECK-NEXT:   1: i
+// CHECK-NEXT:   2: ++[B2.1]
+// CHECK-NEXT:   Preds (1): B3
+// CHECK-NEXT:   Succs (1): B5
+// CHECK:      [B3]
+// CHECK-NEXT:   1: CFGScopeEnd(unused1)
+// CHECK-NEXT:   Succs (1): B2
+// CHECK:      [B4]
+// CHECK-NEXT:   1: CFGScopeBegin(unused1)
+// CHECK-NEXT:   2: int unused1;
+// CHECK-NEXT:   3: CFGScopeEnd(unused1)
+// CHECK-NEXT:   T: break;
+// CHECK-NEXT:   Preds (1): B5
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B5]
+// CHECK-NEXT:   1: i
+// CHECK-NEXT:   2: [B5.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   3: 3
+// CHECK-NEXT:   4: [B5.2] < [B5.3]
+// CHECK-NEXT:   T: for (...; [B5.4]; ...)
+// CHECK-NEXT:   Preds (2): B2 B6
+// CHECK-NEXT:   Succs (2): B4 B1
+// CHECK:      [B6]
+// CHECK-NEXT:   1: CFGScopeBegin(i)
+// CHECK-NEXT:   2: 0
+// CHECK-NEXT:   3: int i = 0;
+// CHECK-NEXT:   Preds (1): B7
+// CHECK-NEXT:   Succs (1): B5
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_for_compound_and_break() {
+  for (int i = 0; i < 3; ++i) {
+    {
+      int unused1;
+      break;
+    }
+  }
+  {
+    int unused2;
+  }
+}
+
+// CHECK:      [B6 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B5
+// CHECK:      [B1]
+// CHECK-NEXT:   1: CFGScopeEnd(__end1)
+// CHECK-NEXT:   2: CFGScopeEnd(__begin1)
+// CHECK-NEXT:   3: CFGScopeEnd(__range1)
+// CHECK-NEXT:   4: [B5.3].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B2]
+// CHECK-NEXT:   1: __begin1
+// CHECK-NEXT:   2: [B2.1] (ImplicitCastExpr, LValueToRValue, class A *)
+// CHECK-NEXT:   3: __end1
+// CHECK-NEXT:   4: [B2.3] (ImplicitCastExpr, LValueToRValue, class A *)
+// CHECK-NEXT:   5: [B2.2] != [B2.4]
+// CHECK-NEXT:   T: for (auto &i : [B5.4]) {
+// CHECK:         [B4.11];
+// CHECK-NEXT:}
+// CHECK-NEXT:   Preds (2): B3 B5
+// CHECK-NEXT:   Succs (2): B4 B1
+// CHECK:      [B3]
+// CHECK-NEXT:   1: __begin1
+// CHECK-NEXT:   2: ++[B3.1]
+// CHECK-NEXT:   Preds (1): B4
+// CHECK-NEXT:   Succs (1): B2
+// CHECK:      [B4]
+// CHECK-NEXT:   1: CFGScopeBegin(i)
+// CHECK-NEXT:   2: __begin1
+// CHECK-NEXT:   3: [B4.2] (ImplicitCastExpr, LValueToRValue, class A *)
+// CHECK-NEXT:   4: *[B4.3]
+// CHECK-NEXT:   5: auto &i = *__begin1;
+// CHECK-NEXT:   6: operator=
+// CHECK-NEXT:   7: [B4.6] (ImplicitCastExpr, FunctionToPointerDecay, class A &(*)(const class A &) noexcept)
+// CHECK-NEXT:   8: i
+// CHECK-NEXT:   9: b
+// CHECK-NEXT:  10: [B4.9] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:  11: [B4.8] = [B4.10] (OperatorCall)
+// CHECK-NEXT:  12: CFGScopeEnd(i)
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B3
+// CHECK:      [B5]
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B5.3], class A [10])
+// CHECK-NEXT:   3: A a[10];
+// CHECK-NEXT:   4: a
+// CHECK-NEXT:   5: auto &&__range1 = a;
+// CHECK-NEXT:   6: CFGScopeBegin(__end1)
+// CHECK-NEXT:   7: __range1
+// CHECK-NEXT:   8: [B5.7] (ImplicitCastExpr, ArrayToPointerDecay, class A *)
+// CHECK-NEXT:   9: 10L
+// CHECK-NEXT:  10: [B5.8] + [B5.9]
+// CHECK-NEXT:  11: auto __end1 = __range1 + 10L;
+// CHECK-NEXT:  12: __range1
+// CHECK-NEXT:  13: [B5.12] (ImplicitCastExpr, ArrayToPointerDecay, class A *)
+// CHECK-NEXT:  14: auto __begin1 = __range1;
+// CHECK-NEXT:   Preds (1): B6
+// CHECK-NEXT:   Succs (1): B2
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_range_for(A &b) {
+  A a[10];
+  for (auto &i : a)
+    i = b;
+}
+
+// CHECK:      [B8 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B2
+// CHECK:      [B1]
+// CHECK-NEXT:   1: CFGScopeEnd(i)
+// CHECK-NEXT:   2: 1
+// CHECK-NEXT:   3: int k = 1;
+// CHECK-NEXT:   4: CFGScopeEnd(c)
+// CHECK-NEXT:   Preds (3): B3 B5 B6
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B2]
+// CHECK-NEXT:   1: CFGScopeBegin(c)
+// CHECK-NEXT:   2: '1'
+// CHECK-NEXT:   3: char c = '1';
+// CHECK-NEXT:   4: CFGScopeBegin(i)
+// CHECK-NEXT:   5: getX
+// CHECK-NEXT:   6: [B2.5] (ImplicitCastExpr, FunctionToPointerDecay, int (*)(void))
+// CHECK-NEXT:   7: [B2.6]()
+// CHECK-NEXT:   8: int i = getX();
+// CHECK-NEXT:   9: i
+// CHECK-NEXT:  10: [B2.9] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   T: switch [B2.10]
+// CHECK-NEXT:   Preds (1): B8
+// CHECK-NEXT:   Succs (5): B4 B5 B6 B7 B3
+// CHECK:      [B3]
+// CHECK-NEXT:  default:
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2: 0
+// CHECK-NEXT:   3: int a = 0;
+// CHECK-NEXT:   4: i
+// CHECK-NEXT:   5: ++[B3.4]
+// CHECK-NEXT:   6: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (2): B4 B2
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B4]
+// CHECK-NEXT:  case 3:
+// CHECK-NEXT:   1: '2'
+// CHECK-NEXT:   2: c
+// CHECK-NEXT:   3: [B4.2] = [B4.1]
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B3
+// CHECK:      [B5]
+// CHECK-NEXT:  case 2:
+// CHECK-NEXT:   1: '2'
+// CHECK-NEXT:   2: c
+// CHECK-NEXT:   3: [B5.2] = [B5.1]
+// CHECK-NEXT:   T: break;
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B6]
+// CHECK-NEXT:  case 1:
+// CHECK-NEXT:   1: '3'
+// CHECK-NEXT:   2: c
+// CHECK-NEXT:   3: [B6.2] = [B6.1]
+// CHECK-NEXT:   T: break;
+// CHECK-NEXT:   Preds (2): B2 B7
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B7]
+// CHECK-NEXT:  case 0:
+// CHECK-NEXT:   1: '2'
+// CHECK-NEXT:   2: c
+// CHECK-NEXT:   3: [B7.2] = [B7.1]
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B6
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_switch_with_compound_with_default() {
+  char c = '1';
+  switch (int i = getX()) {
+    case 0:
+      c = '2';
+    case 1:
+      c = '3';
+      break;
+    case 2: {
+      c = '2';
+      break;
+    }
+    case 3:
+      c = '2';
+    default: {
+      int a = 0;
+      ++i;
+    }
+    }
+  int k = 1;
+}
+
+// CHECK:      [B6 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B2
+// CHECK:      [B1]
+// CHECK-NEXT:   1: CFGScopeEnd(i)
+// CHECK-NEXT:   2: 3
+// CHECK-NEXT:   3: int k = 3;
+// CHECK-NEXT:   4: CFGScopeEnd(c)
+// CHECK-NEXT:   Preds (3): B3 B4 B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B2]
+// CHECK-NEXT:   1: CFGScopeBegin(c)
+// CHECK-NEXT:   2: '1'
+// CHECK-NEXT:   3: char c = '1';
+// CHECK-NEXT:   4: CFGScopeBegin(i)
+// CHECK-NEXT:   5: getX
+// CHECK-NEXT:   6: [B2.5] (ImplicitCastExpr, FunctionToPointerDecay, int (*)(void))
+// CHECK-NEXT:   7: [B2.6]()
+// CHECK-NEXT:   8: int i = getX();
+// CHECK-NEXT:   9: i
+// CHECK-NEXT:  10: [B2.9] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   T: switch [B2.10]
+// CHECK-NEXT:   Preds (1): B6
+// CHECK-NEXT:   Succs (4): B3 B4 B5 B1
+// CHECK:      [B3]
+// CHECK-NEXT:  case 2:
+// CHECK-NEXT:   1: '3'
+// CHECK-NEXT:   2: c
+// CHECK-NEXT:   3: [B3.2] = [B3.1]
+// CHECK-NEXT:   T: break;
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B4]
+// CHECK-NEXT:  case 1:
+// CHECK-NEXT:   1: '1'
+// CHECK-NEXT:   2: c
+// CHECK-NEXT:   3: [B4.2] = [B4.1]
+// CHECK-NEXT:   T: break;
+// CHECK-NEXT:   Preds (2): B2 B5
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B5]
+// CHECK-NEXT:  case 0:
+// CHECK-NEXT:   1: '2'
+// CHECK-NEXT:   2: c
+// CHECK-NEXT:   3: [B5.2] = [B5.1]
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B4
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+int test_switch_with_compound_without_default() {
+  char c = '1';
+  switch (int i = getX()) {
+    case 0:
+      c = '2';
+    case 1:
+      c = '1';
+      break;
+    case 2:
+      c = '3';
+      break;
+   }
+  int k = 3;
+}
+
+// CHECK:      [B5 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B2
+// CHECK:      [B1]
+// CHECK-NEXT:   1: CFGScopeEnd(i)
+// CHECK-NEXT:   2: 1
+// CHECK-NEXT:   3: int k = 1;
+// CHECK-NEXT:   4: CFGScopeEnd(s)
+// CHECK-NEXT:   Preds (1): B3
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B2]
+// CHECK-NEXT:   1: CFGScopeBegin(s)
+// CHECK-NEXT:   2: '1'
+// CHECK-NEXT:   3: char s = '1';
+// CHECK-NEXT:   4: CFGScopeBegin(i)
+// CHECK-NEXT:   5: getX
+// CHECK-NEXT:   6: [B2.5] (ImplicitCastExpr, FunctionToPointerDecay, int (*)(void))
+// CHECK-NEXT:   7: [B2.6]()
+// CHECK-NEXT:   8: int i = getX();
+// CHECK-NEXT:   9: i
+// CHECK-NEXT:  10: [B2.9] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   T: switch [B2.10]
+// CHECK-NEXT:   Preds (1): B5
+// CHECK-NEXT:   Succs (2): B4 B3
+// CHECK:      [B3]
+// CHECK-NEXT:  default:
+// CHECK-NEXT:   1: CFGScopeBegin(a)
+// CHECK-NEXT:   2: 0
+// CHECK-NEXT:   3: int a = 0;
+// CHECK-NEXT:   4: i
+// CHECK-NEXT:   5: ++[B3.4]
+// CHECK-NEXT:   6: CFGScopeEnd(a)
+// CHECK-NEXT:   Preds (2): B4 B2
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B4]
+// CHECK-NEXT:  case 0:
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B3
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_without_compound() {
+  char s = '1';
+  switch (int i = getX())
+    case 0:
+    default: {
+      int a = 0;
+      ++i;
+    }
+  int k = 1;
+}
+
+// CHECK:      [B12 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B11
+// CHECK:      [B1]
+// CHECK-NEXT:   1: CFGScopeEnd(i)
+// CHECK-NEXT:   Preds (2): B4 B10
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:      [B2]
+// CHECK-NEXT:   1: i
+// CHECK-NEXT:   2: ++[B2.1]
+// CHECK-NEXT:   Preds (2): B3 B7
+// CHECK-NEXT:   Succs (1): B10
+// CHECK:      [B3]
+// CHECK-NEXT:   1: CFGScopeEnd(z)
+// CHECK-NEXT:   Succs (1): B2
+// CHECK:      [B4]
+// CHECK-NEXT:   1: CFGScopeBegin(z)
+// CHECK-NEXT:   2: 5
+// CHECK-NEXT:   3: int z = 5;
+// CHECK-NEXT:   4: CFGScopeEnd(z)
+// CHECK-NEXT:   T: break;
+// CHECK-NEXT:   Preds (2): B6 B8
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:      [B5]
+// CHECK-NEXT:   1: x
+// CHECK-NEXT:   2: [B5.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   T: switch [B5.2]
+// CHECK-NEXT:   Preds (1): B10
+// CHECK-NEXT:   Succs (4): B7 B8 B9 B6
+// CHECK:      [B6]
+// CHECK-NEXT:  default:
+// CHECK-NEXT:   1: 3
+// CHECK-NEXT:   2: y
+// CHECK-NEXT:   3: [B6.2] = [B6.1]
+// CHECK-NEXT:   Preds (1): B5
+// CHECK-NEXT:   Succs (1): B4
+// CHECK:      [B7]
+// CHECK-NEXT:  case 2:
+// CHECK-NEXT:   1: 4
+// CHECK-NEXT:   2: y
+// CHECK-NEXT:   3: [B7.2] = [B7.1]
+// CHECK-NEXT:   T: continue;
+// CHECK-NEXT:   Preds (1): B5
+// CHECK-NEXT:   Succs (1): B2
+// CHECK:      [B8]
+// CHECK-NEXT:  case 1:
+// CHECK-NEXT:   1: 2
+// CHECK-NEXT:   2: y
+// CHECK-NEXT:   3: [B8.2] = [B8.1]
+// CHECK-NEXT:   T: break;
+// CHECK-NEXT:   Preds (2): B5 B9
+// CHECK-NEXT:   Succs (1): B4
+// CHECK:      [B9]
+// CHECK-NEXT:  case 0:
+// CHECK-NEXT:   1: 1
+// CHECK-NEXT:   2: y
+// CHECK-NEXT:   3: [B9.2] = [B9.1]
+// CHECK-NEXT:   Preds (1): B5
+// CHECK-NEXT:   Succs (1): B8
+// CHECK:      [B10]
+// CHECK-NEXT:   1: i
+// CHECK-NEXT:   2: [B10.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   3: 1000
+// CHECK-NEXT:   4: [B10.2] < [B10.3]
+// CHECK-NEXT:   T: for (...; [B10.4]; ...)
+// CHECK-NEXT:   Preds (2): B2 B11
+// CHECK-NEXT:   Succs (2): B5 B1
+// CHECK:      [B11]
+// CHECK-NEXT:   1: CFGScopeBegin(i)
+// CHECK-NEXT:   2: int i;
+// CHECK-NEXT:   3: int x;
+// CHECK-NEXT:   4: int y;
+// CHECK-NEXT:   5: 0
+// CHECK-NEXT:   6: i
+// CHECK-NEXT:   7: [B11.6] = [B11.5]
+// CHECK-NEXT:   Preds (1): B12
+// CHECK-NEXT:   Succs (1): B10
+// CHECK:      [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_for_switch_in_for() {
+  int i, x, y;
+  for (i = 0; i < 1000; ++i) {
+    switch (x) {
+    case 0:
+      y = 1;
+    case 1:
+      y = 2;
+      break; // break from switch
+    case 2:
+      y = 4;
+      continue; // continue in loop
+    default:
+      y = 3;
+    }
+    {
+      int z = 5;
+      break; // break from loop
+    }
+  }
+}




More information about the cfe-commits mailing list