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 <m...@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();
 }


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();
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to