summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/AnalysisBasedWarnings.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2014-03-29 00:35:20 +0000
committerTed Kremenek <kremenek@apple.com>2014-03-29 00:35:20 +0000
commitec3bbf4933d70fd1c907f883acd45da4ab1f10ee (patch)
treedcd8e6bb16ecfd1b1d0da0b1e308b6bf44956d63 /clang/lib/Sema/AnalysisBasedWarnings.cpp
parentfdf496cb4807647276ad43f9c4ae5aa30bad299c (diff)
downloadbcm5719-llvm-ec3bbf4933d70fd1c907f883acd45da4ab1f10ee.tar.gz
bcm5719-llvm-ec3bbf4933d70fd1c907f883acd45da4ab1f10ee.zip
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. llvm-svn: 205069
Diffstat (limited to 'clang/lib/Sema/AnalysisBasedWarnings.cpp')
-rw-r--r--clang/lib/Sema/AnalysisBasedWarnings.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index efaf966562c..75d7060e2d8 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/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, ")");
+ }
+ }
}
};
}
OpenPOWER on IntegriCloud