[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-28 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-ppc64-aix` running 
on `aix-ppc64` while building `clang` at step 6 
"test-build-unified-tree-check-all".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/64/builds/3884


Here is the relevant piece of the build log for the reference

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'lit :: timeout-hang.py' FAILED 
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 13
not env -u FILECHECK_OPTS 
"/home/llvm/llvm-external-buildbots/workers/env/bin/python3.11" 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/utils/lit/lit.py
 -j1 --order=lexical Inputs/timeout-hang/run-nonexistent.txt  --timeout=1 
--param external=0 | 
"/home/llvm/llvm-external-buildbots/workers/env/bin/python3.11" 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/utils/lit/tests/timeout-hang.py
 1
# executed command: not env -u FILECHECK_OPTS 
/home/llvm/llvm-external-buildbots/workers/env/bin/python3.11 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/utils/lit/lit.py
 -j1 --order=lexical Inputs/timeout-hang/run-nonexistent.txt --timeout=1 
--param external=0
# .---command stderr
# | lit.py: 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 1 seconds was requested on the command line. Forcing 
timeout to be 1 seconds.
# `-
# executed command: 
/home/llvm/llvm-external-buildbots/workers/env/bin/python3.11 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/utils/lit/tests/timeout-hang.py
 1
# .---command stdout
# | Testing took as long or longer than timeout
# `-
# error: command failed with exit status: 1

--




```



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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-28 Thread Aaron Ballman via cfe-commits

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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-27 Thread Ian Anderson via cfe-commits

https://github.com/ian-twilightcoder approved this pull request.


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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-22 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/140890

>From 10cb78bd9f361dd442c40702dad3c7809f466615 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Wed, 21 May 2025 08:59:47 -0400
Subject: [PATCH 1/4] [C2y] Add stdcountof.h

WG14 N3469 changed _Lengthof to _Countof but it also introduced the
 header to expose a macro with a non-ugly identifier.
GCC vends this header as part of the compiler implementation, so Clang
should do the same.
---
 clang/docs/ReleaseNotes.rst|  4 +++-
 clang/lib/Headers/stdcountof.h | 15 +++
 clang/test/C/C2y/n3469.c   | 13 +++--
 3 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 clang/lib/Headers/stdcountof.h

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b466f3758e0b6..7b2777f711b8d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -249,7 +249,9 @@ C2y Feature Support
   a conforming extension in earlier C language modes, but not in C++ language
   modes (``std::extent`` and ``std::size`` already provide the same
   functionality but with more granularity). The feature can be tested via
-  ``__has_feature(c_countof)`` or ``__has_extension(c_countof)``.
+  ``__has_feature(c_countof)`` or ``__has_extension(c_countof)``. This also
+  adds the  header file which exposes the ``countof`` macro
+  which expands to ``_Countof``.
 
 C23 Feature Support
 ^^^
diff --git a/clang/lib/Headers/stdcountof.h b/clang/lib/Headers/stdcountof.h
new file mode 100644
index 0..5714e6d6ff860
--- /dev/null
+++ b/clang/lib/Headers/stdcountof.h
@@ -0,0 +1,15 @@
+/*=== stdcountof.h - Standard header for countof ---===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+#ifndef __STDCOUNTOF_H
+#define __STDCOUNTOF_H
+
+#define countof _Countof
+
+#endif /* __STDCOUNTOF_H */
diff --git a/clang/test/C/C2y/n3469.c b/clang/test/C/C2y/n3469.c
index 3d9ac8e6411e9..4660596614075 100644
--- a/clang/test/C/C2y/n3469.c
+++ b/clang/test/C/C2y/n3469.c
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c2y -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c2y -verify -ffreestanding %s
 
 /* WG14 N3469: Clang 21
  * The Big Array Size Survey
  *
- * This renames _Lengthof to _Countof.
+ * This renames _Lengthof to _Countof and introduces the stdcountof.h header.
  */
 
 void test() {
@@ -12,3 +12,12 @@ void test() {
expected-error {{expected expression}}
 }
 
+#ifdef countof
+#error "why is countof defined as a macro?"
+#endif
+
+#include 
+
+#ifndef countof
+#error "why is countof not defined as a macro?"
+#endif

>From 7d94ea7a3d0b663ffca61f89bca2ca56ef585f7d Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Wed, 21 May 2025 09:33:56 -0400
Subject: [PATCH 2/4] Update other places where the builtin header needs to be
 mentioned

---
 clang/lib/Headers/CMakeLists.txt | 1 +
 clang/lib/Headers/module.modulemap   | 5 +
 clang/lib/Lex/ModuleMap.cpp  | 1 +
 clang/lib/Lex/PPDirectives.cpp   | 4 ++--
 clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc   | 1 +
 .../Modules/Inputs/builtin-headers/system-modules.modulemap  | 5 +
 6 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index 449feb012481f..013bd13d1d276 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -18,6 +18,7 @@ set(core_files
   __stdarg_va_list.h
   stdatomic.h
   stdbool.h
+  stdcountof.h
   stdckdint.h
   stddef.h
   __stddef_header_macro.h
diff --git a/clang/lib/Headers/module.modulemap 
b/clang/lib/Headers/module.modulemap
index dcaf09e8f2c55..35897a3ed0e79 100644
--- a/clang/lib/Headers/module.modulemap
+++ b/clang/lib/Headers/module.modulemap
@@ -231,6 +231,11 @@ module _Builtin_stdbool [system] {
   export *
 }
 
+module _Builtin_stdcountof [system] {
+  header "stdcountof.h"
+  export *
+}
+
 module _Builtin_stddef [system] {
   textual header "stddef.h"
 
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 4175959d8f55b..be9cab8afb9b3 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -260,6 +260,7 @@ static bool isBuiltinHeaderName(StringRef FileName) {
.Case("stdarg.h", true)
.Case("stdatomic.h", true)
.Case("stdbool.h", true)
+   .Case("stdcountof.h", true)
.Case("stddef.h", true)
.Case("stdint.h", true)
.Case("tgmath.h", true)
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirective

[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-22 Thread Aaron Ballman via cfe-commits


@@ -389,6 +389,7 @@ SYMBOL(cosh, None, )
 SYMBOL(coshf, None, )
 SYMBOL(coshl, None, )
 SYMBOL(cosl, None, )
+SYMBOL(countof, None, )

AaronBallman wrote:

Yup, I missed:
```
// Generated from cppreference offline HTML book (modified on 2018-10-28).
//===--===//
```
at the top of the file. So I'll pull this change back, good catch!

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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-22 Thread via cfe-commits


@@ -389,6 +389,7 @@ SYMBOL(cosh, None, )
 SYMBOL(coshf, None, )
 SYMBOL(coshl, None, )
 SYMBOL(cosl, None, )
+SYMBOL(countof, None, )

cor3ntin wrote:

That file is code-generated, right?

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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-22 Thread Aaron Ballman via cfe-commits


@@ -49,6 +49,11 @@ module cstd [system] [no_undeclared_includes] {
 export *
   }
 
+  module stdcountof {
+header "stdcountof.h"
+export *
+  }
+

AaronBallman wrote:

Good catch! I've updated that test as well.

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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-22 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/140890

>From 10cb78bd9f361dd442c40702dad3c7809f466615 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Wed, 21 May 2025 08:59:47 -0400
Subject: [PATCH 1/3] [C2y] Add stdcountof.h

WG14 N3469 changed _Lengthof to _Countof but it also introduced the
 header to expose a macro with a non-ugly identifier.
GCC vends this header as part of the compiler implementation, so Clang
should do the same.
---
 clang/docs/ReleaseNotes.rst|  4 +++-
 clang/lib/Headers/stdcountof.h | 15 +++
 clang/test/C/C2y/n3469.c   | 13 +++--
 3 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 clang/lib/Headers/stdcountof.h

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b466f3758e0b6..7b2777f711b8d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -249,7 +249,9 @@ C2y Feature Support
   a conforming extension in earlier C language modes, but not in C++ language
   modes (``std::extent`` and ``std::size`` already provide the same
   functionality but with more granularity). The feature can be tested via
-  ``__has_feature(c_countof)`` or ``__has_extension(c_countof)``.
+  ``__has_feature(c_countof)`` or ``__has_extension(c_countof)``. This also
+  adds the  header file which exposes the ``countof`` macro
+  which expands to ``_Countof``.
 
 C23 Feature Support
 ^^^
diff --git a/clang/lib/Headers/stdcountof.h b/clang/lib/Headers/stdcountof.h
new file mode 100644
index 0..5714e6d6ff860
--- /dev/null
+++ b/clang/lib/Headers/stdcountof.h
@@ -0,0 +1,15 @@
+/*=== stdcountof.h - Standard header for countof ---===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+#ifndef __STDCOUNTOF_H
+#define __STDCOUNTOF_H
+
+#define countof _Countof
+
+#endif /* __STDCOUNTOF_H */
diff --git a/clang/test/C/C2y/n3469.c b/clang/test/C/C2y/n3469.c
index 3d9ac8e6411e9..4660596614075 100644
--- a/clang/test/C/C2y/n3469.c
+++ b/clang/test/C/C2y/n3469.c
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c2y -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c2y -verify -ffreestanding %s
 
 /* WG14 N3469: Clang 21
  * The Big Array Size Survey
  *
- * This renames _Lengthof to _Countof.
+ * This renames _Lengthof to _Countof and introduces the stdcountof.h header.
  */
 
 void test() {
@@ -12,3 +12,12 @@ void test() {
expected-error {{expected expression}}
 }
 
+#ifdef countof
+#error "why is countof defined as a macro?"
+#endif
+
+#include 
+
+#ifndef countof
+#error "why is countof not defined as a macro?"
+#endif

>From 7d94ea7a3d0b663ffca61f89bca2ca56ef585f7d Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Wed, 21 May 2025 09:33:56 -0400
Subject: [PATCH 2/3] Update other places where the builtin header needs to be
 mentioned

---
 clang/lib/Headers/CMakeLists.txt | 1 +
 clang/lib/Headers/module.modulemap   | 5 +
 clang/lib/Lex/ModuleMap.cpp  | 1 +
 clang/lib/Lex/PPDirectives.cpp   | 4 ++--
 clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc   | 1 +
 .../Modules/Inputs/builtin-headers/system-modules.modulemap  | 5 +
 6 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index 449feb012481f..013bd13d1d276 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -18,6 +18,7 @@ set(core_files
   __stdarg_va_list.h
   stdatomic.h
   stdbool.h
+  stdcountof.h
   stdckdint.h
   stddef.h
   __stddef_header_macro.h
diff --git a/clang/lib/Headers/module.modulemap 
b/clang/lib/Headers/module.modulemap
index dcaf09e8f2c55..35897a3ed0e79 100644
--- a/clang/lib/Headers/module.modulemap
+++ b/clang/lib/Headers/module.modulemap
@@ -231,6 +231,11 @@ module _Builtin_stdbool [system] {
   export *
 }
 
+module _Builtin_stdcountof [system] {
+  header "stdcountof.h"
+  export *
+}
+
 module _Builtin_stddef [system] {
   textual header "stddef.h"
 
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 4175959d8f55b..be9cab8afb9b3 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -260,6 +260,7 @@ static bool isBuiltinHeaderName(StringRef FileName) {
.Case("stdarg.h", true)
.Case("stdatomic.h", true)
.Case("stdbool.h", true)
+   .Case("stdcountof.h", true)
.Case("stddef.h", true)
.Case("stdint.h", true)
.Case("tgmath.h", true)
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirective

[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-21 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman created 
https://github.com/llvm/llvm-project/pull/140890

WG14 N3469 changed _Lengthof to _Countof but it also introduced the 
 header to expose a macro with a non-ugly identifier. GCC vends 
this header as part of the compiler implementation, so Clang should do the same.

>From 10cb78bd9f361dd442c40702dad3c7809f466615 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Wed, 21 May 2025 08:59:47 -0400
Subject: [PATCH] [C2y] Add stdcountof.h

WG14 N3469 changed _Lengthof to _Countof but it also introduced the
 header to expose a macro with a non-ugly identifier.
GCC vends this header as part of the compiler implementation, so Clang
should do the same.
---
 clang/docs/ReleaseNotes.rst|  4 +++-
 clang/lib/Headers/stdcountof.h | 15 +++
 clang/test/C/C2y/n3469.c   | 13 +++--
 3 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 clang/lib/Headers/stdcountof.h

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b466f3758e0b6..7b2777f711b8d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -249,7 +249,9 @@ C2y Feature Support
   a conforming extension in earlier C language modes, but not in C++ language
   modes (``std::extent`` and ``std::size`` already provide the same
   functionality but with more granularity). The feature can be tested via
-  ``__has_feature(c_countof)`` or ``__has_extension(c_countof)``.
+  ``__has_feature(c_countof)`` or ``__has_extension(c_countof)``. This also
+  adds the  header file which exposes the ``countof`` macro
+  which expands to ``_Countof``.
 
 C23 Feature Support
 ^^^
diff --git a/clang/lib/Headers/stdcountof.h b/clang/lib/Headers/stdcountof.h
new file mode 100644
index 0..5714e6d6ff860
--- /dev/null
+++ b/clang/lib/Headers/stdcountof.h
@@ -0,0 +1,15 @@
+/*=== stdcountof.h - Standard header for countof ---===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+#ifndef __STDCOUNTOF_H
+#define __STDCOUNTOF_H
+
+#define countof _Countof
+
+#endif /* __STDCOUNTOF_H */
diff --git a/clang/test/C/C2y/n3469.c b/clang/test/C/C2y/n3469.c
index 3d9ac8e6411e9..4660596614075 100644
--- a/clang/test/C/C2y/n3469.c
+++ b/clang/test/C/C2y/n3469.c
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c2y -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c2y -verify -ffreestanding %s
 
 /* WG14 N3469: Clang 21
  * The Big Array Size Survey
  *
- * This renames _Lengthof to _Countof.
+ * This renames _Lengthof to _Countof and introduces the stdcountof.h header.
  */
 
 void test() {
@@ -12,3 +12,12 @@ void test() {
expected-error {{expected expression}}
 }
 
+#ifdef countof
+#error "why is countof defined as a macro?"
+#endif
+
+#include 
+
+#ifndef countof
+#error "why is countof not defined as a macro?"
+#endif

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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-21 Thread Alejandro Colomar via cfe-commits

alejandro-colomar wrote:

> > Thanks!
> > For the first commit:
> > ```
> > Suggested-by: Alejandro Colomar 
> > ```
> 
> Happy to add it,

Thanks!  :)

> but for my own education: what's that do? :-D



Quoting that:

```
A Suggested-by: tag indicates that the patch idea is suggested by
the person named and ensures credit to the person for the idea:
if we diligently credit our idea reporters, they will, hopefully,
be inspired to help us again in the future. Note, this is one of
only three tags you might be able to use without explicit
permission of the person named (see ‘Tagging people requires
permission’ below for details).
```

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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-21 Thread Erich Keane via cfe-commits


@@ -260,6 +260,7 @@ static bool isBuiltinHeaderName(StringRef FileName) {
.Case("stdarg.h", true)
.Case("stdatomic.h", true)
.Case("stdbool.h", true)
+   .Case("stdcountof.h", true)

erichkeane wrote:

These too!

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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-21 Thread Alejandro Colomar via cfe-commits

https://github.com/alejandro-colomar approved this pull request.

Thanks!

For the first commit:
```
Suggested-by: Alejandro Colomar 
```

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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-21 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> I still have no problem with this, but it is now into things I have zero 
> confidence reviewing :) Please have someone who has ever used modules review 
> this.

I've added some modules reviewers, so hopefully they can take a look. Yeah, I 
agree that tablegen would be a nice thing to have here, but it's a bit odd 
because the header file itself cannot be table generated.

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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-21 Thread Erich Keane via cfe-commits

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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-21 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions c,h,cpp,inc -- 
clang/lib/Headers/stdcountof.h clang/lib/Lex/ModuleMap.cpp 
clang/lib/Lex/PPDirectives.cpp 
clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc clang/test/C/C2y/n3469.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index be9cab8af..aea71808f 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -253,19 +253,19 @@ OptionalFileEntryRef ModuleMap::findHeader(
 /// headers.
 static bool isBuiltinHeaderName(StringRef FileName) {
   return llvm::StringSwitch(FileName)
-   .Case("float.h", true)
-   .Case("iso646.h", true)
-   .Case("limits.h", true)
-   .Case("stdalign.h", true)
-   .Case("stdarg.h", true)
-   .Case("stdatomic.h", true)
-   .Case("stdbool.h", true)
-   .Case("stdcountof.h", true)
-   .Case("stddef.h", true)
-   .Case("stdint.h", true)
-   .Case("tgmath.h", true)
-   .Case("unwind.h", true)
-   .Default(false);
+  .Case("float.h", true)
+  .Case("iso646.h", true)
+  .Case("limits.h", true)
+  .Case("stdalign.h", true)
+  .Case("stdarg.h", true)
+  .Case("stdatomic.h", true)
+  .Case("stdbool.h", true)
+  .Case("stdcountof.h", true)
+  .Case("stddef.h", true)
+  .Case("stdint.h", true)
+  .Case("tgmath.h", true)
+  .Case("unwind.h", true)
+  .Default(false);
 }
 
 /// Determine whether the given module name is the name of a builtin
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 68f9ca9cb..502dd015a 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -248,50 +248,58 @@ static bool warnByDefaultOnWrongCase(StringRef Include) {
 
   // The standard C/C++ and Posix headers
   return llvm::StringSwitch(LowerInclude)
-// C library headers
-.Cases("assert.h", "complex.h", "ctype.h", "errno.h", "fenv.h", true)
-.Cases("float.h", "inttypes.h", "iso646.h", "limits.h", "locale.h", true)
-.Cases("math.h", "setjmp.h", "signal.h", "stdalign.h", "stdarg.h", true)
-.Cases("stdatomic.h", "stdbool.h", "stdckdint.h", "stdcountof.h", true)
-.Cases("stddef.h", "stdint.h", "stdio.h", "stdlib.h", "stdnoreturn.h", 
true)
-.Cases("string.h", "tgmath.h", "threads.h", "time.h", "uchar.h", true)
-.Cases("wchar.h", "wctype.h", true)
-
-// C++ headers for C library facilities
-.Cases("cassert", "ccomplex", "cctype", "cerrno", "cfenv", true)
-.Cases("cfloat", "cinttypes", "ciso646", "climits", "clocale", true)
-.Cases("cmath", "csetjmp", "csignal", "cstdalign", "cstdarg", true)
-.Cases("cstdbool", "cstddef", "cstdint", "cstdio", "cstdlib", true)
-.Cases("cstring", "ctgmath", "ctime", "cuchar", "cwchar", true)
-.Case("cwctype", true)
-
-// C++ library headers
-.Cases("algorithm", "fstream", "list", "regex", "thread", true)
-.Cases("array", "functional", "locale", "scoped_allocator", "tuple", true)
-.Cases("atomic", "future", "map", "set", "type_traits", true)
-.Cases("bitset", "initializer_list", "memory", "shared_mutex", 
"typeindex", true)
-.Cases("chrono", "iomanip", "mutex", "sstream", "typeinfo", true)
-.Cases("codecvt", "ios", "new", "stack", "unordered_map", true)
-.Cases("complex", "iosfwd", "numeric", "stdexcept", "unordered_set", true)
-.Cases("condition_variable", "iostream", "ostream", "streambuf", 
"utility", true)
-.Cases("deque", "istream", "queue", "string", "valarray", true)
-.Cases("exception", "iterator", "random", "strstream", "vector", true)
-.Cases("forward_list", "limits", "ratio", "system_error", true)
-
-// POSIX headers (which aren't also C headers)
-.Cases("aio.h", "arpa/inet.h", "cpio.h", "dirent.h", "dlfcn.h", true)
-.Cases("fcntl.h", "fmtmsg.h", "fnmatch.h", "ftw.h", "glob.h", true)
-.Cases("grp.h", "iconv.h", "langinfo.h", "libgen.h", "monetary.h", true)
-.Cases("mqueue.h", "ndbm.h", "net/if.h", "netdb.h", "netinet/in.h", true)
-.Cases("netinet/tcp.h", "nl_types.h", "poll.h", "pthread.h", "pwd.h", true)
-.Cases("regex.h", "sched.h", "search.h", "semaphore.h", "spawn.h", true)
-.Cases("strings.h", "stropts.h", "sys/ipc.h", "sys/mman.h", "sys/msg.h", 
true)
-.Cases("sys/resource.h", "sys/select.h",  "sys/sem.h", "sys/shm.h", 
"sys/socket.h", true)
-.Cases("sys/stat.h", "sys/statvfs.h", "sys/time.h", "sys/times.h", 
"sys/types.h", true)
-.Cases("sys/uio.h", "sys/un.h", "sys/utsname.h", "sys/wait.h", "syslog.h", 
true)
-.Cases("tar.h", "termios.h", "trace.h", "ulimit.h", true)
-.Cases("unistd.h", "utime.h", "utmpx.h", "wordexp.h", true)
-.Default(false);
+

[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-21 Thread Erich Keane via cfe-commits


@@ -252,8 +252,8 @@ static bool warnByDefaultOnWrongCase(StringRef Include) {
 .Cases("assert.h", "complex.h", "ctype.h", "errno.h", "fenv.h", true)

erichkeane wrote:

The fact that these aren't tablegened somewhere is frightening!

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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-21 Thread Erich Keane via cfe-commits

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

I still have no problem with this, but it is now into things I have zero 
confidence reviewing :)  Please have someone who has ever used modules review 
this.

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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-21 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/140890

>From 10cb78bd9f361dd442c40702dad3c7809f466615 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Wed, 21 May 2025 08:59:47 -0400
Subject: [PATCH 1/2] [C2y] Add stdcountof.h

WG14 N3469 changed _Lengthof to _Countof but it also introduced the
 header to expose a macro with a non-ugly identifier.
GCC vends this header as part of the compiler implementation, so Clang
should do the same.
---
 clang/docs/ReleaseNotes.rst|  4 +++-
 clang/lib/Headers/stdcountof.h | 15 +++
 clang/test/C/C2y/n3469.c   | 13 +++--
 3 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 clang/lib/Headers/stdcountof.h

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b466f3758e0b6..7b2777f711b8d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -249,7 +249,9 @@ C2y Feature Support
   a conforming extension in earlier C language modes, but not in C++ language
   modes (``std::extent`` and ``std::size`` already provide the same
   functionality but with more granularity). The feature can be tested via
-  ``__has_feature(c_countof)`` or ``__has_extension(c_countof)``.
+  ``__has_feature(c_countof)`` or ``__has_extension(c_countof)``. This also
+  adds the  header file which exposes the ``countof`` macro
+  which expands to ``_Countof``.
 
 C23 Feature Support
 ^^^
diff --git a/clang/lib/Headers/stdcountof.h b/clang/lib/Headers/stdcountof.h
new file mode 100644
index 0..5714e6d6ff860
--- /dev/null
+++ b/clang/lib/Headers/stdcountof.h
@@ -0,0 +1,15 @@
+/*=== stdcountof.h - Standard header for countof ---===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+#ifndef __STDCOUNTOF_H
+#define __STDCOUNTOF_H
+
+#define countof _Countof
+
+#endif /* __STDCOUNTOF_H */
diff --git a/clang/test/C/C2y/n3469.c b/clang/test/C/C2y/n3469.c
index 3d9ac8e6411e9..4660596614075 100644
--- a/clang/test/C/C2y/n3469.c
+++ b/clang/test/C/C2y/n3469.c
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c2y -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c2y -verify -ffreestanding %s
 
 /* WG14 N3469: Clang 21
  * The Big Array Size Survey
  *
- * This renames _Lengthof to _Countof.
+ * This renames _Lengthof to _Countof and introduces the stdcountof.h header.
  */
 
 void test() {
@@ -12,3 +12,12 @@ void test() {
expected-error {{expected expression}}
 }
 
+#ifdef countof
+#error "why is countof defined as a macro?"
+#endif
+
+#include 
+
+#ifndef countof
+#error "why is countof not defined as a macro?"
+#endif

>From 7d94ea7a3d0b663ffca61f89bca2ca56ef585f7d Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Wed, 21 May 2025 09:33:56 -0400
Subject: [PATCH 2/2] Update other places where the builtin header needs to be
 mentioned

---
 clang/lib/Headers/CMakeLists.txt | 1 +
 clang/lib/Headers/module.modulemap   | 5 +
 clang/lib/Lex/ModuleMap.cpp  | 1 +
 clang/lib/Lex/PPDirectives.cpp   | 4 ++--
 clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc   | 1 +
 .../Modules/Inputs/builtin-headers/system-modules.modulemap  | 5 +
 6 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index 449feb012481f..013bd13d1d276 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -18,6 +18,7 @@ set(core_files
   __stdarg_va_list.h
   stdatomic.h
   stdbool.h
+  stdcountof.h
   stdckdint.h
   stddef.h
   __stddef_header_macro.h
diff --git a/clang/lib/Headers/module.modulemap 
b/clang/lib/Headers/module.modulemap
index dcaf09e8f2c55..35897a3ed0e79 100644
--- a/clang/lib/Headers/module.modulemap
+++ b/clang/lib/Headers/module.modulemap
@@ -231,6 +231,11 @@ module _Builtin_stdbool [system] {
   export *
 }
 
+module _Builtin_stdcountof [system] {
+  header "stdcountof.h"
+  export *
+}
+
 module _Builtin_stddef [system] {
   textual header "stddef.h"
 
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 4175959d8f55b..be9cab8afb9b3 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -260,6 +260,7 @@ static bool isBuiltinHeaderName(StringRef FileName) {
.Case("stdarg.h", true)
.Case("stdatomic.h", true)
.Case("stdbool.h", true)
+   .Case("stdcountof.h", true)
.Case("stddef.h", true)
.Case("stdint.h", true)
.Case("tgmath.h", true)
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirective

[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-21 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

Precommit CI caught a relevant failure that only happens when testing against 
an install target, so yay for that! I've got a fix coming along with some other 
updated support files I found when looking at stdalign.h

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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-21 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

CC @alejandro-colomar 

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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-21 Thread Erich Keane via cfe-commits

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


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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)


Changes

WG14 N3469 changed _Lengthof to _Countof but it also introduced the 
 header to expose a macro with a non-ugly identifier. GCC 
vends this header as part of the compiler implementation, so Clang should do 
the same.

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3-1) 
- (added) clang/lib/Headers/stdcountof.h (+15) 
- (modified) clang/test/C/C2y/n3469.c (+11-2) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b466f3758e0b6..7b2777f711b8d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -249,7 +249,9 @@ C2y Feature Support
   a conforming extension in earlier C language modes, but not in C++ language
   modes (``std::extent`` and ``std::size`` already provide the same
   functionality but with more granularity). The feature can be tested via
-  ``__has_feature(c_countof)`` or ``__has_extension(c_countof)``.
+  ``__has_feature(c_countof)`` or ``__has_extension(c_countof)``. This also
+  adds the  header file which exposes the ``countof`` macro
+  which expands to ``_Countof``.
 
 C23 Feature Support
 ^^^
diff --git a/clang/lib/Headers/stdcountof.h b/clang/lib/Headers/stdcountof.h
new file mode 100644
index 0..5714e6d6ff860
--- /dev/null
+++ b/clang/lib/Headers/stdcountof.h
@@ -0,0 +1,15 @@
+/*=== stdcountof.h - Standard header for countof ---===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+#ifndef __STDCOUNTOF_H
+#define __STDCOUNTOF_H
+
+#define countof _Countof
+
+#endif /* __STDCOUNTOF_H */
diff --git a/clang/test/C/C2y/n3469.c b/clang/test/C/C2y/n3469.c
index 3d9ac8e6411e9..4660596614075 100644
--- a/clang/test/C/C2y/n3469.c
+++ b/clang/test/C/C2y/n3469.c
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c2y -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c2y -verify -ffreestanding %s
 
 /* WG14 N3469: Clang 21
  * The Big Array Size Survey
  *
- * This renames _Lengthof to _Countof.
+ * This renames _Lengthof to _Countof and introduces the stdcountof.h header.
  */
 
 void test() {
@@ -12,3 +12,12 @@ void test() {
expected-error {{expected expression}}
 }
 
+#ifdef countof
+#error "why is countof defined as a macro?"
+#endif
+
+#include 
+
+#ifndef countof
+#error "why is countof not defined as a macro?"
+#endif

``




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