Skip to content

Commit 7d7951e

Browse files
LunNovajustinkb
authored andcommitted
HACK: Get canonical GCC include path so doesn't have ../../../../
1 parent 3bdd7cb commit 7d7951e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3390,29 +3390,33 @@ bool Generic_GCC::addLibStdCXXIncludePaths(Twine IncludeDir, StringRef Triple,
33903390
if (!getVFS().exists(IncludeDir))
33913391
return false;
33923392

3393+
SmallString<260> CanonicalIncludeDir;
3394+
if (getVFS().getRealPath(IncludeDir, CanonicalIncludeDir))
3395+
return false;
3396+
33933397
// Debian native gcc uses g++-multiarch-incdir.diff which uses
33943398
// include/x86_64-linux-gnu/c++/10$IncludeSuffix instead of
33953399
// include/c++/10/x86_64-linux-gnu$IncludeSuffix.
3396-
std::string Dir = IncludeDir.str();
33973400
StringRef Include =
3398-
llvm::sys::path::parent_path(llvm::sys::path::parent_path(Dir));
3401+
llvm::sys::path::parent_path(llvm::sys::path::parent_path(CanonicalIncludeDir));
33993402
std::string Path =
3400-
(Include + "/" + Triple + Dir.substr(Include.size()) + IncludeSuffix)
3403+
(Include + "/" + Triple + CanonicalIncludeDir.substr(Include.size()) + IncludeSuffix)
34013404
.str();
34023405
if (DetectDebian && !getVFS().exists(Path))
34033406
return false;
34043407

34053408
// GPLUSPLUS_INCLUDE_DIR
3406-
addSystemInclude(DriverArgs, CC1Args, IncludeDir);
3409+
addSystemInclude(DriverArgs, CC1Args, CanonicalIncludeDir);
34073410
// GPLUSPLUS_TOOL_INCLUDE_DIR. If Triple is not empty, add a target-dependent
34083411
// include directory.
34093412
if (DetectDebian)
34103413
addSystemInclude(DriverArgs, CC1Args, Path);
34113414
else if (!Triple.empty())
34123415
addSystemInclude(DriverArgs, CC1Args,
3413-
IncludeDir + "/" + Triple + IncludeSuffix);
3416+
CanonicalIncludeDir + "/" + Triple + IncludeSuffix);
34143417
// GPLUSPLUS_BACKWARD_INCLUDE_DIR
3415-
addSystemInclude(DriverArgs, CC1Args, IncludeDir + "/backward");
3418+
if (getVFS().exists(CanonicalIncludeDir + "/backward"))
3419+
addSystemInclude(DriverArgs, CC1Args, CanonicalIncludeDir + "/backward");
34163420
return true;
34173421
}
34183422

0 commit comments

Comments
 (0)