Skip to content

Commit 309e169

Browse files
Merge pull request swiftlang#7616 from ian-twilightcoder/split-stdarg-stddef
[cherry-pick stable/20230725] [Headers][Modules] Make separate headers for the stdarg.h and stddef.h pieces so that they can be modularized
2 parents 7568fda + 938f0a5 commit 309e169

File tree

24 files changed

+313
-88
lines changed

24 files changed

+313
-88
lines changed

clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,21 @@ namespace find_all_symbols {
1313

1414
const HeaderMapCollector::RegexHeaderMap *getSTLPostfixHeaderMap() {
1515
static const HeaderMapCollector::RegexHeaderMap STLPostfixHeaderMap = {
16+
{"include/__stdarg___gnuc_va_list.h$", "<cstdarg>"},
17+
{"include/__stdarg___va_copy.h$", "<cstdarg>"},
18+
{"include/__stdarg_va_arg.h$", "<cstdarg>"},
19+
{"include/__stdarg_va_copy.h$", "<cstdarg>"},
20+
{"include/__stdarg_va_list.h$", "<cstdarg>"},
1621
{"include/__stddef_max_align_t.h$", "<cstddef>"},
22+
{"include/__stddef_null.h$", "<cstddef>"},
23+
{"include/__stddef_nullptr_t.h$", "<cstddef>"},
24+
{"include/__stddef_offsetof.h$", "<cstddef>"},
25+
{"include/__stddef_ptrdiff_t.h$", "<cstddef>"},
26+
{"include/__stddef_rsize_t.h$", "<cstddef>"},
27+
{"include/__stddef_size_t.h$", "<cstddef>"},
28+
{"include/__stddef_unreachable.h$", "<cstddef>"},
29+
{"include/__stddef_wchar_t.h$", "<cstddef>"},
30+
{"include/__stddef_wint_t.h$", "<cstddef>"},
1731
{"include/__wmmintrin_aes.h$", "<wmmintrin.h>"},
1832
{"include/__wmmintrin_pclmul.h$", "<wmmintrin.h>"},
1933
{"include/adxintrin.h$", "<immintrin.h>"},

clang-tools-extra/clangd/index/CanonicalIncludes.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,21 @@ namespace clang {
1616
namespace clangd {
1717
namespace {
1818
const std::pair<llvm::StringRef, llvm::StringRef> IncludeMappings[] = {
19+
{"include/__stdarg___gnuc_va_list.h", "<cstdarg>"},
20+
{"include/__stdarg___va_copy.h", "<cstdarg>"},
21+
{"include/__stdarg_va_arg.h", "<cstdarg>"},
22+
{"include/__stdarg_va_copy.h", "<cstdarg>"},
23+
{"include/__stdarg_va_list.h", "<cstdarg>"},
1924
{"include/__stddef_max_align_t.h", "<cstddef>"},
25+
{"include/__stddef_null.h", "<cstddef>"},
26+
{"include/__stddef_nullptr_t.h", "<cstddef>"},
27+
{"include/__stddef_offsetof.h", "<cstddef>"},
28+
{"include/__stddef_ptrdiff_t.h", "<cstddef>"},
29+
{"include/__stddef_rsize_t.h", "<cstddef>"},
30+
{"include/__stddef_size_t.h", "<cstddef>"},
31+
{"include/__stddef_unreachable.h", "<cstddef>"},
32+
{"include/__stddef_wchar_t.h", "<cstddef>"},
33+
{"include/__stddef_wint_t.h", "<cstddef>"},
2034
{"include/__wmmintrin_aes.h", "<wmmintrin.h>"},
2135
{"include/__wmmintrin_pclmul.h", "<wmmintrin.h>"},
2236
{"include/adxintrin.h", "<immintrin.h>"},

clang/lib/Headers/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,24 @@ set(core_files
1010
module.modulemap
1111
stdalign.h
1212
stdarg.h
13+
__stdarg___gnuc_va_list.h
14+
__stdarg___va_copy.h
15+
__stdarg_va_arg.h
16+
__stdarg_va_copy.h
17+
__stdarg_va_list.h
1318
stdatomic.h
1419
stdbool.h
1520
stddef.h
1621
__stddef_max_align_t.h
22+
__stddef_null.h
23+
__stddef_nullptr_t.h
24+
__stddef_offsetof.h
25+
__stddef_ptrdiff_t.h
26+
__stddef_rsize_t.h
27+
__stddef_size_t.h
28+
__stddef_unreachable.h
29+
__stddef_wchar_t.h
30+
__stddef_wint_t.h
1731
stdint.h
1832
stdnoreturn.h
1933
tgmath.h
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*===---- __stdarg___gnuc_va_list.h - Definition of __gnuc_va_list ---------===
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+
10+
#ifndef __GNUC_VA_LIST
11+
#define __GNUC_VA_LIST
12+
typedef __builtin_va_list __gnuc_va_list;
13+
#endif
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*===---- __stdarg___va_copy.h - Definition of __va_copy -------------------===
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+
10+
#ifndef __va_copy
11+
#define __va_copy(d, s) __builtin_va_copy(d, s)
12+
#endif
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*===---- __stdarg_va_arg.h - Definitions of va_start, va_arg, va_end-------===
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+
10+
#ifndef va_arg
11+
12+
/* FIXME: This is using the placeholder dates Clang produces for these macros
13+
in C2x mode; switch to the correct values once they've been published. */
14+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L
15+
/* C2x does not require the second parameter for va_start. */
16+
#define va_start(ap, ...) __builtin_va_start(ap, 0)
17+
#else
18+
/* Versions before C2x do require the second parameter. */
19+
#define va_start(ap, param) __builtin_va_start(ap, param)
20+
#endif
21+
#define va_end(ap) __builtin_va_end(ap)
22+
#define va_arg(ap, type) __builtin_va_arg(ap, type)
23+
24+
#endif
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*===---- __stdarg_va_copy.h - Definition of va_copy------------------------===
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+
10+
#ifndef va_copy
11+
#define va_copy(dest, src) __builtin_va_copy(dest, src)
12+
#endif
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*===---- __stdarg_va_list.h - Definition of va_list -----------------------===
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+
10+
#ifndef _VA_LIST
11+
#define _VA_LIST
12+
typedef __builtin_va_list va_list;
13+
#endif

clang/lib/Headers/__stddef_null.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*===---- __stddef_null.h - Definition of NULL -----------------------------===
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+
10+
#undef NULL
11+
#ifdef __cplusplus
12+
#if !defined(__MINGW32__) && !defined(_MSC_VER)
13+
#define NULL __null
14+
#else
15+
#define NULL 0
16+
#endif
17+
#else
18+
#define NULL ((void *)0)
19+
#endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*===---- __stddef_nullptr_t.h - Definition of nullptr_t -------------------===
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+
10+
#if !defined(_NULLPTR_T) || __has_feature(modules)
11+
/* Always define nullptr_t when modules are available. */
12+
#if !__has_feature(modules)
13+
#define _NULLPTR_T
14+
#endif
15+
#ifdef __cplusplus
16+
#if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED)
17+
namespace std {
18+
typedef decltype(nullptr) nullptr_t;
19+
}
20+
using ::std::nullptr_t;
21+
#endif
22+
#else
23+
typedef typeof(nullptr) nullptr_t;
24+
#endif
25+
#endif

0 commit comments

Comments
 (0)