[cfe-commits] r173486 - in /cfe/trunk: lib/Sema/AnalysisBasedWarnings.cpp test/SemaCXX/switch-implicit-fallthrough.cpp
Alexander Kornienko
alexfh at google.com
Fri Jan 25 12:44:56 PST 2013
Author: alexfh
Date: Fri Jan 25 14:44:56 2013
New Revision: 173486
URL: http://llvm.org/viewvc/llvm-project?rev=173486&view=rev
Log:
Silence unintended fallthrough diagnostic on a case label preceded with a normal label.
Summary:
It's unlikely that a fallthrough is unintended in the following code:
switch (n) {
...
label:
case 1:
...
goto label;
...
}
Reviewers: rsmith, doug.gregor
Reviewed By: doug.gregor
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D329
Modified:
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/test/SemaCXX/switch-implicit-fallthrough.cpp
Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=173486&r1=173485&r2=173486&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Fri Jan 25 14:44:56 2013
@@ -722,6 +722,10 @@
if (SW && SW->getSubStmt() == B.getLabel() && P->begin() == P->end())
continue; // Previous case label has no statements, good.
+ const LabelStmt *L = dyn_cast_or_null<LabelStmt>(P->getLabel());
+ if (L && L->getSubStmt() == B.getLabel() && P->begin() == P->end())
+ continue; // Case label is preceded with a normal label, good.
+
if (P->pred_begin() == P->pred_end()) { // The block is unreachable.
// This only catches trivially unreachable blocks.
for (CFGBlock::const_iterator ElIt = P->begin(), ElEnd = P->end();
Modified: cfe/trunk/test/SemaCXX/switch-implicit-fallthrough.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/switch-implicit-fallthrough.cpp?rev=173486&r1=173485&r2=173486&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/switch-implicit-fallthrough.cpp (original)
+++ cfe/trunk/test/SemaCXX/switch-implicit-fallthrough.cpp Fri Jan 25 14:44:56 2013
@@ -38,6 +38,18 @@
case 68:
break;
}
+ switch (n / 15) {
+label_case_70:
+ case 70:
+ n += 333;
+ break;
+ case 71:
+ n += 334;
+ goto label_case_70;
+ case 72:
+ n += 335;
+ break;
+ }
switch (n / 20) {
case 7:
n += 400;
More information about the cfe-commits
mailing list