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

Matthias Gehre via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 21 23:04:44 PDT 2015

mgehre created this revision.
mgehre added a reviewer: krememek.
mgehre added a subscriber: cfe-commits.

VisitReturnStmt would create a new block with including Dtors, so the Dtors created
in VisitCompoundStmts would be in an unreachable block.


struct S {

void f()
  S s;

void g()
  S s;

Before this patch, f has one additional unreachable block containing just the
destructor of S. With this patch, both f and g have the same blocks.



Index: lib/Analysis/CFG.cpp
--- lib/Analysis/CFG.cpp
+++ 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() && !dyn_cast<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();

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13973.38089.patch
Type: text/x-patch
Size: 724 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151022/55f02db4/attachment.bin>

More information about the cfe-commits mailing list