diff options
author | Ted Kremenek <kremenek@apple.com> | 2014-03-29 00:35:20 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2014-03-29 00:35:20 +0000 |
commit | e1f53884e483c92c497eab5f12f479c136f6ba94 (patch) | |
tree | ab006dbc9f76246f5ffea87564c9da3c28743ff2 /lib/Sema/AnalysisBasedWarnings.cpp | |
parent | ed699a2323ef722d56fa89e6ffcdcfe62308b56d (diff) |
Improve -Wunreachable-code to provide a means to indicate code is intentionally marked dead via if((0)).
Taking a hint from -Wparentheses, use an extra '()' as a sigil that
a dead condition is intentionally dead. For example:
if ((0)) { dead }
When this sigil is found, do not emit a dead code warning. When the
analysis sees:
if (0)
it suggests inserting '()' as a Fix-It.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205069 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/AnalysisBasedWarnings.cpp')
-rw-r--r-- | lib/Sema/AnalysisBasedWarnings.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index efaf966562..75d7060e2d 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -66,7 +66,9 @@ namespace { UnreachableCodeHandler(Sema &s) : S(s) {} void HandleUnreachable(reachable_code::UnreachableKind UK, - SourceLocation L, SourceRange R1, + SourceLocation L, + SourceRange SilenceableCondVal, + SourceRange R1, SourceRange R2) override { unsigned diag = diag::warn_unreachable; switch (UK) { @@ -84,6 +86,17 @@ namespace { } S.Diag(L, diag) << R1 << R2; + + SourceLocation Open = SilenceableCondVal.getBegin(); + if (Open.isValid()) { + SourceLocation Close = SilenceableCondVal.getEnd(); + Close = S.PP.getLocForEndOfToken(Close); + if (Close.isValid()) { + S.Diag(Open, diag::note_unreachable_silence) + << FixItHint::CreateInsertion(Open, "/* DISABLES CODE */ (") + << FixItHint::CreateInsertion(Close, ")"); + } + } } }; } |