aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clang/docs/ReleaseNotes.rst4
-rw-r--r--clang/lib/Headers/CMakeLists.txt1
-rw-r--r--clang/lib/Headers/module.modulemap5
-rw-r--r--clang/lib/Headers/stdcountof.h15
-rw-r--r--clang/lib/Lex/ModuleMap.cpp1
-rw-r--r--clang/lib/Lex/PPDirectives.cpp4
-rw-r--r--clang/test/C/C2y/n3469.c13
-rw-r--r--clang/test/Modules/Inputs/builtin-headers/system-modules.modulemap5
-rw-r--r--clang/test/Modules/builtin-headers.mm1
9 files changed, 44 insertions, 5 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ee74431..c83f135 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -251,7 +251,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 ``<stdcountof.h>`` header file which exposes the ``countof`` macro
+ which expands to ``_Countof``.
C23 Feature Support
^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index 53219dc..24f5327 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 dcaf09e8..35897a3 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/Headers/stdcountof.h b/clang/lib/Headers/stdcountof.h
new file mode 100644
index 0000000..5714e6d
--- /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/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index c088e4e..637a08f 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -258,6 +258,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/PPDirectives.cpp
index b2a8459..68f9ca9 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -252,8 +252,8 @@ static bool warnByDefaultOnWrongCase(StringRef Include) {
.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", "stddef.h", true)
- .Cases("stdint.h", "stdio.h", "stdlib.h", "stdnoreturn.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)
diff --git a/clang/test/C/C2y/n3469.c b/clang/test/C/C2y/n3469.c
index 3d9ac8e..4660596 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 <stdcountof.h>
+
+#ifndef countof
+#error "why is countof not defined as a macro?"
+#endif
diff --git a/clang/test/Modules/Inputs/builtin-headers/system-modules.modulemap b/clang/test/Modules/Inputs/builtin-headers/system-modules.modulemap
index 0161ff8..1869651 100644
--- a/clang/test/Modules/Inputs/builtin-headers/system-modules.modulemap
+++ b/clang/test/Modules/Inputs/builtin-headers/system-modules.modulemap
@@ -49,6 +49,11 @@ module cstd [system] [no_undeclared_includes] {
export *
}
+ module stdcountof {
+ header "stdcountof.h"
+ export *
+ }
+
module stddef {
header "stddef.h"
export *
diff --git a/clang/test/Modules/builtin-headers.mm b/clang/test/Modules/builtin-headers.mm
index 4c9ddec..ad2d66a 100644
--- a/clang/test/Modules/builtin-headers.mm
+++ b/clang/test/Modules/builtin-headers.mm
@@ -17,6 +17,7 @@
@import _Builtin_stdarg;
@import _Builtin_stdatomic;
@import _Builtin_stdbool;
+@import _Builtin_stdcountof;
@import _Builtin_stddef;
@import _Builtin_stdint;
@import _Builtin_stdnoreturn;