Skip to content

Commit 879640c

Browse files
authored
[libc++] Implements the new version header generator. (llvm#97847)
The generator makes a few changes to the output - removes the synopsis, it did not really show what was implemented correctly. - the output now is clang-format clean. This code uses the new FTM data structure. Since the contents of this structure are not up-to-date the code is only used in its tests.
1 parent d1e5dc2 commit 879640c

File tree

7 files changed

+390
-2
lines changed

7 files changed

+390
-2
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# ===----------------------------------------------------------------------===##
2+
#
3+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
# ===----------------------------------------------------------------------===##
8+
9+
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/test/libcxx/feature_test_macro/test_data.json
10+
11+
import sys
12+
13+
sys.path.append(sys.argv[1])
14+
from generate_feature_test_macro_components import FeatureTestMacros
15+
16+
17+
def test(output, expected):
18+
assert output == expected, f"expected\n{expected}\n\noutput\n{output}"
19+
20+
21+
ftm = FeatureTestMacros(sys.argv[2])
22+
test(
23+
ftm.ftm_metadata,
24+
{
25+
"__cpp_lib_any": {
26+
"headers": ["any"],
27+
"test_suite_guard": None,
28+
"libcxx_guard": None,
29+
},
30+
"__cpp_lib_barrier": {
31+
"headers": ["barrier"],
32+
"test_suite_guard": "!defined(_LIBCPP_HAS_NO_THREADS) && (!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_SYNC)",
33+
"libcxx_guard": "!defined(_LIBCPP_HAS_NO_THREADS) && _LIBCPP_AVAILABILITY_HAS_SYNC",
34+
},
35+
"__cpp_lib_format": {
36+
"headers": ["format"],
37+
"test_suite_guard": None,
38+
"libcxx_guard": None,
39+
},
40+
"__cpp_lib_parallel_algorithm": {
41+
"headers": ["algorithm", "numeric"],
42+
"test_suite_guard": None,
43+
"libcxx_guard": None,
44+
},
45+
"__cpp_lib_variant": {
46+
"headers": ["variant"],
47+
"test_suite_guard": None,
48+
"libcxx_guard": None,
49+
},
50+
},
51+
)

libcxx/test/libcxx/feature_test_macro/implemented_ftms.sh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test(output, expected):
3131
"__cpp_lib_barrier": {
3232
"c++20": "201907L",
3333
"c++23": "201907L",
34-
"c++26": "201907L",
34+
"c++26": "299900L",
3535
},
3636
"__cpp_lib_format": {
3737
"c++20": None,

libcxx/test/libcxx/feature_test_macro/standard_ftms.sh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test(output, expected):
3131
"__cpp_lib_barrier": {
3232
"c++20": "201907L",
3333
"c++23": "201907L",
34-
"c++26": "201907L",
34+
"c++26": "299900L",
3535
},
3636
"__cpp_lib_format": {
3737
"c++20": "202110L",

libcxx/test/libcxx/feature_test_macro/test_data.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
"implemented": true
2424
}
2525
]
26+
},
27+
"c++26": {
28+
"299900": [
29+
{
30+
"implemented": true
31+
}
32+
]
2633
}
2734
},
2835
"headers": [
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# ===----------------------------------------------------------------------===##
2+
#
3+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
# ===----------------------------------------------------------------------===##
8+
9+
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/test/libcxx/feature_test_macro/test_data.json
10+
11+
import sys
12+
13+
sys.path.append(sys.argv[1])
14+
from generate_feature_test_macro_components import FeatureTestMacros
15+
16+
17+
def test(output, expected):
18+
assert output == expected, f"expected\n{expected}\n\noutput\n{output}"
19+
20+
21+
ftm = FeatureTestMacros(sys.argv[2])
22+
test(
23+
ftm.version_header,
24+
"""// -*- C++ -*-
25+
//===----------------------------------------------------------------------===//
26+
//
27+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
28+
// See https://llvm.org/LICENSE.txt for license information.
29+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
30+
//
31+
//===----------------------------------------------------------------------===//
32+
33+
#ifndef _LIBCPP_VERSION
34+
#define _LIBCPP_VERSION
35+
36+
#include <__config>
37+
38+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
39+
# pragma GCC system_header
40+
#endif
41+
42+
#if _LIBCPP_STD_VER >= 17
43+
# define __cpp_lib_any 201606L
44+
# define __cpp_lib_parallel_algorithm 201603L
45+
# define __cpp_lib_variant 202102L
46+
#endif // _LIBCPP_STD_VER >= 17
47+
48+
#if _LIBCPP_STD_VER >= 20
49+
# if !defined(_LIBCPP_HAS_NO_THREADS) && _LIBCPP_AVAILABILITY_HAS_SYNC
50+
# define __cpp_lib_barrier 201907L
51+
# endif
52+
// define __cpp_lib_format 202110L
53+
# undef __cpp_lib_variant
54+
# define __cpp_lib_variant 202106L
55+
#endif // _LIBCPP_STD_VER >= 20
56+
57+
#if _LIBCPP_STD_VER >= 23
58+
// define __cpp_lib_format 202207L
59+
#endif // _LIBCPP_STD_VER >= 23
60+
61+
#if _LIBCPP_STD_VER >= 26
62+
# if !defined(_LIBCPP_HAS_NO_THREADS) && _LIBCPP_AVAILABILITY_HAS_SYNC
63+
# undef __cpp_lib_barrier
64+
# define __cpp_lib_barrier 299900L
65+
# endif
66+
// define __cpp_lib_format 202311L
67+
# undef __cpp_lib_variant
68+
# define __cpp_lib_variant 202306L
69+
#endif // _LIBCPP_STD_VER >= 26
70+
71+
#endif // _LIBCPP_VERSION
72+
""",
73+
)
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# ===----------------------------------------------------------------------===##
2+
#
3+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
# ===----------------------------------------------------------------------===##
8+
9+
# RUN: %{python} %s %{libcxx-dir}/utils %{libcxx-dir}/test/libcxx/feature_test_macro/test_data.json
10+
11+
import sys
12+
13+
sys.path.append(sys.argv[1])
14+
from generate_feature_test_macro_components import FeatureTestMacros
15+
16+
17+
def test(output, expected):
18+
assert output == expected, f"expected\n{expected}\n\noutput\n{output}"
19+
20+
21+
ftm = FeatureTestMacros(sys.argv[2])
22+
test(
23+
ftm.version_header_implementation,
24+
{
25+
"17": [
26+
{
27+
"__cpp_lib_any": {
28+
"value": "201606L",
29+
"implemented": True,
30+
"need_undef": False,
31+
"condition": None,
32+
},
33+
},
34+
{
35+
"__cpp_lib_parallel_algorithm": {
36+
"value": "201603L",
37+
"implemented": True,
38+
"need_undef": False,
39+
"condition": None,
40+
},
41+
},
42+
{
43+
"__cpp_lib_variant": {
44+
"value": "202102L",
45+
"implemented": True,
46+
"need_undef": False,
47+
"condition": None,
48+
},
49+
},
50+
],
51+
"20": [
52+
{
53+
"__cpp_lib_barrier": {
54+
"value": "201907L",
55+
"implemented": True,
56+
"need_undef": False,
57+
"condition": "!defined(_LIBCPP_HAS_NO_THREADS) && _LIBCPP_AVAILABILITY_HAS_SYNC",
58+
},
59+
},
60+
{
61+
"__cpp_lib_format": {
62+
"value": "202110L",
63+
"implemented": False,
64+
"need_undef": False,
65+
"condition": None,
66+
},
67+
},
68+
{
69+
"__cpp_lib_variant": {
70+
"value": "202106L",
71+
"implemented": True,
72+
"need_undef": True,
73+
"condition": None,
74+
},
75+
},
76+
],
77+
"23": [
78+
{
79+
"__cpp_lib_format": {
80+
"value": "202207L",
81+
"implemented": False,
82+
"need_undef": False,
83+
"condition": None,
84+
},
85+
},
86+
],
87+
"26": [
88+
{
89+
"__cpp_lib_barrier": {
90+
"value": "299900L",
91+
"implemented": True,
92+
"need_undef": True,
93+
"condition": "!defined(_LIBCPP_HAS_NO_THREADS) && _LIBCPP_AVAILABILITY_HAS_SYNC",
94+
},
95+
},
96+
{
97+
"__cpp_lib_format": {
98+
"value": "202311L",
99+
"implemented": False,
100+
"need_undef": False,
101+
"condition": None,
102+
},
103+
},
104+
{
105+
"__cpp_lib_variant": {
106+
"value": "202306L",
107+
"implemented": True,
108+
"need_undef": True,
109+
"condition": None,
110+
},
111+
},
112+
],
113+
},
114+
)

0 commit comments

Comments
 (0)