Skip to content

Commit f9439cb

Browse files
authored
Merge pull request #8706 from ian-twilightcoder/no-decl-in-textual
[cherry-pick swift/release/6.0][clang][modules] stdarg.h and stddef.h shouldn't directly declare anything
2 parents 715517d + d7ee56b commit f9439cb

File tree

9 files changed

+51
-45
lines changed

9 files changed

+51
-45
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ const HeaderMapCollector::RegexHeaderMap *getSTLPostfixHeaderMap() {
1515
static const HeaderMapCollector::RegexHeaderMap STLPostfixHeaderMap = {
1616
{"include/__stdarg___gnuc_va_list.h$", "<cstdarg>"},
1717
{"include/__stdarg___va_copy.h$", "<cstdarg>"},
18+
{"include/__stdarg_header_macro.h$", "<cstdarg>"},
1819
{"include/__stdarg_va_arg.h$", "<cstdarg>"},
1920
{"include/__stdarg_va_copy.h$", "<cstdarg>"},
2021
{"include/__stdarg_va_list.h$", "<cstdarg>"},
22+
{"include/__stddef_header_macro.h$", "<cstddef>"},
2123
{"include/__stddef_max_align_t.h$", "<cstddef>"},
2224
{"include/__stddef_null.h$", "<cstddef>"},
2325
{"include/__stddef_nullptr_t.h$", "<cstddef>"},

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ namespace {
1818
const std::pair<llvm::StringRef, llvm::StringRef> IncludeMappings[] = {
1919
{"include/__stdarg___gnuc_va_list.h", "<cstdarg>"},
2020
{"include/__stdarg___va_copy.h", "<cstdarg>"},
21+
{"include/__stdarg_header_macro.h", "<cstdarg>"},
2122
{"include/__stdarg_va_arg.h", "<cstdarg>"},
2223
{"include/__stdarg_va_copy.h", "<cstdarg>"},
2324
{"include/__stdarg_va_list.h", "<cstdarg>"},
25+
{"include/__stddef_header_macro.h", "<cstddef>"},
2426
{"include/__stddef_max_align_t.h", "<cstddef>"},
2527
{"include/__stddef_null.h", "<cstddef>"},
2628
{"include/__stddef_nullptr_t.h", "<cstddef>"},

clang/lib/Headers/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ set(core_files
1212
stdarg.h
1313
__stdarg___gnuc_va_list.h
1414
__stdarg___va_copy.h
15+
__stdarg_header_macro.h
1516
__stdarg_va_arg.h
1617
__stdarg_va_copy.h
1718
__stdarg_va_list.h
1819
stdatomic.h
1920
stdbool.h
2021
stddef.h
22+
__stddef_header_macro.h
2123
__stddef_max_align_t.h
2224
__stddef_null.h
2325
__stddef_nullptr_t.h
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*===---- __stdarg_header_macro.h ------------------------------------------===
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 __STDARG_H
11+
#define __STDARG_H
12+
#endif
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*===---- __stddef_header_macro.h ------------------------------------------===
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 __STDDEF_H
11+
#define __STDDEF_H
12+
#endif

clang/lib/Headers/module.modulemap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ module _Builtin_stdarg [system] {
203203
export *
204204
}
205205

206+
explicit module header_macro {
207+
header "__stdarg_header_macro.h"
208+
export *
209+
}
210+
206211
explicit module va_arg {
207212
header "__stdarg_va_arg.h"
208213
export *
@@ -232,6 +237,10 @@ module _Builtin_stdbool [system] {
232237
module _Builtin_stddef [system] {
233238
textual header "stddef.h"
234239

240+
explicit module header_macro {
241+
header "__stddef_header_macro.h"
242+
export *
243+
}
235244
// __stddef_max_align_t.h is always in this module, even if
236245
// -fbuiltin-headers-in-system-modules is passed.
237246
explicit module max_align_t {

clang/lib/Headers/stdarg.h

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,15 @@
1414
* need to use some of its interfaces. Otherwise this header provides all of
1515
* the expected interfaces.
1616
*
17-
* When clang modules are enabled, this header is a textual header. It ignores
18-
* its header guard so that multiple submodules can export its interfaces.
19-
* Take module SM with submodules A and B, whose headers both include stdarg.h
20-
* When SM.A builds, __STDARG_H will be defined. When SM.B builds, the
21-
* definition from SM.A will leak when building without local submodule
22-
* visibility. stdarg.h wouldn't include any of its implementation headers, and
23-
* SM.B wouldn't import any of the stdarg modules, and SM.B's `export *`
24-
* wouldn't export any stdarg interfaces as expected. However, since stdarg.h
25-
* ignores its header guard when building with modules, it all works as
26-
* expected.
27-
*
28-
* When clang modules are not enabled, the header guards can function in the
29-
* normal simple fashion.
17+
* When clang modules are enabled, this header is a textual header to support
18+
* the multiple include behavior. As such, it doesn't directly declare anything
19+
* so that it doesn't add duplicate declarations to all of its includers'
20+
* modules.
3021
*/
31-
#if !defined(__STDARG_H) || __has_feature(modules) || \
32-
defined(__need___va_list) || defined(__need_va_list) || \
33-
defined(__need_va_arg) || defined(__need___va_copy) || \
34-
defined(__need_va_copy)
35-
3622
#if !defined(__need___va_list) && !defined(__need_va_list) && \
3723
!defined(__need_va_arg) && !defined(__need___va_copy) && \
3824
!defined(__need_va_copy)
39-
#define __STDARG_H
25+
#include <__stdarg_header_macro.h>
4026
#define __need___va_list
4127
#define __need_va_list
4228
#define __need_va_arg
@@ -75,5 +61,3 @@
7561
#include <__stdarg_va_copy.h>
7662
#undef __need_va_copy
7763
#endif /* defined(__need_va_copy) */
78-
79-
#endif

clang/lib/Headers/stddef.h

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,10 @@
1414
* need to use some of its interfaces. Otherwise this header provides all of
1515
* the expected interfaces.
1616
*
17-
* When clang modules are enabled, this header is a textual header. It ignores
18-
* its header guard so that multiple submodules can export its interfaces.
19-
* Take module SM with submodules A and B, whose headers both include stddef.h
20-
* When SM.A builds, __STDDEF_H will be defined. When SM.B builds, the
21-
* definition from SM.A will leak when building without local submodule
22-
* visibility. stddef.h wouldn't include any of its implementation headers, and
23-
* SM.B wouldn't import any of the stddef modules, and SM.B's `export *`
24-
* wouldn't export any stddef interfaces as expected. However, since stddef.h
25-
* ignores its header guard when building with modules, it all works as
26-
* expected.
27-
*
28-
* When clang modules are not enabled, the header guards can function in the
29-
* normal simple fashion.
17+
* When clang modules are enabled, this header is a textual header to support
18+
* the multiple include behavior. As such, it doesn't directly declare anything
19+
* so that it doesn't add duplicate declarations to all of its includers'
20+
* modules.
3021
*/
3122

3223
#if defined(__musl__)
@@ -36,20 +27,12 @@
3627

3728
#else
3829

39-
#if !defined(__STDDEF_H) || __has_feature(modules) || \
40-
(defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1) || \
41-
defined(__need_ptrdiff_t) || defined(__need_size_t) || \
42-
defined(__need_rsize_t) || defined(__need_wchar_t) || \
43-
defined(__need_NULL) || defined(__need_nullptr_t) || \
44-
defined(__need_unreachable) || defined(__need_max_align_t) || \
45-
defined(__need_offsetof) || defined(__need_wint_t)
46-
4730
#if !defined(__need_ptrdiff_t) && !defined(__need_size_t) && \
4831
!defined(__need_rsize_t) && !defined(__need_wchar_t) && \
4932
!defined(__need_NULL) && !defined(__need_nullptr_t) && \
5033
!defined(__need_unreachable) && !defined(__need_max_align_t) && \
5134
!defined(__need_offsetof) && !defined(__need_wint_t)
52-
#define __STDDEF_H
35+
#include <__stddef_header_macro.h>
5336
#define __need_ptrdiff_t
5437
#define __need_size_t
5538
/* ISO9899:2011 7.20 (C11 Annex K): Define rsize_t if __STDC_WANT_LIB_EXT1__ is
@@ -130,6 +113,4 @@ __WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */
130113
#undef __need_wint_t
131114
#endif /* __need_wint_t */
132115

133-
#endif
134-
135116
#endif /* !defined(__musl__) */

llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ copy("Headers") {
9797
"__clang_hip_stdlib.h",
9898
"__stdarg___gnuc_va_list.h",
9999
"__stdarg___va_copy.h",
100+
"__stdarg_header_macro.h",
100101
"__stdarg_va_arg.h",
101102
"__stdarg_va_copy.h",
102103
"__stdarg_va_list.h",
104+
"__stddef_header_macro.h",
103105
"__stddef_max_align_t.h",
104106
"__stddef_null.h",
105107
"__stddef_nullptr_t.h",

0 commit comments

Comments
 (0)