Skip to content

Commit 7adce0d

Browse files
git apple-llvm automergerian-twilightcoder
authored andcommitted
[cherry-pick stable/20230725] [Modules] Make clang modules for the C standard library headers
Differential Revision: https://reviews.llvm.org/D159064 rdar://105819340
1 parent 3e89013 commit 7adce0d

26 files changed

+598
-163
lines changed

clang/lib/Basic/Module.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,7 @@ bool Module::directlyUses(const Module *Requested) {
308308
// Anyone is allowed to use our builtin stdarg.h and stddef.h and their
309309
// accompanying modules.
310310
if (Requested->getTopLevelModuleName() == "_Builtin_stdarg" ||
311-
Requested->getTopLevelModuleName() == "_Builtin_stddef" ||
312-
(!Requested->Parent && Requested->Name == "_Builtin_stddef_max_align_t"))
311+
Requested->getTopLevelModuleName() == "_Builtin_stddef")
313312
return true;
314313

315314
if (NoUndeclaredIncludes)

clang/lib/Headers/__stddef_max_align_t.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*===---- __stddef_max_align_t.h - Definition of max_align_t for modules ---===
1+
/*===---- __stddef_max_align_t.h - Definition of max_align_t ---------------===
22
*
33
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
* See https://llvm.org/LICENSE.txt for license information.

clang/lib/Headers/__stddef_null.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
*===-----------------------------------------------------------------------===
88
*/
99

10+
#if !defined(NULL) || !__has_feature(modules)
11+
12+
/* linux/stddef.h will define NULL to 0. glibc (and other) headers then define
13+
* __need_NULL and rely on stddef.h to redefine NULL to the correct value again.
14+
* Modules don't support redefining macros like that, but support that pattern
15+
* in the non-modules case.
16+
*/
1017
#undef NULL
18+
1119
#ifdef __cplusplus
1220
#if !defined(__MINGW32__) && !defined(_MSC_VER)
1321
#define NULL __null
@@ -17,3 +25,5 @@
1725
#else
1826
#define NULL ((void *)0)
1927
#endif
28+
29+
#endif

clang/lib/Headers/__stddef_nullptr_t.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@
77
*===-----------------------------------------------------------------------===
88
*/
99

10-
#if !defined(_NULLPTR_T) || __has_feature(modules)
11-
/* Always define nullptr_t when modules are available. */
12-
#if !__has_feature(modules)
10+
#ifndef _NULLPTR_T
1311
#define _NULLPTR_T
14-
#endif
12+
1513
#ifdef __cplusplus
1614
#if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED)
1715
namespace std {
1816
typedef decltype(nullptr) nullptr_t;
1917
}
2018
using ::std::nullptr_t;
2119
#endif
22-
#else
20+
/* FIXME: This is using the placeholder dates Clang produces for these macros
21+
in C2x mode; switch to the correct values once they've been published. */
22+
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L
2323
typedef typeof(nullptr) nullptr_t;
2424
#endif
25+
2526
#endif

clang/lib/Headers/__stddef_offsetof.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*===-----------------------------------------------------------------------===
88
*/
99

10-
#if !defined(offsetof) || __has_feature(modules)
11-
/* Always define offsetof when modules are available. */
10+
#ifndef offsetof
1211
#define offsetof(t, d) __builtin_offsetof(t, d)
1312
#endif

clang/lib/Headers/__stddef_ptrdiff_t.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
*===-----------------------------------------------------------------------===
88
*/
99

10-
#if !defined(_PTRDIFF_T) || __has_feature(modules)
11-
/* Always define ptrdiff_t when modules are available. */
12-
#if !__has_feature(modules)
10+
#ifndef _PTRDIFF_T
1311
#define _PTRDIFF_T
14-
#endif
12+
1513
typedef __PTRDIFF_TYPE__ ptrdiff_t;
14+
1615
#endif

clang/lib/Headers/__stddef_rsize_t.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
*===-----------------------------------------------------------------------===
88
*/
99

10-
#if !defined(_RSIZE_T) || __has_feature(modules)
11-
/* Always define rsize_t when modules are available. */
12-
#if !__has_feature(modules)
10+
#ifndef _RSIZE_T
1311
#define _RSIZE_T
14-
#endif
12+
1513
typedef __SIZE_TYPE__ rsize_t;
14+
1615
#endif

clang/lib/Headers/__stddef_size_t.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
*===-----------------------------------------------------------------------===
88
*/
99

10-
#if !defined(_SIZE_T) || __has_feature(modules)
11-
/* Always define size_t when modules are available. */
12-
#if !__has_feature(modules)
10+
#ifndef _SIZE_T
1311
#define _SIZE_T
14-
#endif
12+
1513
typedef __SIZE_TYPE__ size_t;
14+
1615
#endif

clang/lib/Headers/__stddef_unreachable.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*===-----------------------------------------------------------------------===
88
*/
99

10-
#if !defined(unreachable) || __has_feature(modules)
11-
/* Always define unreachable when modules are available. */
10+
#ifndef unreachable
1211
#define unreachable() __builtin_unreachable()
1312
#endif

clang/lib/Headers/__stddef_wchar_t.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
*/
99

1010
#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)
11+
12+
#ifndef _WCHAR_T
1413
#define _WCHAR_T
15-
#if defined(_MSC_EXTENSIONS)
14+
15+
#ifdef _MSC_EXTENSIONS
1616
#define _WCHAR_T_DEFINED
1717
#endif
18-
#endif
18+
1919
typedef __WCHAR_TYPE__ wchar_t;
20+
2021
#endif
22+
2123
#endif

0 commit comments

Comments
 (0)