diff options
| -rw-r--r-- | clang/lib/Analysis/CFG.cpp | 10 | ||||
| -rw-r--r-- | clang/test/Analysis/no-unreachable-dtors.cpp | 11 |
2 files changed, 20 insertions, 1 deletions
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 6cb63f2b175..fba9a41f232 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -1942,7 +1942,15 @@ CFGBlock *CFGBuilder::VisitChooseExpr(ChooseExpr *C, CFGBlock *CFGBuilder::VisitCompoundStmt(CompoundStmt *C) { - addLocalScopeAndDtors(C); + LocalScope::const_iterator scopeBeginPos = ScopePos; + if (BuildOpts.AddImplicitDtors) { + addLocalScopeForStmt(C); + } + if (!C->body_empty() && !isa<ReturnStmt>(*C->body_rbegin())) { + // If the body ends with a ReturnStmt, the dtors will be added in VisitReturnStmt + addAutomaticObjDtors(ScopePos, scopeBeginPos, C); + } + CFGBlock *LastBlock = Block; for (CompoundStmt::reverse_body_iterator I=C->body_rbegin(), E=C->body_rend(); diff --git a/clang/test/Analysis/no-unreachable-dtors.cpp b/clang/test/Analysis/no-unreachable-dtors.cpp new file mode 100644 index 00000000000..e0893b3f4e6 --- /dev/null +++ b/clang/test/Analysis/no-unreachable-dtors.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=debug.Stats -verify -Wno-unreachable-code %s + +struct S { + ~S(); +}; + +// the return at the end of an CompoundStmt does not lead to an unreachable block containing the dtors +void test() { // expected-warning-re{{test -> Total CFGBlocks: {{[0-9]+}} | Unreachable CFGBlocks: 0 | Exhausted Block: no | Empty WorkList: yes}} + S s; + return; +} |

