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/3] [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/3] 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/3] 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"
 

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

Reply via email to