[clang] [clang] Don't warn on __COUNTER__ in system macros (PR #196689)

2026-05-13 Thread Aaron Ballman via cfe-commits


@@ -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();

AaronBallman wrote:

Nevermind, after closer inspection that's not related.

https://github.com/llvm/llvm-project/pull/196689
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Don't warn on __COUNTER__ in system macros (PR #196689)

2026-05-13 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

LGTM though I think this is worth a backport and add a release note at that 
time.

https://github.com/llvm/llvm-project/pull/196689
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Don't warn on __COUNTER__ in system macros (PR #196689)

2026-05-12 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman edited 
https://github.com/llvm/llvm-project/pull/196689
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Don't warn on __COUNTER__ in system macros (PR #196689)

2026-05-11 Thread Aaron Ballman via cfe-commits


@@ -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

AaronBallman wrote:

Can you add a `-pedantic-errors` RUN line? (I am hoping that also silences the 
diagnostic and doesn't produce errors, but let's test to be sure.)

https://github.com/llvm/llvm-project/pull/196689
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Don't warn on __COUNTER__ in system macros (PR #196689)

2026-05-11 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman edited 
https://github.com/llvm/llvm-project/pull/196689
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Don't warn on __COUNTER__ in system macros (PR #196689)

2026-05-11 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

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

https://github.com/llvm/llvm-project/pull/196689
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Don't warn on __COUNTER__ in system macros (PR #196689)

2026-05-11 Thread Aaron Ballman via cfe-commits


@@ -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();

AaronBallman wrote:

Can you also add a test case like what's happening in 
https://github.com/llvm/llvm-project/issues/196474 ? I believe that issue 
should also be resolved by these changes.

https://github.com/llvm/llvm-project/pull/196689
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Don't warn on __COUNTER__ in system macros (PR #196689)

2026-05-09 Thread Oliver Hunt via cfe-commits

https://github.com/ojhunt created 
https://github.com/llvm/llvm-project/pull/196689

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.

>From 6bb9cd1601ddcbf698512289afb7ba0aa27b7158 Mon Sep 17 00:00:00 2001
From: Oliver Hunt 
Date: Fri, 8 May 2026 21:20:44 -0700
Subject: [PATCH] [clang] Don't warn on __COUNTER__ in system macros

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.
---
 clang/include/clang/Basic/DiagnosticLexKinds.td   |  4 ++--
 .../test/Lexer/Inputs/__counter__-system-header.h |  7 +++
 clang/test/Lexer/__counter__-system-include.c | 15 +++
 3 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Lexer/Inputs/__counter__-system-header.h
 create mode 100644 clang/test/Lexer/__counter__-system-include.c

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;
+  "'__COUNTER__' is a C2y extension">, InGroup, SuppressInSystemMacro;
 def warn_counter : Warning<
   "'__COUNTER__' is incompatible with standards before C2y">,
-  InGroup, DefaultIgnore;
+  InGroup, 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 0..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 0..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();

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Don't warn on __COUNTER__ in system macros (PR #196689)

2026-05-09 Thread Oliver Hunt via cfe-commits

https://github.com/ojhunt updated 
https://github.com/llvm/llvm-project/pull/196689

>From bb174f43dff05e2140fbe458a7535ad4eeedf61b Mon Sep 17 00:00:00 2001
From: Oliver Hunt 
Date: Fri, 8 May 2026 21:20:44 -0700
Subject: [PATCH] [clang] Don't warn on __COUNTER__ in system macros

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.
---
 clang/include/clang/Basic/DiagnosticLexKinds.td   |  4 ++--
 .../test/Lexer/Inputs/__counter__-system-header.h |  7 +++
 clang/test/Lexer/__counter__-system-include.c | 15 +++
 3 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Lexer/Inputs/__counter__-system-header.h
 create mode 100644 clang/test/Lexer/__counter__-system-include.c

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;
+  "'__COUNTER__' is a C2y extension">, InGroup, SuppressInSystemMacro;
 def warn_counter : Warning<
   "'__COUNTER__' is incompatible with standards before C2y">,
-  InGroup, DefaultIgnore;
+  InGroup, 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 0..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 0..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();

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Don't warn on __COUNTER__ in system macros (PR #196689)

2026-05-09 Thread via cfe-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-clang

Author: Oliver Hunt (ojhunt)


Changes

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/196689.diff


3 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticLexKinds.td (+2-2) 
- (added) clang/test/Lexer/Inputs/__counter__-system-header.h (+7) 
- (added) clang/test/Lexer/__counter__-system-include.c (+15) 


``diff
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;
+  "'__COUNTER__' is a C2y extension">, InGroup, SuppressInSystemMacro;
 def warn_counter : Warning<
   "'__COUNTER__' is incompatible with standards before C2y">,
-  InGroup, DefaultIgnore;
+  InGroup, 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 0..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 0..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();

``




https://github.com/llvm/llvm-project/pull/196689
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Don't warn on __COUNTER__ in system macros (PR #196689)

2026-05-09 Thread Oliver Hunt via cfe-commits

https://github.com/ojhunt edited 
https://github.com/llvm/llvm-project/pull/196689
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Don't warn on __COUNTER__ in system macros (PR #196689)

2026-05-09 Thread Corentin Jabot via cfe-commits

cor3ntin wrote:

@AaronBallman The disruption continues

https://github.com/llvm/llvm-project/pull/196689
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits