[clang] [clang][driver] Add \<executable\>/../include/c++/v1 to include path on Darwin (PR #70817)

Louis Dionne via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 8 16:29:41 PST 2023


================
@@ -2494,6 +2494,19 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
                    << "\"\n";
     }
 
+    // Check for the folder where the executable is located, if different.
+    if (getDriver().getInstalledDir() != getDriver().Dir) {
+      InstallBin = llvm::StringRef(getDriver().Dir.c_str());
+      llvm::sys::path::append(InstallBin, "..", "include", "c++", "v1");
+      if (getVFS().exists(InstallBin)) {
+        addSystemInclude(DriverArgs, CC1Args, InstallBin);
+        return;
+      } else if (DriverArgs.hasArg(options::OPT_v)) {
+        llvm::errs() << "ignoring nonexistent directory \"" << InstallBin
+                     << "\"\n";
+      }
+    }
+
     // Otherwise, check for (2)
     llvm::SmallString<128> SysrootUsr = Sysroot;
     llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1");
----------------
ldionne wrote:

I think you probably want to add new tests in `clang/test/Driver/darwin-header-search-libcxx.cpp`. You also mentioned that other platforms (e.g. Linux?) handle search paths this way, right? Can you show where this is handled? They might have some tests you could take inspiration from?

https://github.com/llvm/llvm-project/pull/70817


More information about the cfe-commits mailing list