[PATCH] Attempt to fix up condition variables with temp dtors.
Manuel Klimek
klimek at google.com
Sat May 3 08:16:02 PDT 2014
Hi krememek, jordan_rose,
I discovered this problem when playing around with slightly
different block split-ups when inserting temp dtors; a test
would fail with "garbage value accessed" warning. After following
some red herrings while debugging, I realized that the initializer
(MyClass c = ...) was after the temp destructor call (see the test
I had to fix). I just replaced the special-case logic in VisitIfStmt
with a call to addStmt, which invokes VisitDeclStmt, which already
handles all the temporary destructor logic correctly.
If you can come up with tests that this breaks, please let me know ;)
http://reviews.llvm.org/D3603
Files:
lib/Analysis/CFG.cpp
test/Analysis/temp-obj-dtors-cfg-output.cpp
Index: lib/Analysis/CFG.cpp
===================================================================
--- lib/Analysis/CFG.cpp
+++ lib/Analysis/CFG.cpp
@@ -2107,14 +2107,12 @@
// blocks will be pointed to be "Block".
CFGBlock *LastBlock = addStmt(I->getCond());
- // Finally, if the IfStmt contains a condition variable, add both the IfStmt
- // and the condition variable initialization to the CFG.
+ // Finally, if the IfStmt contains a condition variable, add it and its
+ // initializer to the CFG.
if (VarDecl *VD = I->getConditionVariable()) {
- if (Expr *Init = VD->getInit()) {
- autoCreateBlock();
- appendStmt(Block, I->getConditionVariableDeclStmt());
- LastBlock = addStmt(Init);
- }
+ autoCreateBlock();
+ LastBlock =
+ addStmt(const_cast<DeclStmt *>(I->getConditionVariableDeclStmt()));
}
return LastBlock;
Index: test/Analysis/temp-obj-dtors-cfg-output.cpp
===================================================================
--- test/Analysis/temp-obj-dtors-cfg-output.cpp
+++ test/Analysis/temp-obj-dtors-cfg-output.cpp
@@ -611,28 +611,28 @@
// CHECK: [B5 (ENTRY)]
// CHECK: Succs (1): B4
// CHECK: [B1]
-// CHECK: 1: [B4.7].~C() (Implicit destructor)
+// CHECK: 1: [B4.6].~C() (Implicit destructor)
// CHECK: Succs (1): B0
// CHECK: [B2]
// CHECK: 1: 0
// CHECK: 2: return [B2.1];
-// CHECK: 3: [B4.7].~C() (Implicit destructor)
+// CHECK: 3: [B4.6].~C() (Implicit destructor)
// CHECK: Preds (1): B4
// CHECK: Succs (1): B0
// CHECK: [B3]
// CHECK: 1: 1
// CHECK: 2: return [B3.1];
-// CHECK: 3: [B4.7].~C() (Implicit destructor)
+// CHECK: 3: [B4.6].~C() (Implicit destructor)
// CHECK: Preds (1): B4
// CHECK: Succs (1): B0
// CHECK: [B4]
// CHECK: 1: C() (CXXConstructExpr, struct C)
// CHECK: 2: [B4.1] (BindTemporary)
// CHECK: 3: [B4.2] (ImplicitCastExpr, NoOp, const struct C)
// CHECK: 4: [B4.3]
// CHECK: 5: [B4.4] (CXXConstructExpr, struct C)
-// CHECK: 6: ~C() (Temporary object destructor)
-// CHECK: 7: C c = C();
+// CHECK: 6: C c = C();
+// CHECK: 7: ~C() (Temporary object destructor)
// CHECK: 8: c
// CHECK: 9: [B4.8].operator bool
// CHECK: 10: [B4.8]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3603.9060.patch
Type: text/x-patch
Size: 2284 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140503/914c214d/attachment.bin>
More information about the cfe-commits
mailing list