[cfe-commits] [PATCH] Silence unintended fallthrough diagnostic on a case label preceded with a normal label.
Alexander Kornienko
alexfh at google.com
Fri Jan 25 08:27:25 PST 2013
Hi rsmith, doug.gregor,
It's unlikely that a fallthrough is unintended in the following code:
switch (n) {
...
label:
case 1:
...
goto label;
...
}
http://llvm-reviews.chandlerc.com/D329
Files:
lib/Sema/AnalysisBasedWarnings.cpp
test/SemaCXX/switch-implicit-fallthrough.cpp
Index: lib/Sema/AnalysisBasedWarnings.cpp
===================================================================
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -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();
Index: test/SemaCXX/switch-implicit-fallthrough.cpp
===================================================================
--- test/SemaCXX/switch-implicit-fallthrough.cpp
+++ test/SemaCXX/switch-implicit-fallthrough.cpp
@@ -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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D329.1.patch
Type: text/x-patch
Size: 1316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130125/6ef1fc59/attachment.bin>
More information about the cfe-commits
mailing list