Repository navigation
[clang] Don't warn on __COUNTER__ in system macros - #196689
Conversation
|
@llvm/pr-subscribers-clang Author: Oliver Hunt (ojhunt) ChangesThe introduction of extension and compatibility warnings means that COUNTER has started causing warnings (and -Werror=) build failures due to use of system APIs. This PR simply ensures that these diagnostics don't get reported for system macro expansions as well. 3 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 85fa290de6fd9..0ac7ac27a0271 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -93,10 +93,10 @@ def err_conflict_marker : Error<"version control conflict marker in file">;
def err_counter_overflow : Error<
"'__COUNTER__' value cannot exceed 2'147'483'647">;
def ext_counter : Extension<
- "'__COUNTER__' is a C2y extension">, InGroup<C2y>;
+ "'__COUNTER__' is a C2y extension">, InGroup<C2y>, SuppressInSystemMacro;
def warn_counter : Warning<
"'__COUNTER__' is incompatible with standards before C2y">,
- InGroup<CPre2yCompat>, DefaultIgnore;
+ InGroup<CPre2yCompat>, DefaultIgnore, SuppressInSystemMacro;
def err_raw_delim_too_long : Error<
"raw string delimiter longer than 16 characters"
diff --git a/clang/test/Lexer/Inputs/__counter__-system-header.h b/clang/test/Lexer/Inputs/__counter__-system-header.h
new file mode 100644
index 0000000000000..60619215abd27
--- /dev/null
+++ b/clang/test/Lexer/Inputs/__counter__-system-header.h
@@ -0,0 +1,7 @@
+#define COUNTER_ALIAS __COUNTER__
+#define COUNTER_MACRO() __COUNTER__
+
+int header_counter_value = __COUNTER__;
+int header_counter_alias = COUNTER_ALIAS;
+int header_counter_macro = COUNTER_MACRO();
+
diff --git a/clang/test/Lexer/__counter__-system-include.c b/clang/test/Lexer/__counter__-system-include.c
new file mode 100644
index 0000000000000..6574190258d47
--- /dev/null
+++ b/clang/test/Lexer/__counter__-system-include.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -Wpedantic %s -fsyntax-only -isystem %S/Inputs -verify=ext
+// RUN: %clang_cc1 -std=c2y -Wpedantic %s -fsyntax-only -isystem %S/Inputs -verify
+// RUN: %clang_cc1 -std=c2y -Wpre-c2y-compat %s -fsyntax-only -isystem %S/Inputs -verify=pre
+// RUN: %clang_cc1 -pedantic %s -fsyntax-only -isystem %S/Inputs -verify=ext
+// RUN: %clang_cc1 -std=c2y -Wpre-c2y-compat -pedantic %s -fsyntax-only -isystem %S/Inputs -verify=pre
+
+#include <__counter__-system-header.h>
+
+// expected-no-diagnostics
+
+int tu_direct_reference = __COUNTER__;
+// ext-warning@-1 {{'__COUNTER__' is a C2y extension}}
+// pre-warning@-2 {{'__COUNTER__' is incompatible with standards before C2y}}
+int tu_counter_alias = COUNTER_ALIAS;
+int tu_counter_macro = COUNTER_MACRO();
|
6bb9cd1 to
bb174f4
Compare
|
@AaronBallman The disruption continues |
AaronBallman
left a comment
There was a problem hiding this comment.
This should come with a release note eventually but I'd like to backport this to Clang 22.x. One testing request, but I think this generally LGTM
|
I'm no longer convinced that this is the correct fix. No other compiler warns on We should not be papering over a bug by trying to suppress it in one of the many places it is triggered. |
Strong -1; we absolutely should be telling users about extensions when they enable the flag documented to tell them about extensions. There are other compilers which do not support https://godbolt.org/z/8s1EYo9zM That said, I'm strongly in favor of reducing contention in practice. I think we should introduce (The only folks who should be seeing this diagnostic are people who explicitly enabled extension diagnostics, so if this is being enabled through other, that's a different situation and possibly a bug. But the current behavior is intentional in that users asking for extension diagnostics will get extension diagnostics and that sometimes means extensions we've supported for a long time will start being diagnosed, same as any other fix for a false negative.) |
bb174f4 to
4be40f7
Compare
The introduction of extension and compatibility warnings means that __COUNTER__ has started causing warnings (and -Werror= build failures) due to use of system APIs. This PR simply ensures that these diagnostics don't get reported for system macro expansions as well.
4be40f7 to
fbb6e2e
Compare
|
@AaronBallman @cor3ntin now with pedantic-errors tests -- I'm more willing to accept a system macro only extension here as the non-system macro failures involved projects doing questionable things |
Agreed, someone could easily make the counter argument, "I want warning on all extensions and I am not happy you carved out an exception, I want what is written on the label". The simplest path is stick with consistent approach and provide |
We currently support warnings that don't get error promoted with -Werror, but that doesn't work for extensions as it asserts the diagnostic is a warning. I can't tell if the reason for the assertion is to explicitly say "this only applies to warnings" or to prevent an actual error diagnostic being downgraded to a warning. The other question for such approach is the intended user. While I disagree about this being captured by pedantic-errors is actually expected by users in this case, it does feel like maybe warning->error promotion (and promotion suppression) might be worth separating |
|
(sigh very nearly landed w/o review because of GH's terrible UI) |
I believe it's to prevent actual error diagnostics from being downgraded into warnings rather than something specific to not applying to extensions or errors.
I would not recommend |
AaronBallman
left a comment
There was a problem hiding this comment.
LGTM though I think this is worth a backport and add a release note at that time.
The introduction of extension and compatibility warnings means that `__COUNTER__` has started causing warnings (and -Werror= build failures) due to use of system APIs. This PR simply ensures that these diagnostics don't get reported for system macro expansions as well.
The introduction of extension and compatibility warnings means that `__COUNTER__` has started causing warnings (and -Werror= build failures) due to use of system APIs. This PR simply ensures that these diagnostics don't get reported for system macro expansions as well.
The introduction of extension and compatibility warnings means that `__COUNTER__` has started causing warnings (and -Werror= build failures) due to use of system APIs. This PR simply ensures that these diagnostics don't get reported for system macro expansions as well.
`vmactions/openbsd-vm` now provides OpenBSD 8.0 by default with Clang 22.1.6, which triggers `-Wc2y-extensions` on `__COUNTER__`. Disable the warning temporarily until the fix becomes available in Clang. See upstream LLVM items: - llvm/llvm-project#196557 - llvm/llvm-project#196689 - llvm/llvm-project#218669
1b742cf ci: Fix OpenBSD job (Hennadii Stepanov) Pull request description: `vmactions/openbsd-vm` now [provides](https://github.com/vmactions/openbsd-vm/releases/tag/v1.4.9) OpenBSD 8.0 by default with Clang 22.1.6, which triggers `-Wc2y-extensions` on `__COUNTER__`. Disable the warning temporarily until the fix becomes available in Clang. See upstream LLVM items: - llvm/llvm-project#196557 - llvm/llvm-project#196689 - llvm/llvm-project#218669 Related: - #371 - https://github.com/bitcoin-core/libmultiprocess/actions/runs/39768415425/job/119789556263?pr=380 ACKs for top commit: maflcko: lgtm ACK 1b742cf xyzconstant: ACK 1b742cf ViniciusCestarii: ACK 1b742cf Tree-SHA512: 673e5b61073ae1df8f577b6f12b31a33b7c9de1df64b5d57bb2bc61434d52ff3920be77cbcdb105bc72a610018ea9b5dc8eb1ad50a0a355842b38c7b3b0e95bf
The introduction of extension and compatibility warnings means that
__COUNTER__has started causing warnings (and -Werror= build failures) due to use of system APIs.This PR simply ensures that these diagnostics don't get reported for system macro expansions as well.