[PATCH] D24759: [RFC][StaticAnalyser] fix unreachable code false positives when block numbers mismatch
Daniel Marjamäki via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 23 04:49:30 PDT 2016
danielmarjamaki updated this revision to Diff 72252.
danielmarjamaki added a comment.
Updated CFGBuilder::VisitDoStmt
https://reviews.llvm.org/D24759
Files:
lib/Analysis/CFG.cpp
test/Analysis/uninit-sometimes.cpp
test/Analysis/unreachable-code-path.c
Index: test/Analysis/unreachable-code-path.c
===================================================================
--- test/Analysis/unreachable-code-path.c
+++ test/Analysis/unreachable-code-path.c
@@ -158,3 +158,14 @@
}
}
}
+
+// Ensure that ExplodedGraph and unoptimized CFG match.
+void test12(int x) {
+ switch (x) {
+ case 1:
+ break; // not unreachable
+ case 2:
+ do { } while (0);
+ break;
+ }
+}
Index: test/Analysis/uninit-sometimes.cpp
===================================================================
--- test/Analysis/uninit-sometimes.cpp
+++ test/Analysis/uninit-sometimes.cpp
@@ -374,9 +374,10 @@
int PR13360(bool b) {
int x; // expected-note {{variable}}
if (b) { // expected-warning {{variable 'x' is used uninitialized whenever 'if' condition is true}} expected-note {{remove}}
- do {
+ // TODO: Uncomment "do { } while(0);" below. Warning should still be shown.
+ //do {
foo();
- } while (0);
+ //} while (0);
} else {
x = 1;
}
Index: lib/Analysis/CFG.cpp
===================================================================
--- lib/Analysis/CFG.cpp
+++ lib/Analysis/CFG.cpp
@@ -2983,22 +2983,18 @@
return nullptr;
}
- if (!KnownVal.isFalse()) {
- // Add an intermediate block between the BodyBlock and the
- // ExitConditionBlock to represent the "loop back" transition. Create an
- // empty block to represent the transition block for looping back to the
- // head of the loop.
- // FIXME: Can we do this more efficiently without adding another block?
- Block = nullptr;
- Succ = BodyBlock;
- CFGBlock *LoopBackBlock = createBlock();
- LoopBackBlock->setLoopTarget(D);
+ // Add an intermediate block between the BodyBlock and the
+ // ExitConditionBlock to represent the "loop back" transition. Create an
+ // empty block to represent the transition block for looping back to the
+ // head of the loop.
+ // FIXME: Can we do this more efficiently without adding another block?
+ Block = nullptr;
+ Succ = BodyBlock;
+ CFGBlock *LoopBackBlock = createBlock();
+ LoopBackBlock->setLoopTarget(D);
- // Add the loop body entry as a successor to the condition.
- addSuccessor(ExitConditionBlock, LoopBackBlock);
- }
- else
- addSuccessor(ExitConditionBlock, nullptr);
+ // Add the loop body entry as a successor to the condition.
+ addSuccessor(ExitConditionBlock, LoopBackBlock);
}
// Link up the condition block with the code that follows the loop.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24759.72252.patch
Type: text/x-patch
Size: 2559 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160923/d8aff09f/attachment-0001.bin>
More information about the cfe-commits
mailing list