[cfe-commits] r110353 - in /cfe/trunk: lib/Checker/UnreachableCodeChecker.cpp test/Analysis/unreachable-code-path.c
Tom Care
tcare at apple.com
Thu Aug 5 10:53:44 PDT 2010
Author: tcare
Date: Thu Aug 5 12:53:44 2010
New Revision: 110353
URL: http://llvm.org/viewvc/llvm-project?rev=110353&view=rev
Log:
Fixed logic error in UnreachableCodeChecker's marking algorithm that would sometimes allow for multiple sequential statements to be flagged.
Modified:
cfe/trunk/lib/Checker/UnreachableCodeChecker.cpp
cfe/trunk/test/Analysis/unreachable-code-path.c
Modified: cfe/trunk/lib/Checker/UnreachableCodeChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/UnreachableCodeChecker.cpp?rev=110353&r1=110352&r2=110353&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/UnreachableCodeChecker.cpp (original)
+++ cfe/trunk/lib/Checker/UnreachableCodeChecker.cpp Thu Aug 5 12:53:44 2010
@@ -149,10 +149,13 @@
for (CFGBlock::const_pred_iterator I = CB->pred_begin(); I != CB->pred_end();
++I) {
// Recurse over all unreachable blocks
- if (!reachable.count((*I)->getBlockID())
- && !visited.count((*I)->getBlockID())) {
- FindUnreachableEntryPoints(*I);
+ if (!reachable.count((*I)->getBlockID())) {
+ // At least one predeccessor was unreachable
allPredecessorsReachable = false;
+
+ // Only visit the block once
+ if (!visited.count((*I)->getBlockID()))
+ FindUnreachableEntryPoints(*I);
}
}
Modified: cfe/trunk/test/Analysis/unreachable-code-path.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/unreachable-code-path.c?rev=110353&r1=110352&r2=110353&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/unreachable-code-path.c (original)
+++ cfe/trunk/test/Analysis/unreachable-code-path.c Thu Aug 5 12:53:44 2010
@@ -88,3 +88,17 @@
a = 5;
}
+// Check for bugs where multiple statements are reported
+void test9(unsigned a) {
+ switch (a) {
+ if (a) // expected-warning{{never executed}}
+ foo(a + 5); // no-warning
+ else // no-warning
+ foo(a); // no-warning
+ case 1:
+ case 2:
+ break;
+ default:
+ break;
+ }
+}
More information about the cfe-commits
mailing list