diff --git a/clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp b/clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp --- a/clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp +++ b/clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp @@ -14,6 +14,7 @@ const HeaderMapCollector::RegexHeaderMap *getSTLPostfixHeaderMap() { static const HeaderMapCollector::RegexHeaderMap STLPostfixHeaderMap = { {"include/__stddef_max_align_t.h$", ""}, + {"include/__stddef_null.h$", ""}, {"include/__wmmintrin_aes.h$", ""}, {"include/__wmmintrin_pclmul.h$", ""}, {"include/adxintrin.h$", ""}, diff --git a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp --- a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp +++ b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp @@ -20,6 +20,7 @@ namespace { const std::pair IncludeMappings[] = { {"include/__stddef_max_align_t.h", ""}, + {"include/__stddef_null.h", ""}, {"include/__wmmintrin_aes.h", ""}, {"include/__wmmintrin_pclmul.h", ""}, {"include/adxintrin.h", ""}, diff --git a/clang/docs/tools/clang-formatted-files.txt b/clang/docs/tools/clang-formatted-files.txt --- a/clang/docs/tools/clang-formatted-files.txt +++ b/clang/docs/tools/clang-formatted-files.txt @@ -492,6 +492,7 @@ clang/lib/Headers/__clang_cuda_texture_intrinsics.h clang/lib/Headers/__clang_hip_libdevice_declares.h clang/lib/Headers/__stddef_max_align_t.h +clang/lib/Headers/__stddef_null.h clang/lib/Headers/openmp_wrappers/complex.h clang/lib/Headers/openmp_wrappers/complex_cmath.h clang/lib/Headers/openmp_wrappers/math.h diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp --- a/clang/lib/Basic/Module.cpp +++ b/clang/lib/Basic/Module.cpp @@ -298,8 +298,9 @@ if (Requested->isSubModuleOf(Use)) return true; - // Anyone is allowed to use our builtin stddef.h and its accompanying module. - if (!Requested->Parent && Requested->Name == "_Builtin_stddef_max_align_t") + // Anyone is allowed to use our builtin stddef.h and its accompanying modules. + if (!Requested->Parent && (Requested->Name == "_Builtin_stddef_max_align_t" || + Requested->Name == "_Builtin_stddef_null")) return true; if (NoUndeclaredIncludes) diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt --- a/clang/lib/Headers/CMakeLists.txt +++ b/clang/lib/Headers/CMakeLists.txt @@ -14,6 +14,7 @@ stdbool.h stddef.h __stddef_max_align_t.h + __stddef_null.h stdint.h stdnoreturn.h tgmath.h diff --git a/clang/lib/Headers/__stddef_null.h b/clang/lib/Headers/__stddef_null.h new file mode 100644 --- /dev/null +++ b/clang/lib/Headers/__stddef_null.h @@ -0,0 +1,32 @@ +/*===---- __stddef_null.h - Definition of NULL -----------------------------=== + * + * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. + * See https://llvm.org/LICENSE.txt for license information. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + * + *===-----------------------------------------------------------------------=== + */ + +#ifndef __STDDEF_NULL_H +#define __STDDEF_NULL_H + +#undef NULL +#ifdef __cplusplus +#if !defined(__MINGW32__) && !defined(_MSC_VER) +#define NULL __null +#else +#define NULL 0 +#endif +#else +#define NULL ((void *)0) +#endif +#ifdef __cplusplus +#if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED) +namespace std { +typedef decltype(nullptr) nullptr_t; +} +using ::std::nullptr_t; +#endif +#endif + +#endif diff --git a/clang/lib/Headers/module.modulemap b/clang/lib/Headers/module.modulemap --- a/clang/lib/Headers/module.modulemap +++ b/clang/lib/Headers/module.modulemap @@ -157,6 +157,11 @@ header "__stddef_max_align_t.h" } +module _Builtin_stddef_null [system] { + header "__stddef_null.h" + export * +} + module opencl_c { requires opencl header "opencl-c.h" diff --git a/clang/lib/Headers/stddef.h b/clang/lib/Headers/stddef.h --- a/clang/lib/Headers/stddef.h +++ b/clang/lib/Headers/stddef.h @@ -78,22 +78,7 @@ #endif /* defined(__need_wchar_t) */ #if defined(__need_NULL) -#undef NULL -#ifdef __cplusplus -# if !defined(__MINGW32__) && !defined(_MSC_VER) -# define NULL __null -# else -# define NULL 0 -# endif -#else -# define NULL ((void*)0) -#endif -#ifdef __cplusplus -#if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED) -namespace std { typedef decltype(nullptr) nullptr_t; } -using ::std::nullptr_t; -#endif -#endif +#include <__stddef_null.h> #undef __need_NULL #endif /* defined(__need_NULL) */ diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -529,7 +529,7 @@ // We have found a module, but we don't use it. if (NotUsed) { Diags.Report(FilenameLoc, diag::err_undeclared_use_of_module) - << RequestingModule->getTopLevelModule()->Name << Filename; + << RequestingModule->getFullModuleName() << Filename; return; } diff --git a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h --- a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h +++ b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h @@ -20,6 +20,7 @@ #include #include // IWYU pragma: no_include <__stddef_max_align_t.h> +// IWYU pragma: no_include <__stddef_null.h> namespace gwp_asan { // This class is the primary implementation of the allocator portion of GWP- diff --git a/llvm/test/DebugInfo/Generic/assignment-tracking/sroa/unspecified-var-size.ll b/llvm/test/DebugInfo/Generic/assignment-tracking/sroa/unspecified-var-size.ll --- a/llvm/test/DebugInfo/Generic/assignment-tracking/sroa/unspecified-var-size.ll +++ b/llvm/test/DebugInfo/Generic/assignment-tracking/sroa/unspecified-var-size.ll @@ -34,22 +34,23 @@ !5 = !DINamespace(name: "std", scope: null) !6 = !DIDerivedType(tag: DW_TAG_typedef, name: "max_align_t", file: !7, line: 24, baseType: !8) !7 = !DIFile(filename: "clang/12.0.0/include/__stddef_max_align_t.h", directory: "/") -!8 = !DICompositeType(tag: DW_TAG_structure_type, file: !7, line: 19, size: 256, flags: DIFlagFwdDecl, identifier: "_ZTS11max_align_t") -!9 = !DIFile(filename: "include/c++/7.5.0/cstddef", directory: "") -!10 = !{i32 7, !"Dwarf Version", i32 4} -!11 = !{i32 2, !"Debug Info Version", i32 3} -!12 = !{i32 1, !"wchar_size", i32 4} -!13 = !{!"clang version 12.0.0"} -!14 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funDn", scope: !1, file: !1, line: 20, type: !15, scopeLine: 20, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !20) -!15 = !DISubroutineType(types: !16) -!16 = !{null, !17} -!17 = !DIDerivedType(tag: DW_TAG_typedef, name: "nullptr_t", scope: !5, file: !18, line: 235, baseType: !19) -!18 = !DIFile(filename: "include/x86_64-linux-gnu/c++/7.5.0/bits/c++config.h", directory: "") -!19 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)") -!20 = !{!21} -!21 = !DILocalVariable(arg: 1, scope: !14, file: !1, line: 20, type: !17) -!22 = distinct !DIAssignID() -!23 = !DILocation(line: 0, scope: !14) -!28 = distinct !DIAssignID() -!29 = !DILocation(line: 20, column: 27, scope: !14) -!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true} +!8 = !DIFile(filename: "clang/12.0.0/include/__stddef_null.h", directory: "/") +!9 = !DICompositeType(tag: DW_TAG_structure_type, file: !7, line: 19, size: 256, flags: DIFlagFwdDecl, identifier: "_ZTS11max_align_t") +!10 = !DIFile(filename: "include/c++/7.5.0/cstddef", directory: "") +!11 = !{i32 7, !"Dwarf Version", i32 4} +!12 = !{i32 2, !"Debug Info Version", i32 3} +!13 = !{i32 1, !"wchar_size", i32 4} +!14 = !{!"clang version 12.0.0"} +!15 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funDn", scope: !1, file: !1, line: 20, type: !15, scopeLine: 20, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !20) +!16 = !DISubroutineType(types: !16) +!17 = !{null, !17} +!18 = !DIDerivedType(tag: DW_TAG_typedef, name: "nullptr_t", scope: !5, file: !18, line: 235, baseType: !19) +!19 = !DIFile(filename: "include/x86_64-linux-gnu/c++/7.5.0/bits/c++config.h", directory: "") +!20 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)") +!21 = !{!21} +!22 = !DILocalVariable(arg: 1, scope: !14, file: !1, line: 20, type: !17) +!23 = distinct !DIAssignID() +!24 = !DILocation(line: 0, scope: !14) +!29 = distinct !DIAssignID() +!30 = !DILocation(line: 20, column: 27, scope: !14) +!1001 = !{i32 7, !"debug-info-assignment-tracking", i1 true} diff --git a/llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn b/llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn --- a/llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn +++ b/llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn @@ -88,6 +88,7 @@ "__clang_hip_runtime_wrapper.h", "__clang_hip_stdlib.h", "__stddef_max_align_t.h", + "__stddef_null.h", "__wmmintrin_aes.h", "__wmmintrin_pclmul.h", "adxintrin.h",