[clang] [clang][Driver] Fix libc++ include path on NetBSD (PR #212716)

Rainer Orth via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 29 02:18:40 PDT 2026


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 <ro at gcc.gnu.org>
Date: Wed, 29 Jul 2026 10:52:08 +0200
Subject: [PATCH 1/2] [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 <ro at gcc.gnu.org>
Date: Wed, 29 Jul 2026 11:18:16 +0200
Subject: [PATCH 2/2] 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"



More information about the cfe-commits mailing list