Path: blob/main/contrib/llvm-project/clang/lib/Driver/ToolChains/Cygwin.cpp
213799 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "Cygwin.h"9#include "clang/Config/config.h"10#include "clang/Driver/CommonArgs.h"11#include "clang/Driver/Driver.h"12#include "clang/Driver/Options.h"13#include "llvm/Support/Path.h"14#include "llvm/Support/VirtualFileSystem.h"1516using namespace clang::driver;17using namespace clang::driver::toolchains;18using namespace clang;19using namespace llvm::opt;2021using tools::addPathIfExists;2223Cygwin::Cygwin(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)24: Generic_GCC(D, Triple, Args) {25GCCInstallation.init(Triple, Args);26std::string SysRoot = computeSysRoot();27ToolChain::path_list &PPaths = getProgramPaths();2829Generic_GCC::PushPPaths(PPaths);3031path_list &Paths = getFilePaths();3233Generic_GCC::AddMultiarchPaths(D, SysRoot, "lib", Paths);3435// Similar to the logic for GCC above, if we are currently running Clang36// inside of the requested system root, add its parent library path to those37// searched.38// FIXME: It's not clear whether we should use the driver's installed39// directory ('Dir' below) or the ResourceDir.40if (StringRef(D.Dir).starts_with(SysRoot))41addPathIfExists(D, D.Dir + "/../lib", Paths);4243addPathIfExists(D, SysRoot + "/lib", Paths);44addPathIfExists(D, SysRoot + "/usr/lib", Paths);45addPathIfExists(D, SysRoot + "/usr/lib/w32api", Paths);46}4748llvm::ExceptionHandling Cygwin::GetExceptionModel(const ArgList &Args) const {49if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64 ||50getArch() == llvm::Triple::arm || getArch() == llvm::Triple::thumb)51return llvm::ExceptionHandling::WinEH;52return llvm::ExceptionHandling::DwarfCFI;53}5455void Cygwin::AddClangSystemIncludeArgs(const ArgList &DriverArgs,56ArgStringList &CC1Args) const {57const Driver &D = getDriver();58std::string SysRoot = computeSysRoot();5960if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))61return;6263if (!DriverArgs.hasArg(options::OPT_nostdlibinc))64addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include");6566if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {67SmallString<128> P(D.ResourceDir);68llvm::sys::path::append(P, "include");69addSystemInclude(DriverArgs, CC1Args, P);70}7172if (DriverArgs.hasArg(options::OPT_nostdlibinc))73return;7475// Check for configure-time C include directories.76StringRef CIncludeDirs(C_INCLUDE_DIRS);77if (CIncludeDirs != "") {78SmallVector<StringRef, 5> Dirs;79CIncludeDirs.split(Dirs, ":");80for (StringRef Dir : Dirs) {81StringRef Prefix =82llvm::sys::path::is_absolute(Dir) ? "" : StringRef(SysRoot);83addExternCSystemInclude(DriverArgs, CC1Args, Prefix + Dir);84}85return;86}8788// Lacking those, try to detect the correct set of system includes for the89// target triple.9091AddMultilibIncludeArgs(DriverArgs, CC1Args);9293// On systems using multiarch, add /usr/include/$triple before94// /usr/include.95std::string MultiarchIncludeDir = getTriple().str();96if (!MultiarchIncludeDir.empty() &&97D.getVFS().exists(SysRoot + "/usr/include/" + MultiarchIncludeDir))98addExternCSystemInclude(DriverArgs, CC1Args,99SysRoot + "/usr/include/" + MultiarchIncludeDir);100101// Add an include of '/include' directly. This isn't provided by default by102// system GCCs, but is often used with cross-compiling GCCs, and harmless to103// add even when Clang is acting as-if it were a system compiler.104addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include");105106addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");107addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/w32api");108}109110111