[clang] [Clang] Fix assertion failure in SDiagsWriter when finish() is not called (PR #181712)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 16 10:05:37 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: mitchell (zeyi2)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/181712.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+1)
- (modified) clang/lib/Frontend/SerializedDiagnosticPrinter.cpp (+4-1)
- (added) clang/test/Tooling/serialize-diagnostics.cpp (+6)
``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6063c3fbf48c8..01da9a3104e2f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -265,6 +265,7 @@ Bug Fixes in This Version
- Clang now outputs relative paths of embeds for dependency output. (#GH161950)
- Fixed an assertion failure when evaluating ``_Countof`` on invalid ``void``-typed operands. (#GH180893)
- Fixed a ``-Winvalid-noreturn`` false positive for unreachable ``try`` blocks following an unconditional ``throw``. (#GH174822)
+- Fixed an assertion failure in the serialized diagnostic printer when it is destroyed without calling ``finish()``. (#GH140433)
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Frontend/SerializedDiagnosticPrinter.cpp b/clang/lib/Frontend/SerializedDiagnosticPrinter.cpp
index 1dffe7cb2b9f0..fe2dca090b09e 100644
--- a/clang/lib/Frontend/SerializedDiagnosticPrinter.cpp
+++ b/clang/lib/Frontend/SerializedDiagnosticPrinter.cpp
@@ -146,7 +146,10 @@ class SDiagsWriter : public DiagnosticConsumer {
EmitPreamble();
}
- ~SDiagsWriter() override {}
+ ~SDiagsWriter() override {
+ if (OriginalInstance && !IsFinishing)
+ finish();
+ }
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
const Diagnostic &Info) override;
diff --git a/clang/test/Tooling/serialize-diagnostics.cpp b/clang/test/Tooling/serialize-diagnostics.cpp
new file mode 100644
index 0000000000000..fbf5554fc90a2
--- /dev/null
+++ b/clang/test/Tooling/serialize-diagnostics.cpp
@@ -0,0 +1,6 @@
+// RUN: clang-check %s -- -Wunknown-warning-option --serialize-diagnostics %t.dia 2>&1 | FileCheck %s --allow-empty
+// RUN: ls %t.dia
+
+int main() {
+ return 0;
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/181712
More information about the cfe-commits
mailing list