https://github.com/smallp-o-p created 
https://github.com/llvm/llvm-project/pull/165814

Resolves #165790

- Don't add `-nobuiltininc` when `-ibuiltininc` is passed with `-nostdinc`
- Add tests

>From 55de88d2b00284aa4182a9727f778081d84bde8a Mon Sep 17 00:00:00 2001
From: William Tran-Viet <[email protected]>
Date: Thu, 30 Oct 2025 00:17:56 -0400
Subject: [PATCH 1/2] Solve problem

---
 clang/lib/Driver/ToolChains/Clang.cpp    |  4 +++-
 clang/test/Driver/nostdinc-ibuiltininc.c | 10 ++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Driver/nostdinc-ibuiltininc.c

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 79edc561c551f..f9a894205771a 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6172,7 +6172,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // Pass options for controlling the default header search paths.
   if (Args.hasArg(options::OPT_nostdinc)) {
     CmdArgs.push_back("-nostdsysteminc");
-    CmdArgs.push_back("-nobuiltininc");
+    if (!Args.hasArg(options::OPT_ibuiltininc)) {
+      CmdArgs.push_back("-nobuiltininc");
+    }
   } else {
     if (Args.hasArg(options::OPT_nostdlibinc))
       CmdArgs.push_back("-nostdsysteminc");
diff --git a/clang/test/Driver/nostdinc-ibuiltininc.c 
b/clang/test/Driver/nostdinc-ibuiltininc.c
new file mode 100644
index 0000000000000..d4bc885264c45
--- /dev/null
+++ b/clang/test/Driver/nostdinc-ibuiltininc.c
@@ -0,0 +1,10 @@
+// RUN: %clang -target x86_64-unknown-unknown -nostdinc -ibuiltininc 
-ffreestanding -fsyntax-only %s
+// RUN: %clang -target x86_64-unknown-unknown -ibuiltininc -nostdinc 
-ffreestanding -fsyntax-only %s
+
+#if !__has_include("stddef.h")
+#error "expected to be able to find compiler builtin headers!"
+#endif
+
+#if __has_include("stdlib.h")
+#error "expected to *not* be able to find standard C headers"
+#endif
\ No newline at end of file

>From 90cb21aef987798ea97472184f8b7c6453852e8a Mon Sep 17 00:00:00 2001
From: William Tran-Viet <[email protected]>
Date: Thu, 30 Oct 2025 21:57:56 -0400
Subject: [PATCH 2/2] Update documentation

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e6e33e7a9a280..7e0e6ca5f564b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -505,6 +505,7 @@ Bug Fixes to AST Handling
 Miscellaneous Bug Fixes
 ^^^^^^^^^^^^^^^^^^^^^^^
 - Fixed missing diagnostics of ``diagnose_if`` on templates involved in 
initialization. (#GH160776)
+- Fix `-ibuiltininc` compiler flag being ignored if `-nostdinc` is specified. 
(#GH165790)
 
 Miscellaneous Clang Crashes Fixed
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to