[clang] [Driver] Fix detection of libc++ with empty sysroot. (PR #66947)

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 20 12:28:11 PDT 2023


https://github.com/sam-mccall created https://github.com/llvm/llvm-project/pull/66947

b1e3cd1d79443603dc003441e07cdd8d30bb7f26 dropped the leading slash here,
presumably unintentionally.

(I don't understand Driver well enough to know how/where this is supposed
to be tested, but it broke clangd on any project that uses the
system-installed -stdlib=libc++ on a standard debian install)


>From 00ef242c40dd453157ee3b31e367fd6240d68a5a Mon Sep 17 00:00:00 2001
From: Sam McCall <sam.mccall at gmail.com>
Date: Wed, 20 Sep 2023 21:19:03 +0200
Subject: [PATCH] [Driver] Fix detection of libc++ with empty sysroot.

b1e3cd1d79443603dc003441e07cdd8d30bb7f26 dropped the leading slash here,
presumably unintentionally.

(I don't understand Driver well enough to know how/where this is supposed
to be tested, but it broke clangd on any project that uses the
system-installed -stdlib=libc++ on a standard debian install)
---
 clang/lib/Driver/ToolChains/Gnu.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index e909549d20708fe..f2fd85021a777b4 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -3139,11 +3139,11 @@ Generic_GCC::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
   // not be found at ../include/c++ but it likely to be found at
   // one of the following two locations:
   SmallString<128> UsrLocalIncludeDir(SysRoot);
-  llvm::sys::path::append(UsrLocalIncludeDir, "usr", "local", "include");
+  llvm::sys::path::append(UsrLocalIncludeDir, "/usr", "local", "include");
   if (AddIncludePath(UsrLocalIncludeDir))
     return;
   SmallString<128> UsrIncludeDir(SysRoot);
-  llvm::sys::path::append(UsrIncludeDir, "usr", "include");
+  llvm::sys::path::append(UsrIncludeDir, "/usr", "include");
   if (AddIncludePath(UsrIncludeDir))
     return;
 }



More information about the cfe-commits mailing list