llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Fangrui Song (MaskRay)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/184756.diff
2 Files Affected:
- (modified) clang/lib/Basic/DiagnosticIDs.cpp (+7-2)
- (modified) clang/test/Misc/diag-mapping.c (+5)
``````````diff
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!
``````````
</details>
https://github.com/llvm/llvm-project/pull/184756
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits