[clang] [clang][Diagnostics] Don't drop "no-" when reporting an unknown -Wno-error= option (PR #239212)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 6 23:21:09 PST 2026
https://github.com/nehaGautam07 updated https://github.com/llvm/llvm-project/pull/239212
>From 49a64e75334a6f04c75f2b20d2f1336cf06a3b6c Mon Sep 17 00:00:00 2001
From: neharaj <neharajgautam07 at gmail.com>
Date: Thu, 5 Nov 2026 11:56:09 +0000
Subject: [PATCH 1/2] [clang][Diagnostics] Preserve 'no-' prefix for unknown
-Wno-error= options
-Wno-error=foo was reported as '-Werror=foo'. Use isPositive for the
prefix, like the -W and -R paths already do. Same for -Wno-fatal-errors=.
Fixes #227392
---
clang/docs/ReleaseNotes.md | 5 +++++
clang/lib/Basic/Warnings.cpp | 8 ++++++--
clang/test/Frontend/warning-options.cpp | 9 +++++++++
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 456c861307cb83..7f5a317d7ebed1 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -784,6 +784,11 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and
`-Wunsafe-buffer-usage-in-format-attr-call` now works when it is the only
Safe Buffers warning enabled.
+- Fixed the `no-` prefix being dropped when diagnosing an unknown
+ `-Wno-error=` or `-Wno-fatal-errors=` warning option. Clang now reports the
+ option as it was written on the command line instead of its positive form.
+ (#GH227392)
+
### Improvements to Clang's time-trace
### Improvements to Coverage Mapping
diff --git a/clang/lib/Basic/Warnings.cpp b/clang/lib/Basic/Warnings.cpp
index 91cce2e45d5f4d..18e6274f53267a 100644
--- a/clang/lib/Basic/Warnings.cpp
+++ b/clang/lib/Basic/Warnings.cpp
@@ -160,7 +160,9 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
// Set the warning as error flag for this specifier.
Diags.setDiagnosticGroupWarningAsError(Specifier, isPositive);
} else if (DiagIDs->getDiagnosticsInGroup(Flavor, Specifier, _Diags)) {
- EmitUnknownDiagWarning(Diags, Flavor, "-Werror=", Specifier);
+ EmitUnknownDiagWarning(
+ Diags, Flavor,
+ isPositive ? "-Werror=" : "-Wno-error=", Specifier);
}
continue;
}
@@ -188,7 +190,9 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
// Set the error as fatal flag for this specifier.
Diags.setDiagnosticGroupErrorAsFatal(Specifier, isPositive);
} else if (DiagIDs->getDiagnosticsInGroup(Flavor, Specifier, _Diags)) {
- EmitUnknownDiagWarning(Diags, Flavor, "-Wfatal-errors=", Specifier);
+ EmitUnknownDiagWarning(
+ Diags, Flavor,
+ isPositive ? "-Wfatal-errors=" : "-Wno-fatal-errors=", Specifier);
}
continue;
}
diff --git a/clang/test/Frontend/warning-options.cpp b/clang/test/Frontend/warning-options.cpp
index e6ddf2e0aad5ea..ad47e8399a0468 100644
--- a/clang/test/Frontend/warning-options.cpp
+++ b/clang/test/Frontend/warning-options.cpp
@@ -13,3 +13,12 @@
// 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_cc1 -Werror=monkey -Wno-error=monkey -Wfatal-errors=monkey \
+// RUN: -Wno-fatal-errors=monkey -Wno-error=unused-command-line-arguments \
+// RUN: %s 2>&1 | FileCheck --check-prefix=SPECIFIER %s
+// SPECIFIER: unknown warning option '-Werror=monkey'
+// SPECIFIER-NEXT: unknown warning option '-Wno-error=monkey'
+// SPECIFIER-NEXT: unknown warning option '-Wfatal-errors=monkey'
+// SPECIFIER-NEXT: unknown warning option '-Wno-fatal-errors=monkey'
+// SPECIFIER-NEXT: unknown warning option '-Wno-error=unused-command-line-arguments'; did you mean '-Wno-error=unused-command-line-argument'?
>From 39019d278a538efdf3165f923c25e85f9f2a1f47 Mon Sep 17 00:00:00 2001
From: Neha <151068751+nehaGautam07 at users.noreply.github.com>
Date: Sat, 7 Nov 2026 11:36:36 +0530
Subject: [PATCH 2/2] Update clang/docs/ReleaseNotes.md
Co-authored-by: Chen Miao <chenmiao.ku at gmail.com>
---
clang/docs/ReleaseNotes.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 7f5a317d7ebed1..e7974fffd76969 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -785,8 +785,8 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and
Safe Buffers warning enabled.
- Fixed the `no-` prefix being dropped when diagnosing an unknown
- `-Wno-error=` or `-Wno-fatal-errors=` warning option. Clang now reports the
- option as it was written on the command line instead of its positive form.
+ `-Wno-error=` or `-Wno-fatal-errors=` warning option. Clang now preserves
+ the no- prefix in the diagnostic and spelling suggestion.
(#GH227392)
### Improvements to Clang's time-trace
More information about the cfe-commits
mailing list