https://github.com/rorth updated 
https://github.com/llvm/llvm-project/pull/212716

>From b83adc46e93341e46eec64c1b4396181816d27aa Mon Sep 17 00:00:00 2001
From: Rainer Orth <[email protected]>
Date: Wed, 29 Jul 2026 10:52:08 +0200
Subject: [PATCH 1/5] [clang][Driver] Fix libc++ include path on NetBSD

`clang++` defaults to `-stdlib=libc++` on NetBSD.  When building with both
`clang` and `libcxx` included, the freshly built `clang++` fails to find
`<__config_site>`:

```
In file included from /usr/include/strings.h:68:
In file included from bin/../include/c++/v1/string.h:57:
bin/../include/c++/v1/__config:13:10: fatal
error: '__config_site' file not found
   13 | #include <__config_site>
      |          ^~~~~~~~~~~~~~~
```

The file is present in `include/<triplet>/c++/v1`, but that isn't searched
by default.  NetBSD has its own version of addLibCxxIncludePaths which
misses that directory.

Rather than replicating yet another part of the generic version in
`Gnu.cpp`, this patch just calls `Generic_GCC::addLibCxxIncludePaths` from
there.  It keeps to also include `/usr/include/c++`, although this
directory only contains empty directories in my installation.

Tested on `amd64-pc-netbsd10.1`.

I know that this patch also needs testcases (currently there are none that
are affected by this change), but I'd like to get this into the system
first to check that the approach is sound.
---
 clang/lib/Driver/ToolChains/NetBSD.cpp | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 31a5723c17c2f..186a34143da37 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -6,6 +6,7 @@
 //
 
//===----------------------------------------------------------------------===//
 
+#include "Gnu.h"
 #include "NetBSD.h"
 #include "Arch/ARM.h"
 #include "Arch/Mips.h"
@@ -497,23 +498,14 @@ void NetBSD::AddClangSystemIncludeArgs(
 
 void NetBSD::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
                                    llvm::opt::ArgStringList &CC1Args) const {
-  const std::string Candidates[] = {
-    // directory relative to build tree
-    concat(getDriver().Dir, "/../include/c++/v1"),
-    // system install with full upstream path
-    concat(getDriver().SysRoot, "/usr/include/c++/v1"),
-    // system install from src
-    concat(getDriver().SysRoot, "/usr/include/c++"),
-  };
-
-  for (const auto &IncludePath : Candidates) {
-    if (!getVFS().exists(IncludePath + "/__config"))
-      continue;
-
-    // Use the first candidate that looks valid.
+  Generic_GCC::addLibCxxIncludePaths(DriverArgs, CC1Args);
+
+  // system install from src
+  const std::string IncludePath =
+      concat(getDriver().SysRoot, "/usr/include/c++");
+
+  if (getVFS().exists(IncludePath + "/__config"))
     addSystemInclude(DriverArgs, CC1Args, IncludePath);
-    return;
-  }
 }
 
 void NetBSD::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,

>From bea68297d2651f2002e865c4f0f48e4391885022 Mon Sep 17 00:00:00 2001
From: Rainer Orth <[email protected]>
Date: Wed, 29 Jul 2026 11:18:16 +0200
Subject: [PATCH 2/5] Fix formatting.

---
 clang/lib/Driver/ToolChains/NetBSD.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 186a34143da37..c89f5a04d94e3 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -6,11 +6,11 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#include "Gnu.h"
 #include "NetBSD.h"
 #include "Arch/ARM.h"
 #include "Arch/Mips.h"
 #include "Arch/Sparc.h"
+#include "Gnu.h"
 #include "clang/Config/config.h"
 #include "clang/Driver/CommonArgs.h"
 #include "clang/Driver/Compilation.h"

>From f51ea31acb6c36c56b0570315ce83f86b189a4a0 Mon Sep 17 00:00:00 2001
From: Rainer Orth <[email protected]>
Date: Thu, 30 Jul 2026 16:50:40 +0200
Subject: [PATCH 3/5] Remove NetBSD::addLibCxxIncludePaths. Add testcase. -

---
 clang/lib/Driver/ToolChains/NetBSD.cpp | 13 -------------
 clang/lib/Driver/ToolChains/NetBSD.h   |  3 ---
 clang/test/Driver/netbsd.cpp           |  2 ++
 3 files changed, 2 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index c89f5a04d94e3..f03114b53bb61 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -10,7 +10,6 @@
 #include "Arch/ARM.h"
 #include "Arch/Mips.h"
 #include "Arch/Sparc.h"
-#include "Gnu.h"
 #include "clang/Config/config.h"
 #include "clang/Driver/CommonArgs.h"
 #include "clang/Driver/Compilation.h"
@@ -496,18 +495,6 @@ void NetBSD::AddClangSystemIncludeArgs(
                           concat(D.SysRoot, "/usr/include"));
 }
 
-void NetBSD::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
-                                   llvm::opt::ArgStringList &CC1Args) const {
-  Generic_GCC::addLibCxxIncludePaths(DriverArgs, CC1Args);
-
-  // system install from src
-  const std::string IncludePath =
-      concat(getDriver().SysRoot, "/usr/include/c++");
-
-  if (getVFS().exists(IncludePath + "/__config"))
-    addSystemInclude(DriverArgs, CC1Args, IncludePath);
-}
-
 void NetBSD::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
                                       llvm::opt::ArgStringList &CC1Args) const 
{
   addLibStdCXXIncludePaths(concat(getDriver().SysRoot, "/usr/include/g++"), 
"", "",
diff --git a/clang/lib/Driver/ToolChains/NetBSD.h 
b/clang/lib/Driver/ToolChains/NetBSD.h
index c6a40ff34036c..bb0953c02e62e 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.h
+++ b/clang/lib/Driver/ToolChains/NetBSD.h
@@ -61,9 +61,6 @@ class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
                             llvm::opt::ArgStringList &CC1Args) const override;
-  void addLibCxxIncludePaths(
-      const llvm::opt::ArgList &DriverArgs,
-      llvm::opt::ArgStringList &CC1Args) const override;
   void addLibStdCxxIncludePaths(
       const llvm::opt::ArgList &DriverArgs,
       llvm::opt::ArgStringList &CC1Args) const override;
diff --git a/clang/test/Driver/netbsd.cpp b/clang/test/Driver/netbsd.cpp
index 6b8a86d6ee532..6fcb8f212dce5 100644
--- a/clang/test/Driver/netbsd.cpp
+++ b/clang/test/Driver/netbsd.cpp
@@ -188,6 +188,8 @@
 // RUN: %clang -### %s --target=x86_64-unknown-netbsd -r 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=DRIVER-PASS-INCLUDES
 // DRIVER-PASS-INCLUDES:      "-cc1" {{.*}}"-resource-dir" "[[RESOURCE:[^"]+]]"
+// DRIVER-PASS-INCLUDES:      "-internal-isystem" "{{.*}}bin/../include/c++/v1"
+// DRIVER-PASS-INCLUDES-NOT:  "-internal-isystem" "{{.*}}/usr/include/c++/v1"
 // DRIVER-PASS-INCLUDES:      "-internal-isystem" 
"[[RESOURCE]]{{/|\\\\}}include"
 // DRIVER-PASS-INCLUDES:      "-internal-externc-isystem" "{{.*}}/usr/include"
 

>From 508ea10acc704d5aa2d4c9a2bd82370caa6b88b8 Mon Sep 17 00:00:00 2001
From: Rainer Orth <[email protected]>
Date: Fri, 31 Jul 2026 23:33:10 +0200
Subject: [PATCH 4/5] Fixed testcase.

---
 clang/test/Driver/netbsd.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/clang/test/Driver/netbsd.cpp b/clang/test/Driver/netbsd.cpp
index 6fcb8f212dce5..78d48cb88b747 100644
--- a/clang/test/Driver/netbsd.cpp
+++ b/clang/test/Driver/netbsd.cpp
@@ -188,11 +188,17 @@
 // RUN: %clang -### %s --target=x86_64-unknown-netbsd -r 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=DRIVER-PASS-INCLUDES
 // DRIVER-PASS-INCLUDES:      "-cc1" {{.*}}"-resource-dir" "[[RESOURCE:[^"]+]]"
-// DRIVER-PASS-INCLUDES:      "-internal-isystem" "{{.*}}bin/../include/c++/v1"
-// DRIVER-PASS-INCLUDES-NOT:  "-internal-isystem" "{{.*}}/usr/include/c++/v1"
 // DRIVER-PASS-INCLUDES:      "-internal-isystem" 
"[[RESOURCE]]{{/|\\\\}}include"
 // DRIVER-PASS-INCLUDES:      "-internal-externc-isystem" "{{.*}}/usr/include"
 
+// Test that NetBSD prefers install tree libc++ headers over system ones.
+// RUN: %clang -### %s --target=x86_64-unknown-netbsd -r 2>&1 \
+// RUN:     -ccc-install-dir %S/Inputs/basic_baremetal_tree/bin \
+// RUN:     --sysroot=%S/Inputs/basic_netbsd_tree \
+// RUN:   | FileCheck %s --check-prefix=DRIVER-INSTALL-INCLUDES
+// DRIVER-INSTALL-INCLUDES:      "-internal-isystem" 
"{{.*}}bin/../include/c++/v1"
+// DRIVER-INSTALL-INCLUDES-NOT:  "-internal-isystem" 
"{{.*}}/usr/include/c++/v1"
+
 // Test NetBSD with libstdc++ when the sysroot path ends with `/`.
 // RUN: %clangxx -### %s 2>&1 \
 // RUN:     --target=x86_64-unknown-netbsd \

>From 302786eb8f520f0fe9d1230d6b9bedfc124bc820 Mon Sep 17 00:00:00 2001
From: Rainer Orth <[email protected]>
Date: Sun, 2 Aug 2026 13:14:40 +0200
Subject: [PATCH 5/5] Allow for Windows path separator. Add
 install_tree_with_libcxx for reproducability.

---
 clang/test/Driver/Inputs/install_tree_with_libcxx/bin/.keep | 0
 .../Inputs/install_tree_with_libcxx/include/c++/v1/.keep    | 0
 clang/test/Driver/Inputs/install_tree_with_libcxx/lib/.keep | 0
 clang/test/Driver/netbsd.cpp                                | 6 +++---
 4 files changed, 3 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Driver/Inputs/install_tree_with_libcxx/bin/.keep
 create mode 100644 
clang/test/Driver/Inputs/install_tree_with_libcxx/include/c++/v1/.keep
 create mode 100644 clang/test/Driver/Inputs/install_tree_with_libcxx/lib/.keep

diff --git a/clang/test/Driver/Inputs/install_tree_with_libcxx/bin/.keep 
b/clang/test/Driver/Inputs/install_tree_with_libcxx/bin/.keep
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git 
a/clang/test/Driver/Inputs/install_tree_with_libcxx/include/c++/v1/.keep 
b/clang/test/Driver/Inputs/install_tree_with_libcxx/include/c++/v1/.keep
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/install_tree_with_libcxx/lib/.keep 
b/clang/test/Driver/Inputs/install_tree_with_libcxx/lib/.keep
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/netbsd.cpp b/clang/test/Driver/netbsd.cpp
index 78d48cb88b747..97ed44b841ed8 100644
--- a/clang/test/Driver/netbsd.cpp
+++ b/clang/test/Driver/netbsd.cpp
@@ -193,11 +193,11 @@
 
 // Test that NetBSD prefers install tree libc++ headers over system ones.
 // RUN: %clang -### %s --target=x86_64-unknown-netbsd -r 2>&1 \
-// RUN:     -ccc-install-dir %S/Inputs/basic_baremetal_tree/bin \
+// RUN:     -ccc-install-dir %S/Inputs/install_tree_with_libcxx/bin \
 // RUN:     --sysroot=%S/Inputs/basic_netbsd_tree \
 // RUN:   | FileCheck %s --check-prefix=DRIVER-INSTALL-INCLUDES
-// DRIVER-INSTALL-INCLUDES:      "-internal-isystem" 
"{{.*}}bin/../include/c++/v1"
-// DRIVER-INSTALL-INCLUDES-NOT:  "-internal-isystem" 
"{{.*}}/usr/include/c++/v1"
+// DRIVER-INSTALL-INCLUDES:      "-internal-isystem" 
"{{.*}}bin[[SEP:/|\\\\]]..[[SEP]]include[[SEP]]c++[[SEP]]v1"
+// DRIVER-INSTALL-INCLUDES-NOT:  "-internal-isystem" 
"{{.*}}usr[[SEP]]include[[SEP]]c++[[SEP]]v1"
 
 // Test NetBSD with libstdc++ when the sysroot path ends with `/`.
 // RUN: %clangxx -### %s 2>&1 \

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

Reply via email to