diff --git a/clang/include/clang/Driver/Multilib.h b/clang/include/clang/Driver/Multilib.h index 6c3738a9cc03..d19097b0a7de 100644 --- a/clang/include/clang/Driver/Multilib.h +++ b/clang/include/clang/Driver/Multilib.h @@ -97,6 +97,10 @@ public: typedef multilib_list::iterator iterator; typedef multilib_list::const_iterator const_iterator; + typedef std::function( + StringRef InstallDir, StringRef Triple, const Multilib &M)> + IncludeDirsFunc; + struct FilterCallback { virtual ~FilterCallback() {}; /// \return true iff the filter should remove the Multilib from the set @@ -105,6 +109,7 @@ public: private: multilib_list Multilibs; + IncludeDirsFunc IncludeCallback; public: MultilibSet() {} @@ -150,6 +155,12 @@ public: void print(raw_ostream &OS) const; + MultilibSet &setIncludeDirsCallback(IncludeDirsFunc F) { + IncludeCallback = F; + return *this; + } + IncludeDirsFunc includeDirsCallback() const { return IncludeCallback; } + private: /// Apply the filter to Multilibs and return the subset that remains static multilib_list filterCopy(const FilterCallback &F, diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index 15ae27cb89d3..63ad2619d9cd 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -1726,7 +1726,14 @@ static bool findMIPSMultilibs(const llvm::Triple &TargetTriple, StringRef Path, .Maybe(SoftFloat) .Maybe(Nan2008) .FilterOut(".*sof/nan2008") - .FilterOut(NonExistent); + .FilterOut(NonExistent) + .setIncludeDirsCallback([]( + StringRef InstallDir, StringRef TripleStr, const Multilib &M) { + std::vector Dirs; + Dirs.push_back((InstallDir + "/include").str()); + Dirs.push_back((InstallDir + "/../../../../sysroot/usr/include").str()); + return Dirs; + }); } // Check for Code Sourcery toolchain multilibs @@ -1771,7 +1778,15 @@ static bool findMIPSMultilibs(const llvm::Triple &TargetTriple, StringRef Path, .Maybe(MAbi64) .FilterOut("/mips16.*/64") .FilterOut("/micromips.*/64") - .FilterOut(NonExistent); + .FilterOut(NonExistent) + .setIncludeDirsCallback([]( + StringRef InstallDir, StringRef TripleStr, const Multilib &M) { + std::vector Dirs; + Dirs.push_back((InstallDir + "/include").str()); + Dirs.push_back((InstallDir + "/../../../../" + TripleStr + + "/libc/usr/include").str()); + return Dirs; + }); } MultilibSet AndroidMipsMultilibs = MultilibSet() @@ -1813,7 +1828,14 @@ static bool findMIPSMultilibs(const llvm::Triple &TargetTriple, StringRef Path, .Maybe(Mips64r6) .Maybe(MAbi64) .Maybe(LittleEndian) - .FilterOut(NonExistent); + .FilterOut(NonExistent) + .setIncludeDirsCallback([]( + StringRef InstallDir, StringRef TripleStr, const Multilib &M) { + std::vector Dirs; + Dirs.push_back((InstallDir + "/include").str()); + Dirs.push_back((InstallDir + "/../../../../sysroot/usr/include").str()); + return Dirs; + }); } StringRef CPUName; @@ -3215,20 +3237,16 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, // Lacking those, try to detect the correct set of system includes for the // target triple. - // Sourcery CodeBench and modern FSF Mips toolchains put extern C - // system includes under three additional directories. - if (GCCInstallation.isValid() && isMipsArch(getTriple().getArch())) { - addExternCSystemIncludeIfExists( - DriverArgs, CC1Args, GCCInstallation.getInstallPath() + "/include"); - - addExternCSystemIncludeIfExists( - DriverArgs, CC1Args, - GCCInstallation.getInstallPath() + "/../../../../" + - GCCInstallation.getTriple().str() + "/libc/usr/include"); - - addExternCSystemIncludeIfExists( - DriverArgs, CC1Args, - GCCInstallation.getInstallPath() + "/../../../../sysroot/usr/include"); + // Add include directories specific to the selected multilib set and multilib. + if (GCCInstallation.isValid()) { + auto Callback = Multilibs.includeDirsCallback(); + if (Callback) { + const auto IncludePaths = Callback(GCCInstallation.getInstallPath(), + GCCInstallation.getTriple().str(), + GCCInstallation.getMultilib()); + for (const auto &Path : IncludePaths) + addExternCSystemIncludeIfExists(DriverArgs, CC1Args, Path); + } } // Implement generic Debian multiarch support.