[PATCH] D148436: [clang-tidy] Fix crash in --dump-config

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 15 11:11:29 PDT 2023


njames93 created this revision.
njames93 added reviewers: PiotrZSL, carlosgalvezp.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
njames93 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

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 <me at piotrzegar.pl>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148436

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/infrastructure/dump-config-invalid.cpp


Index: clang-tools-extra/test/clang-tidy/infrastructure/dump-config-invalid.cpp
===================================================================
--- /dev/null
+++ 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
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -101,6 +101,8 @@
 - 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
 ^^^^^^^^^^
 
Index: clang-tools-extra/clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -498,6 +498,11 @@
       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();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148436.513930.patch
Type: text/x-patch
Size: 1727 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230415/e1eb4904/attachment.bin>


More information about the cfe-commits mailing list