summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
diff options
context:
space:
mode:
authorMatthias Gehre <M.Gehre@gmx.de>2016-09-24 16:06:53 +0000
committerMatthias Gehre <M.Gehre@gmx.de>2016-09-24 16:06:53 +0000
commit41a83a7d2b654de40bc623821ff111e56191236c (patch)
tree98cdb1bc879f0d4d8438b7b1853d6d673179ed5e /clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
parent907cde3cc2e96b8558960641d2d2c78870a019b4 (diff)
downloadbcm5719-llvm-41a83a7d2b654de40bc623821ff111e56191236c.tar.gz
bcm5719-llvm-41a83a7d2b654de40bc623821ff111e56191236c.zip
[clang-tidy] fix for NOLINT after macro expansion
Summary: When having ``` c++ #define MACRO code-with-warning MACRO; // NOLINT ``` clang-tidy would still show the warning, because it searched for "NOLINT" only in the first line, not on the second. This caused e.g. https://llvm.org/bugs/show_bug.cgi?id=29089 (where the macro was defined in a system header). See also the added test cases. Now clang-tidy looks at the line of macro invocation and every line of macro definition for a NOLINT comment. Reviewers: alexfh, aaron.ballman, hokein Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D24845 llvm-svn: 282330
Diffstat (limited to 'clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 8dbae40e4e9..ca3877207f8 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -294,12 +294,24 @@ static bool LineIsMarkedWithNOLINT(SourceManager& SM, SourceLocation Loc) {
return false;
}
+static bool LineIsMarkedWithNOLINTinMacro(SourceManager &SM,
+ SourceLocation Loc) {
+ while (true) {
+ if (LineIsMarkedWithNOLINT(SM, Loc))
+ return true;
+ if (!Loc.isMacroID())
+ return false;
+ Loc = SM.getImmediateExpansionRange(Loc).first;
+ }
+ return false;
+}
+
void ClangTidyDiagnosticConsumer::HandleDiagnostic(
DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) {
if (Info.getLocation().isValid() &&
DiagLevel != DiagnosticsEngine::Error &&
DiagLevel != DiagnosticsEngine::Fatal &&
- LineIsMarkedWithNOLINT(Diags->getSourceManager(), Info.getLocation())) {
+ LineIsMarkedWithNOLINTinMacro(Diags->getSourceManager(), Info.getLocation())) {
++Context.Stats.ErrorsIgnoredNOLINT;
return;
}
OpenPOWER on IntegriCloud