diff options
author | Alexander Kornienko <alexfh@google.com> | 2012-06-02 01:01:07 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2012-06-02 01:01:07 +0000 |
commit | 1973634e445d4f1abdeedc2809f2d281929253b6 (patch) | |
tree | f9be16facb1db76bc0ec3503e556aef6e442df2b /lib | |
parent | c0e71a15bce9bb8c0d4ec1c42fab70c03140f9e0 (diff) |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/AnalysisBasedWarnings.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index 8f16e70b15..cea8a765c8 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -814,13 +814,17 @@ namespace { }; } -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 @@ static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC) { 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 @@ 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. |