|
@@ -814,13 +814,17 @@ namespace {
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
-static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC) {
|
|
|
|
|
|
+static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC,
|
|
|
|
+ bool PerMethod) {
|
|
FallthroughMapper FM(S);
|
|
FallthroughMapper FM(S);
|
|
FM.TraverseStmt(AC.getBody());
|
|
FM.TraverseStmt(AC.getBody());
|
|
|
|
|
|
if (!FM.foundSwitchStatements())
|
|
if (!FM.foundSwitchStatements())
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
+ if (PerMethod && FM.getFallthroughStmts().empty())
|
|
|
|
+ return;
|
|
|
|
+
|
|
CFG *Cfg = AC.getCFG();
|
|
CFG *Cfg = AC.getCFG();
|
|
|
|
|
|
if (!Cfg)
|
|
if (!Cfg)
|
|
@@ -838,7 +842,9 @@ static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC) {
|
|
if (!FM.checkFallThroughIntoBlock(B, AnnotatedCnt))
|
|
if (!FM.checkFallThroughIntoBlock(B, AnnotatedCnt))
|
|
continue;
|
|
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) {
|
|
if (!AnnotatedCnt) {
|
|
SourceLocation L = Label->getLocStart();
|
|
SourceLocation L = Label->getLocStart();
|
|
@@ -1324,9 +1330,14 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- 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.
|
|
// Collect statistics about the CFG if it was built.
|