https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/233241
>From c217e801d958f0bf15fbfddd4680373ab4c6587e Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov <[email protected]> Date: Sun, 18 Oct 2026 17:17:43 +0300 Subject: [PATCH 1/4] [clang] Make SARIF better handle diagnostic about unknown argument --- clang/lib/Frontend/SARIFDiagnosticPrinter.cpp | 3 ++- clang/test/Driver/unknown-arg.c | 7 +++++++ clang/test/Frontend/warning-options.cpp | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/clang/lib/Frontend/SARIFDiagnosticPrinter.cpp b/clang/lib/Frontend/SARIFDiagnosticPrinter.cpp index 72b796f8db798..edc021f556965 100644 --- a/clang/lib/Frontend/SARIFDiagnosticPrinter.cpp +++ b/clang/lib/Frontend/SARIFDiagnosticPrinter.cpp @@ -47,7 +47,6 @@ void SARIFDiagnosticPrinter::EndSourceFile() { void SARIFDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level, const Diagnostic &Info) { - assert(SARIFDiag && "SARIFDiagnostic has not been set."); // Default implementation (Warnings/errors count). Keeps track of the // number of errors. DiagnosticConsumer::HandleDiagnostic(Level, Info); @@ -68,6 +67,8 @@ void SARIFDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level, return; } + assert(SARIFDiag && "SARIFDiagnostic has not been set."); + // Assert that the rest of our infrastructure is setup properly. assert(Info.hasSourceManager() && "Unexpected diagnostic with no source manager"); diff --git a/clang/test/Driver/unknown-arg.c b/clang/test/Driver/unknown-arg.c index 26032a407f413..030952089b4ac 100644 --- a/clang/test/Driver/unknown-arg.c +++ b/clang/test/Driver/unknown-arg.c @@ -65,6 +65,13 @@ // IGNORED: warning: unknown warning option '-Wunknown-to-clang-option' +// RUN %clang -fdiagnostics-format=sarif -Wunknown-to-clang-option + +// FIXME: unlike TextDiagnosticPrinter, SARIFDiagnosticPrinter can't yet emit +// diagnostics in this limited mode without SourceManager, etc. +// At the moment all we can do is to ensure we don't crash with and without +// assertions. + // RUN: %clang -### -offload-arch=sm_70 --offload-arch=sm_70 -offload-device-only -o ffload-device-only \ // RUN: -output -o foo %s 2>&1 | FileCheck --check-prefix=O-WARN %s // O-WARN: warning: joined argument treated as '-o ffload-arch=sm_70'; did you mean '--offload-arch=sm_70'? diff --git a/clang/test/Frontend/warning-options.cpp b/clang/test/Frontend/warning-options.cpp index 444733c8b7f36..e6ddf2e0aad5e 100644 --- a/clang/test/Frontend/warning-options.cpp +++ b/clang/test/Frontend/warning-options.cpp @@ -6,3 +6,10 @@ // CHECK: unknown warning option '-Wmodule-build'; did you mean '-Wmodule-conflict'? // CHECK-NEXT: unknown -Werror warning specifier: '-Werror-vla' // CHECK: unknown remark option '-Rmodule-built'; did you mean '-Rmodule-build'? + +// RUN: %clang_cc1 -Wmonkey -Wno-monkey -Wno-unused-command-line-arguments \ +// RUN: -Wno-unused-command-line-argument -Wmodule-build -Werror-vla -Rmodule-built -fdiagnostics-format sarif %s 2>&1 +// FIXME: unlike TextDiagnosticPrinter, SARIFDiagnosticPrinter can't yet emit +// diagnostics in this limited mode without SourceManager, etc. +// At the moment all we can do is to ensure we don't crash with and without +// assertions. >From 9284359d9fb1d3ebb21c02f7335fb79c0b932e63 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov <[email protected]> Date: Sun, 18 Oct 2026 20:54:52 +0400 Subject: [PATCH 2/4] Update clang/test/Driver/unknown-arg.c Co-authored-by: Kazu Hirata <[email protected]> --- clang/test/Driver/unknown-arg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Driver/unknown-arg.c b/clang/test/Driver/unknown-arg.c index 030952089b4ac..1c8f257aa4db7 100644 --- a/clang/test/Driver/unknown-arg.c +++ b/clang/test/Driver/unknown-arg.c @@ -65,7 +65,7 @@ // IGNORED: warning: unknown warning option '-Wunknown-to-clang-option' -// RUN %clang -fdiagnostics-format=sarif -Wunknown-to-clang-option +// RUN: %clang -S %s -o %t.s -fdiagnostics-format=sarif -Wunknown-to-clang-option // FIXME: unlike TextDiagnosticPrinter, SARIFDiagnosticPrinter can't yet emit // diagnostics in this limited mode without SourceManager, etc. >From 4a600a1ae493d6579ed1fab30249cf2d2ec4d882 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov <[email protected]> Date: Mon, 19 Oct 2026 19:49:33 +0300 Subject: [PATCH 3/4] Add a release note --- clang/docs/ReleaseNotes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 3f0c48cf36644..6e5b956237912 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -273,6 +273,10 @@ features cannot lower the translation-unit ABI level; - Added `__builtin_sort_pack` to sort a pack of types using the same order as `__builtin_type_order`. +- Clang no longer crashes on unknown command-line argument when + `-fdiagnostics-format=sarif` is passed + ([#233241](https://github.com/llvm/llvm-project/issues/233241)). + - Updates Unicode Names data to Unicode 18.0 (from Unicode 18.0 Beta). - `clang-scan-deps` now reports the directories whose listing a module depends >From 61c8e8a840f5cb63054f7c203c2acfef7caaef6c Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov <[email protected]> Date: Mon, 19 Oct 2026 21:06:39 +0400 Subject: [PATCH 4/4] Update clang/docs/ReleaseNotes.md Co-authored-by: Corentin Jabot <[email protected]> --- clang/docs/ReleaseNotes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 6e5b956237912..7393c7b46e282 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -275,7 +275,7 @@ features cannot lower the translation-unit ABI level; - Clang no longer crashes on unknown command-line argument when `-fdiagnostics-format=sarif` is passed - ([#233241](https://github.com/llvm/llvm-project/issues/233241)). + (#GH233241). - Updates Unicode Names data to Unicode 18.0 (from Unicode 18.0 Beta). _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
