From 37da24c1f6480d3baef1e46aa53cc1435673aa5b Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 24 Oct 2023 15:15:10 +0200 Subject: [PATCH] [Xtensa] Fix Clang builtins include directory This fixes https://github.com/espressif/llvm-project/issues/83 In short, it adjusts the include path logic to include the builtins directory as long as `-nostdinc` or `-nobuiltininc` isn't specified. Previously, the builtins directory would not be included if either the GCC installation wasn't found, or `-nostdlibinc` was specified (both of which aren't related to the builtins directory). --- clang/lib/Driver/ToolChains/Xtensa.cpp | 41 +++++++++++++++----------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Xtensa.cpp b/clang/lib/Driver/ToolChains/Xtensa.cpp index 0e37e746a83268..d8a877688a3558 100644 --- a/clang/lib/Driver/ToolChains/Xtensa.cpp +++ b/clang/lib/Driver/ToolChains/Xtensa.cpp @@ -145,29 +145,34 @@ Tool *XtensaToolChain::buildAssembler() const { void XtensaToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { - if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) || - DriverArgs.hasArg(options::OPT_nostdlibinc)) + if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc)) return; - if (!getDriver().SysRoot.empty()) { - SmallString<128> Dir(getDriver().SysRoot); - llvm::sys::path::append(Dir, "include"); - addSystemInclude(DriverArgs, CC1Args, Dir.str()); - } else if (GCCInstallation.isValid()) { - SmallString<128> Path1(getDriver().ResourceDir); - llvm::sys::path::append(Path1, "include"); - SmallString<128> Path2(GCCToolchainDir); - llvm::sys::path::append(Path2, GCCToolchainName, "sys-include"); - SmallString<128> Path3(GCCToolchainDir); - llvm::sys::path::append(Path3, GCCToolchainName, "include"); - - const StringRef Paths[] = {Path1, Path2, Path3}; - addSystemIncludes(DriverArgs, CC1Args, Paths); - } else { - SmallString<128> Dir(computeSysRoot()); + if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { + SmallString<128> Dir(getDriver().ResourceDir); llvm::sys::path::append(Dir, "include"); addSystemInclude(DriverArgs, CC1Args, Dir.str()); } + + if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) { + if (!getDriver().SysRoot.empty()) { + SmallString<128> Dir(getDriver().SysRoot); + llvm::sys::path::append(Dir, "include"); + addSystemInclude(DriverArgs, CC1Args, Dir.str()); + } else if (GCCInstallation.isValid()) { + SmallString<128> Path1(GCCToolchainDir); + llvm::sys::path::append(Path1, GCCToolchainName, "sys-include"); + SmallString<128> Path2(GCCToolchainDir); + llvm::sys::path::append(Path2, GCCToolchainName, "include"); + + const StringRef Paths[] = {Path1, Path2}; + addSystemIncludes(DriverArgs, CC1Args, Paths); + } else { + SmallString<128> Dir(computeSysRoot()); + llvm::sys::path::append(Dir, "include"); + addSystemInclude(DriverArgs, CC1Args, Dir.str()); + } + } } void XtensaToolChain::addLibStdCxxIncludePaths(