Skip to content

Commit

Permalink
[clang-tidy] Fix crash in --dump-config
Browse files Browse the repository at this point in the history
Fixes a crash in dump-config when checks emit warnings trying to read the config

Fixes #50876

Co-authored-by: Piotr Zegar <me@piotrzegar.pl>

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D148436
  • Loading branch information
njames93 committed Apr 15, 2023
1 parent ac1b6d4 commit 6128bcd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions clang-tools-extra/clang-tidy/ClangTidy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,11 @@ getCheckOptions(const ClangTidyOptions &Options,
std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions(),
Options),
AllowEnablingAnalyzerAlphaCheckers);
ClangTidyDiagnosticConsumer DiagConsumer(Context);
DiagnosticsEngine DE(llvm::makeIntrusiveRefCnt<DiagnosticIDs>(),
llvm::makeIntrusiveRefCnt<DiagnosticOptions>(),
&DiagConsumer, /*ShouldOwnClient=*/false);
Context.setDiagnosticsEngine(&DE);
ClangTidyASTConsumerFactory Factory(Context);
return Factory.getCheckOptions();
}
Expand Down
2 changes: 2 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6128bcd

Please sign in to comment.