diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -1959,9 +1959,12 @@ llvm::SmallVector dirs; CIncludeDirs.split(dirs, ":"); for (llvm::StringRef dir : dirs) { - llvm::StringRef Prefix = - llvm::sys::path::is_absolute(dir) ? "" : llvm::StringRef(Sysroot); - addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); + if (llvm::sys::path::is_absolute(dir)) + addExternCSystemInclude(DriverArgs, CC1Args, dir); + else { + addExternCSystemInclude(DriverArgs, CC1Args, + StringRef(Sysroot) + "/" + dir); + } } } else { // Otherwise, add /usr/include. diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp b/clang/lib/Driver/ToolChains/Fuchsia.cpp --- a/clang/lib/Driver/ToolChains/Fuchsia.cpp +++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp @@ -296,9 +296,12 @@ SmallVector dirs; CIncludeDirs.split(dirs, ":"); for (StringRef dir : dirs) { - StringRef Prefix = - llvm::sys::path::is_absolute(dir) ? "" : StringRef(D.SysRoot); - addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); + if (llvm::sys::path::is_absolute(dir)) + addExternCSystemInclude(DriverArgs, CC1Args, dir); + else { + addExternCSystemInclude(DriverArgs, CC1Args, + StringRef(D.SysRoot) + "/" + dir); + } } return; } diff --git a/clang/lib/Driver/ToolChains/Hurd.cpp b/clang/lib/Driver/ToolChains/Hurd.cpp --- a/clang/lib/Driver/ToolChains/Hurd.cpp +++ b/clang/lib/Driver/ToolChains/Hurd.cpp @@ -158,9 +158,12 @@ SmallVector Dirs; CIncludeDirs.split(Dirs, ":"); for (StringRef Dir : Dirs) { - StringRef Prefix = - llvm::sys::path::is_absolute(Dir) ? "" : StringRef(SysRoot); - addExternCSystemInclude(DriverArgs, CC1Args, Prefix + Dir); + if (llvm::sys::path::is_absolute(Dir)) + addExternCSystemInclude(DriverArgs, CC1Args, Dir); + else { + addExternCSystemInclude(DriverArgs, CC1Args, + StringRef(SysRoot) + "/" + Dir); + } } return; } diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -578,9 +578,12 @@ SmallVector dirs; CIncludeDirs.split(dirs, ":"); for (StringRef dir : dirs) { - StringRef Prefix = - llvm::sys::path::is_absolute(dir) ? "" : StringRef(SysRoot); - addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); + if (llvm::sys::path::is_absolute(dir)) + addExternCSystemInclude(DriverArgs, CC1Args, dir); + else { + addExternCSystemInclude(DriverArgs, CC1Args, + StringRef(SysRoot) + "/" + dir); + } } return; } diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp b/clang/lib/Driver/ToolChains/OpenBSD.cpp --- a/clang/lib/Driver/ToolChains/OpenBSD.cpp +++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp @@ -274,9 +274,12 @@ SmallVector dirs; CIncludeDirs.split(dirs, ":"); for (StringRef dir : dirs) { - StringRef Prefix = - llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : ""; - addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); + if (llvm::sys::path::is_absolute(dir)) + addExternCSystemInclude(DriverArgs, CC1Args, dir); + else { + addExternCSystemInclude(DriverArgs, CC1Args, + StringRef(D.SysRoot) + "/" + dir); + } } return; } diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp --- a/clang/lib/Driver/ToolChains/Solaris.cpp +++ b/clang/lib/Driver/ToolChains/Solaris.cpp @@ -245,9 +245,12 @@ SmallVector dirs; CIncludeDirs.split(dirs, ":"); for (StringRef dir : dirs) { - StringRef Prefix = - llvm::sys::path::is_absolute(dir) ? "" : StringRef(D.SysRoot); - addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); + if (llvm::sys::path::is_absolute(dir)) + addExternCSystemInclude(DriverArgs, CC1Args, dir); + else { + addExternCSystemInclude(DriverArgs, CC1Args, + StringRef(D.SysRoot) + "/" + dir); + } } return; } diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp --- a/clang/lib/Driver/ToolChains/WebAssembly.cpp +++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp @@ -331,9 +331,12 @@ SmallVector dirs; CIncludeDirs.split(dirs, ":"); for (StringRef dir : dirs) { - StringRef Prefix = - llvm::sys::path::is_absolute(dir) ? "" : StringRef(D.SysRoot); - addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); + if (llvm::sys::path::is_absolute(dir)) + addExternCSystemInclude(DriverArgs, CC1Args, dir); + else { + addExternCSystemInclude(DriverArgs, CC1Args, + StringRef(D.SysRoot) + "/" + dir); + } } return; }