19#include "clang/Config/config.h"
28#include "llvm/ADT/STLExtras.h"
29#include "llvm/ADT/SmallString.h"
30#include "llvm/ADT/StringExtras.h"
31#include "llvm/ADT/StringRef.h"
32#include "llvm/ADT/Twine.h"
33#include "llvm/Config/llvm-config.h"
34#include "llvm/MC/MCTargetOptions.h"
35#include "llvm/MC/TargetRegistry.h"
36#include "llvm/Option/Arg.h"
37#include "llvm/Option/ArgList.h"
38#include "llvm/Option/OptTable.h"
39#include "llvm/Option/Option.h"
40#include "llvm/Support/ErrorHandling.h"
41#include "llvm/Support/FileSystem.h"
42#include "llvm/Support/FileUtilities.h"
43#include "llvm/Support/Path.h"
44#include "llvm/Support/Process.h"
45#include "llvm/Support/VersionTuple.h"
46#include "llvm/Support/VirtualFileSystem.h"
47#include "llvm/TargetParser/AArch64TargetParser.h"
48#include "llvm/TargetParser/RISCVISAInfo.h"
49#include "llvm/TargetParser/TargetParser.h"
50#include "llvm/TargetParser/Triple.h"
57using namespace driver;
63 return Args.getLastArg(options::OPT_mkernel, options::OPT_fapple_kext,
64 options::OPT_fno_rtti, options::OPT_frtti);
68 const llvm::Triple &Triple,
69 const Arg *CachedRTTIArg) {
72 if (CachedRTTIArg->getOption().matches(options::OPT_frtti))
79 bool NoRTTI = Triple.isPS() || Triple.isDriverKit();
84 if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
96 auto addIfExists = [
this](
path_list &List,
const std::string &
Path) {
112 llvm::sys::fs::createTemporaryFile(
"toolchain-program",
"txt", OutputFile);
113 llvm::FileRemover OutputRemover(OutputFile.c_str());
114 std::optional<llvm::StringRef> Redirects[] = {
120 std::string ErrorMessage;
121 int SecondsToWait = 60;
122 if (std::optional<std::string> Str =
123 llvm::sys::Process::GetEnv(
"CLANG_TOOLCHAIN_PROGRAM_TIMEOUT")) {
124 if (!llvm::to_integer(*Str, SecondsToWait))
125 return llvm::createStringError(std::error_code(),
126 "CLANG_TOOLCHAIN_PROGRAM_TIMEOUT expected "
127 "an integer, got '" +
129 SecondsToWait = std::min(SecondsToWait, 0);
131 if (llvm::sys::ExecuteAndWait(Executable, {}, {}, Redirects, SecondsToWait,
133 return llvm::createStringError(std::error_code(),
134 Executable +
": " + ErrorMessage);
136 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> OutputBuf =
137 llvm::MemoryBuffer::getFile(OutputFile.c_str());
139 return llvm::createStringError(OutputBuf.getError(),
140 "Failed to read stdout of " + Executable +
141 ": " + OutputBuf.getError().message());
142 return std::move(*OutputBuf);
146 Triple.setEnvironment(
Env);
147 if (EffectiveTriple != llvm::Triple())
148 EffectiveTriple.setEnvironment(
Env);
158 return Args.hasFlag(options::OPT_fintegrated_as,
159 options::OPT_fno_integrated_as,
167 "(Non-)integrated backend set incorrectly!");
169 bool IBackend = Args.hasFlag(options::OPT_fintegrated_objemitter,
170 options::OPT_fno_integrated_objemitter,
178 DiagID = clang::diag::err_drv_unsupported_opt_for_target;
180 DiagID = clang::diag::warn_drv_unsupported_opt_for_target;
181 Arg *A = Args.getLastArg(options::OPT_fno_integrated_objemitter);
183 D.
Diag(DiagID) << A->getAsString(Args) << Triple.getTriple();
184 A = Args.getLastArg(options::OPT_fintegrated_objemitter);
186 D.
Diag(DiagID) << A->getAsString(Args) << Triple.getTriple();
192 return ENABLE_X86_RELAX_RELOCATIONS;
196 return PPC_LINUX_DEFAULT_IEEELONGDOUBLE &&
getTriple().isOSLinux();
200 const llvm::Triple &Triple,
201 const llvm::opt::ArgList &Args,
203 std::vector<StringRef> Features;
206 llvm::DenseSet<StringRef> FeatureSet(UnifiedFeatures.begin(),
207 UnifiedFeatures.end());
208 std::vector<std::string> MArch;
209 for (
const auto &Ext : AArch64::Extensions)
210 if (!Ext.UserVisibleName.empty())
211 if (FeatureSet.contains(Ext.PosTargetFeature))
212 MArch.push_back(Ext.UserVisibleName.str());
213 for (
const auto &Ext : AArch64::Extensions)
214 if (!Ext.UserVisibleName.empty())
215 if (FeatureSet.contains(Ext.NegTargetFeature))
216 MArch.push_back((
"no" + Ext.UserVisibleName).str());
218 for (
const auto &ArchInfo : AArch64::ArchInfos)
219 if (FeatureSet.contains(ArchInfo->ArchFeature))
220 ArchName = ArchInfo->Name;
221 assert(!ArchName.empty() &&
"at least one architecture should be found");
222 MArch.insert(MArch.begin(), (
"-march=" + ArchName).str());
223 Result.push_back(llvm::join(MArch,
"+"));
227 const llvm::Triple &Triple,
228 const llvm::opt::ArgList &Args,
230 std::vector<StringRef> Features;
232 D, Triple, Args, Features,
false ,
true );
234 llvm::DenseSet<StringRef> FeatureSet(UnifiedFeatures.begin(),
235 UnifiedFeatures.end());
236 std::vector<std::string> MArch;
237 for (
const auto &Ext : ARM::ARCHExtNames)
238 if (!Ext.Name.empty())
239 if (FeatureSet.contains(Ext.Feature))
240 MArch.push_back(Ext.Name.str());
241 for (
const auto &Ext : ARM::ARCHExtNames)
242 if (!Ext.Name.empty())
243 if (FeatureSet.contains(Ext.NegFeature))
244 MArch.push_back((
"no" + Ext.Name).str());
245 MArch.insert(MArch.begin(), (
"-march=" + Triple.getArchName()).str());
246 Result.push_back(llvm::join(MArch,
"+"));
249#define ARM_FPU(NAME, KIND, VERSION, NEON_SUPPORT, RESTRICTION) \
250 case llvm::ARM::KIND: \
251 Result.push_back("-mfpu=" NAME); \
253#include "llvm/TargetParser/ARMTargetParser.def"
255 llvm_unreachable(
"Invalid FPUKind");
259 case arm::FloatABI::Soft:
260 Result.push_back(
"-mfloat-abi=soft");
262 case arm::FloatABI::SoftFP:
263 Result.push_back(
"-mfloat-abi=softfp");
265 case arm::FloatABI::Hard:
266 Result.push_back(
"-mfloat-abi=hard");
268 case arm::FloatABI::Invalid:
269 llvm_unreachable(
"Invalid float ABI");
274 const llvm::opt::ArgList &Args,
278 auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
280 if (!llvm::errorToBool(ISAInfo.takeError()))
281 Result.push_back(
"-march=" + (*ISAInfo)->toString());
290 std::vector<std::string>
Result;
292 Result.push_back(
"--target=" + Triple.str());
294 switch (Triple.getArch()) {
295 case llvm::Triple::aarch64:
296 case llvm::Triple::aarch64_32:
297 case llvm::Triple::aarch64_be:
300 case llvm::Triple::arm:
301 case llvm::Triple::armeb:
302 case llvm::Triple::thumb:
303 case llvm::Triple::thumbeb:
306 case llvm::Triple::riscv32:
307 case llvm::Triple::riscv64:
317 Result.push_back(
"-fno-rtti");
319 Result.push_back(
"-frtti");
322 Result.push_back(
"-fno-exceptions");
324 Result.push_back(
"-fexceptions");
334 SanitizerArgs SanArgs(*
this, JobArgs, !SanitizerArgsChecked);
335 SanitizerArgsChecked =
true;
341 XRayArguments.reset(
new XRayArgs(*
this, Args));
342 return *XRayArguments;
349 const char *ModeFlag;
358 static const DriverSuffix DriverSuffixes[] = {
360 {
"clang++",
"--driver-mode=g++"},
361 {
"clang-c++",
"--driver-mode=g++"},
362 {
"clang-cc",
nullptr},
363 {
"clang-cpp",
"--driver-mode=cpp"},
364 {
"clang-g++",
"--driver-mode=g++"},
365 {
"clang-gcc",
nullptr},
366 {
"clang-cl",
"--driver-mode=cl"},
368 {
"cpp",
"--driver-mode=cpp"},
369 {
"cl",
"--driver-mode=cl"},
370 {
"++",
"--driver-mode=g++"},
371 {
"flang",
"--driver-mode=flang"},
372 {
"clang-dxc",
"--driver-mode=dxc"},
375 for (
const auto &DS : DriverSuffixes) {
376 StringRef Suffix(DS.Suffix);
377 if (ProgName.ends_with(Suffix)) {
378 Pos = ProgName.size() - Suffix.size();
388 std::string ProgName = std::string(llvm::sys::path::filename(Argv0));
389 if (is_style_windows(llvm::sys::path::Style::native)) {
391 std::transform(ProgName.begin(), ProgName.end(), ProgName.begin(),
407 if (!DS && ProgName.ends_with(
".exe")) {
410 ProgName = ProgName.drop_back(StringRef(
".exe").size());
417 ProgName = ProgName.rtrim(
"0123456789.");
424 ProgName = ProgName.slice(0, ProgName.rfind(
'-'));
437 size_t SuffixEnd = SuffixPos + strlen(DS->Suffix);
439 size_t LastComponent = ProgName.rfind(
'-', SuffixPos);
440 if (LastComponent == std::string::npos)
442 std::string ModeSuffix = ProgName.substr(LastComponent + 1,
443 SuffixEnd - LastComponent - 1);
446 StringRef Prefix(ProgName);
447 Prefix = Prefix.slice(0, LastComponent);
448 std::string IgnoredError;
450 llvm::TargetRegistry::lookupTarget(std::string(Prefix), IgnoredError);
459 switch (Triple.getArch()) {
460 case llvm::Triple::aarch64: {
465 case llvm::Triple::aarch64_32:
467 case llvm::Triple::ppc:
469 case llvm::Triple::ppcle:
471 case llvm::Triple::ppc64:
473 case llvm::Triple::ppc64le:
476 return Triple.getArchName();
489Tool *ToolChain::getClang()
const {
495Tool *ToolChain::getFlang()
const {
506 llvm_unreachable(
"Linking is not supported by this toolchain");
510 llvm_unreachable(
"Creating static lib is not supported by this toolchain");
513Tool *ToolChain::getAssemble()
const {
516 return Assemble.get();
519Tool *ToolChain::getClangAs()
const {
522 return Assemble.get();
525Tool *ToolChain::getLink()
const {
531Tool *ToolChain::getStaticLibTool()
const {
534 return StaticLibTool.get();
537Tool *ToolChain::getIfsMerge()
const {
540 return IfsMerge.get();
543Tool *ToolChain::getOffloadBundler()
const {
549Tool *ToolChain::getOffloadPackager()
const {
555Tool *ToolChain::getLinkerWrapper()
const {
564 return getAssemble();
567 return getIfsMerge();
573 return getStaticLibTool();
582 llvm_unreachable(
"Invalid tool kind.");
596 return getOffloadBundler();
599 return getOffloadPackager();
601 return getLinkerWrapper();
604 llvm_unreachable(
"Invalid tool kind.");
608 const ArgList &Args) {
609 const llvm::Triple &Triple = TC.
getTriple();
610 bool IsWindows = Triple.isOSWindows();
613 return Triple.getArchName();
615 if (TC.
getArch() == llvm::Triple::arm || TC.
getArch() == llvm::Triple::armeb)
621 if (TC.
getArch() == llvm::Triple::x86 && Triple.isAndroid())
624 if (TC.
getArch() == llvm::Triple::x86_64 && Triple.isX32())
627 return llvm::Triple::getArchTypeName(TC.
getArch());
631 if (Triple.isOSDarwin())
634 switch (Triple.getOS()) {
635 case llvm::Triple::FreeBSD:
637 case llvm::Triple::NetBSD:
639 case llvm::Triple::OpenBSD:
641 case llvm::Triple::Solaris:
643 case llvm::Triple::AIX:
657 }
else if (Triple.isOSUnknown()) {
658 llvm::sys::path::append(
Path,
"lib");
662 return std::string(
Path);
669 return llvm::sys::path::filename(CRTAbsolutePath).str();
675 bool AddArch)
const {
677 bool IsITANMSVCWindows =
678 TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment();
685 Suffix = IsITANMSVCWindows ?
".obj" :
".o";
688 Suffix = IsITANMSVCWindows ?
".lib" :
".a";
691 Suffix = TT.isOSWindows()
692 ? (TT.isWindowsGNUEnvironment() ?
".dll.a" :
".lib")
697 std::string ArchAndEnv;
700 const char *
Env = TT.isAndroid() ?
"-android" :
"";
701 ArchAndEnv = (
"-" + Arch +
Env).str();
703 return (Prefix + Twine(
"clang_rt.") + Component + ArchAndEnv + Suffix).str();
709 std::string CRTBasename =
714 llvm::sys::path::append(
P, CRTBasename);
716 return std::string(
P);
727 llvm::sys::path::append(OldPath, CRTBasename);
729 return std::string(OldPath);
734 return std::string(
Path);
746std::optional<std::string>
747ToolChain::getFallbackAndroidTargetPath(StringRef BaseDir)
const {
748 llvm::Triple TripleWithoutLevel(
getTriple());
749 TripleWithoutLevel.setEnvironmentName(
"android");
750 const std::string &TripleWithoutLevelStr = TripleWithoutLevel.str();
751 unsigned TripleVersion =
getTriple().getEnvironmentVersion().getMajor();
752 unsigned BestVersion = 0;
755 bool UsingUnversionedDir =
false;
757 for (llvm::vfs::directory_iterator LI =
getVFS().dir_begin(BaseDir, EC), LE;
758 !EC && LI != LE; LI = LI.increment(EC)) {
759 StringRef DirName = llvm::sys::path::filename(LI->path());
760 StringRef DirNameSuffix = DirName;
761 if (DirNameSuffix.consume_front(TripleWithoutLevelStr)) {
762 if (DirNameSuffix.empty() && TripleDir.empty()) {
764 UsingUnversionedDir =
true;
767 if (!DirNameSuffix.getAsInteger(10, Version) && Version > BestVersion &&
768 Version < TripleVersion) {
769 BestVersion = Version;
771 UsingUnversionedDir =
false;
777 if (TripleDir.empty())
781 llvm::sys::path::append(
P, TripleDir);
782 if (UsingUnversionedDir)
784 return std::string(
P);
787std::optional<std::string>
789 auto getPathForTriple =
790 [&](
const llvm::Triple &Triple) -> std::optional<std::string> {
792 llvm::sys::path::append(
P, Triple.str());
794 return std::string(
P);
818 ArmTriple.setArch(Triple::arm);
819 if (
auto Path = getPathForTriple(ArmTriple))
824 return getFallbackAndroidTargetPath(BaseDir);
831 llvm::sys::path::append(
P,
"lib");
835 if (Triple.isOSDarwin())
837 llvm::sys::path::append(
P, Triple.str());
838 return std::string(
P);
843 llvm::sys::path::append(
P,
"..",
"lib");
849 llvm::sys::path::append(
P,
"..",
"include");
858 llvm::sys::path::append(
Path,
"lib");
860 llvm::sys::path::append(
Path, S);
861 Paths.push_back(std::string(
Path));
870 if (Args.hasArg(options::OPT_noprofilelib))
873 return Args.hasArg(options::OPT_fprofile_generate) ||
874 Args.hasArg(options::OPT_fprofile_generate_EQ) ||
875 Args.hasArg(options::OPT_fcs_profile_generate) ||
876 Args.hasArg(options::OPT_fcs_profile_generate_EQ) ||
877 Args.hasArg(options::OPT_fprofile_instr_generate) ||
878 Args.hasArg(options::OPT_fprofile_instr_generate_EQ) ||
879 Args.hasArg(options::OPT_fcreate_profile) ||
880 Args.hasArg(options::OPT_forder_file_instrumentation);
884 return Args.hasArg(options::OPT_coverage) ||
885 Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
891 if (
getDriver().ShouldUseClangCompiler(JA))
return getClang();
909 *LinkerIsLLD =
false;
913 const Arg* A = Args.getLastArg(options::OPT_fuse_ld_EQ);
914 StringRef UseLinker = A ? A->getValue() : CLANG_DEFAULT_LINKER;
921 if (
const Arg *A = Args.getLastArg(options::OPT_ld_path_EQ)) {
922 std::string
Path(A->getValue());
924 if (llvm::sys::path::parent_path(
Path).empty())
926 if (llvm::sys::fs::can_execute(
Path)) {
928 *LinkerIsLLD = UseLinker ==
"lld";
929 return std::string(
Path);
932 getDriver().
Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args);
937 if (UseLinker.empty() || UseLinker ==
"ld") {
939 if (llvm::sys::path::is_absolute(DefaultLinker))
940 return std::string(DefaultLinker);
949 if (UseLinker.contains(
'/'))
952 if (llvm::sys::path::is_absolute(UseLinker)) {
955 if (llvm::sys::fs::can_execute(UseLinker))
956 return std::string(UseLinker);
959 if (Triple.isOSDarwin())
960 LinkerName.append(
"ld64.");
962 LinkerName.append(
"ld.");
963 LinkerName.append(UseLinker);
966 if (llvm::sys::fs::can_execute(LinkerPath)) {
968 *LinkerIsLLD = UseLinker ==
"lld";
974 getDriver().
Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args);
981 if (Triple.isOSDarwin())
993 id = types::TY_Fortran;
1003 llvm::Triple HostTriple(LLVM_HOST_TRIPLE);
1004 switch (HostTriple.getArch()) {
1007 case llvm::Triple::arm:
1008 case llvm::Triple::armeb:
1009 case llvm::Triple::thumb:
1010 case llvm::Triple::thumbeb:
1011 return getArch() != llvm::Triple::arm &&
getArch() != llvm::Triple::thumb &&
1012 getArch() != llvm::Triple::armeb &&
getArch() != llvm::Triple::thumbeb;
1014 return HostTriple.getArch() !=
getArch();
1023llvm::ExceptionHandling
1025 return llvm::ExceptionHandling::None;
1029 if (Model ==
"single") {
1031 return Triple.getArch() == llvm::Triple::arm ||
1032 Triple.getArch() == llvm::Triple::armeb ||
1033 Triple.getArch() == llvm::Triple::thumb ||
1034 Triple.getArch() == llvm::Triple::thumbeb || Triple.isWasm();
1035 }
else if (Model ==
"posix")
1047 case llvm::Triple::x86_64: {
1049 if (!Triple.isOSBinFormatMachO())
1052 if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
1055 StringRef MArch = A->getValue();
1056 if (MArch ==
"x86_64h")
1057 Triple.setArchName(MArch);
1059 return Triple.getTriple();
1061 case llvm::Triple::aarch64: {
1064 if (!Triple.isOSBinFormatMachO())
1065 return Triple.getTriple();
1067 if (Triple.isArm64e())
1068 return Triple.getTriple();
1073 Triple.setArchName(
"arm64");
1074 return Triple.getTriple();
1076 case llvm::Triple::aarch64_32:
1078 case llvm::Triple::arm:
1079 case llvm::Triple::armeb:
1080 case llvm::Triple::thumb:
1081 case llvm::Triple::thumbeb: {
1085 return Triple.getTriple();
1100 ArgStringList &CC1Args)
const {
1105 const ArgList &DriverArgs, ArgStringList &CC1Args,
1109 ArgStringList &CC1ASArgs)
const {}
1114 llvm::opt::ArgStringList &CmdArgs)
const {
1122 const ArgList &Args)
const {
1124 return *runtimeLibType;
1126 const Arg* A = Args.getLastArg(options::OPT_rtlib_EQ);
1127 StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_RTLIB;
1130 if (LibName ==
"compiler-rt")
1132 else if (LibName ==
"libgcc")
1134 else if (LibName ==
"platform")
1139 << A->getAsString(Args);
1144 return *runtimeLibType;
1148 const ArgList &Args)
const {
1150 return *unwindLibType;
1152 const Arg *A = Args.getLastArg(options::OPT_unwindlib_EQ);
1153 StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_UNWINDLIB;
1155 if (LibName ==
"none")
1157 else if (LibName ==
"platform" || LibName ==
"") {
1166 }
else if (LibName ==
"libunwind") {
1170 }
else if (LibName ==
"libgcc")
1175 << A->getAsString(Args);
1180 return *unwindLibType;
1185 return *cxxStdlibType;
1187 const Arg *A = Args.getLastArg(options::OPT_stdlib_EQ);
1188 StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_CXX_STDLIB;
1191 if (LibName ==
"libc++")
1193 else if (LibName ==
"libstdc++")
1195 else if (LibName ==
"platform")
1200 << A->getAsString(Args);
1205 return *cxxStdlibType;
1210 ArgStringList &CC1Args,
1211 const Twine &
Path) {
1212 CC1Args.push_back(
"-internal-isystem");
1213 CC1Args.push_back(DriverArgs.MakeArgString(
Path));
1225 ArgStringList &CC1Args,
1226 const Twine &
Path) {
1227 CC1Args.push_back(
"-internal-externc-isystem");
1228 CC1Args.push_back(DriverArgs.MakeArgString(
Path));
1232 ArgStringList &CC1Args,
1233 const Twine &
Path) {
1234 if (llvm::sys::fs::exists(
Path))
1240 ArgStringList &CC1Args,
1242 for (
const auto &
Path : Paths) {
1243 CC1Args.push_back(
"-internal-isystem");
1244 CC1Args.push_back(DriverArgs.MakeArgString(
Path));
1249 const Twine &B,
const Twine &
C,
1252 llvm::sys::path::append(
Result, llvm::sys::path::Style::posix, A, B,
C,
D);
1253 return std::string(
Result);
1259 std::string MaxVersionString;
1261 llvm::sys::path::append(
Path,
"c++");
1262 for (llvm::vfs::directory_iterator LI =
getVFS().dir_begin(
Path, EC), LE;
1263 !EC && LI != LE; LI = LI.increment(EC)) {
1264 StringRef VersionText = llvm::sys::path::filename(LI->path());
1266 if (VersionText[0] ==
'v' &&
1267 !VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) {
1268 if (Version > MaxVersion) {
1269 MaxVersion = Version;
1270 MaxVersionString = std::string(VersionText);
1276 return MaxVersionString;
1280 ArgStringList &CC1Args)
const {
1290 DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ);
1294 const llvm::opt::ArgList &DriverArgs,
1295 llvm::opt::ArgStringList &CC1Args)
const {
1296 DriverArgs.ClaimAllArgs(options::OPT_stdlibxx_isystem);
1305 if (!DriverArgs.hasArg(options::OPT_nostdincxx))
1306 for (
const auto &
P :
1307 DriverArgs.getAllArgValues(options::OPT_stdlibxx_isystem))
1313 !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
1314 options::OPT_nostdlibxx);
1318 ArgStringList &CmdArgs)
const {
1319 assert(!Args.hasArg(options::OPT_nostdlibxx) &&
1320 "should not have called this");
1325 CmdArgs.push_back(
"-lc++");
1326 if (Args.hasArg(options::OPT_fexperimental_library))
1327 CmdArgs.push_back(
"-lc++experimental");
1331 CmdArgs.push_back(
"-lstdc++");
1337 ArgStringList &CmdArgs)
const {
1339 if(LibPath.length() > 0)
1340 CmdArgs.push_back(Args.MakeArgString(StringRef(
"-L") + LibPath));
1344 ArgStringList &CmdArgs)
const {
1345 CmdArgs.push_back(
"-lcc_kext");
1349 std::string &
Path)
const {
1353 bool Default = !Args.hasArgNoClaim(options::OPT_shared);
1359 Arg *A = Args.getLastArg(
1360 options::OPT_ffast_math, options::OPT_fno_fast_math,
1361 options::OPT_funsafe_math_optimizations,
1362 options::OPT_fno_unsafe_math_optimizations, options::OPT_ffp_model_EQ);
1364 if (!A || A->getOption().getID() == options::OPT_fno_fast_math ||
1365 A->getOption().getID() == options::OPT_fno_unsafe_math_optimizations)
1367 if (A && A->getOption().getID() == options::OPT_ffp_model_EQ) {
1368 StringRef Model = A->getValue();
1369 if (Model !=
"fast" && Model !=
"aggressive")
1376 if (!Args.hasFlag(options::OPT_mdaz_ftz, options::OPT_mno_daz_ftz,
Default))
1381 return (
Path !=
"crtfastmath.o");
1385 ArgStringList &CmdArgs)
const {
1388 CmdArgs.push_back(Args.MakeArgString(
Path));
1406 (SanitizerKind::CFI & ~SanitizerKind::CFIICall) |
1407 SanitizerKind::CFICastStrict | SanitizerKind::FloatDivideByZero |
1408 SanitizerKind::KCFI | SanitizerKind::UnsignedIntegerOverflow |
1409 SanitizerKind::UnsignedShiftBase | SanitizerKind::ImplicitConversion |
1410 SanitizerKind::Nullability | SanitizerKind::LocalBounds;
1411 if (
getTriple().getArch() == llvm::Triple::x86 ||
1412 getTriple().getArch() == llvm::Triple::x86_64 ||
1413 getTriple().getArch() == llvm::Triple::arm ||
1417 Res |= SanitizerKind::CFIICall;
1418 if (
getTriple().getArch() == llvm::Triple::x86_64 ||
1420 Res |= SanitizerKind::ShadowCallStack;
1422 Res |= SanitizerKind::MemTag;
1427 ArgStringList &CC1Args)
const {}
1430 ArgStringList &CC1Args)
const {}
1438 ArgStringList &CC1Args)
const {}
1442 return VersionTuple(Version);
1444 if (Version < 10000)
1445 return VersionTuple(Version / 100, Version % 100);
1447 unsigned Build = 0, Factor = 1;
1448 for (; Version > 10000; Version = Version / 10, Factor = Factor * 10)
1449 Build = Build + (Version % 10) * Factor;
1450 return VersionTuple(Version / 100, Version % 100, Build);
1455 const llvm::opt::ArgList &Args)
const {
1456 const Arg *MSCVersion = Args.getLastArg(options::OPT_fmsc_version);
1457 const Arg *MSCompatibilityVersion =
1458 Args.getLastArg(options::OPT_fms_compatibility_version);
1460 if (MSCVersion && MSCompatibilityVersion) {
1462 D->Diag(diag::err_drv_argument_not_allowed_with)
1463 << MSCVersion->getAsString(Args)
1464 << MSCompatibilityVersion->getAsString(Args);
1465 return VersionTuple();
1468 if (MSCompatibilityVersion) {
1470 if (MSVT.tryParse(MSCompatibilityVersion->getValue())) {
1472 D->Diag(diag::err_drv_invalid_value)
1473 << MSCompatibilityVersion->getAsString(Args)
1474 << MSCompatibilityVersion->getValue();
1481 unsigned Version = 0;
1482 if (StringRef(MSCVersion->getValue()).getAsInteger(10, Version)) {
1484 D->Diag(diag::err_drv_invalid_value)
1485 << MSCVersion->getAsString(Args) << MSCVersion->getValue();
1491 return VersionTuple();
1495 const llvm::opt::DerivedArgList &Args,
bool SameTripleAsHost,
1497 DerivedArgList *DAL =
new DerivedArgList(Args.getBaseArgs());
1499 bool Modified =
false;
1502 for (
auto *A : Args) {
1507 if (A->getOption().matches(options::OPT_m_Group)) {
1510 if (SameTripleAsHost ||
1511 A->getOption().matches(options::OPT_mcode_object_version_EQ))
1520 bool XOpenMPTargetNoTriple =
1521 A->getOption().matches(options::OPT_Xopenmp_target);
1523 if (A->getOption().matches(options::OPT_Xopenmp_target_EQ)) {
1528 Index = Args.getBaseArgs().MakeIndex(A->getValue(1));
1531 }
else if (XOpenMPTargetNoTriple) {
1533 Index = Args.getBaseArgs().MakeIndex(A->getValue(0));
1541 std::unique_ptr<Arg> XOpenMPTargetArg(Opts.ParseOneArg(Args, Index));
1542 if (!XOpenMPTargetArg || Index > Prev + 1) {
1543 getDriver().
Diag(diag::err_drv_invalid_Xopenmp_target_with_args)
1544 << A->getAsString(Args);
1547 if (XOpenMPTargetNoTriple && XOpenMPTargetArg &&
1548 Args.getAllArgValues(options::OPT_fopenmp_targets_EQ).size() != 1) {
1549 getDriver().
Diag(diag::err_drv_Xopenmp_target_missing_triple);
1552 XOpenMPTargetArg->setBaseArg(A);
1553 A = XOpenMPTargetArg.release();
1554 AllocatedArgs.push_back(A);
1570 const llvm::opt::DerivedArgList &Args, llvm::opt::Arg *&A,
1571 llvm::opt::DerivedArgList *DAL,
1574 unsigned ValuePos = 1;
1575 if (A->getOption().matches(options::OPT_Xarch_device) ||
1576 A->getOption().matches(options::OPT_Xarch_host))
1579 unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(ValuePos));
1580 unsigned Prev = Index;
1581 std::unique_ptr<llvm::opt::Arg> XarchArg(Opts.ParseOneArg(Args, Index));
1590 if (!XarchArg || Index > Prev + 1) {
1591 getDriver().
Diag(diag::err_drv_invalid_Xarch_argument_with_args)
1592 << A->getAsString(Args);
1598 "invalid Xarch argument: '%0', not all driver "
1599 "options can be forwared via Xarch argument");
1600 Diags.Report(DiagID) << A->getAsString(Args);
1603 XarchArg->setBaseArg(A);
1604 A = XarchArg.release();
1606 DAL->AddSynthesizedArg(A);
1608 AllocatedArgs->push_back(A);
1612 const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
1615 DerivedArgList *DAL =
new DerivedArgList(Args.getBaseArgs());
1616 bool Modified =
false;
1619 for (Arg *A : Args) {
1620 bool NeedTrans =
false;
1622 if (A->getOption().matches(options::OPT_Xarch_device)) {
1623 NeedTrans = IsDevice;
1625 }
else if (A->getOption().matches(options::OPT_Xarch_host)) {
1626 NeedTrans = !IsDevice;
1628 }
else if (A->getOption().matches(options::OPT_Xarch__) && IsDevice) {
1632 if (BoundArch.empty() || A->getValue(0) != BoundArch)
1637 if (NeedTrans || Skip)
Defines types useful for describing an Objective-C runtime.
Defines the clang::SanitizerKind enum.
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
The basic abstraction for the target Objective-C runtime.
@ GNUstep
'gnustep' is the modern non-fragile GNUstep runtime.
@ GCC
'gcc' is the Objective-C runtime shipped with GCC, implementing a fragile Objective-C ABI
The base class of the type hierarchy.
ActionClass getKind() const
@ OffloadUnbundlingJobClass
@ OffloadBundlingJobClass
@ VerifyDebugInfoJobClass
@ OffloadPackagerJobClass
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
std::string SysRoot
sysroot, if present
std::string GetFilePath(StringRef Name, const ToolChain &TC) const
GetFilePath - Lookup Name in the list of file search paths.
DiagnosticsEngine & getDiags() const
DiagnosticBuilder Diag(unsigned DiagID) const
const llvm::opt::OptTable & getOpts() const
std::string GetProgramPath(StringRef Name, const ToolChain &TC) const
GetProgramPath - Lookup Name in the list of program search paths.
std::string ResourceDir
The path to the compiler resource directory.
llvm::vfs::FileSystem & getVFS() const
std::string Dir
The path the driver executable was in, as invoked from the command line.
bool IsFlangMode() const
Whether the driver should invoke flang for fortran inputs.
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
std::vector< std::string > flags_list
ID lookupTypeForExtension(llvm::StringRef Ext)
lookupTypeForExtension - Lookup the type to use for the file extension Ext.
bool isOptimizationLevelFast(const llvm::opt::ArgList &Args)
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
const FunctionProtoType * T
Diagnostic wrappers for TextAPI types for error reporting.
Helper structure used to pass information extracted from clang executable name such as i686-linux-and...