Implementation of a "soft opt-in" option for -Wimplicit-fallthrough diagnostics: -Wimplicit-fallthrough-per-method
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157871 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp
index 8f16e70..cea8a76 100644
--- a/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/lib/Sema/AnalysisBasedWarnings.cpp
@@ -814,13 +814,17 @@
};
}
-static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC) {
+static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC,
+ bool PerMethod) {
FallthroughMapper FM(S);
FM.TraverseStmt(AC.getBody());
if (!FM.foundSwitchStatements())
return;
+ if (PerMethod && FM.getFallthroughStmts().empty())
+ return;
+
CFG *Cfg = AC.getCFG();
if (!Cfg)
@@ -838,7 +842,9 @@
if (!FM.checkFallThroughIntoBlock(B, AnnotatedCnt))
continue;
- S.Diag(Label->getLocStart(), diag::warn_unannotated_fallthrough);
+ S.Diag(Label->getLocStart(),
+ PerMethod ? diag::warn_unannotated_fallthrough_per_method
+ : diag::warn_unannotated_fallthrough);
if (!AnnotatedCnt) {
SourceLocation L = Label->getLocStart();
@@ -1324,9 +1330,14 @@
}
}
- if (Diags.getDiagnosticLevel(diag::warn_unannotated_fallthrough,
- D->getLocStart()) != DiagnosticsEngine::Ignored) {
- DiagnoseSwitchLabelsFallthrough(S, AC);
+ bool FallThroughDiagFull =
+ Diags.getDiagnosticLevel(diag::warn_unannotated_fallthrough,
+ D->getLocStart()) != DiagnosticsEngine::Ignored;
+ bool FallThroughDiagPerMethod =
+ Diags.getDiagnosticLevel(diag::warn_unannotated_fallthrough_per_method,
+ D->getLocStart()) != DiagnosticsEngine::Ignored;
+ if (FallThroughDiagFull || FallThroughDiagPerMethod) {
+ DiagnoseSwitchLabelsFallthrough(S, AC, !FallThroughDiagFull);
}
// Collect statistics about the CFG if it was built.