[clang] a42ebde - [clang][Diagnostics] Don't drop "no-" when reporting an unknown -Wno-error= option (#239212)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 7 01:23:45 PST 2026
Author: Neha
Date: 2026-11-07T17:23:40+08:00
New Revision: a42ebde1426c8f0da696836b3a6efb48ed01179f
URL: https://github.com/llvm/llvm-project/commit/a42ebde1426c8f0da696836b3a6efb48ed01179f
DIFF: https://github.com/llvm/llvm-project/commit/a42ebde1426c8f0da696836b3a6efb48ed01179f.diff
LOG: [clang][Diagnostics] Don't drop "no-" when reporting an unknown -Wno-error= option (#239212)
Fixes #227392
If you pass `-Wno-error=foo` and clang doesn't know the `foo` warning
group, the
message you get back is about `-Werror=foo`. The `no-` is gone, and the
"did you
mean" suggestion drops it as well, so the flag in the message isn't the
one you
actually passed. The reporter hit this with
`-Wno-error=maybe-uninitialized`
from a GCC build and couldn't tell what to remove.
Nothing is lost before this point. `ProcessWarningOptions` pulls off the
`no-`
and stores it in `isPositive`, and the plain `-W` and `-R` paths already
use it
when building the prefix. The `-Werror=` and `-Wfatal-errors=` paths had
the
prefix hardcoded to the positive form, so I just pass `isPositive` there
too.
Before:
error: unknown warning option '-Werror=maybe-uninitialized'; did you
mean '-Werror=uninitialized'?
After:
error: unknown warning option '-Wno-error=maybe-uninitialized'; did you
mean '-Wno-error=uninitialized'?
The option is of course still unknown to clang, `maybe-uninitialized` is
a GCC
warning. This only changes which flag name gets printed.
The test now covers all four forms and the suggestion, so the positive
ones
can't regress either.
The deprecated `-Wno-error-implicit-function-declaration` spelling still
gets
printed with `=` as the separator. That was the case before this change
too, so
I left it.
---------
Co-authored-by: Chen Miao <chenmiao.ku at gmail.com>
Added:
Modified:
clang/docs/ReleaseNotes.md
clang/lib/Basic/Warnings.cpp
clang/test/Frontend/warning-options.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index b0fce4ab04f4db..b2ce1c1cc9b6c3 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -801,6 +801,10 @@ 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 preserves
+ the no- prefix in the diagnostic and spelling suggestion.
+ (#GH227392)
- Clang will now no longer assert or miscompile on a constructor that has more than 65535 base and member initializers. (#GH219366)
### Improvements to Clang's time-trace
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'?
More information about the cfe-commits
mailing list