[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:23:08 PST 2026
https://github.com/zeyi2 updated https://github.com/llvm/llvm-project/pull/181712
>From 58ef46e8d18ae14aed22c59e227380b121bac1f4 Mon Sep 17 00:00:00 2001
From: mtx <mitchell.xu2 at gmail.com>
Date: Tue, 17 Feb 2026 02:04:52 +0800
Subject: [PATCH 1/2] [Clang] Fix assertion failure in SDiagsWriter when
finish() is not called
---
clang/docs/ReleaseNotes.rst | 1 +
clang/lib/Frontend/SerializedDiagnosticPrinter.cpp | 5 ++++-
clang/test/Tooling/serialize-diagnostics.cpp | 6 ++++++
3 files changed, 11 insertions(+), 1 deletion(-)
create mode 100644 clang/test/Tooling/serialize-diagnostics.cpp
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;
+}
>From 820bf60c666e2e0c08dd75e3f55b7fa08144680b Mon Sep 17 00:00:00 2001
From: mtx <mitchell.xu2 at gmail.com>
Date: Tue, 17 Feb 2026 02:22:28 +0800
Subject: [PATCH 2/2] fixup the testcases...
---
clang/test/Tooling/serialize-diagnostics.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/clang/test/Tooling/serialize-diagnostics.cpp b/clang/test/Tooling/serialize-diagnostics.cpp
index fbf5554fc90a2..7b2a6e3c2fdd5 100644
--- a/clang/test/Tooling/serialize-diagnostics.cpp
+++ b/clang/test/Tooling/serialize-diagnostics.cpp
@@ -1,6 +1,10 @@
-// RUN: clang-check %s -- -Wunknown-warning-option --serialize-diagnostics %t.dia 2>&1 | FileCheck %s --allow-empty
+// RUN: clang-check %s -- -Wdoes-not-exist --serialize-diagnostics %t.dia 2>&1 | FileCheck %s
// RUN: ls %t.dia
+// CHECK: warning: unknown warning option '-Wdoes-not-exist'
+// CHECK-NOT: Assertion failed
+// CHECK-NOT: Stack dump
+
int main() {
return 0;
}
More information about the cfe-commits
mailing list