From cb50e23ba86ecfbb22f0eb1eec2fde9cc0c55569 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Fri, 2 Nov 2018 10:01:59 +0000 Subject: [clang-tidy] Get ClangTidyContext out of the business of storing diagnostics. NFC Summary: Currently ClangTidyContext::diag() sends the diagnostics to a DiagnosticsEngine, which probably delegates to a ClangTidyDiagnosticsConsumer, which is supposed to go back and populate ClangTidyContext::Errors. After this patch, the diagnostics are stored in the ClangTidyDiagnosticsConsumer itself and can be retrieved from there. Why? - the round-trip from context -> engine -> consumer -> context is confusing and makes it harder to establish layering between these things. - context does too many things, and makes it hard to use clang-tidy as a library - everyone who actually wants the diagnostics has access to the ClangTidyDiagnosticsConsumer The most natural implementation (ClangTidyDiagnosticsConsumer::take() finalizes diagnostics) causes a test failure: clang-tidy-run-with-database.cpp asserts that clang-tidy exits successfully when trying to process a file that doesn't exist. In clang-tidy today, this happens because finish() is never called, so the diagnostic is never flushed. This looks like a bug to me. For now, this patch carefully preserves that behavior, but I'll ping the authors to see whether it's deliberate and worth preserving. Reviewers: hokein Subscribers: xazax.hun, cfe-commits, alexfh Differential Revision: https://reviews.llvm.org/D53953 llvm-svn: 345961 --- .../test/clang-tidy/clang-tidy-run-with-database.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'clang-tools-extra/test') diff --git a/clang-tools-extra/test/clang-tidy/clang-tidy-run-with-database.cpp b/clang-tools-extra/test/clang-tidy/clang-tidy-run-with-database.cpp index 05bc14c4fa0..f9b2955c6fd 100644 --- a/clang-tools-extra/test/clang-tidy/clang-tidy-run-with-database.cpp +++ b/clang-tools-extra/test/clang-tidy/clang-tidy-run-with-database.cpp @@ -8,7 +8,13 @@ // RUN: echo 'int *HP = 0;' > %T/compilation-database-test/include/header.h // RUN: echo '#include "header.h"' > %T/compilation-database-test/b/d.cpp // RUN: sed 's|test_dir|%/T/compilation-database-test|g' %S/Inputs/compilation-database/template.json > %T/compile_commands.json -// RUN: clang-tidy --checks=-*,modernize-use-nullptr -p %T %T/compilation-database-test/b/not-exist -header-filter=.* + +// Regression test: shouldn't crash. +// RUN: not clang-tidy --checks=-*,modernize-use-nullptr -p %T %T/compilation-database-test/b/not-exist -header-filter=.* 2>&1 | FileCheck %s -check-prefix=CHECK-NOT-EXIST +// CHECK-NOT-EXIST: Error while processing {{.*}}/not-exist. +// CHECK-NOT-EXIST: unable to handle compilation +// CHECK-NOT-EXIST: Found compiler error + // RUN: clang-tidy --checks=-*,modernize-use-nullptr -p %T %T/compilation-database-test/a/a.cpp %T/compilation-database-test/a/b.cpp %T/compilation-database-test/b/b.cpp %T/compilation-database-test/b/c.cpp %T/compilation-database-test/b/d.cpp -header-filter=.* -fix // RUN: FileCheck -input-file=%T/compilation-database-test/a/a.cpp %s -check-prefix=CHECK-FIX1 // RUN: FileCheck -input-file=%T/compilation-database-test/a/b.cpp %s -check-prefix=CHECK-FIX2 -- cgit v1.2.3