r207985 - Fix handling of condition variables in the face of temp dtors.
Manuel Klimek
klimek at google.com
Mon May 5 11:21:07 PDT 2014
Author: klimek
Date: Mon May 5 13:21:06 2014
New Revision: 207985
URL: http://llvm.org/viewvc/llvm-project?rev=207985&view=rev
Log:
Fix handling of condition variables in the face of temp dtors.
The assignment needs to be before the destruction of the temporary.
This patch calls out to addStmt, which invokes VisitDeclStmt, which has
all the correct logic for handling temporaries.
Modified:
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/test/Analysis/temp-obj-dtors-cfg-output.cpp
Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=207985&r1=207984&r2=207985&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Mon May 5 13:21:06 2014
@@ -2107,14 +2107,11 @@ CFGBlock *CFGBuilder::VisitIfStmt(IfStmt
// 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.
- if (VarDecl *VD = I->getConditionVariable()) {
- if (Expr *Init = VD->getInit()) {
- autoCreateBlock();
- appendStmt(Block, I->getConditionVariableDeclStmt());
- LastBlock = addStmt(Init);
- }
+ // Finally, if the IfStmt contains a condition variable, add it and its
+ // initializer to the CFG.
+ if (const DeclStmt* DS = I->getConditionVariableDeclStmt()) {
+ autoCreateBlock();
+ LastBlock = addStmt(const_cast<DeclStmt *>(DS));
}
return LastBlock;
Modified: cfe/trunk/test/Analysis/temp-obj-dtors-cfg-output.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/temp-obj-dtors-cfg-output.cpp?rev=207985&r1=207984&r2=207985&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/temp-obj-dtors-cfg-output.cpp (original)
+++ cfe/trunk/test/Analysis/temp-obj-dtors-cfg-output.cpp Mon May 5 13:21:06 2014
@@ -611,18 +611,18 @@ int testConsistencyNestedNormalReturn(bo
// 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]
@@ -631,8 +631,8 @@ int testConsistencyNestedNormalReturn(bo
// 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]
More information about the cfe-commits
mailing list