[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-10-03 Thread Ian Anderson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9a7a6dd3c358: [Modules] Make clang modules for the C 
standard library headers (authored by iana).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

Files:
  clang/lib/Basic/Module.cpp
  clang/lib/Headers/__stddef_max_align_t.h
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/module.modulemap
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/Inputs/System/usr/include/complex.h
  clang/test/Modules/Inputs/System/usr/include/inttypes.h
  clang/test/Modules/Inputs/System/usr/include/math.h
  clang/test/Modules/Inputs/System/usr/include/module.map
  clang/test/Modules/Inputs/System/usr/include/stdint.h
  clang/test/Modules/compiler_builtins.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -4,4 +4,6 @@
 
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,13 +1,29 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
 ptrdiff_t pdt;
 
-size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@__stddef_size_t.h:* {{here}}
+// size_t is declared in both size_t.h and __stddef_size_t.h, both of which are
+// modular headers. Regardless of whether stddef.h joins the StdDef test module
+// or is in its _Builtin_stddef module, __stddef_size_t.h will be in
+// _Builtin_stddef.size_t. It's not defined which module will win as the expected
+// provider of size_t. For the purposes of this test it doesn't matter which header
+// gets reported, just as long as it isn't other.h or include_again.h.
+size_t st; // expected-error-re {{missing '#include "{{size_t|__stddef_size_t}}.h"'; 'size_t' must be declared before it is used}}
+// expected-note@size_t.h:* 0+ {{here}}
+// expected-note@__stddef_size_t.h:* 0+ {{here}}
 
 #include "include_again.h"
+// Includes  which includes <__stddef_size_t.h> which imports the
+// _Builtin_stddef.size_t module.
 
 size_t st2;
+
+#include "size_t.h"
+// Redeclares size_t, but the type merger should figure it out.
+
+size_t st3;
Index: clang/test/Modules/compiler_builtins.m
===
--- clang/test/Modules/compiler_builtins.m
+++ clang/test/Modules/compiler_builtins.m
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -DNO_SYSTEM_MODULES -verify
 // expected-no-diagnostics
 
 #ifdef __SSE__
@@ -11,3 +11,19 @@
 #ifdef __AVX2__
 @import _Builtin_intrinsics.intel.avx2;
 #endif
+
+#ifndef NO_SYSTEM_MODULES
+@import _Builtin_float;
+@import _Builtin_inttypes;
+@import _Builtin_iso646;
+@import _Builtin_limits;
+@import 

[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-10-02 Thread Ian Anderson via Phabricator via cfe-commits
iana marked 5 inline comments as done.
iana added inline comments.



Comment at: clang/test/Modules/Inputs/System/usr/include/stdint.h:2
 typedef int my_awesome_nonstandard_integer_type;
+
+/* C99 7.18.1.1 Exact-width integer types.

dexonsmith wrote:
> Bigcheese wrote:
> > iana wrote:
> > > dexonsmith wrote:
> > > > benlangmuir wrote:
> > > > > iana wrote:
> > > > > > iana wrote:
> > > > > > > benlangmuir wrote:
> > > > > > > > Why do we need all this code now (I assume this is copied from 
> > > > > > > > the real header)?
> > > > > > > It's to support the tests I added to Modules/compiler_builtins.m. 
> > > > > > > stdatomic.h and inttypes.h rely on stdint.h contents from the C 
> > > > > > > library, and on complex.h and inttypes.h and math.h being 
> > > > > > > present. I could just test the modules with `-ffreestanding` I 
> > > > > > > think, would that be better?
> > > > > > (and yes I just copied it from the builtin header)
> > > > > I'm not sure what the best approach is here, but this seems heavy for 
> > > > > a test.  Do we expect to need to keep this up to date? If so maybe 
> > > > > ffreestanding for the specific test cases this affects would be a 
> > > > > better tradeoff.  Maybe someone else has a suggestion here
> > > > This reflects *most* of the content in `stdint.h`.
> > > > 
> > > > One idea would be to copy the full header over during the test setup 
> > > > and fix it up, either:
> > > > - strip out the header/footer or
> > > > - `sed -e "s/__STDC_HOSTED__/0/g"`
> > > > so that it always provides content (even when not freestanding).
> > > IMO it doesn't need to be that sophisticated, the types just have to 
> > > exist for stdtomic.h to compile. I could chop all the comments and define 
> > > everything to `int` and I think that'd be fine too.
> > Looking at stdatomic.h I think this approach would be fine. It just wants 
> > the types to exist.
> SGTM.
Mostly copied clang/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/stdint.h


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-10-02 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 557549.
iana added a comment.

Minimize the testing stdint.h


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

Files:
  clang/lib/Basic/Module.cpp
  clang/lib/Headers/__stddef_max_align_t.h
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/module.modulemap
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/Inputs/System/usr/include/complex.h
  clang/test/Modules/Inputs/System/usr/include/inttypes.h
  clang/test/Modules/Inputs/System/usr/include/math.h
  clang/test/Modules/Inputs/System/usr/include/module.map
  clang/test/Modules/Inputs/System/usr/include/stdint.h
  clang/test/Modules/compiler_builtins.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -4,4 +4,6 @@
 
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,13 +1,29 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
 ptrdiff_t pdt;
 
-size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@__stddef_size_t.h:* {{here}}
+// size_t is declared in both size_t.h and __stddef_size_t.h, both of which are
+// modular headers. Regardless of whether stddef.h joins the StdDef test module
+// or is in its _Builtin_stddef module, __stddef_size_t.h will be in
+// _Builtin_stddef.size_t. It's not defined which module will win as the expected
+// provider of size_t. For the purposes of this test it doesn't matter which header
+// gets reported, just as long as it isn't other.h or include_again.h.
+size_t st; // expected-error-re {{missing '#include "{{size_t|__stddef_size_t}}.h"'; 'size_t' must be declared before it is used}}
+// expected-note@size_t.h:* 0+ {{here}}
+// expected-note@__stddef_size_t.h:* 0+ {{here}}
 
 #include "include_again.h"
+// Includes  which includes <__stddef_size_t.h> which imports the
+// _Builtin_stddef.size_t module.
 
 size_t st2;
+
+#include "size_t.h"
+// Redeclares size_t, but the type merger should figure it out.
+
+size_t st3;
Index: clang/test/Modules/compiler_builtins.m
===
--- clang/test/Modules/compiler_builtins.m
+++ clang/test/Modules/compiler_builtins.m
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -DNO_SYSTEM_MODULES -verify
 // expected-no-diagnostics
 
 #ifdef __SSE__
@@ -11,3 +11,19 @@
 #ifdef __AVX2__
 @import _Builtin_intrinsics.intel.avx2;
 #endif
+
+#ifndef NO_SYSTEM_MODULES
+@import _Builtin_float;
+@import _Builtin_inttypes;
+@import _Builtin_iso646;
+@import _Builtin_limits;
+@import _Builtin_stdalign;
+@import _Builtin_stdarg;
+@import _Builtin_stdatomic;
+@import _Builtin_stdbool;

[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

2023-09-28 Thread Ian Anderson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0ea3d88bdb16: [Modules] Add a flag to control builtin 
headers being in system modules (authored by iana).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159483/new/

https://reviews.llvm.org/D159483

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/test/Driver/Inputs/MacOSX99.0.sdk/SDKSettings.json
  clang/test/Driver/darwin-builtin-modules.c
  clang/test/Modules/Werror-Wsystem-headers.m
  clang/test/Modules/context-hash.c
  clang/test/Modules/crash-vfs-include-pch.m
  clang/test/Modules/cstd.m
  clang/test/Modules/pch-used.m
  clang/test/Modules/shadowed-submodule.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -3,5 +3,5 @@
 size_t getSize(void);
 
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
Index: clang/test/Modules/shadowed-submodule.m
===
--- clang/test/Modules/shadowed-submodule.m
+++ clang/test/Modules/shadowed-submodule.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/shadowed-submodule/Foo -I %S/Inputs/shadowed-submodule/A2 %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/shadowed-submodule/Foo -I %S/Inputs/shadowed-submodule/A2 %s -verify
 
 @import Foo; // expected-error {{module 'A' was built in directory}}
  // expected-note@shadowed-submodule.m:4 {{imported by module 'Foo'}}
Index: clang/test/Modules/pch-used.m
===
--- clang/test/Modules/pch-used.m
+++ clang/test/Modules/pch-used.m
@@ -1,8 +1,8 @@
 // UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
 // RUN: rm -rf %t
 // RUN: mkdir %t
-// RUN: %clang_cc1 -x objective-c-header -emit-pch %S/Inputs/pch-used.h -o %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include
-// RUN: %clang_cc1 %s -include-pch %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -x objective-c-header -emit-pch %S/Inputs/pch-used.h -o %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include
+// RUN: %clang_cc1 %s -include-pch %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include -emit-llvm -o - | FileCheck %s
 
 void f(void) { SPXTrace(); }
 void g(void) { double x = DBL_MAX; }
Index: clang/test/Modules/cstd.m
===
--- clang/test/Modules/cstd.m
+++ clang/test/Modules/cstd.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -internal-isystem %S/Inputs/System/usr/include -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -D__need_wint_t -Werror=implicit-function-declaration %s
+// RUN: %clang_cc1 -fsyntax-only -internal-isystem %S/Inputs/System/usr/include -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -D__need_wint_t -Werror=implicit-function-declaration %s
 
 @import uses_other_constants;
 const double other_value = DBL_MAX;
Index: clang/test/Modules/crash-vfs-include-pch.m
===
--- clang/test/Modules/crash-vfs-include-pch.m
+++ clang/test/Modules/crash-vfs-include-pch.m
@@ -5,14 +5,14 @@
 
 // RUN: %clang_cc1 -x objective-c-header -emit-pch %S/Inputs/pch-used.h \
 // RUN: -o 

[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

2023-09-19 Thread Ian Anderson via Phabricator via cfe-commits
iana marked 2 inline comments as done.
iana added inline comments.



Comment at: clang/include/clang/Basic/LangOptions.def:176
 COMPATIBLE_LANGOPT(CPlusPlusModules, 1, 0, "C++ modules syntax")
+LANGOPT(BuiltinHeadersInSystemModules, 1, 0, "builtin headers belong to system 
modules, and _Builtin_ modules are ignored for cstdlib headers")
 BENIGN_ENUM_LANGOPT(CompilingModule, CompilingModuleKind, 3, CMK_None,

vsapsai wrote:
> iana wrote:
> > vsapsai wrote:
> > > Why not to make the default value `true` to preserve the old behavior and 
> > > switch on the new behavior in the driver? It's not a veiled way to force 
> > > you to change it, I'm genuinely curious and want to consider pro/cons of 
> > > various alternatives.
> > I did it this way because the current behavior is nonintuitive and just 
> > kind of bizarre. I had no idea that `Darwin.C.stdint` also included the 
> > compiler's stdint.h, and that the OS's stdint.h was treated textually. I 
> > thought it would be better for the default behavior to be for modules to 
> > behave consistently and obviously, not have secret special cases, and be 
> > usable with C++.
> > 
> > The con of course is that if anyone besides Apple depends on the current 
> > behavior they're going to either have to fix their OS modules or add this 
> > flag. I'm not sure if other platforms have a convenient driver class where 
> > they can do that.
> I'm fine with the more aggressive approach as long as we test Swift on Linux. 
> That's the only project I know that is willing to keep using clang modules. 
> For other projects if things break and it is a motivation to move to C++ 
> modules, it is a positive direction, as for me.
> 
> Another reason I wanted to be more cautious is because of 
> https://discourse.llvm.org/t/configure-script-breakage-with-the-new-werror-implicit-function-declaration/65213
>  change. Clang started enforcing 20+ years old rule and that has broken some 
> stuff. So I don't see "you should've known better before relying on this 
> behavior" as a good argument.
> 
> Anyway, for Swift testing here is what you can do (if you have your own plan, 
> go ahead):
> 1. Make PR for the same change as this one at 
> https://github.com/apple/llvm-project/
> 2. Create inconsequential PR at https://github.com/apple/swift/
> 3. Use [[ 
> https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#cross-repository-testing
>  | Cross Repository Testing ]] to test clang change from swift on Linux.
If things break I think we would just add the flag to a few more drivers and 
fix it like that. I'm definitely not trying to drive anyone away from clang 
modules, I'm just hoping they don't need the strange current behavior. If it 
turns out to be too much of a mess then it can be on by default and we'll do an 
fno flag instead that we can turn off in the Darwin driver when we're ready.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159483/new/

https://reviews.llvm.org/D159483

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

2023-09-18 Thread Ian Anderson via Phabricator via cfe-commits
iana marked an inline comment as done.
iana added inline comments.



Comment at: clang/include/clang/Basic/LangOptions.def:176
 COMPATIBLE_LANGOPT(CPlusPlusModules, 1, 0, "C++ modules syntax")
+LANGOPT(BuiltinHeadersInSystemModules, 1, 0, "builtin headers belong to system 
modules, and _Builtin_ modules are ignored for cstdlib headers")
 BENIGN_ENUM_LANGOPT(CompilingModule, CompilingModuleKind, 3, CMK_None,

vsapsai wrote:
> Why not to make the default value `true` to preserve the old behavior and 
> switch on the new behavior in the driver? It's not a veiled way to force you 
> to change it, I'm genuinely curious and want to consider pro/cons of various 
> alternatives.
I did it this way because the current behavior is nonintuitive and just kind of 
bizarre. I had no idea that `Darwin.C.stdint` also included the compiler's 
stdint.h, and that the OS's stdint.h was treated textually. I thought it would 
be better for the default behavior to be for modules to behave consistently and 
obviously, not have secret special cases, and be usable with C++.

The con of course is that if anyone besides Apple depends on the current 
behavior they're going to either have to fix their OS modules or add this flag. 
I'm not sure if other platforms have a convenient driver class where they can 
do that.



Comment at: clang/lib/Driver/ToolChains/Darwin.cpp:2860-2861
+return SDKVersion >= VersionTuple(99U);
+  default:
+return true;
+  }

vsapsai wrote:
> Another question regarding defaults. Doesn't look consistent with your 
> position
> > [...] I thought it safer to default to the current behavior which is false.
> 
> Personally I gravitate towards `false` for extra safety but it's not a strong 
> opinion.
default only covers DriverKit, which can be true. Any future platforms should 
also default to true.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159483/new/

https://reviews.llvm.org/D159483

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-18 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D159064#4647709 , @vsapsai wrote:

> Still going through the patch and through the discussion. But wanted to ask 
> if there are any complications in reverting this change? For libc++ we've 
> discussed that we don't really know the perf impact of multiple small 
> modules. So I want to make sure we aren't making decisions that make it 
> impossible to revert the change later.

I don't think we can really revert the C stdlib headers each being in their own 
module; there isn't any other way around the module layering maze. libc++ is a 
bit different, it's not just the C stdlib headers that are each in their own 
module, it's every one of the ~1000 headers right now. I have misgivings about 
that, I made D155141  to reduce that closer 
to 150 modules instead of 1000 but it was poorly received. I might try to 
address some of the concerns after I get this one worked through.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-14 Thread Ian Anderson via Phabricator via cfe-commits
iana added inline comments.



Comment at: clang/lib/Headers/module.modulemap:269
+  explicit module wint_t {
+header "__stddef_wint_t.h"
+export *

iana wrote:
> Arguably this should be textual since stddef.h shouldn't own wint_t and it's 
> just here for compatibility. Otherwise I think the ODR would force wchar.h to 
> define need_wint and include stddef.h which is kind of weird?
wint_t doesn't need to be textual, it can just be split out of stddef so that 
it doesn't get precompiled, and won't be see at all normally.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-13 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 556630.
iana added a comment.

Actually allow the stdarg module


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

Files:
  clang/lib/Basic/Module.cpp
  clang/lib/Headers/__stddef_max_align_t.h
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/module.modulemap
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/Inputs/System/usr/include/complex.h
  clang/test/Modules/Inputs/System/usr/include/inttypes.h
  clang/test/Modules/Inputs/System/usr/include/math.h
  clang/test/Modules/Inputs/System/usr/include/module.map
  clang/test/Modules/Inputs/System/usr/include/stdint.h
  clang/test/Modules/compiler_builtins.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -4,4 +4,6 @@
 
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,12 +1,22 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=no-stddef-module -fno-modules-error-recovery
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=yes-stddef-module -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
 ptrdiff_t pdt;
 
-size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@__stddef_size_t.h:* {{here}}
+// size_t is declared in both size_t.h and __stddef_size_t.h, both of which are
+// modular headers. Regardless of whether stddef.h joins the StdDef test module
+// or is in its _Builtin_stddef module, __stddef_size_t.h will be in
+// _Builtin_stddef.size_t. It's not defined which module will win as the expected
+// provider of size_t. For the purposes of this test it doesn't matter which header
+// gets reported, just as long as it isn't other.h or include_again.h.
+size_t st; // no-stddef-module-error {{missing '#include "size_t.h"'; 'size_t' must be declared before it is used}} \
+  yes-stddef-module-error {{missing '#include "size_t.h"'; 'size_t' must be declared before it is used}}
+// no-stddef-module-note@size_t.h:* {{here}}
+// yes-stddef-module-note@size_t.h:* {{here}}
 
 #include "include_again.h"
 
Index: clang/test/Modules/compiler_builtins.m
===
--- clang/test/Modules/compiler_builtins.m
+++ clang/test/Modules/compiler_builtins.m
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -DNO_SYSTEM_MODULES -verify
 // expected-no-diagnostics
 
 #ifdef __SSE__
@@ -11,3 +11,19 @@
 #ifdef __AVX2__
 @import _Builtin_intrinsics.intel.avx2;
 #endif
+
+#ifndef NO_SYSTEM_MODULES
+@import _Builtin_float;
+@import _Builtin_inttypes;
+@import _Builtin_iso646;
+@import _Builtin_limits;
+@import 

[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-13 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 556629.
iana added a comment.

Adjust for the changes in D159483 .

Mostly the header guards that were added in that review have moved to this one, 
the stdarg module needs to always be allowed, and a few tests needed to adjust 
for the stdarg/stddef implemenetation header being always modular.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

Files:
  clang/lib/Basic/Module.cpp
  clang/lib/Headers/__stddef_max_align_t.h
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/module.modulemap
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/Inputs/System/usr/include/complex.h
  clang/test/Modules/Inputs/System/usr/include/inttypes.h
  clang/test/Modules/Inputs/System/usr/include/math.h
  clang/test/Modules/Inputs/System/usr/include/module.map
  clang/test/Modules/Inputs/System/usr/include/stdint.h
  clang/test/Modules/compiler_builtins.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -4,4 +4,6 @@
 
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,12 +1,22 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=no-stddef-module -fno-modules-error-recovery
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=yes-stddef-module -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
 ptrdiff_t pdt;
 
-size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@__stddef_size_t.h:* {{here}}
+// size_t is declared in both size_t.h and __stddef_size_t.h, both of which are
+// modular headers. Regardless of whether stddef.h joins the StdDef test module
+// or is in its _Builtin_stddef module, __stddef_size_t.h will be in
+// _Builtin_stddef.size_t. It's not defined which module will win as the expected
+// provider of size_t. For the purposes of this test it doesn't matter which header
+// gets reported, just as long as it isn't other.h or include_again.h.
+size_t st; // no-stddef-module-error {{missing '#include "size_t.h"'; 'size_t' must be declared before it is used}} \
+  yes-stddef-module-error {{missing '#include "size_t.h"'; 'size_t' must be declared before it is used}}
+// no-stddef-module-note@size_t.h:* {{here}}
+// yes-stddef-module-note@size_t.h:* {{here}}
 
 #include "include_again.h"
 
Index: clang/test/Modules/compiler_builtins.m
===
--- clang/test/Modules/compiler_builtins.m
+++ clang/test/Modules/compiler_builtins.m
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -DNO_SYSTEM_MODULES -verify
 // 

[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

2023-09-13 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 556627.
iana added a comment.

__stddef_max_align_t.h always needs a header guard, because the type merger 
can't handle struct's. If it has a header guard then it always needs to have a 
module too, even if `-fbuiltin-headers-in-system-modules` is passed.

Change ModuleMap to not ignore the builtin modules completely, but rather to 
just skip their top level headers (which is isBuiltinHeaderName + inttypes.h 
and stdnoreturn.h). With that change, the implementation headers are always 
modular, and `__has_feature(builtin_headers_in_system_modules)` is no longer 
necessary anywhere.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159483/new/

https://reviews.llvm.org/D159483

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/test/Driver/Inputs/MacOSX99.0.sdk/SDKSettings.json
  clang/test/Driver/darwin-builtin-modules.c
  clang/test/Modules/Werror-Wsystem-headers.m
  clang/test/Modules/context-hash.c
  clang/test/Modules/crash-vfs-include-pch.m
  clang/test/Modules/cstd.m
  clang/test/Modules/pch-used.m
  clang/test/Modules/shadowed-submodule.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -3,5 +3,5 @@
 size_t getSize(void);
 
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
Index: clang/test/Modules/shadowed-submodule.m
===
--- clang/test/Modules/shadowed-submodule.m
+++ clang/test/Modules/shadowed-submodule.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/shadowed-submodule/Foo -I %S/Inputs/shadowed-submodule/A2 %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/shadowed-submodule/Foo -I %S/Inputs/shadowed-submodule/A2 %s -verify
 
 @import Foo; // expected-error {{module 'A' was built in directory}}
  // expected-note@shadowed-submodule.m:4 {{imported by module 'Foo'}}
Index: clang/test/Modules/pch-used.m
===
--- clang/test/Modules/pch-used.m
+++ clang/test/Modules/pch-used.m
@@ -1,8 +1,8 @@
 // UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
 // RUN: rm -rf %t
 // RUN: mkdir %t
-// RUN: %clang_cc1 -x objective-c-header -emit-pch %S/Inputs/pch-used.h -o %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include
-// RUN: %clang_cc1 %s -include-pch %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -x objective-c-header -emit-pch %S/Inputs/pch-used.h -o %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include
+// RUN: %clang_cc1 %s -include-pch %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include -emit-llvm -o - | FileCheck %s
 
 void f(void) { SPXTrace(); }
 void g(void) { double x = DBL_MAX; }
Index: clang/test/Modules/cstd.m
===
--- clang/test/Modules/cstd.m
+++ clang/test/Modules/cstd.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -internal-isystem %S/Inputs/System/usr/include -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -D__need_wint_t -Werror=implicit-function-declaration %s
+// RUN: %clang_cc1 -fsyntax-only -internal-isystem %S/Inputs/System/usr/include -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -D__need_wint_t 

[PATCH] D158021: [clang][modules] Mark builtin header 'inttypes.h' for modules

2023-09-12 Thread Ian Anderson via Phabricator via cfe-commits
iana requested changes to this revision.
iana added a comment.
This revision now requires changes to proceed.

I was talking to Ben about this one a little today since I ended up needing to 
make the same `-isystem`/`-I` -> `-internal-isystem` switch in some of the unit 
tests in D159064 . I think it's just plain 
not supported to put isysroot/usr/include before resource-dir/include. That 
said, fusing resource-dir/include/inttypes.h with isysroot/usr/include is 
probably going to break the projects that messed that up, whereas having the 
two in different modules probably won't. So even though this change is correct, 
IMO it's not worth the trouble since we have to do D159064 
 to make the libc++ cstd header work anyway.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158021/new/

https://reviews.llvm.org/D158021

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-09 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 556356.
iana added a comment.

- Drop the -verify off the stddef tests so that I can get the full errors


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

Files:
  clang/lib/Basic/Module.cpp
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/module.modulemap
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/Inputs/System/usr/include/complex.h
  clang/test/Modules/Inputs/System/usr/include/inttypes.h
  clang/test/Modules/Inputs/System/usr/include/math.h
  clang/test/Modules/Inputs/System/usr/include/module.map
  clang/test/Modules/Inputs/System/usr/include/stdint.h
  clang/test/Modules/compiler_builtins.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -3,5 +3,7 @@
 size_t getSize(void);
 
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,12 +1,24 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -fno-modules-error-recovery
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
 ptrdiff_t pdt;
 
-size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@__stddef_size_t.h:* {{here}}
+// When builtin headers join system modules, stddef.h and its sub-headers have no
+// header guards, and so are seen last by include_again.h, which takes all of their
+// declarations including size_t even though size_t.h previously declared it.
+// When builtin headers don't join the system modules and instead get their own
+// modules, none of the stddef.h declarations go in the StdDef test module. size_t
+// is then declared in both StdDef.SizeT and _Builtin_stddef.size_t. For the
+// purposes of this test it doesn't matter which one gets reported, just as long
+// as it isn't other.h or include_again.h.
+size_t st; // no-stddef-module-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}} \
+  yes-stddef-module-error {{missing '#include "size_t.h"'; 'size_t' must be declared before it is used}}
+// no-stddef-module-note@__stddef_size_t.h:* {{here}}
+// yes-stddef-module-note@size_t.h:* {{here}}
 
 #include "include_again.h"
 
Index: clang/test/Modules/compiler_builtins.m
===
--- clang/test/Modules/compiler_builtins.m
+++ clang/test/Modules/compiler_builtins.m
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -DNO_SYSTEM_MODULES -verify
 // expected-no-diagnostics
 
 #ifdef __SSE__
@@ -11,3 +11,19 @@
 #ifdef __AVX2__
 @import _Builtin_intrinsics.intel.avx2;
 #endif
+
+#ifndef NO_SYSTEM_MODULES
+@import _Builtin_float;
+@import _Builtin_inttypes;
+@import _Builtin_iso646;
+@import _Builtin_limits;
+@import _Builtin_stdalign;
+@import _Builtin_stdarg;
+@import _Builtin_stdatomic;

[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-09 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 556355.
iana added a comment.

- Drop the -verify off the new tests so that I can get the full errors


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

Files:
  clang/lib/Basic/Module.cpp
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/module.modulemap
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/Inputs/System/usr/include/complex.h
  clang/test/Modules/Inputs/System/usr/include/inttypes.h
  clang/test/Modules/Inputs/System/usr/include/math.h
  clang/test/Modules/Inputs/System/usr/include/module.map
  clang/test/Modules/Inputs/System/usr/include/stdint.h
  clang/test/Modules/compiler_builtins.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -4,4 +4,6 @@
 
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,12 +1,24 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=no-stddef-module -fno-modules-error-recovery
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
 ptrdiff_t pdt;
 
-size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@__stddef_size_t.h:* {{here}}
+// When builtin headers join system modules, stddef.h and its sub-headers have no
+// header guards, and so are seen last by include_again.h, which takes all of their
+// declarations including size_t even though size_t.h previously declared it.
+// When builtin headers don't join the system modules and instead get their own
+// modules, none of the stddef.h declarations go in the StdDef test module. size_t
+// is then declared in both StdDef.SizeT and _Builtin_stddef.size_t. For the
+// purposes of this test it doesn't matter which one gets reported, just as long
+// as it isn't other.h or include_again.h.
+size_t st; // no-stddef-module-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}} \
+  yes-stddef-module-error {{missing '#include "size_t.h"'; 'size_t' must be declared before it is used}}
+// no-stddef-module-note@__stddef_size_t.h:* {{here}}
+// yes-stddef-module-note@size_t.h:* {{here}}
 
 #include "include_again.h"
 
Index: clang/test/Modules/compiler_builtins.m
===
--- clang/test/Modules/compiler_builtins.m
+++ clang/test/Modules/compiler_builtins.m
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -DNO_SYSTEM_MODULES -verify
 // expected-no-diagnostics
 
 #ifdef __SSE__
@@ -11,3 +11,19 @@
 #ifdef __AVX2__
 @import _Builtin_intrinsics.intel.avx2;
 #endif
+
+#ifndef NO_SYSTEM_MODULES
+@import _Builtin_float;
+@import _Builtin_inttypes;
+@import _Builtin_iso646;
+@import _Builtin_limits;
+@import _Builtin_stdalign;
+@import _Builtin_stdarg;
+@import _Builtin_stdatomic;
+@import _Builtin_stdbool;
+@import _Builtin_stddef;
+@import _Builtin_stdint;
+@import _Builtin_stdnoreturn;
+@import _Builtin_tgmath;
+@import 

[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-08 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 556313.
iana added a comment.

Add the header guard comment to __stddef_null.h


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

Files:
  clang/lib/Basic/Module.cpp
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/module.modulemap
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/Inputs/System/usr/include/complex.h
  clang/test/Modules/Inputs/System/usr/include/inttypes.h
  clang/test/Modules/Inputs/System/usr/include/math.h
  clang/test/Modules/Inputs/System/usr/include/module.map
  clang/test/Modules/Inputs/System/usr/include/stdint.h
  clang/test/Modules/compiler_builtins.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -4,4 +4,6 @@
 
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,12 +1,24 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=no-stddef-module -fno-modules-error-recovery
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=yes-stddef-module -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
 ptrdiff_t pdt;
 
-size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@__stddef_size_t.h:* {{here}}
+// When builtin headers join system modules, stddef.h and its sub-headers have no
+// header guards, and so are seen last by include_again.h, which takes all of their
+// declarations including size_t even though size_t.h previously declared it.
+// When builtin headers don't join the system modules and instead get their own
+// modules, none of the stddef.h declarations go in the StdDef test module. size_t
+// is then declared in both StdDef.SizeT and _Builtin_stddef.size_t. For the
+// purposes of this test it doesn't matter which one gets reported, just as long
+// as it isn't other.h or include_again.h.
+size_t st; // no-stddef-module-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}} \
+  yes-stddef-module-error {{missing '#include "size_t.h"'; 'size_t' must be declared before it is used}}
+// no-stddef-module-note@__stddef_size_t.h:* {{here}}
+// yes-stddef-module-note@size_t.h:* {{here}}
 
 #include "include_again.h"
 
Index: clang/test/Modules/compiler_builtins.m
===
--- clang/test/Modules/compiler_builtins.m
+++ clang/test/Modules/compiler_builtins.m
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -DNO_SYSTEM_MODULES -verify
 // expected-no-diagnostics
 
 #ifdef __SSE__
@@ -11,3 +11,19 @@
 #ifdef __AVX2__
 @import _Builtin_intrinsics.intel.avx2;
 #endif
+
+#ifndef NO_SYSTEM_MODULES
+@import _Builtin_float;
+@import _Builtin_inttypes;
+@import _Builtin_iso646;
+@import _Builtin_limits;
+@import _Builtin_stdalign;
+@import _Builtin_stdarg;
+@import _Builtin_stdatomic;
+@import _Builtin_stdbool;
+@import _Builtin_stddef;
+@import _Builtin_stdint;
+@import _Builtin_stdnoreturn;
+@import 

[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-08 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 556311.
iana added a comment.

Try deleting the module cache to fix the failing tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

Files:
  clang/lib/Basic/Module.cpp
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/module.modulemap
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/Inputs/System/usr/include/complex.h
  clang/test/Modules/Inputs/System/usr/include/inttypes.h
  clang/test/Modules/Inputs/System/usr/include/math.h
  clang/test/Modules/Inputs/System/usr/include/module.map
  clang/test/Modules/Inputs/System/usr/include/stdint.h
  clang/test/Modules/compiler_builtins.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -4,4 +4,6 @@
 
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,12 +1,24 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=no-stddef-module -fno-modules-error-recovery
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=yes-stddef-module -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
 ptrdiff_t pdt;
 
-size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@__stddef_size_t.h:* {{here}}
+// When builtin headers join system modules, stddef.h and its sub-headers have no
+// header guards, and so are seen last by include_again.h, which takes all of their
+// declarations including size_t even though size_t.h previously declared it.
+// When builtin headers don't join the system modules and instead get their own
+// modules, none of the stddef.h declarations go in the StdDef test module. size_t
+// is then declared in both StdDef.SizeT and _Builtin_stddef.size_t. For the
+// purposes of this test it doesn't matter which one gets reported, just as long
+// as it isn't other.h or include_again.h.
+size_t st; // no-stddef-module-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}} \
+  yes-stddef-module-error {{missing '#include "size_t.h"'; 'size_t' must be declared before it is used}}
+// no-stddef-module-note@__stddef_size_t.h:* {{here}}
+// yes-stddef-module-note@size_t.h:* {{here}}
 
 #include "include_again.h"
 
Index: clang/test/Modules/compiler_builtins.m
===
--- clang/test/Modules/compiler_builtins.m
+++ clang/test/Modules/compiler_builtins.m
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -DNO_SYSTEM_MODULES -verify
 // expected-no-diagnostics
 
 #ifdef __SSE__
@@ -11,3 +11,19 @@
 #ifdef __AVX2__
 @import _Builtin_intrinsics.intel.avx2;
 #endif
+
+#ifndef NO_SYSTEM_MODULES
+@import _Builtin_float;
+@import _Builtin_inttypes;
+@import _Builtin_iso646;
+@import _Builtin_limits;
+@import _Builtin_stdalign;
+@import _Builtin_stdarg;
+@import _Builtin_stdatomic;
+@import _Builtin_stdbool;
+@import _Builtin_stddef;
+@import _Builtin_stdint;
+@import _Builtin_stdnoreturn;
+@import 

[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-08 Thread Ian Anderson via Phabricator via cfe-commits
iana added inline comments.



Comment at: clang/test/Modules/Inputs/System/usr/include/stdint.h:2
 typedef int my_awesome_nonstandard_integer_type;
+
+/* C99 7.18.1.1 Exact-width integer types.

dexonsmith wrote:
> benlangmuir wrote:
> > iana wrote:
> > > iana wrote:
> > > > benlangmuir wrote:
> > > > > Why do we need all this code now (I assume this is copied from the 
> > > > > real header)?
> > > > It's to support the tests I added to Modules/compiler_builtins.m. 
> > > > stdatomic.h and inttypes.h rely on stdint.h contents from the C 
> > > > library, and on complex.h and inttypes.h and math.h being present. I 
> > > > could just test the modules with `-ffreestanding` I think, would that 
> > > > be better?
> > > (and yes I just copied it from the builtin header)
> > I'm not sure what the best approach is here, but this seems heavy for a 
> > test.  Do we expect to need to keep this up to date? If so maybe 
> > ffreestanding for the specific test cases this affects would be a better 
> > tradeoff.  Maybe someone else has a suggestion here
> This reflects *most* of the content in `stdint.h`.
> 
> One idea would be to copy the full header over during the test setup and fix 
> it up, either:
> - strip out the header/footer or
> - `sed -e "s/__STDC_HOSTED__/0/g"`
> so that it always provides content (even when not freestanding).
IMO it doesn't need to be that sophisticated, the types just have to exist for 
stdtomic.h to compile. I could chop all the comments and define everything to 
`int` and I think that'd be fine too.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-08 Thread Ian Anderson via Phabricator via cfe-commits
iana added inline comments.



Comment at: clang/test/Modules/Inputs/System/usr/include/stdint.h:2
 typedef int my_awesome_nonstandard_integer_type;
+
+/* C99 7.18.1.1 Exact-width integer types.

iana wrote:
> benlangmuir wrote:
> > Why do we need all this code now (I assume this is copied from the real 
> > header)?
> It's to support the tests I added to Modules/compiler_builtins.m. stdatomic.h 
> and inttypes.h rely on stdint.h contents from the C library, and on complex.h 
> and inttypes.h and math.h being present. I could just test the modules with 
> `-ffreestanding` I think, would that be better?
(and yes I just copied it from the builtin header)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-08 Thread Ian Anderson via Phabricator via cfe-commits
iana added inline comments.



Comment at: clang/test/Modules/Inputs/System/usr/include/stdint.h:2
 typedef int my_awesome_nonstandard_integer_type;
+
+/* C99 7.18.1.1 Exact-width integer types.

benlangmuir wrote:
> Why do we need all this code now (I assume this is copied from the real 
> header)?
It's to support the tests I added to Modules/compiler_builtins.m. stdatomic.h 
and inttypes.h rely on stdint.h contents from the C library, and on complex.h 
and inttypes.h and math.h being present. I could just test the modules with 
`-ffreestanding` I think, would that be better?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-08 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 556280.
iana added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

Files:
  clang/lib/Basic/Module.cpp
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/module.modulemap
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/Inputs/System/usr/include/complex.h
  clang/test/Modules/Inputs/System/usr/include/inttypes.h
  clang/test/Modules/Inputs/System/usr/include/math.h
  clang/test/Modules/Inputs/System/usr/include/module.map
  clang/test/Modules/Inputs/System/usr/include/stdint.h
  clang/test/Modules/compiler_builtins.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -4,4 +4,5 @@
 
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,12 +1,23 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=no-stddef-module -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=yes-stddef-module -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
 ptrdiff_t pdt;
 
-size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@__stddef_size_t.h:* {{here}}
+// When builtin headers join system modules, stddef.h and its sub-headers have no
+// header guards, and so are seen last by include_again.h, which takes all of their
+// declarations including size_t even though size_t.h previously declared it.
+// When builtin headers don't join the system modules and instead get their own
+// modules, none of the stddef.h declarations go in the StdDef test module. size_t
+// is then declared in both StdDef.SizeT and _Builtin_stddef.size_t. For the
+// purposes of this test it doesn't matter which one gets reported, just as long
+// as it isn't other.h or include_again.h.
+size_t st; // no-stddef-module-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}} \
+  yes-stddef-module-error {{missing '#include "size_t.h"'; 'size_t' must be declared before it is used}}
+// no-stddef-module-note@__stddef_size_t.h:* {{here}}
+// yes-stddef-module-note@size_t.h:* {{here}}
 
 #include "include_again.h"
 
Index: clang/test/Modules/compiler_builtins.m
===
--- clang/test/Modules/compiler_builtins.m
+++ clang/test/Modules/compiler_builtins.m
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -DNO_SYSTEM_MODULES -verify
 // expected-no-diagnostics
 
 #ifdef __SSE__
@@ -11,3 +11,19 @@
 #ifdef __AVX2__
 @import _Builtin_intrinsics.intel.avx2;
 #endif
+
+#ifndef NO_SYSTEM_MODULES
+@import _Builtin_float;
+@import _Builtin_inttypes;
+@import _Builtin_iso646;
+@import _Builtin_limits;
+@import _Builtin_stdalign;
+@import _Builtin_stdarg;
+@import _Builtin_stdatomic;
+@import _Builtin_stdbool;
+@import _Builtin_stddef;
+@import _Builtin_stdint;
+@import _Builtin_stdnoreturn;
+@import _Builtin_tgmath;
+@import _Builtin_unwind;
+#endif
Index: 

[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

2023-09-08 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 556279.
iana added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159483/new/

https://reviews.llvm.org/D159483

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Headers/__stdarg___gnuc_va_list.h
  clang/lib/Headers/__stdarg___va_copy.h
  clang/lib/Headers/__stdarg_va_arg.h
  clang/lib/Headers/__stdarg_va_copy.h
  clang/lib/Headers/__stdarg_va_list.h
  clang/lib/Headers/__stddef_max_align_t.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/lib/Lex/ModuleMap.cpp
  clang/test/Driver/Inputs/MacOSX99.0.sdk/SDKSettings.json
  clang/test/Driver/darwin-builtin-modules.c
  clang/test/Modules/Werror-Wsystem-headers.m
  clang/test/Modules/context-hash.c
  clang/test/Modules/crash-vfs-include-pch.m
  clang/test/Modules/cstd.m
  clang/test/Modules/pch-used.m
  clang/test/Modules/shadowed-submodule.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -3,5 +3,5 @@
 size_t getSize(void);
 
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
Index: clang/test/Modules/shadowed-submodule.m
===
--- clang/test/Modules/shadowed-submodule.m
+++ clang/test/Modules/shadowed-submodule.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/shadowed-submodule/Foo -I %S/Inputs/shadowed-submodule/A2 %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/shadowed-submodule/Foo -I %S/Inputs/shadowed-submodule/A2 %s -verify
 
 @import Foo; // expected-error {{module 'A' was built in directory}}
  // expected-note@shadowed-submodule.m:4 {{imported by module 'Foo'}}
Index: clang/test/Modules/pch-used.m
===
--- clang/test/Modules/pch-used.m
+++ clang/test/Modules/pch-used.m
@@ -1,8 +1,8 @@
 // UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
 // RUN: rm -rf %t
 // RUN: mkdir %t
-// RUN: %clang_cc1 -x objective-c-header -emit-pch %S/Inputs/pch-used.h -o %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include
-// RUN: %clang_cc1 %s -include-pch %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -x objective-c-header -emit-pch %S/Inputs/pch-used.h -o %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include
+// RUN: %clang_cc1 %s -include-pch %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include -emit-llvm -o - | FileCheck %s
 
 void f(void) { SPXTrace(); }
 void g(void) { double x = DBL_MAX; }
Index: clang/test/Modules/cstd.m
===
--- clang/test/Modules/cstd.m
+++ clang/test/Modules/cstd.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -internal-isystem %S/Inputs/System/usr/include -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -D__need_wint_t -Werror=implicit-function-declaration %s
+// RUN: %clang_cc1 -fsyntax-only -internal-isystem %S/Inputs/System/usr/include -fmodules -fimplicit-module-maps 

[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-08 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 556231.
iana added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

Files:
  clang/lib/Basic/Module.cpp
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/module.modulemap
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/Inputs/System/usr/include/complex.h
  clang/test/Modules/Inputs/System/usr/include/inttypes.h
  clang/test/Modules/Inputs/System/usr/include/math.h
  clang/test/Modules/Inputs/System/usr/include/module.map
  clang/test/Modules/Inputs/System/usr/include/stdint.h
  clang/test/Modules/compiler_builtins.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -4,4 +4,5 @@
 
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,12 +1,23 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=no-stddef-module -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=yes-stddef-module -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
 ptrdiff_t pdt;
 
-size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@__stddef_size_t.h:* {{here}}
+// When builtin headers join system modules, stddef.h and its sub-headers have no
+// header guards, and so are seen last by include_again.h, which takes all of their
+// declarations including size_t even though size_t.h previously declared it.
+// When builtin headers don't join the system modules and instead get their own
+// modules, none of the stddef.h declarations go in the StdDef test module. size_t
+// is then declared in both StdDef.SizeT and _Builtin_stddef.size_t. For the
+// purposes of this test it doesn't matter which one gets reported, just as long
+// as it isn't other.h or include_again.h.
+size_t st; // no-stddef-module-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}} \
+  yes-stddef-module-error {{missing '#include "size_t.h"'; 'size_t' must be declared before it is used}}
+// no-stddef-module-note@__stddef_size_t.h:* {{here}}
+// yes-stddef-module-note@size_t.h:* {{here}}
 
 #include "include_again.h"
 
Index: clang/test/Modules/compiler_builtins.m
===
--- clang/test/Modules/compiler_builtins.m
+++ clang/test/Modules/compiler_builtins.m
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -DNO_SYSTEM_MODULES -verify
 // expected-no-diagnostics
 
 #ifdef __SSE__
@@ -11,3 +11,19 @@
 #ifdef __AVX2__
 @import _Builtin_intrinsics.intel.avx2;
 #endif
+
+#ifndef NO_SYSTEM_MODULES
+@import _Builtin_float;
+@import _Builtin_inttypes;
+@import _Builtin_iso646;
+@import _Builtin_limits;
+@import _Builtin_stdalign;
+@import _Builtin_stdarg;
+@import _Builtin_stdatomic;
+@import _Builtin_stdbool;
+@import _Builtin_stddef;
+@import _Builtin_stdint;
+@import _Builtin_stdnoreturn;
+@import _Builtin_tgmath;
+@import _Builtin_unwind;
+#endif
Index: 

[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

2023-09-08 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 556230.
iana marked 3 inline comments as done.
iana added a comment.

Add comments to stdarg.h and stddef.h explaining their interesting header guard 
setup.
Ignore -fbuiltin-headers-in-system-modules if -fmodules isn't passed.
DriverKit doesn't need to pass -fbuiltin-headers-in-system-modules since it 
doesn't have a module map at all.
Add a test for 
-fbuiltin-headers-in-system-modules/__has_feature(builtin_headers_in_system_modules)
Miscellaneous review feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159483/new/

https://reviews.llvm.org/D159483

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Headers/__stdarg___gnuc_va_list.h
  clang/lib/Headers/__stdarg___va_copy.h
  clang/lib/Headers/__stdarg_va_arg.h
  clang/lib/Headers/__stdarg_va_copy.h
  clang/lib/Headers/__stdarg_va_list.h
  clang/lib/Headers/__stddef_max_align_t.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/lib/Lex/ModuleMap.cpp
  clang/test/Driver/Inputs/MacOSX99.0.sdk/SDKSettings.json
  clang/test/Driver/darwin-builtin-modules.c
  clang/test/Modules/Werror-Wsystem-headers.m
  clang/test/Modules/context-hash.c
  clang/test/Modules/crash-vfs-include-pch.m
  clang/test/Modules/cstd.m
  clang/test/Modules/pch-used.m
  clang/test/Modules/shadowed-submodule.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -3,5 +3,5 @@
 size_t getSize(void);
 
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
Index: clang/test/Modules/shadowed-submodule.m
===
--- clang/test/Modules/shadowed-submodule.m
+++ clang/test/Modules/shadowed-submodule.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/shadowed-submodule/Foo -I %S/Inputs/shadowed-submodule/A2 %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/shadowed-submodule/Foo -I %S/Inputs/shadowed-submodule/A2 %s -verify
 
 @import Foo; // expected-error {{module 'A' was built in directory}}
  // expected-note@shadowed-submodule.m:4 {{imported by module 'Foo'}}
Index: clang/test/Modules/pch-used.m
===
--- clang/test/Modules/pch-used.m
+++ clang/test/Modules/pch-used.m
@@ -1,8 +1,8 @@
 // UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
 // RUN: rm -rf %t
 // RUN: mkdir %t
-// RUN: %clang_cc1 -x objective-c-header -emit-pch %S/Inputs/pch-used.h -o %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include
-// RUN: %clang_cc1 %s -include-pch %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -x objective-c-header -emit-pch %S/Inputs/pch-used.h -o %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include
+// RUN: %clang_cc1 %s -include-pch %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include -emit-llvm -o - | FileCheck %s
 
 void f(void) { SPXTrace(); }
 void g(void) { double x = DBL_MAX; }
Index: clang/test/Modules/cstd.m

[PATCH] D140250: Define NULL in its own header

2023-09-07 Thread Ian Anderson via Phabricator via cfe-commits
iana abandoned this revision.
iana added a comment.

This was succeeded by D158709 .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140250/new/

https://reviews.llvm.org/D140250

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

2023-09-07 Thread Ian Anderson via Phabricator via cfe-commits
iana marked an inline comment as done.
iana added inline comments.



Comment at: clang/include/clang/Basic/Features.def:233
 FEATURE(modules, LangOpts.Modules)
+FEATURE(builtin_headers_in_system_modules, 
LangOpts.BuiltinHeadersInSystemModules)
 FEATURE(safe_stack, LangOpts.Sanitize.has(SanitizerKind::SafeStack))

benlangmuir wrote:
> iana wrote:
> > benlangmuir wrote:
> > > This appears to be in a list of `// C++ TSes`.  Near the bottom there is 
> > > 'Miscellaneous language extensions' which might be a better fit.
> > I thought it went with `FEATURE(modules, LangOpts.Modules)`, but I can put 
> > it down in 'Miscellaneous language extensions' if that's better.
> I think misc is probably better.
 



Comment at: clang/include/clang/Driver/Options.td:2944
   [NoXarchOption], [ClangOption, CLOption]>>;
+def fbuiltin_headers_in_system_modules : Flag <["-"], 
"fbuiltin-headers-in-system-modules">,
+  Group,

benlangmuir wrote:
> iana wrote:
> > I don't love this flag name, but I couldn't come up with anything more 
> > succinct. It actually does two things.
> > 
> >   # Turns on `ModuleMap::isBuiltinHeader` behavior, that is the builtin 
> > headers get added into the system modules.
> >   # Causes the module map parser to ignore all of the new builtin modules 
> > added in D159064. This is needed before the modules are added to assist 
> > with Apple internal staging with the Swift compiler.
> > 
> I think the name is good enough for a -cc1 option, unless someone else has a 
> better suggestion. I suggest adding a HelpText - you could basically copy the 
> description you added to LangOptions.def
Sure



Comment at: clang/lib/Lex/ModuleMap.cpp:1540
+/// or added to Map's Modules/ModuleScopeIDs).
+bool IgnoreModules = false;
+

benlangmuir wrote:
> iana wrote:
> > This an everything under it is gross, but the only other thing I could 
> > think of was to duplicate the module map and decided to load a special one 
> > for BuiltinHeadersInSystemModules. That seemed weirder.
> Would it be possible to get the right semantics using a `requires` decl in 
> the modules plus a new module feature?
Maybe? I guess e.g. _Builtin_stdint would be seen, the new requires flag would 
be seen, and if it's not satisfied then its headers wouldn't be added to the 
module? That seems like a really weird use of requires though.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159483/new/

https://reviews.llvm.org/D159483

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-07 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 556208.
iana added a comment.

Fix formatting issue


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

Files:
  clang/lib/Basic/Module.cpp
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/module.modulemap
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/Inputs/System/usr/include/complex.h
  clang/test/Modules/Inputs/System/usr/include/inttypes.h
  clang/test/Modules/Inputs/System/usr/include/math.h
  clang/test/Modules/Inputs/System/usr/include/module.map
  clang/test/Modules/Inputs/System/usr/include/stdint.h
  clang/test/Modules/compiler_builtins.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -4,4 +4,5 @@
 
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,12 +1,23 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=no-stddef-module -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=yes-stddef-module -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
 ptrdiff_t pdt;
 
-size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@__stddef_size_t.h:* {{here}}
+// When builtin headers join system modules, stddef.h and its sub-headers have no
+// header guards, and so are seen last by include_again.h, which takes all of their
+// declarations including size_t even though size_t.h previously declared it.
+// When builtin headers don't join the system modules and instead get their own
+// modules, none of the stddef.h declarations go in the StdDef test module. size_t
+// is then declared in both StdDef.SizeT and _Builtin_stddef.size_t. For the
+// purposes of this test it doesn't matter which one gets reported, just as long
+// as it isn't other.h or include_again.h.
+size_t st; // no-stddef-module-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}} \
+  yes-stddef-module-error {{missing '#include "size_t.h"'; 'size_t' must be declared before it is used}}
+// no-stddef-module-note@__stddef_size_t.h:* {{here}}
+// yes-stddef-module-note@size_t.h:* {{here}}
 
 #include "include_again.h"
 
Index: clang/test/Modules/compiler_builtins.m
===
--- clang/test/Modules/compiler_builtins.m
+++ clang/test/Modules/compiler_builtins.m
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -DNO_SYSTEM_MODULES -verify
 // expected-no-diagnostics
 
 #ifdef __SSE__
@@ -11,3 +11,19 @@
 #ifdef __AVX2__
 @import _Builtin_intrinsics.intel.avx2;
 #endif
+
+#ifndef NO_SYSTEM_MODULES
+@import _Builtin_float;
+@import _Builtin_inttypes;
+@import _Builtin_iso646;
+@import _Builtin_limits;
+@import _Builtin_stdalign;
+@import _Builtin_stdarg;
+@import _Builtin_stdatomic;
+@import _Builtin_stdbool;
+@import _Builtin_stddef;
+@import _Builtin_stdint;
+@import _Builtin_stdnoreturn;
+@import _Builtin_tgmath;
+@import _Builtin_unwind;
+#endif
Index: 

[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

2023-09-07 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 556207.
iana added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159483/new/

https://reviews.llvm.org/D159483

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Headers/__stdarg___gnuc_va_list.h
  clang/lib/Headers/__stdarg___va_copy.h
  clang/lib/Headers/__stdarg_va_arg.h
  clang/lib/Headers/__stdarg_va_copy.h
  clang/lib/Headers/__stdarg_va_list.h
  clang/lib/Headers/__stddef_max_align_t.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/lib/Lex/ModuleMap.cpp
  clang/test/Modules/Werror-Wsystem-headers.m
  clang/test/Modules/context-hash.c
  clang/test/Modules/crash-vfs-include-pch.m
  clang/test/Modules/cstd.m
  clang/test/Modules/pch-used.m
  clang/test/Modules/shadowed-submodule.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -3,5 +3,5 @@
 size_t getSize(void);
 
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
Index: clang/test/Modules/shadowed-submodule.m
===
--- clang/test/Modules/shadowed-submodule.m
+++ clang/test/Modules/shadowed-submodule.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/shadowed-submodule/Foo -I %S/Inputs/shadowed-submodule/A2 %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/shadowed-submodule/Foo -I %S/Inputs/shadowed-submodule/A2 %s -verify
 
 @import Foo; // expected-error {{module 'A' was built in directory}}
  // expected-note@shadowed-submodule.m:4 {{imported by module 'Foo'}}
Index: clang/test/Modules/pch-used.m
===
--- clang/test/Modules/pch-used.m
+++ clang/test/Modules/pch-used.m
@@ -1,8 +1,8 @@
 // UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
 // RUN: rm -rf %t
 // RUN: mkdir %t
-// RUN: %clang_cc1 -x objective-c-header -emit-pch %S/Inputs/pch-used.h -o %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include
-// RUN: %clang_cc1 %s -include-pch %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -x objective-c-header -emit-pch %S/Inputs/pch-used.h -o %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include
+// RUN: %clang_cc1 %s -include-pch %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include -emit-llvm -o - | FileCheck %s
 
 void f(void) { SPXTrace(); }
 void g(void) { double x = DBL_MAX; }
Index: clang/test/Modules/cstd.m
===
--- clang/test/Modules/cstd.m
+++ clang/test/Modules/cstd.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -internal-isystem %S/Inputs/System/usr/include -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -D__need_wint_t -Werror=implicit-function-declaration %s
+// RUN: %clang_cc1 -fsyntax-only -internal-isystem %S/Inputs/System/usr/include -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -D__need_wint_t -Werror=implicit-function-declaration %s
 
 

[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

2023-09-07 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 556206.
iana added a comment.

Fix formatting


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159483/new/

https://reviews.llvm.org/D159483

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Headers/__stdarg___gnuc_va_list.h
  clang/lib/Headers/__stdarg___va_copy.h
  clang/lib/Headers/__stdarg_va_arg.h
  clang/lib/Headers/__stdarg_va_copy.h
  clang/lib/Headers/__stdarg_va_list.h
  clang/lib/Headers/__stddef_max_align_t.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/lib/Lex/ModuleMap.cpp
  clang/test/Modules/Werror-Wsystem-headers.m
  clang/test/Modules/context-hash.c
  clang/test/Modules/crash-vfs-include-pch.m
  clang/test/Modules/cstd.m
  clang/test/Modules/pch-used.m
  clang/test/Modules/shadowed-submodule.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -3,5 +3,5 @@
 size_t getSize(void);
 
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
Index: clang/test/Modules/shadowed-submodule.m
===
--- clang/test/Modules/shadowed-submodule.m
+++ clang/test/Modules/shadowed-submodule.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/shadowed-submodule/Foo -I %S/Inputs/shadowed-submodule/A2 %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/shadowed-submodule/Foo -I %S/Inputs/shadowed-submodule/A2 %s -verify
 
 @import Foo; // expected-error {{module 'A' was built in directory}}
  // expected-note@shadowed-submodule.m:4 {{imported by module 'Foo'}}
Index: clang/test/Modules/pch-used.m
===
--- clang/test/Modules/pch-used.m
+++ clang/test/Modules/pch-used.m
@@ -1,8 +1,8 @@
 // UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
 // RUN: rm -rf %t
 // RUN: mkdir %t
-// RUN: %clang_cc1 -x objective-c-header -emit-pch %S/Inputs/pch-used.h -o %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include
-// RUN: %clang_cc1 %s -include-pch %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -x objective-c-header -emit-pch %S/Inputs/pch-used.h -o %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include
+// RUN: %clang_cc1 %s -include-pch %t/pch-used.h.pch -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t/cache -O0 -isystem %S/Inputs/System/usr/include -emit-llvm -o - | FileCheck %s
 
 void f(void) { SPXTrace(); }
 void g(void) { double x = DBL_MAX; }
Index: clang/test/Modules/cstd.m
===
--- clang/test/Modules/cstd.m
+++ clang/test/Modules/cstd.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -internal-isystem %S/Inputs/System/usr/include -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -D__need_wint_t -Werror=implicit-function-declaration %s
+// RUN: %clang_cc1 -fsyntax-only -internal-isystem %S/Inputs/System/usr/include -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -D__need_wint_t -Werror=implicit-function-declaration 

[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

2023-09-07 Thread Ian Anderson via Phabricator via cfe-commits
iana marked an inline comment as done.
iana added a comment.

In D159483#4641289 , @benlangmuir 
wrote:

>>> How does this work today? Wouldn't the include guard prevent this?
>>
>> Today they don't define their include guard when building with modules.
>
> Thanks - I can see some headers behave that way, or in other cases there are 
> other sorts of has_feature(modules) checks that I can see you're modifying, 
> but what about all the *va_* headers that currently just seem to have normal 
> header guards?

I think the stdarg ones didn't always work properly in modules and we just got 
lucky.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159483/new/

https://reviews.llvm.org/D159483

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

2023-09-07 Thread Ian Anderson via Phabricator via cfe-commits
iana marked an inline comment as done.
iana added inline comments.



Comment at: clang/include/clang/Basic/Features.def:233
 FEATURE(modules, LangOpts.Modules)
+FEATURE(builtin_headers_in_system_modules, 
LangOpts.BuiltinHeadersInSystemModules)
 FEATURE(safe_stack, LangOpts.Sanitize.has(SanitizerKind::SafeStack))

benlangmuir wrote:
> This appears to be in a list of `// C++ TSes`.  Near the bottom there is 
> 'Miscellaneous language extensions' which might be a better fit.
I thought it went with `FEATURE(modules, LangOpts.Modules)`, but I can put it 
down in 'Miscellaneous language extensions' if that's better.



Comment at: clang/lib/Driver/ToolChains/Darwin.cpp:2851
+  if (!SDKInfo)
+return false;
+  

benlangmuir wrote:
> I would have expected the default to be true; do old SDKs not have SDKInfo or 
> something?
I'm not sure if we ever expect there to not be SDKInfo, but I thought it safer 
to default to the current behavior which is false.



Comment at: clang/lib/Driver/ToolChains/Darwin.cpp:2856
+  case Darwin::MacOS:
+return SDKVersion >= VersionTuple(100U);
+  case Darwin::IPhoneOS:

benlangmuir wrote:
> Are these really supposed to be 100 or is this a placeholder?
Placeholder until we actually update the SDKs.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159483/new/

https://reviews.llvm.org/D159483

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

2023-09-07 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D159483#4641231 , @benlangmuir 
wrote:

>> but need to be repeatedly included when they're used in system modules
>
> How does this work today? Wouldn't the include guard prevent this?

Today they don't define their include guard when building with modules.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159483/new/

https://reviews.llvm.org/D159483

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

2023-09-07 Thread Ian Anderson via Phabricator via cfe-commits
iana added inline comments.



Comment at: clang/include/clang/Driver/Options.td:2944
   [NoXarchOption], [ClangOption, CLOption]>>;
+def fbuiltin_headers_in_system_modules : Flag <["-"], 
"fbuiltin-headers-in-system-modules">,
+  Group,

I don't love this flag name, but I couldn't come up with anything more 
succinct. It actually does two things.

  # Turns on `ModuleMap::isBuiltinHeader` behavior, that is the builtin headers 
get added into the system modules.
  # Causes the module map parser to ignore all of the new builtin modules added 
in D159064. This is needed before the modules are added to assist with Apple 
internal staging with the Swift compiler.




Comment at: clang/include/clang/Driver/Options.td:2945-2946
+def fbuiltin_headers_in_system_modules : Flag <["-"], 
"fbuiltin-headers-in-system-modules">,
+  Group,
+  Flags<[NoXarchOption]>,
+  Visibility<[CC1Option]>,

I don't fully understand what these two do, but I think they apply here?



Comment at: clang/lib/Headers/__stddef_ptrdiff_t.h:10
 
-#if !defined(_PTRDIFF_T) || __has_feature(modules)
-/* Always define ptrdiff_t when modules are available. */
-#if !__has_feature(modules)
+#if !defined(_PTRDIFF_T) || __has_feature(builtin_headers_in_system_modules)
 #define _PTRDIFF_T

This is to support patterns like the Modules/stddef.c test. The module map 
looks like this.

```
module StdDef {
  module Other {
header "other.h" // includes stddef.h
  }
  module PtrDiffT {
header "ptrdiff_t.h" // defines __needs_ptrdiff_t and includes stddef.h
  }
  module IncludeAgain {
header "include_again.h" // includes stddef.h
  }
}
```
With builtin_headers_in_system_modules, __stddef_ptrdiff_t.h will not be in a 
module. It will first be seen in other.h and define its header guard. When it's 
seen again in ptrdiff_t.h, it needs to declare ptrdiff_t again, so it needs to 
ignore its header guard.

Without builtin_headers_in_system_modules, __stddef_ptrdiff_t.h will be in the 
`_Builtin_stddef` module. It needs its header guard there so that it's only 
included once when building the module. Even though ptrdiff_t.h will see the 
header guard, it will still import `_Builtin_stddef.ptrdiff_t` and get the 
declaration.



Comment at: clang/lib/Headers/stddef.h:10
 
-#if !defined(__STDDEF_H) || defined(__need_ptrdiff_t) ||   
\
-defined(__need_size_t) || defined(__need_rsize_t) ||   
\
-defined(__need_wchar_t) || defined(__need_NULL) || 
\
-defined(__need_nullptr_t) || defined(__need_unreachable) ||
\
-defined(__need_max_align_t) || defined(__need_offsetof) || 
\
-defined(__need_wint_t) ||  
\
-(defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1)
+#if !defined(__STDDEF_H) || __has_feature(modules) ||  
\
+(defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1) ||
\

As a `textual` header, this needs to ignore its header guard in module mode, 
even without builtin_headers_in_system_modules. Going back to the 
Modules/stddef.c test.

```
module StdDef {
  module Other {
header "other.h" // includes stddef.h
export *
  }
  module PtrDiffT {
header "ptrdiff_t.h" // defines __needs_ptrdiff_t and includes stddef.h
  }
  module IncludeAgain {
header "include_again.h" // includes stddef.h
export *
  }
}
```

When other.h compiles, __STDDEF_H will get defined and 
`_Builtin_stddef.ptrdiff_t` will be imported. But when include_again.h 
compiles, __STDDEF_H will already be defined and `_Builtin_stddef.ptrdiff_t` 
won't be imported because the include will be skipped in stddef.h. That's ok 
when include_again.h is building because it will see ptrdiff_t from when 
other.h included it. But a client that only includes include_again.h won't see 
any types because `StdDef.IncludeAgain` skipped the contents of stddef.h and 
skipped importing `_Builtin_stddef.ptrdiff_t`, and so there's nothing for 
`export *` to export.

The other solution is to never define __STDDEF_H in module mode, but I think 
that's strange behavior. Several headers in the Apple SDKs test if a header was 
included by checking for its header guard (questionable, but it's what they 
do). stddef.h isn't one of those headers, but it still seems like it should 
define everything in modules mode that it defines without modules.



Comment at: clang/lib/Lex/ModuleMap.cpp:259
+/// headers.
+static bool isBuiltinHeaderName(StringRef FileName) {
+  return llvm::StringSwitch(FileName)

This had to be moved up just because it's used by methods under here.



Comment at: clang/lib/Lex/ModuleMap.cpp:1540
+/// or added to Map's Modules/ModuleScopeIDs).
+bool IgnoreModules = false;
+

[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

2023-09-07 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

A big assumption this patch makes is that `ModuleMap::isBuiltinHeader` is 
primarily to support Apple's unfortunate module needs. Thus this patch turns 
that behavior off by default, which makes things work the way one would expect. 
That is, when usr/include/module.modulemap references stdint.h, that just means 
usr/include/stdint.h and it doesn't also pull in the clang builtin stdint.h, it 
doesn't transform usr/include/stdint.h into a textual header, etc. I'm hoping 
that's acceptable behavior on non-Apple platforms, but if someone knows 
otherwise please let me know and we can rethink how the option should be 
defined and set.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159483/new/

https://reviews.llvm.org/D159483

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-07 Thread Ian Anderson via Phabricator via cfe-commits
iana marked 2 inline comments as done.
iana added inline comments.



Comment at: clang/lib/Headers/module.modulemap:269
+  explicit module wint_t {
+header "__stddef_wint_t.h"
+export *

Arguably this should be textual since stddef.h shouldn't own wint_t and it's 
just here for compatibility. Otherwise I think the ODR would force wchar.h to 
define need_wint and include stddef.h which is kind of weird?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-07 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 556192.
iana added a comment.

Rebase on top of D159483 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

Files:
  clang/lib/Basic/Module.cpp
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/module.modulemap
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/Inputs/System/usr/include/complex.h
  clang/test/Modules/Inputs/System/usr/include/inttypes.h
  clang/test/Modules/Inputs/System/usr/include/math.h
  clang/test/Modules/Inputs/System/usr/include/module.map
  clang/test/Modules/Inputs/System/usr/include/stdint.h
  clang/test/Modules/compiler_builtins.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -4,4 +4,5 @@
 
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,12 +1,23 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=no-stddef-module -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify=yes-stddef-module -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
 ptrdiff_t pdt;
 
-size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@__stddef_size_t.h:* {{here}}
+// When builtin headers join system modules, stddef.h and its sub-headers have no
+// header guards, and so are seen last by include_again.h, which takes all of their
+// declarations including size_t even though size_t.h previously declared it.
+// When builtin headers don't join the system modules and instead get their own
+// modules, none of the stddef.h declarations go in the StdDef test module. size_t
+// is then declared in both StdDef.SizeT and _Builtin_stddef.size_t. For the
+// purposes of this test it doesn't matter which one gets reported, just as long
+// as it isn't other.h or include_again.h.
+size_t st; // no-stddef-module-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}} \
+  yes-stddef-module-error {{missing '#include "size_t.h"'; 'size_t' must be declared before it is used}}
+// no-stddef-module-note@__stddef_size_t.h:* {{here}}
+// yes-stddef-module-note@size_t.h:* {{here}}
 
 #include "include_again.h"
 
Index: clang/test/Modules/compiler_builtins.m
===
--- clang/test/Modules/compiler_builtins.m
+++ clang/test/Modules/compiler_builtins.m
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
-// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t %s -internal-isystem %S/Inputs/System/usr/include -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%resource_dir/module.modulemap -fmodules-cache-path=%t %s -I%S/Inputs/System/usr/include -DNO_SYSTEM_MODULES -verify
 // expected-no-diagnostics
 
 #ifdef __SSE__
@@ -11,3 +11,19 @@
 #ifdef __AVX2__
 @import _Builtin_intrinsics.intel.avx2;
 #endif
+
+#ifndef NO_SYSTEM_MODULES
+@import _Builtin_float;
+@import _Builtin_inttypes;
+@import _Builtin_iso646;
+@import _Builtin_limits;
+@import _Builtin_stdalign;
+@import _Builtin_stdarg;
+@import _Builtin_stdatomic;
+@import _Builtin_stdbool;
+@import _Builtin_stddef;
+@import _Builtin_stdint;
+@import _Builtin_stdnoreturn;
+@import _Builtin_tgmath;
+@import 

[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

2023-09-07 Thread Ian Anderson via Phabricator via cfe-commits
iana created this revision.
iana added reviewers: aaron.ballman, rsmith, efriedma, ldionne, ChuanqiXu, 
Bigcheese, vsapsai, benlangmuir.
Herald added a subscriber: ributzka.
Herald added a project: All.
iana requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Including select builtin headers in system modules is a workaround for module 
cycles, primarily in Apple's Darwin module that includes all of its C standard 
library headers. The workaround is problematic because it doesn't include all 
of the builtin headers (inttypes.h is notably absent), and it also doesn't 
include C++ headers. The straightforward for for this is to make top level 
modules for all of the C standard library headers and unwind.h in C++, clang, 
and the OS.

However, doing so in clang before the OS modules are ready re-introduces the 
module cycles. Add a -fbuiltin-headers-in-system-modules option to control if 
the special builtin headers belong to system modules or builtin modules. Pass 
the option by default for Apple.

The __stdarg and __stddef headers need to use header guards when they're 
precompiled into their builtin modules, but need to be repeatedly included when 
they're used in system modules. Add a builtin_headers_in_system_modules feature 
so those headers can conditionally ignore their header guards. Always define 
the header guards for consistency. stdarg.h and stddef.h will be textual 
headers in the builtin modules, and so need to be repeatedly included in both 
the system and builtin module case. Ignore their header guards when building 
with modules, but still define the guards.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159483

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Headers/__stdarg___gnuc_va_list.h
  clang/lib/Headers/__stdarg___va_copy.h
  clang/lib/Headers/__stdarg_va_arg.h
  clang/lib/Headers/__stdarg_va_copy.h
  clang/lib/Headers/__stdarg_va_list.h
  clang/lib/Headers/__stddef_max_align_t.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/lib/Lex/ModuleMap.cpp
  clang/test/Modules/Werror-Wsystem-headers.m
  clang/test/Modules/context-hash.c
  clang/test/Modules/crash-vfs-include-pch.m
  clang/test/Modules/cstd.m
  clang/test/Modules/pch-used.m
  clang/test/Modules/shadowed-submodule.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

Index: clang/test/Modules/stddef.m
===
--- clang/test/Modules/stddef.m
+++ clang/test/Modules/stddef.m
@@ -3,5 +3,5 @@
 size_t getSize(void);
 
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify
 // expected-no-diagnostics
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I%S/Inputs/StdDef %s -verify -fno-modules-error-recovery
 
 #include "ptrdiff_t.h"
 
Index: clang/test/Modules/shadowed-submodule.m
===
--- clang/test/Modules/shadowed-submodule.m
+++ clang/test/Modules/shadowed-submodule.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/shadowed-submodule/Foo -I %S/Inputs/shadowed-submodule/A2 %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fbuiltin-headers-in-system-modules -fmodules-cache-path=%t -I %S/Inputs/shadowed-submodule/Foo -I %S/Inputs/shadowed-submodule/A2 %s -verify
 
 @import Foo; // expected-error {{module 'A' was built in directory}}
  // expected-note@shadowed-submodule.m:4 {{imported by module 'Foo'}}
Index: clang/test/Modules/pch-used.m
===
--- clang/test/Modules/pch-used.m
+++ clang/test/Modules/pch-used.m
@@ -1,8 +1,8 @@
 // UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
 // RUN: rm -rf %t
 // RUN: mkdir %t
-// RUN: %clang_cc1 -x 

[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-09-01 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

Ah, the tests are failing because some of them are putting the builtin headers 
in other modules. This is going to need the "optionally ignore the builtin 
modules" change first then. I almost have that one finished.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159312: [Headers] Remove a space in NULL define

2023-08-31 Thread Ian Anderson via Phabricator via cfe-commits
iana accepted this revision.
iana added a comment.
This revision is now accepted and ready to land.

Can you add a comment that says the spacing is important please? Although why 
the heck is musl declaring NULL in stdio.h?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159312/new/

https://reviews.llvm.org/D159312

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-08-30 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 554882.
iana added a comment.

Update Module::directlyUses


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

Files:
  clang/lib/Basic/Module.cpp
  clang/lib/Headers/__stddef_max_align_t.h
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/module.modulemap
  clang/lib/Headers/stddef.h
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/compiler_builtins.m

Index: clang/test/Modules/compiler_builtins.m
===
--- clang/test/Modules/compiler_builtins.m
+++ clang/test/Modules/compiler_builtins.m
@@ -11,3 +11,17 @@
 #ifdef __AVX2__
 @import _Builtin_intrinsics.intel.avx2;
 #endif
+
+@import _Builtin_float;
+@import _Builtin_inttypes;
+@import _Builtin_iso646;
+@import _Builtin_limits;
+@import _Builtin_stdalign;
+@import _Builtin_stdarg;
+@import _Builtin_stdatomic;
+@import _Builtin_stdbool;
+@import _Builtin_stddef;
+@import _Builtin_stdint;
+@import _Builtin_stdnoreturn;
+@import _Builtin_tgmath;
+@import _Builtin_unwind;
Index: clang/test/Headers/stddefneeds.c
===
--- clang/test/Headers/stddefneeds.c
+++ clang/test/Headers/stddefneeds.c
@@ -1,36 +1,73 @@
+// RUN: rm -fR %t
 // RUN: %clang_cc1 -fsyntax-only -verify=c99 -std=c99 %s
 // RUN: %clang_cc1 -fsyntax-only -verify=c23 -std=c23 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c99-modules -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c23-modules -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -std=c23 %s
 
 // Use C99 to verify that __need_ can be used to get types that wouldn't normally be available.
 
 struct astruct { char member; };
 
-ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}}
-size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}}
-rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}}
-wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}}
-void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}}
-nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}}
-static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}}
-max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}}
+ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}} \
+ c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}} \
+  c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}} \
+   c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}} \
+c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}} \
+c99-modules-error{{undeclared identifier}} c23-modules-error{{undeclared identifier}}
+nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}} \
+ c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}} \
+   c99-modules-error{{undeclared function}} c23-modules-error{{undeclared identifier}}
+max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}} \
+   c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
 size_t o0 = offsetof(struct astruct, member); // c99-error{{unknown type name 'size_t'}} c99-error{{call to undeclared function 'offsetof'}} c99-error{{expected expression}} c99-error{{use of undeclared identifier 'member'}} \
- c23-error{{unknown type name 'size_t'}} c23-error{{undeclared identifier 'offsetof'}} c23-error{{expected expression}} c23-error{{use of undeclared identifier 

[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-08-30 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 554832.
iana marked an inline comment as done.
iana added a comment.

The nullptr_t submodule can't require c23 because it needs to be used in C++ in 
some cases too. Remove the `requires` from the module map and add a C23 guard 
to the header.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

Files:
  clang/lib/Headers/__stddef_max_align_t.h
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/module.modulemap
  clang/lib/Headers/stddef.h
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/compiler_builtins.m

Index: clang/test/Modules/compiler_builtins.m
===
--- clang/test/Modules/compiler_builtins.m
+++ clang/test/Modules/compiler_builtins.m
@@ -11,3 +11,17 @@
 #ifdef __AVX2__
 @import _Builtin_intrinsics.intel.avx2;
 #endif
+
+@import _Builtin_float;
+@import _Builtin_inttypes;
+@import _Builtin_iso646;
+@import _Builtin_limits;
+@import _Builtin_stdalign;
+@import _Builtin_stdarg;
+@import _Builtin_stdatomic;
+@import _Builtin_stdbool;
+@import _Builtin_stddef;
+@import _Builtin_stdint;
+@import _Builtin_stdnoreturn;
+@import _Builtin_tgmath;
+@import _Builtin_unwind;
Index: clang/test/Headers/stddefneeds.c
===
--- clang/test/Headers/stddefneeds.c
+++ clang/test/Headers/stddefneeds.c
@@ -1,36 +1,73 @@
+// RUN: rm -fR %t
 // RUN: %clang_cc1 -fsyntax-only -verify=c99 -std=c99 %s
 // RUN: %clang_cc1 -fsyntax-only -verify=c23 -std=c23 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c99-modules -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c23-modules -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -std=c23 %s
 
 // Use C99 to verify that __need_ can be used to get types that wouldn't normally be available.
 
 struct astruct { char member; };
 
-ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}}
-size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}}
-rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}}
-wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}}
-void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}}
-nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}}
-static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}}
-max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}}
+ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}} \
+ c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}} \
+  c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}} \
+   c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}} \
+c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}} \
+c99-modules-error{{undeclared identifier}} c23-modules-error{{undeclared identifier}}
+nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}} \
+ c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}} \
+   c99-modules-error{{undeclared function}} c23-modules-error{{undeclared identifier}}
+max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}} \
+   c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
 size_t o0 = offsetof(struct astruct, member); // c99-error{{unknown type name 'size_t'}} c99-error{{call to undeclared function 'offsetof'}} c99-error{{expected expression}} c99-error{{use of undeclared identifier 'member'}} \
- 

[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-08-30 Thread Ian Anderson via Phabricator via cfe-commits
iana marked an inline comment as done.
iana added inline comments.



Comment at: clang/lib/Headers/__stddef_null.h:14
+ * __need_NULL and rely on stddef.h to redefine NULL to the correct value 
again.
+ * Modules don't support redefining macros like that, but support that pattern
+ * in the non-modules case.

dexonsmith wrote:
> iana wrote:
> > I couldn't come up with anything clever to support this in modules. If I 
> > get rid of the guard, `NULL` still doesn't get redefined in modules. If I 
> > move the `undef` to stddef.h then `NULL` gets undefined, but not redefined. 
> > So I think precompiled modules must inherently have `#pragma once` 
> > semantics. If we really had to, we could move this back into stddef.h and 
> > let it be textual, but it's distasteful that `NULL` gets defined in every 
> > single module that includes stddef.h and has to be merged later.
> Modules are, in a way, stronger than `#pragma once`. Each module is a 
> separate translation unit. If there's a module around `__stddef_null.h`, then 
> it will only be compiled once, and any definitions imported from there. Other 
> importing TUs get those definitions per the context the module was compiled 
> in (they don't re-compile the code in their own context...).
> 
> It seems like a regression for `NULL` to degrade from `((void *)0)` to `0` 
> since it loses type safety, which is rather rare and precious in C code. 
> Maybe this header should remain textual when deployed to platforms that rely 
> on this dance.
Sure, but I was a little surprised that this doesn't work.
```
@import _Builtin_stddef.null;
undef NULL
@import _Builtin_stddef.null;
// NULL is undefined
```
It makes perfect sense that the module doesn't get re-compiled on the second 
import (and maybe not even the first), and that when it does get precompiled it 
doesn't see anything that the importing code did with `NULL`. But I //am// a 
bit surprised that re-importing the module doesn't re-expose everything from it.

I guess if we really need to, we could `unifdef` the module map in case some 
platforms need this to be textual, and then lose the guard.



Comment at: clang/lib/Headers/module.modulemap:156
 
-module _Builtin_stddef_max_align_t [system] [extern_c] {
-  header "__stddef_max_align_t.h"

benlangmuir wrote:
> Is the assumption here that directly `@import _Builtin_stddef_max_align_t` is 
> unsupported so we don't need to provide a shim to keep this working?
Yes that is the assumption, but if someone knows different please let me know!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158709: [Headers][Modules] Make separate headers for the stdarg.h and stddef.h pieces so that they can be modularized

2023-08-30 Thread Ian Anderson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG680da4b5d7ec: [Headers][Modules] Make separate headers for 
the stdarg.h and stddef.h pieces… (authored by iana).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158709/new/

https://reviews.llvm.org/D158709

Files:
  clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__stdarg___gnuc_va_list.h
  clang/lib/Headers/__stdarg___va_copy.h
  clang/lib/Headers/__stdarg_va_arg.h
  clang/lib/Headers/__stdarg_va_copy.h
  clang/lib/Headers/__stdarg_va_list.h
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/stddef.c
  compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
  llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
@@ -95,7 +95,21 @@
 "__clang_hip_math.h",
 "__clang_hip_runtime_wrapper.h",
 "__clang_hip_stdlib.h",
+"__stdarg___gnuc_va_list.h",
+"__stdarg___va_copy.h",
+"__stdarg_va_arg.h",
+"__stdarg_va_copy.h",
+"__stdarg_va_list.h",
 "__stddef_max_align_t.h",
+"__stddef_null.h",
+"__stddef_nullptr_t.h",
+"__stddef_offsetof.h",
+"__stddef_ptrdiff_t.h",
+"__stddef_rsize_t.h",
+"__stddef_size_t.h",
+"__stddef_unreachable.h",
+"__stddef_wchar_t.h",
+"__stddef_wint_t.h",
 "__wmmintrin_aes.h",
 "__wmmintrin_pclmul.h",
 "adxintrin.h",
Index: compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
===
--- compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
+++ compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
@@ -20,6 +20,15 @@
 #include 
 #include 
 // IWYU pragma: no_include <__stddef_max_align_t.h>
+// IWYU pragma: no_include <__stddef_null.h>
+// IWYU pragma: no_include <__stddef_nullptr_t.h>
+// IWYU pragma: no_include <__stddef_offsetof.h>
+// IWYU pragma: no_include <__stddef_ptrdiff_t.h>
+// IWYU pragma: no_include <__stddef_rsize_t.h>
+// IWYU pragma: no_include <__stddef_size_t.h>
+// IWYU pragma: no_include <__stddef_unreachable.h>
+// IWYU pragma: no_include <__stddef_wchar_t.h>
+// IWYU pragma: no_include <__stddef_wint_t.h>
 
 namespace gwp_asan {
 // This class is the primary implementation of the allocator portion of GWP-
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -6,7 +6,7 @@
 ptrdiff_t pdt;
 
 size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@stddef.h:* {{here}}
+// expected-note@__stddef_size_t.h:* {{here}}
 
 #include "include_again.h"
 
Index: clang/test/Headers/stddefneeds.c
===
--- clang/test/Headers/stddefneeds.c
+++ clang/test/Headers/stddefneeds.c
@@ -38,7 +38,7 @@
 ptrdiff_t p2;
 size_t s2;
 rsize_t r2; // c99-error{{unknown type}} c23-error{{unknown type}}
-// c99-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+// c99-note@__stddef_size_t.h:*{{'size_t' declared here}} c23-note@__stddef_size_t.h:*{{'size_t' declared here}}
 wchar_t wc2; // c99-error{{unknown type}} c23-error{{unknown type}}
 void *v2 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
 nullptr_t n2; // c99-error{{unknown type}} c23-error{{unknown type}}
@@ -96,7 +96,7 @@
 // __need_nullptr_t generates an error in  // c99-error@stddef.h:*{{expected function body}}
+#include  // c99-error@__stddef_nullptr_t.h:*{{expected function body}}
 
 ptrdiff_t p6;
 size_t s6;
Index: clang/test/Headers/stddef.c
===
--- clang/test/Headers/stddef.c
+++ clang/test/Headers/stddef.c
@@ -22,7 +22,7 @@
 ptrdiff_t p1;
 size_t s1;
 rsize_t r1; // c99-error{{unknown type}} c11-error{{unknown type}} c23-error{{unknown type}}
-// c99-note@stddef.h:*{{'size_t' declared here}} c11-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+// c99-note@__stddef_size_t.h:*{{'size_t' declared 

[PATCH] D159018: [clang][modules] Add a c23 module feature

2023-08-29 Thread Ian Anderson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGadb68c979d84: [clang][modules] Add a c23 module feature 
(authored by iana).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159018/new/

https://reviews.llvm.org/D159018

Files:
  clang/docs/Modules.rst
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Module.cpp
  clang/test/Modules/Inputs/DependsOnModule.framework/module.map
  clang/test/Modules/requires.m


Index: clang/test/Modules/requires.m
===
--- clang/test/Modules/requires.m
+++ clang/test/Modules/requires.m
@@ -35,4 +35,6 @@
 @import DependsOnModule.C11; // expected-note {{module imported here}}
 // expected-error@DependsOnModule.framework/module.map:64 {{module 
'DependsOnModule.C17' requires feature 'c17'}}
 @import DependsOnModule.C17; // expected-note {{module imported here}}
+// expected-error@DependsOnModule.framework/module.map:67 {{module 
'DependsOnModule.C23' requires feature 'c23'}}
+@import DependsOnModule.C23; // expected-note {{module imported here}}
 #endif
Index: clang/test/Modules/Inputs/DependsOnModule.framework/module.map
===
--- clang/test/Modules/Inputs/DependsOnModule.framework/module.map
+++ clang/test/Modules/Inputs/DependsOnModule.framework/module.map
@@ -64,4 +64,7 @@
   explicit module C17 {
 requires c17
   }
+  explicit module C23 {
+requires c23
+  }
 }
Index: clang/lib/Basic/Module.cpp
===
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -113,6 +113,7 @@
 .Case("c99", LangOpts.C99)
 .Case("c11", LangOpts.C11)
 .Case("c17", LangOpts.C17)
+.Case("c23", LangOpts.C23)
 .Case("freestanding", LangOpts.Freestanding)
 .Case("gnuinlineasm", LangOpts.GNUAsm)
 .Case("objc", LangOpts.ObjC)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -107,6 +107,7 @@
   and the ``__STDC_VERSION__`` macro now expands to ``202311L`` instead of its
   previous placeholder value. Clang continues to accept ``-std=c2x`` and
   ``-std=gnu2x`` as aliases for C23 and GNU C23, respectively.
+- Clang now supports `requires c23` for module maps.
 
 Non-comprehensive list of changes in this release
 -
Index: clang/docs/Modules.rst
===
--- clang/docs/Modules.rst
+++ clang/docs/Modules.rst
@@ -588,6 +588,9 @@
 c17
   C17 support is available.
 
+c23
+  C23 support is available.
+
 freestanding
   A freestanding environment is available.
 


Index: clang/test/Modules/requires.m
===
--- clang/test/Modules/requires.m
+++ clang/test/Modules/requires.m
@@ -35,4 +35,6 @@
 @import DependsOnModule.C11; // expected-note {{module imported here}}
 // expected-error@DependsOnModule.framework/module.map:64 {{module 'DependsOnModule.C17' requires feature 'c17'}}
 @import DependsOnModule.C17; // expected-note {{module imported here}}
+// expected-error@DependsOnModule.framework/module.map:67 {{module 'DependsOnModule.C23' requires feature 'c23'}}
+@import DependsOnModule.C23; // expected-note {{module imported here}}
 #endif
Index: clang/test/Modules/Inputs/DependsOnModule.framework/module.map
===
--- clang/test/Modules/Inputs/DependsOnModule.framework/module.map
+++ clang/test/Modules/Inputs/DependsOnModule.framework/module.map
@@ -64,4 +64,7 @@
   explicit module C17 {
 requires c17
   }
+  explicit module C23 {
+requires c23
+  }
 }
Index: clang/lib/Basic/Module.cpp
===
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -113,6 +113,7 @@
 .Case("c99", LangOpts.C99)
 .Case("c11", LangOpts.C11)
 .Case("c17", LangOpts.C17)
+.Case("c23", LangOpts.C23)
 .Case("freestanding", LangOpts.Freestanding)
 .Case("gnuinlineasm", LangOpts.GNUAsm)
 .Case("objc", LangOpts.ObjC)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -107,6 +107,7 @@
   and the ``__STDC_VERSION__`` macro now expands to ``202311L`` instead of its
   previous placeholder value. Clang continues to accept ``-std=c2x`` and
   ``-std=gnu2x`` as aliases for C23 and GNU C23, 

[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-08-29 Thread Ian Anderson via Phabricator via cfe-commits
iana added inline comments.



Comment at: clang/lib/Headers/__stddef_null.h:14
+ * __need_NULL and rely on stddef.h to redefine NULL to the correct value 
again.
+ * Modules don't support redefining macros like that, but support that pattern
+ * in the non-modules case.

I couldn't come up with anything clever to support this in modules. If I get 
rid of the guard, `NULL` still doesn't get redefined in modules. If I move the 
`undef` to stddef.h then `NULL` gets undefined, but not redefined. So I think 
precompiled modules must inherently have `#pragma once` semantics. If we really 
had to, we could move this back into stddef.h and let it be textual, but it's 
distasteful that `NULL` gets defined in every single module that includes 
stddef.h and has to be merged later.



Comment at: clang/test/Headers/stdarg.c:4
 // RUN: %clang_cc1 -fsyntax-only -verify=c99 
-Werror=implicit-function-declaration -std=c99 %t/stdarg0.c
+// RUN: %clang_cc1 -fsyntax-only -verify=c89-modules -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t 
-Werror=implicit-function-declaration -std=c89 %t/stdarg0.c
+// RUN: %clang_cc1 -fsyntax-only -verify=c99-modules -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t 
-Werror=implicit-function-declaration -std=c99 %t/stdarg0.c

I think it's fine to use these same tests to validate that modules mode makes 
the same things visible as non-modules mode depending on the standard and set 
`__need_` macros?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-08-29 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 554193.
iana added a comment.

Add `@import` tests for all of the new modules


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

Files:
  clang/lib/Headers/__stddef_max_align_t.h
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/module.modulemap
  clang/lib/Headers/stddef.h
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/compiler_builtins.m

Index: clang/test/Modules/compiler_builtins.m
===
--- clang/test/Modules/compiler_builtins.m
+++ clang/test/Modules/compiler_builtins.m
@@ -11,3 +11,17 @@
 #ifdef __AVX2__
 @import _Builtin_intrinsics.intel.avx2;
 #endif
+
+@import _Builtin_float;
+@import _Builtin_inttypes;
+@import _Builtin_iso646;
+@import _Builtin_limits;
+@import _Builtin_stdalign;
+@import _Builtin_stdarg;
+@import _Builtin_stdatomic;
+@import _Builtin_stdbool;
+@import _Builtin_stddef;
+@import _Builtin_stdint;
+@import _Builtin_stdnoreturn;
+@import _Builtin_tgmath;
+@import _Builtin_unwind;
Index: clang/test/Headers/stddefneeds.c
===
--- clang/test/Headers/stddefneeds.c
+++ clang/test/Headers/stddefneeds.c
@@ -1,36 +1,73 @@
+// RUN: rm -fR %t
 // RUN: %clang_cc1 -fsyntax-only -verify=c99 -std=c99 %s
 // RUN: %clang_cc1 -fsyntax-only -verify=c23 -std=c23 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c99-modules -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c23-modules -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -std=c23 %s
 
 // Use C99 to verify that __need_ can be used to get types that wouldn't normally be available.
 
 struct astruct { char member; };
 
-ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}}
-size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}}
-rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}}
-wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}}
-void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}}
-nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}}
-static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}}
-max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}}
+ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}} \
+ c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}} \
+  c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}} \
+   c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}} \
+c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}} \
+c99-modules-error{{undeclared identifier}} c23-modules-error{{undeclared identifier}}
+nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}} \
+ c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}} \
+   c99-modules-error{{undeclared function}} c23-modules-error{{undeclared identifier}}
+max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}} \
+   c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
 size_t o0 = offsetof(struct astruct, member); // c99-error{{unknown type name 'size_t'}} c99-error{{call to undeclared function 'offsetof'}} c99-error{{expected expression}} c99-error{{use of undeclared identifier 'member'}} \
- c23-error{{unknown type name 'size_t'}} c23-error{{undeclared identifier 'offsetof'}} c23-error{{expected expression}} c23-error{{use of undeclared identifier 'member'}}

[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-08-28 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 554183.
iana added a comment.

Remove the module cache before running the stdarg/stddef unit tests in module 
mode


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064

Files:
  clang/lib/Headers/__stddef_max_align_t.h
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/module.modulemap
  clang/lib/Headers/stddef.h
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c

Index: clang/test/Headers/stddefneeds.c
===
--- clang/test/Headers/stddefneeds.c
+++ clang/test/Headers/stddefneeds.c
@@ -1,36 +1,73 @@
+// RUN: rm -fR %t
 // RUN: %clang_cc1 -fsyntax-only -verify=c99 -std=c99 %s
 // RUN: %clang_cc1 -fsyntax-only -verify=c23 -std=c23 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c99-modules -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c23-modules -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -std=c23 %s
 
 // Use C99 to verify that __need_ can be used to get types that wouldn't normally be available.
 
 struct astruct { char member; };
 
-ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}}
-size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}}
-rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}}
-wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}}
-void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}}
-nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}}
-static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}}
-max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}}
+ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}} \
+ c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}} \
+  c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}} \
+   c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}} \
+c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}} \
+c99-modules-error{{undeclared identifier}} c23-modules-error{{undeclared identifier}}
+nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}} \
+ c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}} \
+   c99-modules-error{{undeclared function}} c23-modules-error{{undeclared identifier}}
+max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}} \
+   c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
 size_t o0 = offsetof(struct astruct, member); // c99-error{{unknown type name 'size_t'}} c99-error{{call to undeclared function 'offsetof'}} c99-error{{expected expression}} c99-error{{use of undeclared identifier 'member'}} \
- c23-error{{unknown type name 'size_t'}} c23-error{{undeclared identifier 'offsetof'}} c23-error{{expected expression}} c23-error{{use of undeclared identifier 'member'}}
-wint_t wi0; // c99-error{{unknown type name 'wint_t'}} c23-error{{unknown type}}
+ c23-error{{unknown type name 'size_t'}} c23-error{{undeclared identifier 'offsetof'}} c23-error{{expected expression}} c23-error{{use of undeclared identifier 'member'}} \
+ c99-modules-error{{unknown type}} c99-modules-error{{undeclared function}} c99-modules-error{{expected expression}} c99-modules-error{{undeclared identifier}} \
+ c23-modules-error{{unknown type}} c23-modules-error{{undeclared identifier}} 

[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

2023-08-28 Thread Ian Anderson via Phabricator via cfe-commits
iana created this revision.
iana added reviewers: aaron.ballman, rsmith, efriedma, ldionne, ChuanqiXu, 
Bigcheese, vsapsai, benlangmuir, dexonsmith.
Herald added a subscriber: ributzka.
Herald added a project: All.
iana requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Make top level modules for all the C standard library headers. Now that the 
stddef headers are modular, they can lose all of the __has_feature(modules) 
checks and declare their include guards.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159064

Files:
  clang/lib/Headers/__stddef_max_align_t.h
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/module.modulemap
  clang/lib/Headers/stddef.h
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c

Index: clang/test/Headers/stddefneeds.c
===
--- clang/test/Headers/stddefneeds.c
+++ clang/test/Headers/stddefneeds.c
@@ -1,36 +1,72 @@
 // RUN: %clang_cc1 -fsyntax-only -verify=c99 -std=c99 %s
 // RUN: %clang_cc1 -fsyntax-only -verify=c23 -std=c23 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c99-modules -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c23-modules -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -std=c23 %s
 
 // Use C99 to verify that __need_ can be used to get types that wouldn't normally be available.
 
 struct astruct { char member; };
 
-ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}}
-size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}}
-rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}}
-wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}}
-void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}}
-nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}}
-static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}}
-max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}}
+ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}} \
+ c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}} \
+  c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}} \
+   c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}} \
+c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}} \
+c99-modules-error{{undeclared identifier}} c23-modules-error{{undeclared identifier}}
+nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}} \
+ c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
+static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}} \
+   c99-modules-error{{undeclared function}} c23-modules-error{{undeclared identifier}}
+max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}} \
+   c99-modules-error{{unknown type}} c23-modules-error{{unknown type}}
 size_t o0 = offsetof(struct astruct, member); // c99-error{{unknown type name 'size_t'}} c99-error{{call to undeclared function 'offsetof'}} c99-error{{expected expression}} c99-error{{use of undeclared identifier 'member'}} \
- c23-error{{unknown type name 'size_t'}} c23-error{{undeclared identifier 'offsetof'}} c23-error{{expected expression}} c23-error{{use of undeclared identifier 'member'}}
-wint_t wi0; // c99-error{{unknown type name 'wint_t'}} c23-error{{unknown type}}
+ c23-error{{unknown type name 'size_t'}} c23-error{{undeclared identifier 'offsetof'}} c23-error{{expected expression}} c23-error{{use of undeclared identifier 'member'}} \
+ 

[PATCH] D159018: [clang][modules] Add a c23 module feature

2023-08-28 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 554158.
iana added a comment.

remove the extra #endif (which oddly didn't produce an error locally so I 
must've ran the tests wrong the first time...)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159018/new/

https://reviews.llvm.org/D159018

Files:
  clang/docs/Modules.rst
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Module.cpp
  clang/test/Modules/Inputs/DependsOnModule.framework/module.map
  clang/test/Modules/requires.m


Index: clang/test/Modules/requires.m
===
--- clang/test/Modules/requires.m
+++ clang/test/Modules/requires.m
@@ -35,4 +35,6 @@
 @import DependsOnModule.C11; // expected-note {{module imported here}}
 // expected-error@DependsOnModule.framework/module.map:64 {{module 
'DependsOnModule.C17' requires feature 'c17'}}
 @import DependsOnModule.C17; // expected-note {{module imported here}}
+// expected-error@DependsOnModule.framework/module.map:67 {{module 
'DependsOnModule.C23' requires feature 'c23'}}
+@import DependsOnModule.C23; // expected-note {{module imported here}}
 #endif
Index: clang/test/Modules/Inputs/DependsOnModule.framework/module.map
===
--- clang/test/Modules/Inputs/DependsOnModule.framework/module.map
+++ clang/test/Modules/Inputs/DependsOnModule.framework/module.map
@@ -64,4 +64,7 @@
   explicit module C17 {
 requires c17
   }
+  explicit module C23 {
+requires c23
+  }
 }
Index: clang/lib/Basic/Module.cpp
===
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -113,6 +113,7 @@
 .Case("c99", LangOpts.C99)
 .Case("c11", LangOpts.C11)
 .Case("c17", LangOpts.C17)
+.Case("c23", LangOpts.C23)
 .Case("freestanding", LangOpts.Freestanding)
 .Case("gnuinlineasm", LangOpts.GNUAsm)
 .Case("objc", LangOpts.ObjC)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -107,6 +107,7 @@
   and the ``__STDC_VERSION__`` macro now expands to ``202311L`` instead of its
   previous placeholder value. Clang continues to accept ``-std=c2x`` and
   ``-std=gnu2x`` as aliases for C23 and GNU C23, respectively.
+- Clang now supports `requires c23` for module maps.
 
 Non-comprehensive list of changes in this release
 -
Index: clang/docs/Modules.rst
===
--- clang/docs/Modules.rst
+++ clang/docs/Modules.rst
@@ -588,6 +588,9 @@
 c17
   C17 support is available.
 
+c23
+  C23 support is available.
+
 freestanding
   A freestanding environment is available.
 


Index: clang/test/Modules/requires.m
===
--- clang/test/Modules/requires.m
+++ clang/test/Modules/requires.m
@@ -35,4 +35,6 @@
 @import DependsOnModule.C11; // expected-note {{module imported here}}
 // expected-error@DependsOnModule.framework/module.map:64 {{module 'DependsOnModule.C17' requires feature 'c17'}}
 @import DependsOnModule.C17; // expected-note {{module imported here}}
+// expected-error@DependsOnModule.framework/module.map:67 {{module 'DependsOnModule.C23' requires feature 'c23'}}
+@import DependsOnModule.C23; // expected-note {{module imported here}}
 #endif
Index: clang/test/Modules/Inputs/DependsOnModule.framework/module.map
===
--- clang/test/Modules/Inputs/DependsOnModule.framework/module.map
+++ clang/test/Modules/Inputs/DependsOnModule.framework/module.map
@@ -64,4 +64,7 @@
   explicit module C17 {
 requires c17
   }
+  explicit module C23 {
+requires c23
+  }
 }
Index: clang/lib/Basic/Module.cpp
===
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -113,6 +113,7 @@
 .Case("c99", LangOpts.C99)
 .Case("c11", LangOpts.C11)
 .Case("c17", LangOpts.C17)
+.Case("c23", LangOpts.C23)
 .Case("freestanding", LangOpts.Freestanding)
 .Case("gnuinlineasm", LangOpts.GNUAsm)
 .Case("objc", LangOpts.ObjC)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -107,6 +107,7 @@
   and the ``__STDC_VERSION__`` macro now expands to ``202311L`` instead of its
   previous placeholder value. Clang continues to accept ``-std=c2x`` and
   ``-std=gnu2x`` as aliases for C23 

[PATCH] D159018: [clang][modules] Add a c23 module feature

2023-08-28 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

Would we want to back port this to llvm 17?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159018/new/

https://reviews.llvm.org/D159018

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159018: [clang][modules] Add a c23 module feature

2023-08-28 Thread Ian Anderson via Phabricator via cfe-commits
iana created this revision.
iana added reviewers: ChuanqiXu, Bigcheese, v.g.vassilev, aaron.ballman.
Herald added a subscriber: ributzka.
Herald added a project: All.
iana requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add a c23 module feature for `requires`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159018

Files:
  clang/docs/Modules.rst
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Module.cpp
  clang/test/Modules/Inputs/DependsOnModule.framework/module.map
  clang/test/Modules/requires.m


Index: clang/test/Modules/requires.m
===
--- clang/test/Modules/requires.m
+++ clang/test/Modules/requires.m
@@ -36,3 +36,6 @@
 // expected-error@DependsOnModule.framework/module.map:64 {{module 
'DependsOnModule.C17' requires feature 'c17'}}
 @import DependsOnModule.C17; // expected-note {{module imported here}}
 #endif
+// expected-error@DependsOnModule.framework/module.map:67 {{module 
'DependsOnModule.C23' requires feature 'c23'}}
+@import DependsOnModule.C23; // expected-note {{module imported here}}
+#endif
Index: clang/test/Modules/Inputs/DependsOnModule.framework/module.map
===
--- clang/test/Modules/Inputs/DependsOnModule.framework/module.map
+++ clang/test/Modules/Inputs/DependsOnModule.framework/module.map
@@ -64,4 +64,7 @@
   explicit module C17 {
 requires c17
   }
+  explicit module C23 {
+requires c23
+  }
 }
Index: clang/lib/Basic/Module.cpp
===
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -113,6 +113,7 @@
 .Case("c99", LangOpts.C99)
 .Case("c11", LangOpts.C11)
 .Case("c17", LangOpts.C17)
+.Case("c23", LangOpts.C23)
 .Case("freestanding", LangOpts.Freestanding)
 .Case("gnuinlineasm", LangOpts.GNUAsm)
 .Case("objc", LangOpts.ObjC)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -107,6 +107,7 @@
   and the ``__STDC_VERSION__`` macro now expands to ``202311L`` instead of its
   previous placeholder value. Clang continues to accept ``-std=c2x`` and
   ``-std=gnu2x`` as aliases for C23 and GNU C23, respectively.
+- Clang now supports `requires c23` for module maps.
 
 Non-comprehensive list of changes in this release
 -
Index: clang/docs/Modules.rst
===
--- clang/docs/Modules.rst
+++ clang/docs/Modules.rst
@@ -588,6 +588,9 @@
 c17
   C17 support is available.
 
+c23
+  C23 support is available.
+
 freestanding
   A freestanding environment is available.
 


Index: clang/test/Modules/requires.m
===
--- clang/test/Modules/requires.m
+++ clang/test/Modules/requires.m
@@ -36,3 +36,6 @@
 // expected-error@DependsOnModule.framework/module.map:64 {{module 'DependsOnModule.C17' requires feature 'c17'}}
 @import DependsOnModule.C17; // expected-note {{module imported here}}
 #endif
+// expected-error@DependsOnModule.framework/module.map:67 {{module 'DependsOnModule.C23' requires feature 'c23'}}
+@import DependsOnModule.C23; // expected-note {{module imported here}}
+#endif
Index: clang/test/Modules/Inputs/DependsOnModule.framework/module.map
===
--- clang/test/Modules/Inputs/DependsOnModule.framework/module.map
+++ clang/test/Modules/Inputs/DependsOnModule.framework/module.map
@@ -64,4 +64,7 @@
   explicit module C17 {
 requires c17
   }
+  explicit module C23 {
+requires c23
+  }
 }
Index: clang/lib/Basic/Module.cpp
===
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -113,6 +113,7 @@
 .Case("c99", LangOpts.C99)
 .Case("c11", LangOpts.C11)
 .Case("c17", LangOpts.C17)
+.Case("c23", LangOpts.C23)
 .Case("freestanding", LangOpts.Freestanding)
 .Case("gnuinlineasm", LangOpts.GNUAsm)
 .Case("objc", LangOpts.ObjC)
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -107,6 +107,7 @@
   and the ``__STDC_VERSION__`` macro now expands to ``202311L`` instead of its
   previous placeholder value. Clang continues to accept ``-std=c2x`` and
   ``-std=gnu2x`` as aliases for C23 and GNU C23, respectively.
+- Clang now supports `requires c23` 

[PATCH] D158709: [Headers][Modules] Make separate headers for the stdarg.h and stddef.h pieces so that they can be modularized

2023-08-28 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D158709#4621199 , @aaron.ballman 
wrote:

> At a high-level (not just for this patch, but for the entire series): is this 
> need specific to your downstream or is this a more general need? e.g., should 
> this complexity be kept downstream until we've got a second platform needing 
> it?

I think it's a general need to properly modularize the clang headers, I don't 
think it's really Apple specific.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158709/new/

https://reviews.llvm.org/D158709

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158709: [Headers][Modules] Make separate headers for the stdarg.h and stddef.h pieces so that they can be modularized

2023-08-25 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 553677.
iana added a comment.

Modules don't support the #include #undef #include pattern to redefine macros, 
the second include has no effect. Move the #undef of NULL into __stddef_null.h 
so that the textual behavior is preserved, but the module behavior doesn't 
leave NULL undefined.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158709/new/

https://reviews.llvm.org/D158709

Files:
  clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__stdarg___gnuc_va_list.h
  clang/lib/Headers/__stdarg___va_copy.h
  clang/lib/Headers/__stdarg_va_arg.h
  clang/lib/Headers/__stdarg_va_copy.h
  clang/lib/Headers/__stdarg_va_list.h
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/stddef.c
  compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
  llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
@@ -95,7 +95,21 @@
 "__clang_hip_math.h",
 "__clang_hip_runtime_wrapper.h",
 "__clang_hip_stdlib.h",
+"__stdarg___gnuc_va_list.h",
+"__stdarg___va_copy.h",
+"__stdarg_va_arg.h",
+"__stdarg_va_copy.h",
+"__stdarg_va_list.h",
 "__stddef_max_align_t.h",
+"__stddef_null.h",
+"__stddef_nullptr_t.h",
+"__stddef_offsetof.h",
+"__stddef_ptrdiff_t.h",
+"__stddef_rsize_t.h",
+"__stddef_size_t.h",
+"__stddef_unreachable.h",
+"__stddef_wchar_t.h",
+"__stddef_wint_t.h",
 "__wmmintrin_aes.h",
 "__wmmintrin_pclmul.h",
 "adxintrin.h",
Index: compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
===
--- compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
+++ compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
@@ -20,6 +20,15 @@
 #include 
 #include 
 // IWYU pragma: no_include <__stddef_max_align_t.h>
+// IWYU pragma: no_include <__stddef_null.h>
+// IWYU pragma: no_include <__stddef_nullptr_t.h>
+// IWYU pragma: no_include <__stddef_offsetof.h>
+// IWYU pragma: no_include <__stddef_ptrdiff_t.h>
+// IWYU pragma: no_include <__stddef_rsize_t.h>
+// IWYU pragma: no_include <__stddef_size_t.h>
+// IWYU pragma: no_include <__stddef_unreachable.h>
+// IWYU pragma: no_include <__stddef_wchar_t.h>
+// IWYU pragma: no_include <__stddef_wint_t.h>
 
 namespace gwp_asan {
 // This class is the primary implementation of the allocator portion of GWP-
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -6,7 +6,7 @@
 ptrdiff_t pdt;
 
 size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@stddef.h:* {{here}}
+// expected-note@__stddef_size_t.h:* {{here}}
 
 #include "include_again.h"
 
Index: clang/test/Headers/stddefneeds.c
===
--- clang/test/Headers/stddefneeds.c
+++ clang/test/Headers/stddefneeds.c
@@ -38,7 +38,7 @@
 ptrdiff_t p2;
 size_t s2;
 rsize_t r2; // c99-error{{unknown type}} c23-error{{unknown type}}
-// c99-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+// c99-note@__stddef_size_t.h:*{{'size_t' declared here}} c23-note@__stddef_size_t.h:*{{'size_t' declared here}}
 wchar_t wc2; // c99-error{{unknown type}} c23-error{{unknown type}}
 void *v2 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
 nullptr_t n2; // c99-error{{unknown type}} c23-error{{unknown type}}
@@ -96,7 +96,7 @@
 // __need_nullptr_t generates an error in  // c99-error@stddef.h:*{{expected function body}}
+#include  // c99-error@__stddef_nullptr_t.h:*{{expected function body}}
 
 ptrdiff_t p6;
 size_t s6;
Index: clang/test/Headers/stddef.c
===
--- clang/test/Headers/stddef.c
+++ clang/test/Headers/stddef.c
@@ -22,7 +22,7 @@
 ptrdiff_t p1;
 size_t s1;
 rsize_t r1; // c99-error{{unknown type}} c11-error{{unknown type}} c23-error{{unknown type}}
-// c99-note@stddef.h:*{{'size_t' declared here}} c11-note@stddef.h:*{{'size_t' declared 

[PATCH] D158709: [Headers][Modules] Make separate headers for the stdarg.h and stddef.h pieces so that they can be modularized

2023-08-25 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D158709#4617295 , @aaron.ballman 
wrote:

> I'm a bit concerned about the impact on (non-modules) build time performance. 
> This splits stddef.h and stdarg.h into needing to open 14 different files 
> instead of 2. Hopefully that's not a lot of overhead, but given that stddef.h 
> is included in approximately every TU and that sometimes external forces 
> cause files to be slow to open (network drives, AV software, etc), I think we 
> should be cautious and measure the impact. I also really do not like how 
> poorly this scales -- the fact that this is only needed for these two files 
> helps a bit, but this is a lot of C++-specific hoops to jump through for C 
> standard library headers.

This is in support of clang modules, not C++ modules. The plan is to make 
modules like this.

  module _Builtin_stddef [system] {
textual header "stddef.h"
  
explicit module max_align_t {
  header "__stddef_max_align_t.h"
  export *
}
  
explicit module null {
  header "__stddef_null.h"
  export *
}
...
  }

I do agree it's a bit of a file explosion, but I can't really think of any 
better alternatives. It's tough to measure build time performance impact. If 
you have a slow enough file system (and the fs on our builders at Apple is 
quite slow), and you aren't using modules or pch's, and you have quite a lot of 
source files, then probably this would be noticeable? I still don't know what 
we could really do about it besides have `#if !__has_feature(modules)` and 
inline the contents in that case. That seems like a maintenance headache and a 
half though. I would hope that most sizable projects either use clang modules 
or pch's?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158709/new/

https://reviews.llvm.org/D158709

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158709: [Headers][Modules] Make separate headers for the stdarg.h and stddef.h pieces so that they can be modularized

2023-08-24 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 553360.
iana added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158709/new/

https://reviews.llvm.org/D158709

Files:
  clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__stdarg___gnuc_va_list.h
  clang/lib/Headers/__stdarg___va_copy.h
  clang/lib/Headers/__stdarg_va_arg.h
  clang/lib/Headers/__stdarg_va_copy.h
  clang/lib/Headers/__stdarg_va_list.h
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/stddef.c
  compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
  llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
@@ -95,7 +95,21 @@
 "__clang_hip_math.h",
 "__clang_hip_runtime_wrapper.h",
 "__clang_hip_stdlib.h",
+"__stdarg___gnuc_va_list.h",
+"__stdarg___va_copy.h",
+"__stdarg_va_arg.h",
+"__stdarg_va_copy.h",
+"__stdarg_va_list.h",
 "__stddef_max_align_t.h",
+"__stddef_null.h",
+"__stddef_nullptr_t.h",
+"__stddef_offsetof.h",
+"__stddef_ptrdiff_t.h",
+"__stddef_rsize_t.h",
+"__stddef_size_t.h",
+"__stddef_unreachable.h",
+"__stddef_wchar_t.h",
+"__stddef_wint_t.h",
 "__wmmintrin_aes.h",
 "__wmmintrin_pclmul.h",
 "adxintrin.h",
Index: compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
===
--- compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
+++ compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
@@ -20,6 +20,15 @@
 #include 
 #include 
 // IWYU pragma: no_include <__stddef_max_align_t.h>
+// IWYU pragma: no_include <__stddef_null.h>
+// IWYU pragma: no_include <__stddef_nullptr_t.h>
+// IWYU pragma: no_include <__stddef_offsetof.h>
+// IWYU pragma: no_include <__stddef_ptrdiff_t.h>
+// IWYU pragma: no_include <__stddef_rsize_t.h>
+// IWYU pragma: no_include <__stddef_size_t.h>
+// IWYU pragma: no_include <__stddef_unreachable.h>
+// IWYU pragma: no_include <__stddef_wchar_t.h>
+// IWYU pragma: no_include <__stddef_wint_t.h>
 
 namespace gwp_asan {
 // This class is the primary implementation of the allocator portion of GWP-
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -6,7 +6,7 @@
 ptrdiff_t pdt;
 
 size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@stddef.h:* {{here}}
+// expected-note@__stddef_size_t.h:* {{here}}
 
 #include "include_again.h"
 
Index: clang/test/Headers/stddefneeds.c
===
--- clang/test/Headers/stddefneeds.c
+++ clang/test/Headers/stddefneeds.c
@@ -38,7 +38,7 @@
 ptrdiff_t p2;
 size_t s2;
 rsize_t r2; // c99-error{{unknown type}} c23-error{{unknown type}}
-// c99-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+// c99-note@__stddef_size_t.h:*{{'size_t' declared here}} c23-note@__stddef_size_t.h:*{{'size_t' declared here}}
 wchar_t wc2; // c99-error{{unknown type}} c23-error{{unknown type}}
 void *v2 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
 nullptr_t n2; // c99-error{{unknown type}} c23-error{{unknown type}}
@@ -96,7 +96,7 @@
 // __need_nullptr_t generates an error in  // c99-error@stddef.h:*{{expected function body}}
+#include  // c99-error@__stddef_nullptr_t.h:*{{expected function body}}
 
 ptrdiff_t p6;
 size_t s6;
Index: clang/test/Headers/stddef.c
===
--- clang/test/Headers/stddef.c
+++ clang/test/Headers/stddef.c
@@ -22,7 +22,7 @@
 ptrdiff_t p1;
 size_t s1;
 rsize_t r1; // c99-error{{unknown type}} c11-error{{unknown type}} c23-error{{unknown type}}
-// c99-note@stddef.h:*{{'size_t' declared here}} c11-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+// c99-note@__stddef_size_t.h:*{{'size_t' declared here}} c11-note@__stddef_size_t.h:*{{'size_t' declared here}} c23-note@__stddef_size_t.h:*{{'size_t' declared here}}
 wchar_t wc1;
 void 

[PATCH] D158709: [Headers][Modules] Make separate headers for the stdarg.h and stddef.h pieces so that they can be modularized

2023-08-24 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 553242.
iana added a comment.

Fixed the failing test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158709/new/

https://reviews.llvm.org/D158709

Files:
  clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__stdarg___gnuc_va_list.h
  clang/lib/Headers/__stdarg___va_copy.h
  clang/lib/Headers/__stdarg_va_arg.h
  clang/lib/Headers/__stdarg_va_copy.h
  clang/lib/Headers/__stdarg_va_list.h
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  clang/test/Modules/stddef.c
  compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
  llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
@@ -95,7 +95,21 @@
 "__clang_hip_math.h",
 "__clang_hip_runtime_wrapper.h",
 "__clang_hip_stdlib.h",
+"__stdarg___gnuc_va_list.h",
+"__stdarg___va_copy.h",
+"__stdarg_va_arg.h",
+"__stdarg_va_copy.h",
+"__stdarg_va_list.h",
 "__stddef_max_align_t.h",
+"__stddef_null.h",
+"__stddef_nullptr_t.h",
+"__stddef_offsetof.h",
+"__stddef_ptrdiff_t.h",
+"__stddef_rsize_t.h",
+"__stddef_size_t.h",
+"__stddef_unreachable.h",
+"__stddef_wchar_t.h",
+"__stddef_wint_t.h",
 "__wmmintrin_aes.h",
 "__wmmintrin_pclmul.h",
 "adxintrin.h",
Index: compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
===
--- compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
+++ compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
@@ -20,6 +20,15 @@
 #include 
 #include 
 // IWYU pragma: no_include <__stddef_max_align_t.h>
+// IWYU pragma: no_include <__stddef_null.h>
+// IWYU pragma: no_include <__stddef_nullptr_t.h>
+// IWYU pragma: no_include <__stddef_offsetof.h>
+// IWYU pragma: no_include <__stddef_ptrdiff_t.h>
+// IWYU pragma: no_include <__stddef_rsize_t.h>
+// IWYU pragma: no_include <__stddef_size_t.h>
+// IWYU pragma: no_include <__stddef_unreachable.h>
+// IWYU pragma: no_include <__stddef_wchar_t.h>
+// IWYU pragma: no_include <__stddef_wint_t.h>
 
 namespace gwp_asan {
 // This class is the primary implementation of the allocator portion of GWP-
Index: clang/test/Modules/stddef.c
===
--- clang/test/Modules/stddef.c
+++ clang/test/Modules/stddef.c
@@ -6,7 +6,7 @@
 ptrdiff_t pdt;
 
 size_t st; // expected-error {{missing '#include "include_again.h"'; 'size_t' must be declared before it is used}}
-// expected-note@stddef.h:* {{here}}
+// expected-note@__stddef_size_t.h:* {{here}}
 
 #include "include_again.h"
 
Index: clang/test/Headers/stddefneeds.c
===
--- clang/test/Headers/stddefneeds.c
+++ clang/test/Headers/stddefneeds.c
@@ -38,7 +38,7 @@
 ptrdiff_t p2;
 size_t s2;
 rsize_t r2; // c99-error{{unknown type}} c23-error{{unknown type}}
-// c99-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+// c99-note@__stddef_size_t.h:*{{'size_t' declared here}} c23-note@__stddef_size_t.h:*{{'size_t' declared here}}
 wchar_t wc2; // c99-error{{unknown type}} c23-error{{unknown type}}
 void *v2 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
 nullptr_t n2; // c99-error{{unknown type}} c23-error{{unknown type}}
@@ -96,7 +96,7 @@
 // __need_nullptr_t generates an error in  // c99-error@stddef.h:*{{expected function body}}
+#include  // c99-error@__stddef_nullptr_t.h:*{{expected function body}}
 
 ptrdiff_t p6;
 size_t s6;
Index: clang/test/Headers/stddef.c
===
--- clang/test/Headers/stddef.c
+++ clang/test/Headers/stddef.c
@@ -22,7 +22,7 @@
 ptrdiff_t p1;
 size_t s1;
 rsize_t r1; // c99-error{{unknown type}} c11-error{{unknown type}} c23-error{{unknown type}}
-// c99-note@stddef.h:*{{'size_t' declared here}} c11-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+// c99-note@__stddef_size_t.h:*{{'size_t' declared here}} c11-note@__stddef_size_t.h:*{{'size_t' declared here}} c23-note@__stddef_size_t.h:*{{'size_t' declared here}}
 

[PATCH] D158709: [Headers][Modules] Make separate headers for the stdarg.h and stddef.h pieces so that they can be modularized

2023-08-24 Thread Ian Anderson via Phabricator via cfe-commits
iana created this revision.
iana added reviewers: aaron.ballman, rsmith, efriedma, ldionne.
Herald added subscribers: Enna1, ributzka, mstorsjo, kadircet, arphaman.
Herald added a project: All.
iana requested review of this revision.
Herald added projects: clang, Sanitizers, LLVM, clang-tools-extra.
Herald added subscribers: cfe-commits, llvm-commits, Sanitizers.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158709

Files:
  clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__stdarg___gnuc_va_list.h
  clang/lib/Headers/__stdarg___va_copy.h
  clang/lib/Headers/__stdarg_va_arg.h
  clang/lib/Headers/__stdarg_va_copy.h
  clang/lib/Headers/__stdarg_va_list.h
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
  llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
@@ -95,7 +95,21 @@
 "__clang_hip_math.h",
 "__clang_hip_runtime_wrapper.h",
 "__clang_hip_stdlib.h",
+"__stdarg___gnuc_va_list.h",
+"__stdarg___va_copy.h",
+"__stdarg_va_arg.h",
+"__stdarg_va_copy.h",
+"__stdarg_va_list.h",
 "__stddef_max_align_t.h",
+"__stddef_null.h",
+"__stddef_nullptr_t.h",
+"__stddef_offsetof.h",
+"__stddef_ptrdiff_t.h",
+"__stddef_rsize_t.h",
+"__stddef_size_t.h",
+"__stddef_unreachable.h",
+"__stddef_wchar_t.h",
+"__stddef_wint_t.h",
 "__wmmintrin_aes.h",
 "__wmmintrin_pclmul.h",
 "adxintrin.h",
Index: compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
===
--- compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
+++ compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
@@ -20,6 +20,15 @@
 #include 
 #include 
 // IWYU pragma: no_include <__stddef_max_align_t.h>
+// IWYU pragma: no_include <__stddef_null.h>
+// IWYU pragma: no_include <__stddef_nullptr_t.h>
+// IWYU pragma: no_include <__stddef_offsetof.h>
+// IWYU pragma: no_include <__stddef_ptrdiff_t.h>
+// IWYU pragma: no_include <__stddef_rsize_t.h>
+// IWYU pragma: no_include <__stddef_size_t.h>
+// IWYU pragma: no_include <__stddef_unreachable.h>
+// IWYU pragma: no_include <__stddef_wchar_t.h>
+// IWYU pragma: no_include <__stddef_wint_t.h>
 
 namespace gwp_asan {
 // This class is the primary implementation of the allocator portion of GWP-
Index: clang/test/Headers/stddefneeds.c
===
--- clang/test/Headers/stddefneeds.c
+++ clang/test/Headers/stddefneeds.c
@@ -38,7 +38,7 @@
 ptrdiff_t p2;
 size_t s2;
 rsize_t r2; // c99-error{{unknown type}} c23-error{{unknown type}}
-// c99-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+// c99-note@__stddef_size_t.h:*{{'size_t' declared here}} c23-note@__stddef_size_t.h:*{{'size_t' declared here}}
 wchar_t wc2; // c99-error{{unknown type}} c23-error{{unknown type}}
 void *v2 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
 nullptr_t n2; // c99-error{{unknown type}} c23-error{{unknown type}}
@@ -96,7 +96,7 @@
 // __need_nullptr_t generates an error in  // c99-error@stddef.h:*{{expected function body}}
+#include  // c99-error@__stddef_nullptr_t.h:*{{expected function body}}
 
 ptrdiff_t p6;
 size_t s6;
Index: clang/test/Headers/stddef.c
===
--- clang/test/Headers/stddef.c
+++ clang/test/Headers/stddef.c
@@ -22,7 +22,7 @@
 ptrdiff_t p1;
 size_t s1;
 rsize_t r1; // c99-error{{unknown type}} c11-error{{unknown type}} c23-error{{unknown type}}
-// c99-note@stddef.h:*{{'size_t' declared here}} c11-note@stddef.h:*{{'size_t' declared here}} 

[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-24 Thread Ian Anderson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG72da678d8c84: [Headers] Replace __need_STDDEF_H_misc with 
specific __need_ macros (authored by iana).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

Files:
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c

Index: clang/test/Headers/stddefneeds.c
===
--- /dev/null
+++ clang/test/Headers/stddefneeds.c
@@ -0,0 +1,169 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=c99 -std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c23 -std=c23 %s
+
+// Use C99 to verify that __need_ can be used to get types that wouldn't normally be available.
+
+struct astruct { char member; };
+
+ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}}
+size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}}
+rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}}
+wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}}
+void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}}
+nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}}
+static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}}
+max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}}
+size_t o0 = offsetof(struct astruct, member); // c99-error{{unknown type name 'size_t'}} c99-error{{call to undeclared function 'offsetof'}} c99-error{{expected expression}} c99-error{{use of undeclared identifier 'member'}} \
+ c23-error{{unknown type name 'size_t'}} c23-error{{undeclared identifier 'offsetof'}} c23-error{{expected expression}} c23-error{{use of undeclared identifier 'member'}}
+wint_t wi0; // c99-error{{unknown type name 'wint_t'}} c23-error{{unknown type}}
+
+#define __need_ptrdiff_t
+#include 
+
+ptrdiff_t p1;
+size_t s1; // c99-error{{unknown type}} c23-error{{unknown type}}
+rsize_t r1; // c99-error{{unknown type}} c23-error{{unknown type}}
+wchar_t wc1; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v1 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n1; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f1(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m1; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o1 = offsetof(struct astruct, member); // c99-error{{unknown type}} c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{unknown type}} c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi1; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_size_t
+#include 
+
+ptrdiff_t p2;
+size_t s2;
+rsize_t r2; // c99-error{{unknown type}} c23-error{{unknown type}}
+// c99-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+wchar_t wc2; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v2 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n2; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f2(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m2; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o2 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi2; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_rsize_t
+#include 
+
+ptrdiff_t p3;
+size_t s3;
+rsize_t r3;
+wchar_t wc3; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v3 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n3; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f3(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m3; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o3 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi3; // 

[PATCH] D157793: [Headers] Add missing __need_ macros to stdarg.h

2023-08-24 Thread Ian Anderson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG62f769aa82f6: [Headers] Add missing __need_ macros to 
stdarg.h (authored by iana).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157793/new/

https://reviews.llvm.org/D157793

Files:
  clang/lib/Headers/stdarg.h
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c

Index: clang/test/Headers/stdargneeds.c
===
--- /dev/null
+++ clang/test/Headers/stdargneeds.c
@@ -0,0 +1,91 @@
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds0.c
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds1.c
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds2.c
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds3.c
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds4.c
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds5.c
+
+// Split the file so that the "implicitly declaring library function" errors get repeated.
+// Use C89 to verify that __need_ can be used to get types that wouldn't normally be available.
+
+//--- stdargneeds0.c
+static void f(int p, ...) {
+__gnuc_va_list g; // expected-error{{undeclared identifier '__gnuc_va_list'}}
+va_list v; // expected-error{{undeclared identifier 'va_list'}}
+va_start(v, p); // expected-error{{implicitly declaring library function 'va_start'}} expected-note{{include the header  or explicitly provide a declaration for 'va_start'}} expected-error{{undeclared identifier 'v'}}
+int i = va_arg(v, int); // expected-error{{implicit declaration of function 'va_arg'}} expected-error{{expected expression}} expected-error{{use of undeclared identifier 'v'}}
+va_end(v); // expected-error{{implicitly declaring library function 'va_end'}} expected-note{{include the header  or explicitly provide a declaration for 'va_end'}} expected-error{{undeclared identifier 'v'}}
+__va_copy(g, v); // expected-error{{implicit declaration of function '__va_copy'}} expected-error{{use of undeclared identifier 'g'}} expected-error{{use of undeclared identifier 'v'}}
+va_copy(g, v); // expected-error{{implicitly declaring library function 'va_copy'}} expected-note{{include the header  or explicitly provide a declaration for 'va_copy'}} expected-error{{use of undeclared identifier 'g'}} expected-error{{use of undeclared identifier 'v'}}
+}
+
+//--- stdargneeds1.c
+#define __need___va_list
+#include 
+static void f(int p, ...) {
+__gnuc_va_list g;
+va_list v; // expected-error{{undeclared identifier}}
+va_start(v, p); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}} expected-error{{undeclared identifier}}
+int i = va_arg(v, int); // expected-error{{implicit declaration of function}} expected-error{{expected expression}} expected-error{{undeclared identifier}}
+va_end(v); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}} expected-error{{undeclared identifier}}
+__va_copy(g, v); // expected-error{{implicit declaration of function}} expected-error{{undeclared identifier}}
+va_copy(g, v); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}} expected-error{{undeclared identifier}}
+}
+
+//--- stdargneeds2.c
+#define __need_va_list
+#include 
+static void f(int p, ...) {
+__gnuc_va_list g; // expected-error{{undeclared identifier}}
+va_list v;
+va_start(v, p); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}}
+int i = va_arg(v, int); // expected-error{{implicit declaration of function}} expected-error{{expected expression}}
+va_end(v); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}}
+__va_copy(g, v); // expected-error{{implicit declaration of function}} expected-error{{undeclared identifier}}
+va_copy(g, v); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}} expected-error{{undeclared identifier}}
+}
+
+//--- stdargneeds3.c
+#define __need_va_list
+#define __need_va_arg
+#include 
+static void f(int p, ...) {
+__gnuc_va_list g; // expected-error{{undeclared identifier}}
+va_list v;
+va_start(v, p);
+int i = va_arg(v, int);
+va_end(v);
+__va_copy(g, v); // expected-error{{implicit declaration of function}} expected-error{{undeclared identifier}}
+va_copy(g, v); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}} expected-error{{undeclared 

[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-24 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

Windows succeeding earlier, I'm pretty confident that the current crash isn't 
due to this review, so I'm going to go ahead and land.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-24 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 553003.
iana added a comment.

Try rebasing one more time


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

Files:
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c

Index: clang/test/Headers/stddefneeds.c
===
--- /dev/null
+++ clang/test/Headers/stddefneeds.c
@@ -0,0 +1,169 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=c99 -std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c23 -std=c23 %s
+
+// Use C99 to verify that __need_ can be used to get types that wouldn't normally be available.
+
+struct astruct { char member; };
+
+ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}}
+size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}}
+rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}}
+wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}}
+void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}}
+nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}}
+static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}}
+max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}}
+size_t o0 = offsetof(struct astruct, member); // c99-error{{unknown type name 'size_t'}} c99-error{{call to undeclared function 'offsetof'}} c99-error{{expected expression}} c99-error{{use of undeclared identifier 'member'}} \
+ c23-error{{unknown type name 'size_t'}} c23-error{{undeclared identifier 'offsetof'}} c23-error{{expected expression}} c23-error{{use of undeclared identifier 'member'}}
+wint_t wi0; // c99-error{{unknown type name 'wint_t'}} c23-error{{unknown type}}
+
+#define __need_ptrdiff_t
+#include 
+
+ptrdiff_t p1;
+size_t s1; // c99-error{{unknown type}} c23-error{{unknown type}}
+rsize_t r1; // c99-error{{unknown type}} c23-error{{unknown type}}
+wchar_t wc1; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v1 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n1; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f1(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m1; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o1 = offsetof(struct astruct, member); // c99-error{{unknown type}} c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{unknown type}} c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi1; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_size_t
+#include 
+
+ptrdiff_t p2;
+size_t s2;
+rsize_t r2; // c99-error{{unknown type}} c23-error{{unknown type}}
+// c99-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+wchar_t wc2; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v2 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n2; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f2(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m2; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o2 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi2; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_rsize_t
+#include 
+
+ptrdiff_t p3;
+size_t s3;
+rsize_t r3;
+wchar_t wc3; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v3 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n3; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f3(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m3; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o3 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi3; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_wchar_t
+#include 
+
+ptrdiff_t p4;
+size_t s4;
+rsize_t r4;
+wchar_t wc4;
+void *v4 = 

[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-23 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 552971.
iana added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

Files:
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c

Index: clang/test/Headers/stddefneeds.c
===
--- /dev/null
+++ clang/test/Headers/stddefneeds.c
@@ -0,0 +1,169 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=c99 -std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c23 -std=c23 %s
+
+// Use C99 to verify that __need_ can be used to get types that wouldn't normally be available.
+
+struct astruct { char member; };
+
+ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}}
+size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}}
+rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}}
+wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}}
+void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}}
+nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}}
+static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}}
+max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}}
+size_t o0 = offsetof(struct astruct, member); // c99-error{{unknown type name 'size_t'}} c99-error{{call to undeclared function 'offsetof'}} c99-error{{expected expression}} c99-error{{use of undeclared identifier 'member'}} \
+ c23-error{{unknown type name 'size_t'}} c23-error{{undeclared identifier 'offsetof'}} c23-error{{expected expression}} c23-error{{use of undeclared identifier 'member'}}
+wint_t wi0; // c99-error{{unknown type name 'wint_t'}} c23-error{{unknown type}}
+
+#define __need_ptrdiff_t
+#include 
+
+ptrdiff_t p1;
+size_t s1; // c99-error{{unknown type}} c23-error{{unknown type}}
+rsize_t r1; // c99-error{{unknown type}} c23-error{{unknown type}}
+wchar_t wc1; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v1 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n1; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f1(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m1; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o1 = offsetof(struct astruct, member); // c99-error{{unknown type}} c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{unknown type}} c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi1; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_size_t
+#include 
+
+ptrdiff_t p2;
+size_t s2;
+rsize_t r2; // c99-error{{unknown type}} c23-error{{unknown type}}
+// c99-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+wchar_t wc2; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v2 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n2; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f2(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m2; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o2 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi2; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_rsize_t
+#include 
+
+ptrdiff_t p3;
+size_t s3;
+rsize_t r3;
+wchar_t wc3; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v3 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n3; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f3(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m3; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o3 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi3; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_wchar_t
+#include 
+
+ptrdiff_t p4;
+size_t s4;
+rsize_t r4;
+wchar_t wc4;
+void *v4 = NULL; // 

[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-23 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D157757#4611492 , @iana wrote:

> In D157757#4611425 , @ldionne wrote:
>
>> Also we should figure out why the Clang modules build is failing on top of 
>> this, it doesn't look like a false positive.
>
> Where do you see that failure?

Never mind, I see it now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-23 Thread Ian Anderson via Phabricator via cfe-commits
iana marked an inline comment as done.
iana added a comment.

In D157757#4611425 , @ldionne wrote:

> Also we should figure out why the Clang modules build is failing on top of 
> this, it doesn't look like a false positive.

Where do you see that failure?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-23 Thread Ian Anderson via Phabricator via cfe-commits
iana marked 13 inline comments as done.
iana added inline comments.



Comment at: clang/lib/Headers/stddef.h:119-121
+namespace std {
+typedef decltype(nullptr) nullptr_t;
+}

ldionne wrote:
> You could reduce the diff by not reformatting this.
That's what I did initially, but the CI failed its formatting check.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-22 Thread Ian Anderson via Phabricator via cfe-commits
iana added inline comments.



Comment at: clang/lib/Headers/stddef.h:118-122
+#ifdef __cplusplus
+namespace std {
+typedef decltype(nullptr) nullptr_t;
+}
+using ::std::nullptr_t;

aaron.ballman wrote:
> ldionne wrote:
> > iana wrote:
> > > aaron.ballman wrote:
> > > > iana wrote:
> > > > > aaron.ballman wrote:
> > > > > > iana wrote:
> > > > > > > ldionne wrote:
> > > > > > > > iana wrote:
> > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > Related:
> > > > > > > > > > 
> > > > > > > > > > https://github.com/llvm/llvm-project/issues/37564
> > > > > > > > > > https://cplusplus.github.io/LWG/issue3484
> > > > > > > > > > 
> > > > > > > > > > CC @ldionne
> > > > > > > > > I don't _think_ this change actually changes the way 
> > > > > > > > > nullptr_t gets defined in C++, does it?
> > > > > > > > I think we absolutely don't want to touch `std::nullptr_t` from 
> > > > > > > > this header. It's libc++'s responsibility to define that, and 
> > > > > > > > in fact we define it in `std::__1`, so this is even an ABI 
> > > > > > > > break (or I guess it would be a compiler error, not sure).
> > > > > > > I'm really not touching it though. All I did is move it from 
> > > > > > > `__need_NULL` to `__need_nullptr_t`.
> > > > > > > 
> > > > > > > The old behavior is that `std::nullptr_t` would only be touched 
> > > > > > > if (no `__need_` macros were set or if `__need_NULL` was set), 
> > > > > > > and (_MSC_EXTENSIONS and _NATIVE_NULLPTR_SUPPORTED are defined).
> > > > > > > 
> > > > > > > The new behavior is that `std::nullptr_t` will only be touched if 
> > > > > > > ((no `__need_` macros are set) and (_MSC_EXTENSIONS and 
> > > > > > > _NATIVE_NULLPTR_SUPPORTED are defined)) or (the new 
> > > > > > > `__need_nullptr_t` macro is set)
> > > > > > > 
> > > > > > > So the only change is that C++ code that previously set 
> > > > > > > `__need_NULL` will no longer get `std::nullptr_t`. @efriedma felt 
> > > > > > > like that was a fine change.
> > > > > > Does libc++ provide the symbols for a freestanding compilation?
> > > > > > 
> > > > > > I was pointing out those links specifically because the C++ 
> > > > > > standard currently says that stddef.h (the C standard library 
> > > > > > header) needs to provide a definition of `std::nullptr_t`, but that 
> > > > > > LWG thinks that's perhaps not the right way to do that and may be 
> > > > > > removing that requirement.
> > > > > It is weird the standard puts that in stddef.h and not cstddef. I 
> > > > > think libc++ could provide that in their stddef.h anyway, but the 
> > > > > intent in this review is to not rock the boat and only do the minimal 
> > > > > change discussed above.
> > > > Yeah, this discussion is to figure out whether we have an existing bug 
> > > > we need to address and if so, where to address it (libc++, clang, or 
> > > > the C++ standard). I don't think your changes are exacerbating 
> > > > anything, more just that they've potentially pointed out something 
> > > > related.
> > >  
> > > Does libc++ provide the symbols for a freestanding compilation?
> > 
> > I don't think we do. We basically don't support `-ffreestanding` right now 
> > (we support embedded and funky platforms via other mechanisms).
> > 
> > But regardless, `` should never define something in namespace 
> > `std`, that should be libc++'s responsibility IMO. What we could do here 
> > instead is just
> > 
> > ```
> > #ifdef __cplusplus
> > typedef decltype(nullptr) nullptr_t;
> > #else
> > typedef typeof(nullptr) nullptr_t;
> > #endif
> > ```
> > 
> > and then let libc++'s `` do
> > 
> > ```
> > _LIBCPP_BEGIN_NAMESPACE_STD
> > using ::nullptr_t;
> > _LIBCPP_END_NAMESPACE_STD
> > ```
> > 
> > If Clang's `` did define `::nullptr_t`, we could likely remove 
> > libc++'s `` and that might simplify things.
> >> Does libc++ provide the symbols for a freestanding compilation?
> > I don't think we do. We basically don't support -ffreestanding right now 
> > (we support embedded and funky platforms via other mechanisms).
> 
> Okay, that's what I thought as well. Thanks!
> 
> > But regardless,  should never define something in namespace std, 
> > that should be libc++'s responsibility IMO. What we could do here instead 
> > is just
> 
> Ah, so you're thinking stddef.h should provide the global nullptr_t and 
> cstddef should provide the std::nullptr_t. I was thinking stddef.h should not 
> define nullptr_t in C++ mode at all; it's a C header, not a C++ header. That 
> led me to thinking about what the behavior should be in C23 given that it 
> supports nullptr_t.
> 
> Were it not for the current requirement that stddef.h provide nullptr_t, I 
> think stddef.h should do:
> ```
> typedef typeof(nullptr) nullptr_t;
> ```
> in C23 mode and not do anything special for C++ at all. C's `nullptr_t` needs 
> to be ABI compatible with C++'s `nullptr_t`, so a C++ user including the C 
> header should not get any problems linking against a C++ 

[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-22 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 552591.
iana added a comment.

Only define nullptr_t in C++ if _MSC_EXTENSIONS is defined, even if 
__need_nullptr_t is explicitly set.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

Files:
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c

Index: clang/test/Headers/stddefneeds.c
===
--- /dev/null
+++ clang/test/Headers/stddefneeds.c
@@ -0,0 +1,169 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=c99 -std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c23 -std=c23 %s
+
+// Use C99 to verify that __need_ can be used to get types that wouldn't normally be available.
+
+struct astruct { char member; };
+
+ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}}
+size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}}
+rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}}
+wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}}
+void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}}
+nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}}
+static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}}
+max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}}
+size_t o0 = offsetof(struct astruct, member); // c99-error{{unknown type name 'size_t'}} c99-error{{call to undeclared function 'offsetof'}} c99-error{{expected expression}} c99-error{{use of undeclared identifier 'member'}} \
+ c23-error{{unknown type name 'size_t'}} c23-error{{undeclared identifier 'offsetof'}} c23-error{{expected expression}} c23-error{{use of undeclared identifier 'member'}}
+wint_t wi0; // c99-error{{unknown type name 'wint_t'}} c23-error{{unknown type}}
+
+#define __need_ptrdiff_t
+#include 
+
+ptrdiff_t p1;
+size_t s1; // c99-error{{unknown type}} c23-error{{unknown type}}
+rsize_t r1; // c99-error{{unknown type}} c23-error{{unknown type}}
+wchar_t wc1; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v1 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n1; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f1(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m1; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o1 = offsetof(struct astruct, member); // c99-error{{unknown type}} c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{unknown type}} c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi1; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_size_t
+#include 
+
+ptrdiff_t p2;
+size_t s2;
+rsize_t r2; // c99-error{{unknown type}} c23-error{{unknown type}}
+// c99-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+wchar_t wc2; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v2 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n2; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f2(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m2; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o2 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi2; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_rsize_t
+#include 
+
+ptrdiff_t p3;
+size_t s3;
+rsize_t r3;
+wchar_t wc3; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v3 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n3; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f3(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m3; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o3 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi3; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_wchar_t

[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-22 Thread Ian Anderson via Phabricator via cfe-commits
iana added inline comments.



Comment at: clang/lib/Headers/stddef.h:1
 /*=== stddef.h - Basic type definitions ===
  *

aaron.ballman wrote:
> ldionne wrote:
> > Making a thread out of this:
> > 
> > > The relationship between clang's stddef.h and the C Standard Library 
> > > stddef.h is that there is no relationship. clang's header doesn't 
> > > #include_next, and it is in the search path before the OS's cstdlib.
> > 
> > So in that case what is the purpose of the SDK/system providing a 
> > `` header? They basically all provide one and it's never used?
> > 
> The compiler provides `` for the same reason it provides 
> `` and others: the compiler is responsible for defining these 
> interfaces because it's the only thing that knows the correct definitions it 
> expects. The system might know some of it, but for example, `size_t` relates 
> to the maximum size of an object, which is something only the compiler knows 
> the answer to.
I think the purpose is for the SDK/system to support compilers that don't 
provide ``. In the early Apple days that was CodeWarrior, maybe gcc 
didn't used to provide that header? I don't know.

But basically yes, they all provide one and it's practically never used.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-21 Thread Ian Anderson via Phabricator via cfe-commits
iana added inline comments.



Comment at: clang/lib/Headers/stddef.h:118-122
+#ifdef __cplusplus
+namespace std {
+typedef decltype(nullptr) nullptr_t;
+}
+using ::std::nullptr_t;

aaron.ballman wrote:
> iana wrote:
> > aaron.ballman wrote:
> > > iana wrote:
> > > > ldionne wrote:
> > > > > iana wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > Related:
> > > > > > > 
> > > > > > > https://github.com/llvm/llvm-project/issues/37564
> > > > > > > https://cplusplus.github.io/LWG/issue3484
> > > > > > > 
> > > > > > > CC @ldionne
> > > > > > I don't _think_ this change actually changes the way nullptr_t gets 
> > > > > > defined in C++, does it?
> > > > > I think we absolutely don't want to touch `std::nullptr_t` from this 
> > > > > header. It's libc++'s responsibility to define that, and in fact we 
> > > > > define it in `std::__1`, so this is even an ABI break (or I guess it 
> > > > > would be a compiler error, not sure).
> > > > I'm really not touching it though. All I did is move it from 
> > > > `__need_NULL` to `__need_nullptr_t`.
> > > > 
> > > > The old behavior is that `std::nullptr_t` would only be touched if (no 
> > > > `__need_` macros were set or if `__need_NULL` was set), and 
> > > > (_MSC_EXTENSIONS and _NATIVE_NULLPTR_SUPPORTED are defined).
> > > > 
> > > > The new behavior is that `std::nullptr_t` will only be touched if ((no 
> > > > `__need_` macros are set) and (_MSC_EXTENSIONS and 
> > > > _NATIVE_NULLPTR_SUPPORTED are defined)) or (the new `__need_nullptr_t` 
> > > > macro is set)
> > > > 
> > > > So the only change is that C++ code that previously set `__need_NULL` 
> > > > will no longer get `std::nullptr_t`. @efriedma felt like that was a 
> > > > fine change.
> > > Does libc++ provide the symbols for a freestanding compilation?
> > > 
> > > I was pointing out those links specifically because the C++ standard 
> > > currently says that stddef.h (the C standard library header) needs to 
> > > provide a definition of `std::nullptr_t`, but that LWG thinks that's 
> > > perhaps not the right way to do that and may be removing that requirement.
> > It is weird the standard puts that in stddef.h and not cstddef. I think 
> > libc++ could provide that in their stddef.h anyway, but the intent in this 
> > review is to not rock the boat and only do the minimal change discussed 
> > above.
> Yeah, this discussion is to figure out whether we have an existing bug we 
> need to address and if so, where to address it (libc++, clang, or the C++ 
> standard). I don't think your changes are exacerbating anything, more just 
> that they've potentially pointed out something related.
 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-21 Thread Ian Anderson via Phabricator via cfe-commits
iana added inline comments.



Comment at: clang/lib/Headers/stddef.h:118-122
+#ifdef __cplusplus
+namespace std {
+typedef decltype(nullptr) nullptr_t;
+}
+using ::std::nullptr_t;

aaron.ballman wrote:
> iana wrote:
> > ldionne wrote:
> > > iana wrote:
> > > > aaron.ballman wrote:
> > > > > Related:
> > > > > 
> > > > > https://github.com/llvm/llvm-project/issues/37564
> > > > > https://cplusplus.github.io/LWG/issue3484
> > > > > 
> > > > > CC @ldionne
> > > > I don't _think_ this change actually changes the way nullptr_t gets 
> > > > defined in C++, does it?
> > > I think we absolutely don't want to touch `std::nullptr_t` from this 
> > > header. It's libc++'s responsibility to define that, and in fact we 
> > > define it in `std::__1`, so this is even an ABI break (or I guess it 
> > > would be a compiler error, not sure).
> > I'm really not touching it though. All I did is move it from `__need_NULL` 
> > to `__need_nullptr_t`.
> > 
> > The old behavior is that `std::nullptr_t` would only be touched if (no 
> > `__need_` macros were set or if `__need_NULL` was set), and 
> > (_MSC_EXTENSIONS and _NATIVE_NULLPTR_SUPPORTED are defined).
> > 
> > The new behavior is that `std::nullptr_t` will only be touched if ((no 
> > `__need_` macros are set) and (_MSC_EXTENSIONS and 
> > _NATIVE_NULLPTR_SUPPORTED are defined)) or (the new `__need_nullptr_t` 
> > macro is set)
> > 
> > So the only change is that C++ code that previously set `__need_NULL` will 
> > no longer get `std::nullptr_t`. @efriedma felt like that was a fine change.
> Does libc++ provide the symbols for a freestanding compilation?
> 
> I was pointing out those links specifically because the C++ standard 
> currently says that stddef.h (the C standard library header) needs to provide 
> a definition of `std::nullptr_t`, but that LWG thinks that's perhaps not the 
> right way to do that and may be removing that requirement.
It is weird the standard puts that in stddef.h and not cstddef. I think libc++ 
could provide that in their stddef.h anyway, but the intent in this review is 
to not rock the boat and only do the minimal change discussed above.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-18 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D157757#4600357 , @ldionne wrote:

> This is going to be really naive, but can someone explain why we need these 
> `__need_X` macros? Why doesn't `` simply always declare what it 
> should declare? Also, does anybody understand the expected relationship 
> between the C Standard Library headers and these Clang builtin headers? Who 
> defines what?
>
> Everyone I've spoken to so far about this (and myself) was extremely 
> confused. At some point I thought these macros were only needed for 
> compatibility with old glibcs but that wouldn't even be needed anymore, but 
> I'm not certain.

The `__need_` macros are to support some strict mostly POSIX behaviors like 
 is supposed to provide `size_t` but none of the other things in 
. Apple has headers like  and 
 that are expected to provide those types and nothing 
else. Right now they're redeclaring the types, and if you're using clang 
modules with the right flags, that's an error. So I need to switch those to 
doing something like this.

  #define __need_rsize_t
  #include 

The relationship between clang's stddef.h and the C Standard Library stddef.h 
is that there is no relationship. clang's header doesn't #include_next, and it 
is in the search path before the OS's cstdlib.




Comment at: clang/lib/Headers/stddef.h:118-122
+#ifdef __cplusplus
+namespace std {
+typedef decltype(nullptr) nullptr_t;
+}
+using ::std::nullptr_t;

ldionne wrote:
> iana wrote:
> > aaron.ballman wrote:
> > > Related:
> > > 
> > > https://github.com/llvm/llvm-project/issues/37564
> > > https://cplusplus.github.io/LWG/issue3484
> > > 
> > > CC @ldionne
> > I don't _think_ this change actually changes the way nullptr_t gets defined 
> > in C++, does it?
> I think we absolutely don't want to touch `std::nullptr_t` from this header. 
> It's libc++'s responsibility to define that, and in fact we define it in 
> `std::__1`, so this is even an ABI break (or I guess it would be a compiler 
> error, not sure).
I'm really not touching it though. All I did is move it from `__need_NULL` to 
`__need_nullptr_t`.

The old behavior is that `std::nullptr_t` would only be touched if (no 
`__need_` macros were set or if `__need_NULL` was set), and (_MSC_EXTENSIONS 
and _NATIVE_NULLPTR_SUPPORTED are defined).

The new behavior is that `std::nullptr_t` will only be touched if ((no 
`__need_` macros are set) and (_MSC_EXTENSIONS and _NATIVE_NULLPTR_SUPPORTED 
are defined)) or (the new `__need_nullptr_t` macro is set)

So the only change is that C++ code that previously set `__need_NULL` will no 
longer get `std::nullptr_t`. @efriedma felt like that was a fine change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-16 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D157757#4592794 , @iana wrote:

> In D157757#4592766 , @philnik wrote:
>
>> I think these changes would allow us to drop the `stddef.h` compat header 
>> from libc++, which would be really nice.
>
> I'd really rather not change how `nullptr_t` gets declared in this change, 
> can we do these in another one?

Also my preference would be that we take the c++ stuff _out_ of this header and 
put it in the libc++ one, but I'm guessing that would cause issues for 
libstdc++?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-16 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 550826.
iana added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

Files:
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c

Index: clang/test/Headers/stddefneeds.c
===
--- /dev/null
+++ clang/test/Headers/stddefneeds.c
@@ -0,0 +1,169 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=c99 -std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c23 -std=c23 %s
+
+// Use C99 to verify that __need_ can be used to get types that wouldn't normally be available.
+
+struct astruct { char member; };
+
+ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}}
+size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}}
+rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}}
+wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}}
+void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}}
+nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}}
+static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}}
+max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}}
+size_t o0 = offsetof(struct astruct, member); // c99-error{{unknown type name 'size_t'}} c99-error{{call to undeclared function 'offsetof'}} c99-error{{expected expression}} c99-error{{use of undeclared identifier 'member'}} \
+ c23-error{{unknown type name 'size_t'}} c23-error{{undeclared identifier 'offsetof'}} c23-error{{expected expression}} c23-error{{use of undeclared identifier 'member'}}
+wint_t wi0; // c99-error{{unknown type name 'wint_t'}} c23-error{{unknown type}}
+
+#define __need_ptrdiff_t
+#include 
+
+ptrdiff_t p1;
+size_t s1; // c99-error{{unknown type}} c23-error{{unknown type}}
+rsize_t r1; // c99-error{{unknown type}} c23-error{{unknown type}}
+wchar_t wc1; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v1 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n1; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f1(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m1; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o1 = offsetof(struct astruct, member); // c99-error{{unknown type}} c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{unknown type}} c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi1; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_size_t
+#include 
+
+ptrdiff_t p2;
+size_t s2;
+rsize_t r2; // c99-error{{unknown type}} c23-error{{unknown type}}
+// c99-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+wchar_t wc2; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v2 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n2; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f2(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m2; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o2 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi2; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_rsize_t
+#include 
+
+ptrdiff_t p3;
+size_t s3;
+rsize_t r3;
+wchar_t wc3; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v3 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n3; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f3(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m3; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o3 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi3; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_wchar_t
+#include 
+
+ptrdiff_t p4;
+size_t s4;
+rsize_t r4;
+wchar_t wc4;
+void *v4 = NULL; // 

[PATCH] D157793: [Headers] Add missing __need_ macros to stdarg.h

2023-08-16 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 550823.
iana added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157793/new/

https://reviews.llvm.org/D157793

Files:
  clang/lib/Headers/stdarg.h
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c

Index: clang/test/Headers/stdargneeds.c
===
--- /dev/null
+++ clang/test/Headers/stdargneeds.c
@@ -0,0 +1,91 @@
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds0.c
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds1.c
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds2.c
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds3.c
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds4.c
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds5.c
+
+// Split the file so that the "implicitly declaring library function" errors get repeated.
+// Use C89 to verify that __need_ can be used to get types that wouldn't normally be available.
+
+//--- stdargneeds0.c
+static void f(int p, ...) {
+__gnuc_va_list g; // expected-error{{undeclared identifier '__gnuc_va_list'}}
+va_list v; // expected-error{{undeclared identifier 'va_list'}}
+va_start(v, p); // expected-error{{implicitly declaring library function 'va_start'}} expected-note{{include the header  or explicitly provide a declaration for 'va_start'}} expected-error{{undeclared identifier 'v'}}
+int i = va_arg(v, int); // expected-error{{implicit declaration of function 'va_arg'}} expected-error{{expected expression}} expected-error{{use of undeclared identifier 'v'}}
+va_end(v); // expected-error{{implicitly declaring library function 'va_end'}} expected-note{{include the header  or explicitly provide a declaration for 'va_end'}} expected-error{{undeclared identifier 'v'}}
+__va_copy(g, v); // expected-error{{implicit declaration of function '__va_copy'}} expected-error{{use of undeclared identifier 'g'}} expected-error{{use of undeclared identifier 'v'}}
+va_copy(g, v); // expected-error{{implicitly declaring library function 'va_copy'}} expected-note{{include the header  or explicitly provide a declaration for 'va_copy'}} expected-error{{use of undeclared identifier 'g'}} expected-error{{use of undeclared identifier 'v'}}
+}
+
+//--- stdargneeds1.c
+#define __need___va_list
+#include 
+static void f(int p, ...) {
+__gnuc_va_list g;
+va_list v; // expected-error{{undeclared identifier}}
+va_start(v, p); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}} expected-error{{undeclared identifier}}
+int i = va_arg(v, int); // expected-error{{implicit declaration of function}} expected-error{{expected expression}} expected-error{{undeclared identifier}}
+va_end(v); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}} expected-error{{undeclared identifier}}
+__va_copy(g, v); // expected-error{{implicit declaration of function}} expected-error{{undeclared identifier}}
+va_copy(g, v); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}} expected-error{{undeclared identifier}}
+}
+
+//--- stdargneeds2.c
+#define __need_va_list
+#include 
+static void f(int p, ...) {
+__gnuc_va_list g; // expected-error{{undeclared identifier}}
+va_list v;
+va_start(v, p); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}}
+int i = va_arg(v, int); // expected-error{{implicit declaration of function}} expected-error{{expected expression}}
+va_end(v); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}}
+__va_copy(g, v); // expected-error{{implicit declaration of function}} expected-error{{undeclared identifier}}
+va_copy(g, v); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}} expected-error{{undeclared identifier}}
+}
+
+//--- stdargneeds3.c
+#define __need_va_list
+#define __need_va_arg
+#include 
+static void f(int p, ...) {
+__gnuc_va_list g; // expected-error{{undeclared identifier}}
+va_list v;
+va_start(v, p);
+int i = va_arg(v, int);
+va_end(v);
+__va_copy(g, v); // expected-error{{implicit declaration of function}} expected-error{{undeclared identifier}}
+va_copy(g, v); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}} expected-error{{undeclared identifier}}
+}
+
+//--- stdargneeds4.c
+#define __need___va_list
+#define __need_va_list
+#define 

[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-16 Thread Ian Anderson via Phabricator via cfe-commits
iana marked an inline comment as done.
iana added a comment.

In D157757#4592766 , @philnik wrote:

> I think these changes would allow us to drop the `stddef.h` compat header 
> from libc++, which would be really nice.

I'd really rather not change how `nullptr_t` gets declared in this change, can 
we do these in another one?




Comment at: clang/lib/Headers/stddef.h:118-122
+#ifdef __cplusplus
+namespace std {
+typedef decltype(nullptr) nullptr_t;
+}
+using ::std::nullptr_t;

aaron.ballman wrote:
> Related:
> 
> https://github.com/llvm/llvm-project/issues/37564
> https://cplusplus.github.io/LWG/issue3484
> 
> CC @ldionne
I don't _think_ this change actually changes the way nullptr_t gets defined in 
C++, does it?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158021: [clang][modules] Mark builtin header 'inttypes.h' for modules

2023-08-15 Thread Ian Anderson via Phabricator via cfe-commits
iana added a subscriber: vsapsai.
iana added a comment.
Herald added a subscriber: ormris.

Can you add @vsapsai to the reviewers please? He was looking at this one a year 
or two ago.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158021/new/

https://reviews.llvm.org/D158021

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157793: [Headers] Add missing __need_ macros to stdarg.h

2023-08-15 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D157793#4588909 , @jyknight wrote:

> I'm a bit confused by this change vs its description.
>
> It looks like stdarg already supported `__need___va_list`, which is what you 
> said Apple needs. Does Apple //also// require the other __need_va_copy/etc, 
> too? If not, why add support for them? (I think we should prefer not to add 
> support for pieces that are not actually needed)

That name is misleading, `__need___va_list` gives you `__gnuc_va_list` and not 
`va_list`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157793/new/

https://reviews.llvm.org/D157793

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157793: [Headers] Add missing __need_ macros to stdarg.h

2023-08-14 Thread Ian Anderson via Phabricator via cfe-commits
iana added inline comments.



Comment at: clang/test/Headers/stdarg.c:34
+__va_copy(g, v);
+va_copy(g, v); // c89-error{{implicit}} c89-note{{va_copy}} 
c99-no-diagnostics
+}

aaron.ballman wrote:
> You should spell out these diagnostics, and I think `c99-no-diagnostics` 
> should be placed up by the RUN lines so it's more obvious that we expect no 
> diagnostics in C99 mode.
> 
> Actually, this file should perhaps be split into two files as they're testing 
> different things. (I was tripped up seeing no-diagnostics but we have 
> `c99-error` entries above, that's when I realized the split file was being 
> used differently in the RUN lines which is a bit novel.) But I'm not certain 
> I fully understand what your comment means about why we're using split file 
> in the first place, so I might be missing something.
It's only trying to test what including  gets you by default. The 
first chunk is to prove that nothing is provided via built-ins or anything like 
if you don't include anything. The second chunk shows that you get the expected 
declarations in each standard mode if you include  with no `__need_` 
macros.

The problem is this.
```
va_copy(g, v); // The first time you get: implicitly declaring library function 
'va_copy'

va_copy(g, v); // But now the compiler has decided that va_copy has a 
declaration, so you don't get any diagnostics even though va_copy doesn't have 
its real declaration, I think the compiler assumes 'int va_copy(int, int)' or 
something like that.
```

Maybe we don't need to test the include-nothing case both here and 
stdargneeds.c?

D157757 has the same problem for `offsetof` but since it uses C23 also, the 
diagnostics get repeated.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157793/new/

https://reviews.llvm.org/D157793

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157793: [Headers] Add missing __need_ macros to stdarg.h

2023-08-14 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 550121.
iana marked 4 inline comments as done.
iana added a comment.

Review feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157793/new/

https://reviews.llvm.org/D157793

Files:
  clang/lib/Headers/stdarg.h
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c

Index: clang/test/Headers/stdargneeds.c
===
--- /dev/null
+++ clang/test/Headers/stdargneeds.c
@@ -0,0 +1,91 @@
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds0.c
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds1.c
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds2.c
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds3.c
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds4.c
+// RUN: %clang_cc1 -fsyntax-only -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds5.c
+
+// Split the file so that the "implicitly declaring library function" errors get repeated.
+// Use C89 to verify that __need_ can be used to get types that wouldn't normally be available.
+
+//--- stdargneeds0.c
+static void f(int p, ...) {
+__gnuc_va_list g; // expected-error{{undeclared identifier '__gnuc_va_list'}}
+va_list v; // expected-error{{undeclared identifier 'va_list'}}
+va_start(v, p); // expected-error{{implicitly declaring library function 'va_start'}} expected-note{{include the header  or explicitly provide a declaration for 'va_start'}} expected-error{{undeclared identifier 'v'}}
+int i = va_arg(v, int); // expected-error{{implicit declaration of function 'va_arg'}} expected-error{{expected expression}} expected-error{{use of undeclared identifier 'v'}}
+va_end(v); // expected-error{{implicitly declaring library function 'va_end'}} expected-note{{include the header  or explicitly provide a declaration for 'va_end'}} expected-error{{undeclared identifier 'v'}}
+__va_copy(g, v); // expected-error{{implicit declaration of function '__va_copy'}} expected-error{{use of undeclared identifier 'g'}} expected-error{{use of undeclared identifier 'v'}}
+va_copy(g, v); // expected-error{{implicitly declaring library function 'va_copy'}} expected-note{{include the header  or explicitly provide a declaration for 'va_copy'}} expected-error{{use of undeclared identifier 'g'}} expected-error{{use of undeclared identifier 'v'}}
+}
+
+//--- stdargneeds1.c
+#define __need___va_list
+#include 
+static void f(int p, ...) {
+__gnuc_va_list g;
+va_list v; // expected-error{{undeclared identifier}}
+va_start(v, p); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}} expected-error{{undeclared identifier}}
+int i = va_arg(v, int); // expected-error{{implicit declaration of function}} expected-error{{expected expression}} expected-error{{undeclared identifier}}
+va_end(v); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}} expected-error{{undeclared identifier}}
+__va_copy(g, v); // expected-error{{implicit declaration of function}} expected-error{{undeclared identifier}}
+va_copy(g, v); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}} expected-error{{undeclared identifier}}
+}
+
+//--- stdargneeds2.c
+#define __need_va_list
+#include 
+static void f(int p, ...) {
+__gnuc_va_list g; // expected-error{{undeclared identifier}}
+va_list v;
+va_start(v, p); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}}
+int i = va_arg(v, int); // expected-error{{implicit declaration of function}} expected-error{{expected expression}}
+va_end(v); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}}
+__va_copy(g, v); // expected-error{{implicit declaration of function}} expected-error{{undeclared identifier}}
+va_copy(g, v); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}} expected-error{{undeclared identifier}}
+}
+
+//--- stdargneeds3.c
+#define __need_va_list
+#define __need_va_arg
+#include 
+static void f(int p, ...) {
+__gnuc_va_list g; // expected-error{{undeclared identifier}}
+va_list v;
+va_start(v, p);
+int i = va_arg(v, int);
+va_end(v);
+__va_copy(g, v); // expected-error{{implicit declaration of function}} expected-error{{undeclared identifier}}
+va_copy(g, v); // expected-error{{implicitly declaring library function}} expected-note{{provide a declaration}} expected-error{{undeclared identifier}}
+}
+
+//--- stdargneeds4.c
+#define 

[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-14 Thread Ian Anderson via Phabricator via cfe-commits
iana marked an inline comment as done.
iana added inline comments.



Comment at: clang/lib/Headers/stddef.h:16
+defined(__need_wint_t) ||  
\
+(defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1)
 

aaron.ballman wrote:
> C23 K.3.1.1p2: The functions, macros, and types declared or defined in K.3 
> and its subclauses are declared and defined by their respective headers if 
> __STDC_WANT_LIB_EXT1__ is defined as a macro which expands to the integer 
> constant 1 at the point in the source file where the appropriate header is 
> first included.
> 
> So I don't think this should be `>= 1`. Same below. (Though I notice we seem 
> to do this in other places, so perhaps that's more of a general cleanup we 
> should make?)
`>=1` is what stddef.h was already doing, so I'd vote do this later as general 
cleanup.



Comment at: clang/test/Headers/stddef.c:1-3
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify=c99 
-std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify=c11 
-std=c11 %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify=c23 
-std=c23 %s

aaron.ballman wrote:
> Are the triples necessary? Better if we can remove them.
They shouldn't be, I just copied them from stddefneeds.cpp, let me try getting 
rid of them



Comment at: clang/test/Headers/stddef.c:7
+
+ptrdiff_t p0; // c99-error{{unknown}} c11-error{{unknown}} c23-error{{unknown}}
+size_t s0; // c99-error{{unknown}} c11-error{{unknown}} c23-error{{unknown}}

aaron.ballman wrote:
> At least one of these `unknown` errors should be fully spelled out (the rest 
> can then be assumed to be the same wording as the long-form).
Let me know how this looks, I can just fully expand all of them if you prefer. 
I was going by stddefneeds.cpp as an example.



Comment at: clang/test/Headers/stddefneeds.c:1-2
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify=c99 
-std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify=c23 
-std=c23 %s
+

aaron.ballman wrote:
> Do we need the triples?
Looks like no.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-14 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 550091.
iana marked 3 inline comments as done.
iana added a comment.

Review fixes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

Files:
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c

Index: clang/test/Headers/stddefneeds.c
===
--- /dev/null
+++ clang/test/Headers/stddefneeds.c
@@ -0,0 +1,169 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=c99 -std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c23 -std=c23 %s
+
+// Use C99 to verify that __need_ can be used to get types that wouldn't normally be available.
+
+struct astruct { char member; };
+
+ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}}
+size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}}
+rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}}
+wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}}
+void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}}
+nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}}
+static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}}
+max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}}
+size_t o0 = offsetof(struct astruct, member); // c99-error{{unknown type name 'size_t'}} c99-error{{call to undeclared function 'offsetof'}} c99-error{{expected expression}} c99-error{{use of undeclared identifier 'member'}} \
+ c23-error{{unknown type name 'size_t'}} c23-error{{undeclared identifier 'offsetof'}} c23-error{{expected expression}} c23-error{{use of undeclared identifier 'member'}}
+wint_t wi0; // c99-error{{unknown type name 'wint_t'}} c23-error{{unknown type}}
+
+#define __need_ptrdiff_t
+#include 
+
+ptrdiff_t p1;
+size_t s1; // c99-error{{unknown type}} c23-error{{unknown type}}
+rsize_t r1; // c99-error{{unknown type}} c23-error{{unknown type}}
+wchar_t wc1; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v1 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n1; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f1(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m1; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o1 = offsetof(struct astruct, member); // c99-error{{unknown type}} c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{unknown type}} c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi1; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_size_t
+#include 
+
+ptrdiff_t p2;
+size_t s2;
+rsize_t r2; // c99-error{{unknown type}} c23-error{{unknown type}}
+// c99-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+wchar_t wc2; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v2 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n2; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f2(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m2; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o2 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi2; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_rsize_t
+#include 
+
+ptrdiff_t p3;
+size_t s3;
+rsize_t r3;
+wchar_t wc3; // c99-error{{unknown type}} c23-error{{unknown type}}
+void *v3 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
+nullptr_t n3; // c99-error{{unknown type}} c23-error{{unknown type}}
+static void f3(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}}
+max_align_t m3; // c99-error{{unknown type}} c23-error{{unknown type}}
+size_t o3 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
+ c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}}
+wint_t wi3; // c99-error{{unknown type}} c23-error{{unknown type}}
+
+#define __need_wchar_t
+#include 
+
+ptrdiff_t p4;
+size_t s4;
+rsize_t r4;

[PATCH] D157793: [Headers] Add missing __need_ macros to stdarg.h

2023-08-14 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D157793#4585268 , @aaron.ballman 
wrote:

> In D157793#4583698 , @iana wrote:
>
>> In D157793#4583663 , @MaskRay 
>> wrote:
>>
 Apple needs a __need_ macro for va_list. Add one, and also ones for 
 va_start/va_arg/va_end, __va_copy, va_copy.
>>>
>>> Do you have a link to the specification or the source that this is needed?
>>
>> We need is so that our  doesn't have to redeclare 
>> va_list and doesn't pull in all of stdarg.h either. As far as I know there's 
>> no specification for this (or stddef.h) being include-able in pieces.
>
> I'm not opposed, but this adds significant complexity to support a 
> questionable use case -- the C standard library headers are not intended to 
> be partially included, so if the plan is to use these `__need` macros in all 
> of the headers we provide, I think that should go through an RFC process to 
> be sure we want to maintain the added complexity. (Also, who is "we" in this 
> case?)

We is Apple. We have a  header that is generating 
redeclaration warnings in modules mode. I can't just include  instead 
since it would change the semantics of . stdarg.h and 
stddef.h appear to be the only clang headers that Apple needs to use in pieces 
though, I don't think we should add this complexity to any other headers for 
consistency or "just because".


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157793/new/

https://reviews.llvm.org/D157793

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157793: [Headers] Add missing __need_ macros to stdarg.h

2023-08-13 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D157793#4583663 , @MaskRay wrote:

>> Apple needs a __need_ macro for va_list. Add one, and also ones for 
>> va_start/va_arg/va_end, __va_copy, va_copy.
>
> Do you have a link to the specification or the source that this is needed?

We need is so that our  doesn't have to redeclare 
va_list and doesn't pull in all of stdarg.h either. As far as I know there's no 
specification for this (or stddef.h) being include-able in pieces.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157793/new/

https://reviews.llvm.org/D157793

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157793: [Headers] Add missing __need_ macros to stdarg.h

2023-08-12 Thread Ian Anderson via Phabricator via cfe-commits
iana created this revision.
iana added reviewers: zatrazz, jfb, MaskRay, eli.friedman, aaron.ballman, 
rsmith, steplong, efriedma, jyknight, erichkeane.
Herald added a subscriber: ributzka.
Herald added a project: All.
iana requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Apple needs a __need_ macro for va_list. Add one, and also ones for 
va_start/va_arg/va_end, __va_copy, va_copy.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157793

Files:
  clang/lib/Headers/stdarg.h
  clang/test/Headers/stdarg.c
  clang/test/Headers/stdargneeds.c

Index: clang/test/Headers/stdargneeds.c
===
--- /dev/null
+++ clang/test/Headers/stdargneeds.c
@@ -0,0 +1,91 @@
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds0.c
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds1.c
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds2.c
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds3.c
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds4.c
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify -Werror=implicit-function-declaration -std=c89 %t/stdargneeds5.c
+
+// Split the file so that the "implicitly declaring library function" errors get repeated.
+// Use C89 to verify that __need_ can be used to get types that wouldn't normally be available.
+
+//--- stdargneeds0.c
+static void f(int p, ...) {
+__gnuc_va_list g; // expected-error{{undeclared}}
+va_list v; // expected-error{{undeclared}}
+va_start(v, p); // expected-error{{implicit}} expected-note{{va_start}} expected-error{{undeclared}}
+int i = va_arg(v, int); // expected-error{{implicit}} expected-error{{expression}} expected-error{{undeclared}}
+va_end(v); // expected-error{{implicit}} expected-note{{va_end}} expected-error{{undeclared}}
+__va_copy(g, v); // expected-error{{implicit}} expected-error{{undeclared}} expected-error{{undeclared}}
+va_copy(g, v); // expected-error{{implicit}} expected-note{{va_copy}} expected-error{{undeclared}} expected-error{{undeclared}}
+}
+
+//--- stdargneeds1.c
+#define __need___va_list
+#include 
+static void f(int p, ...) {
+__gnuc_va_list g;
+va_list v; // expected-error{{undeclared}}
+va_start(v, p); // expected-error{{implicit}} expected-note{{va_start}} expected-error{{undeclared}}
+int i = va_arg(v, int); // expected-error{{implicit}} expected-error{{expression}} expected-error{{undeclared}}
+va_end(v); // expected-error{{implicit}} expected-note{{va_end}} expected-error{{undeclared}}
+__va_copy(g, v); // expected-error{{implicit}} expected-error{{undeclared}}
+va_copy(g, v); // expected-error{{implicit}} expected-note{{va_copy}} expected-error{{undeclared}}
+}
+
+//--- stdargneeds2.c
+#define __need_va_list
+#include 
+static void f(int p, ...) {
+__gnuc_va_list g; // expected-error{{undeclared}}
+va_list v;
+va_start(v, p); // expected-error{{implicit}} expected-note{{va_start}}
+int i = va_arg(v, int); // expected-error{{implicit}} expected-error{{expression}}
+va_end(v); // expected-error{{implicit}} expected-note{{va_end}}
+__va_copy(g, v); // expected-error{{implicit}} expected-error{{undeclared}}
+va_copy(g, v); // expected-error{{implicit}} expected-note{{va_copy}} expected-error{{undeclared}}
+}
+
+//--- stdargneeds3.c
+#define __need_va_list
+#define __need_va_arg
+#include 
+static void f(int p, ...) {
+__gnuc_va_list g; // expected-error{{undeclared}}
+va_list v;
+va_start(v, p);
+int i = va_arg(v, int);
+va_end(v);
+__va_copy(g, v); // expected-error{{implicit}} expected-error{{undeclared}}
+va_copy(g, v); // expected-error{{implicit}} expected-note{{va_copy}} expected-error{{undeclared}}
+}
+
+//--- stdargneeds4.c
+#define __need___va_list
+#define __need_va_list
+#define __need___va_copy
+#include 
+static void f(int p, ...) {
+__gnuc_va_list g;
+va_list v;
+va_start(v, p); // expected-error{{implicit}} expected-note{{va_start}}
+int i = va_arg(v, int); // expected-error{{implicit}} expected-error{{expression}}
+va_end(v); // expected-error{{implicit}} expected-note{{va_end}}
+__va_copy(g, v);
+va_copy(g, v); // expected-error{{implicit}} expected-note{{va_copy}}
+}
+
+//--- stdargneeds5.c
+#define __need___va_list
+#define __need_va_list
+#define __need_va_copy
+#include 
+static void f(int p, ...) {
+__gnuc_va_list g;
+va_list v;
+va_start(v, p); // 

[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-11 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 549572.
iana added a comment.

Let clang-format update stddef.h


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

Files:
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c

Index: clang/test/Headers/stddefneeds.c
===
--- /dev/null
+++ clang/test/Headers/stddefneeds.c
@@ -0,0 +1,169 @@
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify=c99 -std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify=c23 -std=c23 %s
+
+// Use C99 to verify that __need_ can be used to get types that wouldn't normally be available.
+
+struct astruct { char member; };
+
+ptrdiff_t p0; // c99-error{{unknown}} c23-error{{unknown}}
+size_t s0; // c99-error{{unknown}} c23-error{{unknown}}
+rsize_t r0; // c99-error{{unknown}} c23-error{{unknown}}
+wchar_t wc0; // c99-error{{unknown}} c23-error{{unknown}}
+void *v0 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n0; // c99-error{{unknown}} c23-error{{unknown}}
+static void f0(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m0; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o0 = offsetof(struct astruct, member); // c99-error{{unknown}} c99-error{{undeclared}} c99-error{{expected expression}} c99-error{{undeclared}} \
+ c23-error{{unknown}} c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi0; // c99-error{{unknown}} c23-error{{unknown}}
+
+#define __need_ptrdiff_t
+#include 
+
+ptrdiff_t p1;
+size_t s1; // c99-error{{unknown}} c23-error{{unknown}}
+rsize_t r1; // c99-error{{unknown}} c23-error{{unknown}}
+wchar_t wc1; // c99-error{{unknown}} c23-error{{unknown}}
+void *v1 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n1; // c99-error{{unknown}} c23-error{{unknown}}
+static void f1(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m1; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o1 = offsetof(struct astruct, member); // c99-error{{unknown}} c99-error{{undeclared}} c99-error{{expected expression}} \
+ c23-error{{unknown}} c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi1; // c99-error{{unknown}} c23-error{{unknown}}
+
+#define __need_size_t
+#include 
+
+ptrdiff_t p2;
+size_t s2;
+rsize_t r2; // c99-error{{unknown}} c23-error{{unknown}}
+// c99-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+wchar_t wc2; // c99-error{{unknown}} c23-error{{unknown}}
+void *v2 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n2; // c99-error{{unknown}} c23-error{{unknown}}
+static void f2(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m2; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o2 = offsetof(struct astruct, member); // c99-error{{undeclared}} c99-error{{expected expression}} \
+ c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi2; // c99-error{{unknown}} c23-error{{unknown}}
+
+#define __need_rsize_t
+#include 
+
+ptrdiff_t p3;
+size_t s3;
+rsize_t r3;
+wchar_t wc3; // c99-error{{unknown}} c23-error{{unknown}}
+void *v3 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n3; // c99-error{{unknown}} c23-error{{unknown}}
+static void f3(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m3; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o3 = offsetof(struct astruct, member); // c99-error{{undeclared}} c99-error{{expected expression}} \
+ c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi3; // c99-error{{unknown}} c23-error{{unknown}}
+
+#define __need_wchar_t
+#include 
+
+ptrdiff_t p4;
+size_t s4;
+rsize_t r4;
+wchar_t wc4;
+void *v4 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n4; // c99-error{{unknown}} c23-error{{unknown}}
+static void f4(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m4; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o4 = offsetof(struct astruct, member); // c99-error{{undeclared}} c99-error{{expected expression}} \
+ c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi4; // c99-error{{unknown}} c23-error{{unknown}}
+
+#define __need_NULL
+#include 
+
+ptrdiff_t p5;
+size_t s5;
+rsize_t r5;
+wchar_t wc5;
+void *v5 = NULL;
+nullptr_t n5; // c99-error{{unknown}} 

[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-11 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 549547.
iana marked an inline comment as done.
iana added a comment.

Update the tests to handle diagnostics from stddef.h
Fix stddef.h to support defining __STDC_WANT_LIB_EXT1__ if stddef.h has already 
been included


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

Files:
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c

Index: clang/test/Headers/stddefneeds.c
===
--- /dev/null
+++ clang/test/Headers/stddefneeds.c
@@ -0,0 +1,169 @@
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify=c99 -std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify=c23 -std=c23 %s
+
+// Use C99 to verify that __need_ can be used to get types that wouldn't normally be available.
+
+struct astruct { char member; };
+
+ptrdiff_t p0; // c99-error{{unknown}} c23-error{{unknown}}
+size_t s0; // c99-error{{unknown}} c23-error{{unknown}}
+rsize_t r0; // c99-error{{unknown}} c23-error{{unknown}}
+wchar_t wc0; // c99-error{{unknown}} c23-error{{unknown}}
+void *v0 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n0; // c99-error{{unknown}} c23-error{{unknown}}
+static void f0(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m0; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o0 = offsetof(struct astruct, member); // c99-error{{unknown}} c99-error{{undeclared}} c99-error{{expected expression}} c99-error{{undeclared}} \
+ c23-error{{unknown}} c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi0; // c99-error{{unknown}} c23-error{{unknown}}
+
+#define __need_ptrdiff_t
+#include 
+
+ptrdiff_t p1;
+size_t s1; // c99-error{{unknown}} c23-error{{unknown}}
+rsize_t r1; // c99-error{{unknown}} c23-error{{unknown}}
+wchar_t wc1; // c99-error{{unknown}} c23-error{{unknown}}
+void *v1 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n1; // c99-error{{unknown}} c23-error{{unknown}}
+static void f1(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m1; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o1 = offsetof(struct astruct, member); // c99-error{{unknown}} c99-error{{undeclared}} c99-error{{expected expression}} \
+ c23-error{{unknown}} c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi1; // c99-error{{unknown}} c23-error{{unknown}}
+
+#define __need_size_t
+#include 
+
+ptrdiff_t p2;
+size_t s2;
+rsize_t r2; // c99-error{{unknown}} c23-error{{unknown}}
+// c99-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+wchar_t wc2; // c99-error{{unknown}} c23-error{{unknown}}
+void *v2 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n2; // c99-error{{unknown}} c23-error{{unknown}}
+static void f2(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m2; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o2 = offsetof(struct astruct, member); // c99-error{{undeclared}} c99-error{{expected expression}} \
+ c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi2; // c99-error{{unknown}} c23-error{{unknown}}
+
+#define __need_rsize_t
+#include 
+
+ptrdiff_t p3;
+size_t s3;
+rsize_t r3;
+wchar_t wc3; // c99-error{{unknown}} c23-error{{unknown}}
+void *v3 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n3; // c99-error{{unknown}} c23-error{{unknown}}
+static void f3(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m3; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o3 = offsetof(struct astruct, member); // c99-error{{undeclared}} c99-error{{expected expression}} \
+ c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi3; // c99-error{{unknown}} c23-error{{unknown}}
+
+#define __need_wchar_t
+#include 
+
+ptrdiff_t p4;
+size_t s4;
+rsize_t r4;
+wchar_t wc4;
+void *v4 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n4; // c99-error{{unknown}} c23-error{{unknown}}
+static void f4(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m4; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o4 = offsetof(struct astruct, member); // c99-error{{undeclared}} c99-error{{expected expression}} \
+ c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi4; // c99-error{{unknown}} c23-error{{unknown}}
+

[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-11 Thread Ian Anderson via Phabricator via cfe-commits
iana marked an inline comment as done.
iana added inline comments.



Comment at: clang/test/Headers/stddef.c:20-23
+// rsize_t will only be defined if __STDC_WANT_LIB_EXT1__ is set to >= 1.
+// It would be nice to test the default undefined behavior, but that emits
+// a note coming from stddef.h "rsize_t, did you mean size_t?" that can't be
+// `c99-note`d away.

efriedma wrote:
> iana wrote:
> > Does anyone know a trick to catch the note from stddef.h?
> I think the syntax is something like `expected-warning@stddef.h:10`?  See 
> rGfcc699ae ,  There's also a wildcard syntax; see rG05eedf1f.
Ah ha!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-11 Thread Ian Anderson via Phabricator via cfe-commits
iana added inline comments.



Comment at: clang/test/Headers/stddefneeds.c:85-87
+// __need_nullptr_t generates an error in https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-11 Thread Ian Anderson via Phabricator via cfe-commits
iana marked an inline comment as done.
iana added inline comments.



Comment at: clang/test/Headers/stddef.c:20-23
+// rsize_t will only be defined if __STDC_WANT_LIB_EXT1__ is set to >= 1.
+// It would be nice to test the default undefined behavior, but that emits
+// a note coming from stddef.h "rsize_t, did you mean size_t?" that can't be
+// `c99-note`d away.

Does anyone know a trick to catch the note from stddef.h?



Comment at: clang/test/Headers/stddefneeds.c:35-37
+// If you do these individually, the compiler will add a note
+// coming from stddef.h "rsize_t, did you mean size_t?" that
+// can't be `c99-note`d away.

(same here)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-11 Thread Ian Anderson via Phabricator via cfe-commits
iana marked an inline comment as done.
iana added inline comments.



Comment at: clang/lib/Headers/stddef.h:112
 #if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED)
-namespace std { typedef decltype(nullptr) nullptr_t; }
-using ::std::nullptr_t;
+// __need_NULL would previously define nullptr_t for C++, add it here.
+#define __need_nullptr_t

efriedma wrote:
> I think this code was pulled into the `__need_NULL` conditional by accident; 
> I doubt anyone actually depends on the precise interaction here.  Just move 
> to the same place as the other `__need_` defines.
 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-11 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 549534.
iana added a comment.

Don't define nullptr_t in C++ if __need_NULL is set without __need_nullptr_t


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157757/new/

https://reviews.llvm.org/D157757

Files:
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c

Index: clang/test/Headers/stddefneeds.c
===
--- /dev/null
+++ clang/test/Headers/stddefneeds.c
@@ -0,0 +1,160 @@
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify=c99 -std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify=c23 -std=c23 %s
+
+// Use C99 to verify that __need_ can be used to get types that wouldn't normally be available.
+
+struct astruct { char member; };
+
+ptrdiff_t p0; // c99-error{{unknown}} c23-error{{unknown}}
+size_t s0; // c99-error{{unknown}} c23-error{{unknown}}
+rsize_t r0; // c99-error{{unknown}} c23-error{{unknown}}
+wchar_t wc0; // c99-error{{unknown}} c23-error{{unknown}}
+void *v0 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n0; // c99-error{{unknown}} c23-error{{unknown}}
+static void f0(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m0; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o0 = offsetof(struct astruct, member); // c99-error{{unknown}} c99-error{{undeclared}} c99-error{{expected expression}} c99-error{{undeclared}} \
+ c23-error{{unknown}} c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi0; // c99-error{{unknown}} c23-error{{unknown}}
+
+#define __need_ptrdiff_t
+#include 
+
+ptrdiff_t p1;
+size_t s1; // c99-error{{unknown}} c23-error{{unknown}}
+rsize_t r1; // c99-error{{unknown}} c23-error{{unknown}}
+wchar_t wc1; // c99-error{{unknown}} c23-error{{unknown}}
+void *v1 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n1; // c99-error{{unknown}} c23-error{{unknown}}
+static void f1(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m1; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o1 = offsetof(struct astruct, member); // c99-error{{unknown}} c99-error{{undeclared}} c99-error{{expected expression}} \
+ c23-error{{unknown}} c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi1; // c99-error{{unknown}} c23-error{{unknown}}
+
+// If you do these individually, the compiler will add a note
+// coming from stddef.h "rsize_t, did you mean size_t?" that
+// can't be `c99-note`d away.
+#define __need_size_t
+#define __need_rsize_t
+#include 
+
+ptrdiff_t p2;
+size_t s2;
+rsize_t r2;
+wchar_t wc2; // c99-error{{unknown}} c23-error{{unknown}}
+void *v2 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n2; // c99-error{{unknown}} c23-error{{unknown}}
+static void f2(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m2; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o2 = offsetof(struct astruct, member); // c99-error{{undeclared}} c99-error{{expected expression}} \
+ c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi2; // c99-error{{unknown}} c23-error{{unknown}}
+
+#define __need_wchar_t
+#include 
+
+ptrdiff_t p3;
+size_t s3;
+rsize_t r3;
+wchar_t wc3;
+void *v3 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n3; // c99-error{{unknown}} c23-error{{unknown}}
+static void f3(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m3; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o3 = offsetof(struct astruct, member); // c99-error{{undeclared}} c99-error{{expected expression}} \
+ c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi3; // c99-error{{unknown}} c23-error{{unknown}}
+
+#define __need_NULL
+#include 
+
+ptrdiff_t p4;
+size_t s4;
+rsize_t r4;
+wchar_t wc4;
+void *v4 = NULL;
+nullptr_t n4; // c99-error{{unknown}} c23-error{{unknown}}
+static void f4(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m4; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o4 = offsetof(struct astruct, member); // c99-error{{undeclared}} c99-error{{expected expression}} \
+ c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi4; // c99-error{{unknown}} c23-error{{unknown}}
+
+#if __STDC_VERSION__ >= 202311L
+// __need_nullptr_t generates an error in 
+
+ptrdiff_t p5;
+size_t s5;
+rsize_t r5;
+wchar_t wc5;
+void *v5 = NULL;
+nullptr_t n5; // 

[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-11 Thread Ian Anderson via Phabricator via cfe-commits
iana created this revision.
iana added reviewers: aaron.ballman, rsmith, steplong, efriedma, jyknight, 
erichkeane.
Herald added a subscriber: ributzka.
Herald added a project: All.
iana requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

Apple needs __need_ macros for rsize_t and offsetof. Add those, and also ones 
for nullptr_t, unreachable, max_align_t.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157757

Files:
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c

Index: clang/test/Headers/stddefneeds.c
===
--- /dev/null
+++ clang/test/Headers/stddefneeds.c
@@ -0,0 +1,160 @@
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify=c99 -std=c99 %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify=c23 -std=c23 %s
+
+// Use C99 to verify that __need_ can be used to get types that wouldn't normally be available.
+
+struct astruct { char member; };
+
+ptrdiff_t p0; // c99-error{{unknown}} c23-error{{unknown}}
+size_t s0; // c99-error{{unknown}} c23-error{{unknown}}
+rsize_t r0; // c99-error{{unknown}} c23-error{{unknown}}
+wchar_t wc0; // c99-error{{unknown}} c23-error{{unknown}}
+void *v0 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n0; // c99-error{{unknown}} c23-error{{unknown}}
+static void f0(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m0; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o0 = offsetof(struct astruct, member); // c99-error{{unknown}} c99-error{{undeclared}} c99-error{{expected expression}} c99-error{{undeclared}} \
+ c23-error{{unknown}} c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi0; // c99-error{{unknown}} c23-error{{unknown}}
+
+#define __need_ptrdiff_t
+#include 
+
+ptrdiff_t p1;
+size_t s1; // c99-error{{unknown}} c23-error{{unknown}}
+rsize_t r1; // c99-error{{unknown}} c23-error{{unknown}}
+wchar_t wc1; // c99-error{{unknown}} c23-error{{unknown}}
+void *v1 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n1; // c99-error{{unknown}} c23-error{{unknown}}
+static void f1(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m1; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o1 = offsetof(struct astruct, member); // c99-error{{unknown}} c99-error{{undeclared}} c99-error{{expected expression}} \
+ c23-error{{unknown}} c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi1; // c99-error{{unknown}} c23-error{{unknown}}
+
+// If you do these individually, the compiler will add a note
+// coming from stddef.h "rsize_t, did you mean size_t?" that
+// can't be `c99-note`d away.
+#define __need_size_t
+#define __need_rsize_t
+#include 
+
+ptrdiff_t p2;
+size_t s2;
+rsize_t r2;
+wchar_t wc2; // c99-error{{unknown}} c23-error{{unknown}}
+void *v2 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n2; // c99-error{{unknown}} c23-error{{unknown}}
+static void f2(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m2; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o2 = offsetof(struct astruct, member); // c99-error{{undeclared}} c99-error{{expected expression}} \
+ c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi2; // c99-error{{unknown}} c23-error{{unknown}}
+
+#define __need_wchar_t
+#include 
+
+ptrdiff_t p3;
+size_t s3;
+rsize_t r3;
+wchar_t wc3;
+void *v3 = NULL; // c99-error{{undeclared}} c23-error{{undeclared}}
+nullptr_t n3; // c99-error{{unknown}} c23-error{{unknown}}
+static void f3(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m3; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o3 = offsetof(struct astruct, member); // c99-error{{undeclared}} c99-error{{expected expression}} \
+ c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi3; // c99-error{{unknown}} c23-error{{unknown}}
+
+#define __need_NULL
+#include 
+
+ptrdiff_t p4;
+size_t s4;
+rsize_t r4;
+wchar_t wc4;
+void *v4 = NULL;
+nullptr_t n4; // c99-error{{unknown}} c23-error{{unknown}}
+static void f4(void) { unreachable(); } // c99-error{{undeclared}} c23-error{{undeclared}}
+max_align_t m4; // c99-error{{unknown}} c23-error{{unknown}}
+size_t o4 = offsetof(struct astruct, member); // c99-error{{undeclared}} c99-error{{expected expression}} \
+ c23-error{{undeclared}} c23-error{{expected expression}} c23-error{{undeclared}}
+wint_t wi4; // 

[PATCH] D156948: [clang][modules] Add -Wsystem-headers-in-module=

2023-08-08 Thread Ian Anderson via Phabricator via cfe-commits
iana accepted this revision.
iana added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticOptions.h:128
+  /// whether -Wsystem-headers is enabled on a per-module basis.
+  std::vector SystemHeaderWarningsModules;
+

benlangmuir wrote:
> jansvoboda11 wrote:
> > Out of interest, is there an existing use-case for having multiple modules 
> > here, or is this just future-proofing?
> I'm not using it currently, but I think it makes sense to handle any number. 
> You could have multiple such modules you're testing together.
I'd imagine you'd typically have Framework and Framework_Private in there


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156948/new/

https://reviews.llvm.org/D156948

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103930: [clang][HeaderSearch] Fix implicit module when using header maps

2023-05-10 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

I wonder if clang should have better module interaction with the header maps 
produced by Xcode, or if Xcode should produce better header maps to work with 
clang. Or are you having problems with header maps outside of Xcode?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103930/new/

https://reviews.llvm.org/D103930

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103930: [clang][HeaderSearch] Fix implicit module when using header maps

2023-05-10 Thread Ian Anderson via Phabricator via cfe-commits
iana added inline comments.



Comment at: clang/test/Modules/implicit-module-header-maps.cpp:52
+//header and trip a `#error`, or
+// 2) header maps aren't usesd, as the header name doesn't exist and relies on
+//the header map to remap it to the real header.

usesd -> used


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103930/new/

https://reviews.llvm.org/D103930

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140250: Define NULL in its own header

2023-01-25 Thread Ian Anderson via Phabricator via cfe-commits
iana planned changes to this revision.
iana added a comment.

In D140250#4081133 , @iana wrote:

> In D140250#4081119 , @rsmith wrote:
>
>> In D140250#4081102 , @rsmith wrote:
>>
>>> Our builtin header `stddef.h` shouldn't be built as a module. It 
>>> fundamentally needs to be treated as a textual header, because it consumes 
>>> macros defined by the includer. The module map that we provide with our 
>>> builtin headers does not cover `stddef.h` for that reason.
>>
>> That said... the ` __has_feature(modules)` checks throughout `stddef.h` look 
>> pretty wrong to me. They're probably working around the infelicities of the 
>> `-fno-modules-local-submodule-visibility` mode; maybe we can disable them 
>> when not in that mode?
>
> It ends up being covered by `Darwin.C.stddef` on Apple platforms (due to some 
> builtin shenanigans elsewhere in clang). Maybe we could make stddef.h be a 
> `textual` header in a `_Builtin_stddef` module in clang and that would do the 
> trick instead of splitting it into a bunch of different files.

This seems to work in initial testing. I'll probably drop this diff and make a 
new one to make stddef.h be a `textual` header in a new `_Builtin_stddef` 
module in clang when I do some more testing then.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140250/new/

https://reviews.llvm.org/D140250

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140250: Define NULL in its own header

2023-01-25 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D140250#4081119 , @rsmith wrote:

> In D140250#4081102 , @rsmith wrote:
>
>> Our builtin header `stddef.h` shouldn't be built as a module. It 
>> fundamentally needs to be treated as a textual header, because it consumes 
>> macros defined by the includer. The module map that we provide with our 
>> builtin headers does not cover `stddef.h` for that reason.
>
> That said... the ` __has_feature(modules)` checks throughout `stddef.h` look 
> pretty wrong to me. They're probably working around the infelicities of the 
> `-fno-modules-local-submodule-visibility` mode; maybe we can disable them 
> when not in that mode?

It ends up being covered by `Darwin.C.stddef` on Apple platforms (due to some 
builtin shenanigans elsewhere in clang). Maybe we could make stddef.h be a 
`textual` header in a `_Builtin_stddef` module in clang and that would do the 
trick instead of splitting it into a bunch of different files.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140250/new/

https://reviews.llvm.org/D140250

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140250: Define NULL in its own header

2023-01-25 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D140250#4081044 , @aaron.ballman 
wrote:

> In D140250#4081009 , @iana wrote:
>
>> In D140250#4080990 , @rsmith wrote:
>>
>>> Wait a second... if an OS wants only `NULL`, we already have a supported 
>>> way of achieving that, which is compatible with GCC and glibc and other 
>>> POSIX compilers -- define `__need_NULL` before including the header.
>>>
>>> We shouldn't be providing internal headers with `__mangled_names` for OSes 
>>> to include, those should be implementation details.
>>
>> You can't do that with modules though, `#define __need_NULL #include 
>> ` doesn't work.
>
> Also, from the patch summary: ` i.e. in POSIX headers that are required to 
> define NULL but not the rest of stddef.h.` -- I don't think `__need_NULL` 
> works for this because it gets you `NULL` but it also gets you the rest of 
> the stddef.h header, right?

Once you set one of the `__need` macros, then stddef.h will //only// give you 
those definitions. (Or I'm interpreting the file gravely wrong... it's kind of 
a weird header and its customizations don't really work with modules either.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140250/new/

https://reviews.llvm.org/D140250

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140250: Define NULL in its own header

2023-01-25 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D140250#4080990 , @rsmith wrote:

> Wait a second... if an OS wants only `NULL`, we already have a supported way 
> of achieving that, which is compatible with GCC and glibc and other POSIX 
> compilers -- define `__need_NULL` before including the header.
>
> We shouldn't be providing internal headers with `__mangled_names` for OSes to 
> include, those should be implementation details.

You can't do that with modules though, `#define __need_NULL #include 
` doesn't work.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140250/new/

https://reviews.llvm.org/D140250

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140250: Define NULL in its own header

2023-01-25 Thread Ian Anderson via Phabricator via cfe-commits
iana updated this revision to Diff 492179.
iana added a comment.

Revert the unnecessary changes to unspecified-var-size.ll


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140250/new/

https://reviews.llvm.org/D140250

Files:
  clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang/docs/tools/clang-formatted-files.txt
  clang/lib/Basic/Module.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/module.modulemap
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef_null.cpp
  compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
  llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
+++ 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",
Index: compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
===
--- compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
+++ 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-
Index: clang/test/Headers/stddef_null.cpp
===
--- /dev/null
+++ clang/test/Headers/stddef_null.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.9.0 -verify -Wsentinel -std=c++11 %s
+
+void *v0 = NULL; // expected-error{{undeclared}}
+
+// Shouldn't bring in anything else from stddef.h
+#include <__stddef_null.h>
+void *v1 = NULL;
+ptrdiff_t p1; // expected-error{{unknown}}
+size_t s1; // expected-error{{unknown}}
+wint_t w1; // expected-error{{unknown}}
+max_align_t m1; // expected-error{{unknown}}
+
+
+// linux/stddef.h does something like this for cpp files:
+#undef NULL
+#define NULL 0
+
+// glibc (and other) headers then define __need_NULL and rely on stddef.h
+// to redefine NULL to the correct value again.
+#define __need_NULL
+#include <__stddef_null.h>
+
+// gtk headers then use __attribute__((sentinel)), which doesn't work if NULL
+// is 0.
+void f(const char* c, ...) __attribute__((sentinel));
+void g() {
+  f("", NULL);  // Shouldn't warn.
+}
Index: clang/lib/Headers/stddef.h
===
--- clang/lib/Headers/stddef.h
+++ 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) */
 
Index: clang/lib/Headers/module.modulemap
===
--- clang/lib/Headers/module.modulemap
+++ 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"
Index: clang/lib/Headers/__stddef_null.h
===
--- /dev/null
+++ clang/lib/Headers/__stddef_null.h
@@ -0,0 +1,35 @@
+/*=== __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
+ *
+ *===---===
+ */
+
+#if !defined(__STDDEF_NULL_H) || defined(__need_NULL)
+
+#ifndef __STDDEF_NULL_H
+#define __STDDEF_NULL_H
+#endif
+
+#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
Index: clang/lib/Headers/CMakeLists.txt

[PATCH] D140250: Define NULL in its own header

2023-01-25 Thread Ian Anderson via Phabricator via cfe-commits
iana added inline comments.



Comment at: 
llvm/test/DebugInfo/Generic/assignment-tracking/sroa/unspecified-var-size.ll:37
 !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)
+!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")

dblaikie wrote:
> aaron.ballman wrote:
> > iana wrote:
> > > dblaikie wrote:
> > > > aaron.ballman wrote:
> > > > > iana wrote:
> > > > > > Adding this line is the only reason I changed this file. I'm not 
> > > > > > familiar at all with how these tests work, so I don't really know 
> > > > > > if it's necessary. The test passes with and without these changes.
> > > > > CC @dblaikie and @echristo for questions about whether we should be 
> > > > > updating this debug info test or not.
> > > > Don't think there's any reason/need to - what motivated changing this 
> > > > file?
> > > I found it when I was checking for places that handled 
> > > `__stddef_max_align_t.h` specially. I'm not sure if that's in here to 
> > > check `_ZTS11max_align_t` under it, or if it's just there because 
> > > stddef.h includes it. __stddef_null.h doesn't define any types like that, 
> > > so maybe it's fine to just revert this file?
> > Yeah, I think it's reasonable to revert the changes to this file.
> Yeah, that's just some incidental debug info (because clang doesn't track use 
> of using decls, we emit them rather unconditionally into DWARF, and it's 
> often easier to create/manitain DWARF testing by compiling real code rather 
> than hand crafting the IR metadata) - no need to update it for this case, I 
> think.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140250/new/

https://reviews.llvm.org/D140250

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >