https://github.com/MaskRay created
https://github.com/llvm/llvm-project/pull/184756
While -Wno-long-long suppresses -pedantic-errors diagnostics in both GCC
and Clang, GCC -Wno-error=long-long emits warnings while Clang still
emits errors.
```
% echo 'long long x = 0;' | gcc -std=c89 -pedantic-errors -Wno-error=long-long
-x c -fsyntax-only -
<stdin>:1:6: warning: ISO C90 does not support ‘long long’ [-Wlong-long]
% echo 'long long x = 0;' | clang -std=c89 -pedantic-errors
-Wno-error=long-long -x c -fsyntax-only -
<stdin>:1:1: error: 'long long' is an extension when C99 mode is not enabled
[-Werror,-Wlong-long]
1 | long long x = 0;
| ^
1 error generated.
```
The order of -pedantic-errors and -Wno-error=long-long does not matter.
Change Clang -Wno-error=long-long to match GCC behavior and be more consistent
with
-Wno-long-long.
```
% echo 'long long x = 0;' | myclang -std=c89 -pedantic-errors
-Wno-error=long-long -x c -fsyntax-only -
<stdin>:1:1: warning: 'long long' is an extension when C99 mode is not enabled
[-Wlong-long]
1 | long long x = 0;
| ^
1 warning generated.
```
Fixes https://github.com/llvm/llvm-project/issues/184250
>From a195c719aa96c491ea52bbb8b9e496d2cd6c8445 Mon Sep 17 00:00:00 2001
From: Fangrui Song <[email protected]>
Date: Thu, 5 Mar 2026 00:13:36 -0800
Subject: [PATCH] [clang] Allow -Wno-error=X to downgrade -pedantic-errors
diagnostics to warnings
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
While -Wno-long-long suppresses -pedantic-errors diagnostics in both GCC
and Clang, GCC -Wno-error=long-long emits warnings while Clang still
emits errors.
```
% echo 'long long x = 0;' | gcc -std=c89 -pedantic-errors -Wno-error=long-long
-x c -fsyntax-only -
<stdin>:1:6: warning: ISO C90 does not support ‘long long’ [-Wlong-long]
% echo 'long long x = 0;' | clang -std=c89 -pedantic-errors
-Wno-error=long-long -x c -fsyntax-only -
<stdin>:1:1: error: 'long long' is an extension when C99 mode is not enabled
[-Werror,-Wlong-long]
1 | long long x = 0;
| ^
1 error generated.
```
The order of -pedantic-errors and -Wno-error=long-long does not matter.
Change Clang -Wno-error=long-long to match GCC behavior and be more consistent
with
-Wno-long-long.
```
% echo 'long long x = 0;' | myclang -std=c89 -pedantic-errors
-Wno-error=long-long -x c -fsyntax-only -
<stdin>:1:1: warning: 'long long' is an extension when C99 mode is not enabled
[-Wlong-long]
1 | long long x = 0;
| ^
1 warning generated.
```
Fixes https://github.com/llvm/llvm-project/issues/184250
---
clang/lib/Basic/DiagnosticIDs.cpp | 9 +++++++--
clang/test/Misc/diag-mapping.c | 5 +++++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Basic/DiagnosticIDs.cpp
b/clang/lib/Basic/DiagnosticIDs.cpp
index fcd2d9f34414e..36ed9dbbe8dab 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -501,8 +501,13 @@ DiagnosticIDs::getDiagnosticSeverity(unsigned DiagID,
SourceLocation Loc,
// For extension diagnostics that haven't been explicitly mapped, check if we
// should upgrade the diagnostic.
- if (IsExtensionDiag && !Mapping.isUser())
- Result = std::max(Result, State->ExtBehavior);
+ if (IsExtensionDiag && !Mapping.isUser()) {
+ if (Mapping.hasNoWarningAsError())
+ Result = std::max(Result,
+ std::min(State->ExtBehavior, diag::Severity::Warning));
+ else
+ Result = std::max(Result, State->ExtBehavior);
+ }
// At this point, ignored errors can no longer be upgraded.
if (Result == diag::Severity::Ignored)
diff --git a/clang/test/Misc/diag-mapping.c b/clang/test/Misc/diag-mapping.c
index edc137ec68fef..b17561b098343 100644
--- a/clang/test/Misc/diag-mapping.c
+++ b/clang/test/Misc/diag-mapping.c
@@ -18,12 +18,17 @@
// This should emit an error with -pedantic-errors.
// RUN: not %clang_cc1 %s -pedantic-errors 2>&1 | grep "error:"
+// RUN: %clang_cc1 %s -pedantic -Wno-error=extra-tokens 2>&1 | grep "warning:"
+
// This should emit a warning, because -Wfoo overrides -pedantic*.
// RUN: %clang_cc1 %s -pedantic-errors -Wextra-tokens 2>&1 | grep "warning:"
// This should emit nothing, because -Wno-extra-tokens overrides -pedantic*
// RUN: %clang_cc1 %s -pedantic-errors -Wno-extra-tokens 2>&1 | not grep
diagnostic
+// -Wno-error=extra-tokens should downgrade -pedantic-errors to warning.
+// RUN: %clang_cc1 %s -pedantic-errors -Wno-error=extra-tokens 2>&1 | grep
"warning:"
+
#ifdef foo
#endif bad // extension!
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits