[PATCH] D13973: CFG: Delay creating Dtors for CompoundStmts which end in ReturnStmt

Matthias Gehre via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 13 16:39:29 PST 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL253107: CFG: Delay creating Dtors for CompoundStmts which end in ReturnStmt (authored by mgehre).

Changed prior to commit:
  http://reviews.llvm.org/D13973?vs=38359&id=40188#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D13973

Files:
  cfe/trunk/lib/Analysis/CFG.cpp
  cfe/trunk/test/Analysis/no-unreachable-dtors.cpp

Index: cfe/trunk/lib/Analysis/CFG.cpp
===================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp
+++ cfe/trunk/lib/Analysis/CFG.cpp
@@ -1942,7 +1942,15 @@
 
 
 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();
Index: cfe/trunk/test/Analysis/no-unreachable-dtors.cpp
===================================================================
--- cfe/trunk/test/Analysis/no-unreachable-dtors.cpp
+++ cfe/trunk/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;
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13973.40188.patch
Type: text/x-patch
Size: 1393 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151114/30088e5d/attachment.bin>


More information about the cfe-commits mailing list