From 6128bcd02512eeb0e0bbb8b0a9c4d82f6f9427b2 Mon Sep 17 00:00:00 2001 From: Nathan James Date: Sat, 15 Apr 2023 22:58:15 +0100 Subject: [PATCH] [clang-tidy] Fix crash in --dump-config Fixes a crash in dump-config when checks emit warnings trying to read the config Fixes https://github.com/llvm/llvm-project/issues/50876 Co-authored-by: Piotr Zegar Reviewed By: PiotrZSL Differential Revision: https://reviews.llvm.org/D148436 --- clang-tools-extra/clang-tidy/ClangTidy.cpp | 5 +++++ clang-tools-extra/docs/ReleaseNotes.rst | 2 ++ .../test/clang-tidy/infrastructure/dump-config-invalid.cpp | 6 ++++++ 3 files changed, 13 insertions(+) create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/dump-config-invalid.cpp diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index 7382bf4..445d268 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -498,6 +498,11 @@ getCheckOptions(const ClangTidyOptions &Options, std::make_unique(ClangTidyGlobalOptions(), Options), AllowEnablingAnalyzerAlphaCheckers); + ClangTidyDiagnosticConsumer DiagConsumer(Context); + DiagnosticsEngine DE(llvm::makeIntrusiveRefCnt(), + llvm::makeIntrusiveRefCnt(), + &DiagConsumer, /*ShouldOwnClient=*/false); + Context.setDiagnosticsEngine(&DE); ClangTidyASTConsumerFactory Factory(Context); return Factory.getCheckOptions(); } diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 55474e1..c19636b 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -101,6 +101,8 @@ Improvements to clang-tidy - Support specifying `Checks` as a YAML list in the `.clang-tidy` configuration file. +- Fix a potential crash when using the `--dump-config` option. + New checks ^^^^^^^^^^ diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/dump-config-invalid.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/dump-config-invalid.cpp new file mode 100644 index 0000000..eba40b8d --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/infrastructure/dump-config-invalid.cpp @@ -0,0 +1,6 @@ +// RUN: clang-tidy --checks="-*,modernize-make-shared" \ +// RUN: --config="CheckOptions: [{ \ +// RUN: key: modernize-make-shared.IncludeStyle, value: '0' }]" \ +// RUN: --dump-config -- | FileCheck %s + +// CHECK: modernize-make-shared.IncludeStyle: llvm -- 2.7.4