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 @@ -8,6 +8,7 @@ #include "WebAssembly.h" #include "CommonArgs.h" +#include "clang/Config/config.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" @@ -170,14 +171,39 @@ void WebAssembly::AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { - if (!DriverArgs.hasArg(options::OPT_nostdinc)) { - if (getTriple().getOS() != llvm::Triple::UnknownOS) { - const std::string MultiarchTriple = - getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot); - addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include/" + MultiarchTriple); + if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc)) + return; + + const Driver &D = getDriver(); + + if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { + SmallString<128> P(D.ResourceDir); + llvm::sys::path::append(P, "include"); + addSystemInclude(DriverArgs, CC1Args, P); + } + + if (DriverArgs.hasArg(options::OPT_nostdlibinc)) + return; + + // Check for configure-time C include directories. + StringRef CIncludeDirs(C_INCLUDE_DIRS); + if (CIncludeDirs != "") { + 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); } - addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); + return; + } + + if (getTriple().getOS() != llvm::Triple::UnknownOS) { + const std::string MultiarchTriple = + getMultiarchTriple(D, getTriple(), D.SysRoot); + addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include/" + MultiarchTriple); } + addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include"); } void WebAssembly::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, @@ -188,7 +214,8 @@ const std::string MultiarchTriple = getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot); addSystemInclude(DriverArgs, CC1Args, - getDriver().SysRoot + "/include/" + MultiarchTriple + "/c++/v1"); + getDriver().SysRoot + "/include/" + MultiarchTriple + + "/c++/v1"); } addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include/c++/v1"); diff --git a/clang/lib/Frontend/InitHeaderSearch.cpp b/clang/lib/Frontend/InitHeaderSearch.cpp --- a/clang/lib/Frontend/InitHeaderSearch.cpp +++ b/clang/lib/Frontend/InitHeaderSearch.cpp @@ -414,9 +414,11 @@ default: break; // Everything else continues to use this routine's logic. + case llvm::Triple::Emscripten: case llvm::Triple::Linux: case llvm::Triple::Hurd: case llvm::Triple::Solaris: + case llvm::Triple::WASI: return; case llvm::Triple::Win32: @@ -424,6 +426,12 @@ triple.isOSBinFormatMachO()) return; break; + + case llvm::Triple::UnknownOS: + if (triple.getArch() == llvm::Triple::wasm32 || + triple.getArch() == llvm::Triple::wasm64) + return; + break; } // All header search logic is handled in the Driver for Darwin.