From 50aa2d480ced9bb792d438f6ff92fe06afa6b84e Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 12 Aug 2011 14:41:23 +0000 Subject: [PATCH] Revert "Fix crash in CFGBuilder involving implicit destructor calls and gotos jumping after an object was declared. Fixes PR 10620." llvm-svn: 137459 --- clang/lib/Analysis/CFG.cpp | 14 ++++++-------- clang/test/SemaCXX/cfg.cpp | 23 ----------------------- 2 files changed, 6 insertions(+), 31 deletions(-) delete mode 100644 clang/test/SemaCXX/cfg.cpp diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index ea126a968949..1edb328d013e 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -191,8 +191,8 @@ int LocalScope::const_iterator::distance(LocalScope::const_iterator L) { int D = 0; const_iterator F = *this; while (F.Scope != L.Scope) { - if (F == const_iterator()) - return D; + assert (F != const_iterator() + && "L iterator is not reachable from F iterator."); D += F.VarIter; F = F.Scope->Prev; } @@ -816,12 +816,10 @@ void CFGBuilder::addLocalScopeAndDtors(Stmt* S) { /// performed in place specified with iterator. void CFGBuilder::insertAutomaticObjDtors(CFGBlock* Blk, CFGBlock::iterator I, LocalScope::const_iterator B, LocalScope::const_iterator E, Stmt* S) { - if (int Cnt = B.distance(E)) { - BumpVectorContext& C = cfg->getBumpVectorContext(); - I = Blk->beginAutomaticObjDtorsInsert(I, Cnt, C); - while (B != E) - I = Blk->insertAutomaticObjDtor(I, *B++, S); - } + BumpVectorContext& C = cfg->getBumpVectorContext(); + I = Blk->beginAutomaticObjDtorsInsert(I, B.distance(E), C); + while (B != E) + I = Blk->insertAutomaticObjDtor(I, *B++, S); } /// appendAutomaticObjDtors - Append destructor CFGElements for variables with diff --git a/clang/test/SemaCXX/cfg.cpp b/clang/test/SemaCXX/cfg.cpp deleted file mode 100644 index 93cf90ba452f..000000000000 --- a/clang/test/SemaCXX/cfg.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -fsyntax-only %s - -// Test that the CFG builder handles destructors and gotos jumping between -// scope boundaries. Previously this crashed (PR 10620). -struct S_10620 { - S_10620(const S_10620 &x); - ~S_10620(); -}; -void PR10620(int x, const S_10620& s) { - if (x) { - goto done; - } - const S_10620 s2(s); -done: - ; -} -void PR10620_2(int x, const S_10620& s) { - if (x) - goto done; - const S_10620 s2(s); -done: - ; -} \ No newline at end of file