Skip to content

Commit 680da4b

Browse files
[Headers][Modules] Make separate headers for the stdarg.h and stddef.h pieces so that they can be modularized
stdarg.h and stddef.h have to be textual headers in their upcoming modules to support their `__needs_xxx` macros. That means that they won't get precompiled into their modules' pcm, and instead their declarations will go into every other pcm that uses them. For now that's ok since the type merger can handle the declarations in these headers, but it's suboptimal at best. Make separate headers for all of the pieces so that they can be properly modularized. Reviewed By: aaron.ballman, ChuanqiXu Differential Revision: https://reviews.llvm.org/D158709
1 parent 79d5d9a commit 680da4b

24 files changed

+311
-86
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

clang/lib/Headers/__stdarg_va_arg.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
13+
/* C23 does not require the second parameter for va_start. */
14+
#define va_start(ap, ...) __builtin_va_start(ap, 0)
15+
#else
16+
/* Versions before C23 do require the second parameter. */
17+
#define va_start(ap, param) __builtin_va_start(ap, param)
18+
#endif
19+
#define va_end(ap) __builtin_va_end(ap)
20+
#define va_arg(ap, type) __builtin_va_arg(ap, type)
21+
22+
#endif

clang/lib/Headers/__stdarg_va_copy.h

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

clang/lib/Headers/__stdarg_va_list.h

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

clang/lib/Headers/__stddef_offsetof.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*===---- __stddef_offsetof.h - Definition of offsetof ---------------------===
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(offsetof) || __has_feature(modules)
11+
/* Always define offsetof when modules are available. */
12+
#define offsetof(t, d) __builtin_offsetof(t, d)
13+
#endif
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*===---- __stddef_ptrdiff_t.h - Definition of ptrdiff_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(_PTRDIFF_T) || __has_feature(modules)
11+
/* Always define ptrdiff_t when modules are available. */
12+
#if !__has_feature(modules)
13+
#define _PTRDIFF_T
14+
#endif
15+
typedef __PTRDIFF_TYPE__ ptrdiff_t;
16+
#endif

clang/lib/Headers/__stddef_rsize_t.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*===---- __stddef_rsize_t.h - Definition of rsize_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(_RSIZE_T) || __has_feature(modules)
11+
/* Always define rsize_t when modules are available. */
12+
#if !__has_feature(modules)
13+
#define _RSIZE_T
14+
#endif
15+
typedef __SIZE_TYPE__ rsize_t;
16+
#endif

clang/lib/Headers/__stddef_size_t.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*===---- __stddef_size_t.h - Definition of size_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(_SIZE_T) || __has_feature(modules)
11+
/* Always define size_t when modules are available. */
12+
#if !__has_feature(modules)
13+
#define _SIZE_T
14+
#endif
15+
typedef __SIZE_TYPE__ size_t;
16+
#endif
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*===---- __stddef_unreachable.h - Definition of unreachable ---------------===
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(unreachable) || __has_feature(modules)
11+
/* Always define unreachable when modules are available. */
12+
#define unreachable() __builtin_unreachable()
13+
#endif

clang/lib/Headers/__stddef_wchar_t.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*===---- __stddef_wchar.h - Definition of wchar_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(__cplusplus) || (defined(_MSC_VER) && !_NATIVE_WCHAR_T_DEFINED)
11+
/* Always define wchar_t when modules are available. */
12+
#if !defined(_WCHAR_T) || __has_feature(modules)
13+
#if !__has_feature(modules)
14+
#define _WCHAR_T
15+
#if defined(_MSC_EXTENSIONS)
16+
#define _WCHAR_T_DEFINED
17+
#endif
18+
#endif
19+
typedef __WCHAR_TYPE__ wchar_t;
20+
#endif
21+
#endif

clang/lib/Headers/__stddef_wint_t.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*===---- __stddef_wint.h - Definition of wint_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+
/* Always define wint_t when modules are available. */
11+
#if !defined(_WINT_T) || __has_feature(modules)
12+
#if !__has_feature(modules)
13+
#define _WINT_T
14+
#endif
15+
typedef __WINT_TYPE__ wint_t;
16+
#endif

clang/lib/Headers/stdarg.h

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,41 +30,27 @@
3030
#endif
3131

3232
#ifdef __need___va_list
33-
#ifndef __GNUC_VA_LIST
34-
#define __GNUC_VA_LIST
35-
typedef __builtin_va_list __gnuc_va_list;
36-
#endif
33+
#include <__stdarg___gnuc_va_list.h>
3734
#undef __need___va_list
3835
#endif /* defined(__need___va_list) */
3936

4037
#ifdef __need_va_list
41-
#ifndef _VA_LIST
42-
typedef __builtin_va_list va_list;
43-
#define _VA_LIST
44-
#endif
38+
#include <__stdarg_va_list.h>
4539
#undef __need_va_list
4640
#endif /* defined(__need_va_list) */
4741

4842
#ifdef __need_va_arg
49-
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
50-
/* C23 does not require the second parameter for va_start. */
51-
#define va_start(ap, ...) __builtin_va_start(ap, 0)
52-
#else
53-
/* Versions before C23 do require the second parameter. */
54-
#define va_start(ap, param) __builtin_va_start(ap, param)
55-
#endif
56-
#define va_end(ap) __builtin_va_end(ap)
57-
#define va_arg(ap, type) __builtin_va_arg(ap, type)
43+
#include <__stdarg_va_arg.h>
5844
#undef __need_va_arg
5945
#endif /* defined(__need_va_arg) */
6046

6147
#ifdef __need___va_copy
62-
#define __va_copy(d,s) __builtin_va_copy(d,s)
48+
#include <__stdarg___va_copy.h>
6349
#undef __need___va_copy
6450
#endif /* defined(__need___va_copy) */
6551

6652
#ifdef __need_va_copy
67-
#define va_copy(dest, src) __builtin_va_copy(dest, src)
53+
#include <__stdarg_va_copy.h>
6854
#undef __need_va_copy
6955
#endif /* defined(__need_va_copy) */
7056

0 commit comments

Comments
 (0)