18#include "clang/Config/config.h"
27#include "llvm/ADT/STLExtras.h"
28#include "llvm/ADT/SmallString.h"
29#include "llvm/ADT/StringExtras.h"
30#include "llvm/ADT/StringRef.h"
31#include "llvm/ADT/Twine.h"
32#include "llvm/Config/llvm-config.h"
33#include "llvm/MC/MCTargetOptions.h"
34#include "llvm/MC/TargetRegistry.h"
35#include "llvm/Option/Arg.h"
36#include "llvm/Option/ArgList.h"
37#include "llvm/Option/OptTable.h"
38#include "llvm/Option/Option.h"
39#include "llvm/Support/ErrorHandling.h"
40#include "llvm/Support/FileSystem.h"
41#include "llvm/Support/FileUtilities.h"
42#include "llvm/Support/Path.h"
43#include "llvm/Support/Process.h"
44#include "llvm/Support/VersionTuple.h"
45#include "llvm/Support/VirtualFileSystem.h"
46#include "llvm/TargetParser/AArch64TargetParser.h"
47#include "llvm/TargetParser/TargetParser.h"
48#include "llvm/TargetParser/Triple.h"
55using namespace driver;
61 return Args.getLastArg(options::OPT_mkernel, options::OPT_fapple_kext,
62 options::OPT_fno_rtti, options::OPT_frtti);
66 const llvm::Triple &Triple,
67 const Arg *CachedRTTIArg) {
70 if (CachedRTTIArg->getOption().matches(options::OPT_frtti))
77 bool NoRTTI = Triple.isPS() || Triple.isDriverKit();
82 if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
94 auto addIfExists = [
this](
path_list &List,
const std::string &
Path) {
110 llvm::sys::fs::createTemporaryFile(
"toolchain-program",
"txt", OutputFile);
111 llvm::FileRemover OutputRemover(OutputFile.c_str());
112 std::optional<llvm::StringRef> Redirects[] = {
118 std::string ErrorMessage;
119 int SecondsToWait = 60;
120 if (std::optional<std::string> Str =
121 llvm::sys::Process::GetEnv(
"CLANG_TOOLCHAIN_PROGRAM_TIMEOUT")) {
122 if (!llvm::to_integer(*Str, SecondsToWait))
123 return llvm::createStringError(std::error_code(),
124 "CLANG_TOOLCHAIN_PROGRAM_TIMEOUT expected "
125 "an integer, got '" +
127 SecondsToWait = std::min(SecondsToWait, 0);
129 if (llvm::sys::ExecuteAndWait(Executable, {}, {}, Redirects, SecondsToWait,
131 return llvm::createStringError(std::error_code(),
132 Executable +
": " + ErrorMessage);
134 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> OutputBuf =
135 llvm::MemoryBuffer::getFile(OutputFile.c_str());
137 return llvm::createStringError(OutputBuf.getError(),
138 "Failed to read stdout of " + Executable +
139 ": " + OutputBuf.getError().message());
140 return std::move(*OutputBuf);
144 Triple.setEnvironment(
Env);
145 if (EffectiveTriple != llvm::Triple())
146 EffectiveTriple.setEnvironment(
Env);
156 return Args.hasFlag(options::OPT_fintegrated_as,
157 options::OPT_fno_integrated_as,
165 "(Non-)integrated backend set incorrectly!");
167 bool IBackend = Args.hasFlag(options::OPT_fintegrated_objemitter,
168 options::OPT_fno_integrated_objemitter,
176 DiagID = clang::diag::err_drv_unsupported_opt_for_target;
178 DiagID = clang::diag::warn_drv_unsupported_opt_for_target;
179 Arg *A = Args.getLastArg(options::OPT_fno_integrated_objemitter);
181 D.
Diag(DiagID) << A->getAsString(Args) << Triple.getTriple();
182 A = Args.getLastArg(options::OPT_fintegrated_objemitter);
184 D.
Diag(DiagID) << A->getAsString(Args) << Triple.getTriple();
190 return ENABLE_X86_RELAX_RELOCATIONS;
194 return PPC_LINUX_DEFAULT_IEEELONGDOUBLE &&
getTriple().isOSLinux();
198 const llvm::Triple &Triple,
199 const llvm::opt::ArgList &Args,
201 std::vector<StringRef> Features;
205 UnifiedFeatures.end());
206 std::vector<std::string> MArch;
207 for (
const auto &Ext : AArch64::Extensions)
208 if (!Ext.UserVisibleName.empty())
209 if (FeatureSet.contains(Ext.PosTargetFeature))
210 MArch.push_back(Ext.UserVisibleName.str());
211 for (
const auto &Ext : AArch64::Extensions)
212 if (!Ext.UserVisibleName.empty())
213 if (FeatureSet.contains(Ext.NegTargetFeature))
214 MArch.push_back((
"no" + Ext.UserVisibleName).str());
216 for (
const auto &ArchInfo : AArch64::ArchInfos)
217 if (FeatureSet.contains(ArchInfo->ArchFeature))
218 ArchName = ArchInfo->Name;
219 assert(!ArchName.empty() &&
"at least one architecture should be found");
220 MArch.insert(MArch.begin(), (
"-march=" + ArchName).str());
221 Result.push_back(llvm::join(MArch,
"+"));
225 const llvm::Triple &Triple,
226 const llvm::opt::ArgList &Args,
228 std::vector<StringRef> Features;
230 D, Triple, Args, Features,
false ,
true );
233 UnifiedFeatures.end());
234 std::vector<std::string> MArch;
235 for (
const auto &Ext : ARM::ARCHExtNames)
236 if (!Ext.Name.empty())
237 if (FeatureSet.contains(Ext.Feature))
238 MArch.push_back(Ext.Name.str());
239 for (
const auto &Ext : ARM::ARCHExtNames)
240 if (!Ext.Name.empty())
241 if (FeatureSet.contains(Ext.NegFeature))
242 MArch.push_back((
"no" + Ext.Name).str());
243 MArch.insert(MArch.begin(), (
"-march=" + Triple.getArchName()).str());
244 Result.push_back(llvm::join(MArch,
"+"));
247#define ARM_FPU(NAME, KIND, VERSION, NEON_SUPPORT, RESTRICTION) \
248 case llvm::ARM::KIND: \
249 Result.push_back("-mfpu=" NAME); \
251#include "llvm/TargetParser/ARMTargetParser.def"
253 llvm_unreachable(
"Invalid FPUKind");
257 case arm::FloatABI::Soft:
258 Result.push_back(
"-mfloat-abi=soft");
260 case arm::FloatABI::SoftFP:
261 Result.push_back(
"-mfloat-abi=softfp");
263 case arm::FloatABI::Hard:
264 Result.push_back(
"-mfloat-abi=hard");
266 case arm::FloatABI::Invalid:
267 llvm_unreachable(
"Invalid float ABI");
275 std::vector<std::string>
Result;
277 Result.push_back(
"--target=" + Triple.str());
279 switch (Triple.getArch()) {
280 case llvm::Triple::aarch64:
281 case llvm::Triple::aarch64_32:
282 case llvm::Triple::aarch64_be:
285 case llvm::Triple::arm:
286 case llvm::Triple::armeb:
287 case llvm::Triple::thumb:
288 case llvm::Triple::thumbeb:
298 Result.push_back(
"-fno-rtti");
300 Result.push_back(
"-frtti");
303 Result.push_back(
"-fno-exceptions");
305 Result.push_back(
"-fexceptions");
315 SanitizerArgs SanArgs(*
this, JobArgs, !SanitizerArgsChecked);
316 SanitizerArgsChecked =
true;
322 XRayArguments.reset(
new XRayArgs(*
this, Args));
323 return *XRayArguments;
330 const char *ModeFlag;
339 static const DriverSuffix DriverSuffixes[] = {
341 {
"clang++",
"--driver-mode=g++"},
342 {
"clang-c++",
"--driver-mode=g++"},
343 {
"clang-cc",
nullptr},
344 {
"clang-cpp",
"--driver-mode=cpp"},
345 {
"clang-g++",
"--driver-mode=g++"},
346 {
"clang-gcc",
nullptr},
347 {
"clang-cl",
"--driver-mode=cl"},
349 {
"cpp",
"--driver-mode=cpp"},
350 {
"cl",
"--driver-mode=cl"},
351 {
"++",
"--driver-mode=g++"},
352 {
"flang",
"--driver-mode=flang"},
353 {
"clang-dxc",
"--driver-mode=dxc"},
356 for (
const auto &DS : DriverSuffixes) {
357 StringRef Suffix(DS.Suffix);
358 if (ProgName.ends_with(Suffix)) {
359 Pos = ProgName.size() - Suffix.size();
369 std::string ProgName = std::string(llvm::sys::path::filename(Argv0));
370 if (is_style_windows(llvm::sys::path::Style::native)) {
372 std::transform(ProgName.begin(), ProgName.end(), ProgName.begin(),
388 if (!DS && ProgName.ends_with(
".exe")) {
391 ProgName = ProgName.drop_back(StringRef(
".exe").size());
398 ProgName = ProgName.rtrim(
"0123456789.");
405 ProgName = ProgName.slice(0, ProgName.rfind(
'-'));
418 size_t SuffixEnd = SuffixPos + strlen(DS->Suffix);
420 size_t LastComponent = ProgName.rfind(
'-', SuffixPos);
421 if (LastComponent == std::string::npos)
423 std::string ModeSuffix = ProgName.substr(LastComponent + 1,
424 SuffixEnd - LastComponent - 1);
427 StringRef Prefix(ProgName);
428 Prefix = Prefix.slice(0, LastComponent);
429 std::string IgnoredError;
431 llvm::TargetRegistry::lookupTarget(std::string(Prefix), IgnoredError);
440 switch (Triple.getArch()) {
441 case llvm::Triple::aarch64: {
446 case llvm::Triple::aarch64_32:
448 case llvm::Triple::ppc:
450 case llvm::Triple::ppcle:
452 case llvm::Triple::ppc64:
454 case llvm::Triple::ppc64le:
457 return Triple.getArchName();
470Tool *ToolChain::getClang()
const {
476Tool *ToolChain::getFlang()
const {
487 llvm_unreachable(
"Linking is not supported by this toolchain");
491 llvm_unreachable(
"Creating static lib is not supported by this toolchain");
494Tool *ToolChain::getAssemble()
const {
497 return Assemble.get();
500Tool *ToolChain::getClangAs()
const {
503 return Assemble.get();
506Tool *ToolChain::getLink()
const {
512Tool *ToolChain::getStaticLibTool()
const {
515 return StaticLibTool.get();
518Tool *ToolChain::getIfsMerge()
const {
521 return IfsMerge.get();
524Tool *ToolChain::getOffloadBundler()
const {
530Tool *ToolChain::getOffloadPackager()
const {
536Tool *ToolChain::getLinkerWrapper()
const {
545 return getAssemble();
548 return getIfsMerge();
554 return getStaticLibTool();
563 llvm_unreachable(
"Invalid tool kind.");
577 return getOffloadBundler();
580 return getOffloadPackager();
582 return getLinkerWrapper();
585 llvm_unreachable(
"Invalid tool kind.");
589 const ArgList &Args) {
590 const llvm::Triple &Triple = TC.
getTriple();
591 bool IsWindows = Triple.isOSWindows();
594 return Triple.getArchName();
596 if (TC.
getArch() == llvm::Triple::arm || TC.
getArch() == llvm::Triple::armeb)
602 if (TC.
getArch() == llvm::Triple::x86 && Triple.isAndroid())
605 if (TC.
getArch() == llvm::Triple::x86_64 && Triple.isX32())
608 return llvm::Triple::getArchTypeName(TC.
getArch());
612 if (Triple.isOSDarwin())
615 switch (Triple.getOS()) {
616 case llvm::Triple::FreeBSD:
618 case llvm::Triple::NetBSD:
620 case llvm::Triple::OpenBSD:
622 case llvm::Triple::Solaris:
624 case llvm::Triple::AIX:
638 }
else if (Triple.isOSUnknown()) {
639 llvm::sys::path::append(
Path,
"lib");
643 return std::string(
Path);
650 return llvm::sys::path::filename(CRTAbsolutePath).str();
656 bool AddArch)
const {
658 bool IsITANMSVCWindows =
659 TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment();
666 Suffix = IsITANMSVCWindows ?
".obj" :
".o";
669 Suffix = IsITANMSVCWindows ?
".lib" :
".a";
672 Suffix = TT.isOSWindows()
673 ? (TT.isWindowsGNUEnvironment() ?
".dll.a" :
".lib")
678 std::string ArchAndEnv;
681 const char *
Env = TT.isAndroid() ?
"-android" :
"";
682 ArchAndEnv = (
"-" + Arch +
Env).str();
684 return (Prefix + Twine(
"clang_rt.") + Component + ArchAndEnv + Suffix).str();
690 std::string CRTBasename =
695 llvm::sys::path::append(
P, CRTBasename);
697 return std::string(
P);
708 llvm::sys::path::append(OldPath, CRTBasename);
710 return std::string(OldPath);
715 return std::string(
Path);
727std::optional<std::string>
728ToolChain::getFallbackAndroidTargetPath(StringRef BaseDir)
const {
729 llvm::Triple TripleWithoutLevel(
getTriple());
730 TripleWithoutLevel.setEnvironmentName(
"android");
731 const std::string &TripleWithoutLevelStr = TripleWithoutLevel.str();
732 unsigned TripleVersion =
getTriple().getEnvironmentVersion().getMajor();
733 unsigned BestVersion = 0;
736 bool UsingUnversionedDir =
false;
738 for (llvm::vfs::directory_iterator LI =
getVFS().dir_begin(BaseDir, EC), LE;
739 !EC && LI != LE; LI = LI.increment(EC)) {
740 StringRef DirName = llvm::sys::path::filename(LI->path());
741 StringRef DirNameSuffix = DirName;
742 if (DirNameSuffix.consume_front(TripleWithoutLevelStr)) {
743 if (DirNameSuffix.empty() && TripleDir.empty()) {
745 UsingUnversionedDir =
true;
748 if (!DirNameSuffix.getAsInteger(10, Version) && Version > BestVersion &&
749 Version < TripleVersion) {
750 BestVersion = Version;
752 UsingUnversionedDir =
false;
758 if (TripleDir.empty())
762 llvm::sys::path::append(
P, TripleDir);
763 if (UsingUnversionedDir)
765 return std::string(
P);
768std::optional<std::string>
770 auto getPathForTriple =
771 [&](
const llvm::Triple &Triple) -> std::optional<std::string> {
773 llvm::sys::path::append(
P, Triple.str());
775 return std::string(
P);
799 ArmTriple.setArch(Triple::arm);
800 if (
auto Path = getPathForTriple(ArmTriple))
805 return getFallbackAndroidTargetPath(BaseDir);
812 llvm::sys::path::append(
P,
"lib");
816 if (Triple.isOSDarwin())
818 llvm::sys::path::append(
P, Triple.str());
819 return std::string(
P);
824 llvm::sys::path::append(
P,
"..",
"lib");
830 llvm::sys::path::append(
P,
"..",
"include");
839 llvm::sys::path::append(
Path,
"lib");
841 llvm::sys::path::append(
Path, S);
842 Paths.push_back(std::string(
Path));
851 if (Args.hasArg(options::OPT_noprofilelib))
854 return Args.hasArg(options::OPT_fprofile_generate) ||
855 Args.hasArg(options::OPT_fprofile_generate_EQ) ||
856 Args.hasArg(options::OPT_fcs_profile_generate) ||
857 Args.hasArg(options::OPT_fcs_profile_generate_EQ) ||
858 Args.hasArg(options::OPT_fprofile_instr_generate) ||
859 Args.hasArg(options::OPT_fprofile_instr_generate_EQ) ||
860 Args.hasArg(options::OPT_fcreate_profile) ||
861 Args.hasArg(options::OPT_forder_file_instrumentation);
865 return Args.hasArg(options::OPT_coverage) ||
866 Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
872 if (
getDriver().ShouldUseClangCompiler(JA))
return getClang();
890 *LinkerIsLLD =
false;
894 const Arg* A = Args.getLastArg(options::OPT_fuse_ld_EQ);
895 StringRef UseLinker = A ? A->getValue() : CLANG_DEFAULT_LINKER;
902 if (
const Arg *A = Args.getLastArg(options::OPT_ld_path_EQ)) {
903 std::string
Path(A->getValue());
905 if (llvm::sys::path::parent_path(
Path).empty())
907 if (llvm::sys::fs::can_execute(
Path)) {
909 *LinkerIsLLD = UseLinker ==
"lld";
910 return std::string(
Path);
913 getDriver().
Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args);
918 if (UseLinker.empty() || UseLinker ==
"ld") {
920 if (llvm::sys::path::is_absolute(DefaultLinker))
921 return std::string(DefaultLinker);
930 if (UseLinker.contains(
'/'))
933 if (llvm::sys::path::is_absolute(UseLinker)) {
936 if (llvm::sys::fs::can_execute(UseLinker))
937 return std::string(UseLinker);
940 if (Triple.isOSDarwin())
941 LinkerName.append(
"ld64.");
943 LinkerName.append(
"ld.");
944 LinkerName.append(UseLinker);
947 if (llvm::sys::fs::can_execute(LinkerPath)) {
949 *LinkerIsLLD = UseLinker ==
"lld";
955 getDriver().
Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args);
962 if (Triple.isOSDarwin())
974 id = types::TY_Fortran;
984 llvm::Triple HostTriple(LLVM_HOST_TRIPLE);
985 switch (HostTriple.getArch()) {
988 case llvm::Triple::arm:
989 case llvm::Triple::armeb:
990 case llvm::Triple::thumb:
991 case llvm::Triple::thumbeb:
992 return getArch() != llvm::Triple::arm &&
getArch() != llvm::Triple::thumb &&
993 getArch() != llvm::Triple::armeb &&
getArch() != llvm::Triple::thumbeb;
995 return HostTriple.getArch() !=
getArch();
1004llvm::ExceptionHandling
1006 return llvm::ExceptionHandling::None;
1010 if (Model ==
"single") {
1012 return Triple.getArch() == llvm::Triple::arm ||
1013 Triple.getArch() == llvm::Triple::armeb ||
1014 Triple.getArch() == llvm::Triple::thumb ||
1015 Triple.getArch() == llvm::Triple::thumbeb || Triple.isWasm();
1016 }
else if (Model ==
"posix")
1028 case llvm::Triple::x86_64: {
1030 if (!Triple.isOSBinFormatMachO())
1033 if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
1036 StringRef MArch = A->getValue();
1037 if (MArch ==
"x86_64h")
1038 Triple.setArchName(MArch);
1040 return Triple.getTriple();
1042 case llvm::Triple::aarch64: {
1045 if (!Triple.isOSBinFormatMachO())
1046 return Triple.getTriple();
1048 if (Triple.isArm64e())
1049 return Triple.getTriple();
1054 Triple.setArchName(
"arm64");
1055 return Triple.getTriple();
1057 case llvm::Triple::aarch64_32:
1059 case llvm::Triple::arm:
1060 case llvm::Triple::armeb:
1061 case llvm::Triple::thumb:
1062 case llvm::Triple::thumbeb: {
1066 return Triple.getTriple();
1081 ArgStringList &CC1Args)
const {
1086 const ArgList &DriverArgs, ArgStringList &CC1Args,
1090 ArgStringList &CC1ASArgs)
const {}
1095 llvm::opt::ArgStringList &CmdArgs)
const {
1103 const ArgList &Args)
const {
1105 return *runtimeLibType;
1107 const Arg* A = Args.getLastArg(options::OPT_rtlib_EQ);
1108 StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_RTLIB;
1111 if (LibName ==
"compiler-rt")
1113 else if (LibName ==
"libgcc")
1115 else if (LibName ==
"platform")
1120 << A->getAsString(Args);
1125 return *runtimeLibType;
1129 const ArgList &Args)
const {
1131 return *unwindLibType;
1133 const Arg *A = Args.getLastArg(options::OPT_unwindlib_EQ);
1134 StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_UNWINDLIB;
1136 if (LibName ==
"none")
1138 else if (LibName ==
"platform" || LibName ==
"") {
1147 }
else if (LibName ==
"libunwind") {
1151 }
else if (LibName ==
"libgcc")
1156 << A->getAsString(Args);
1161 return *unwindLibType;
1166 return *cxxStdlibType;
1168 const Arg *A = Args.getLastArg(options::OPT_stdlib_EQ);
1169 StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_CXX_STDLIB;
1172 if (LibName ==
"libc++")
1174 else if (LibName ==
"libstdc++")
1176 else if (LibName ==
"platform")
1181 << A->getAsString(Args);
1186 return *cxxStdlibType;
1191 ArgStringList &CC1Args,
1192 const Twine &
Path) {
1193 CC1Args.push_back(
"-internal-isystem");
1194 CC1Args.push_back(DriverArgs.MakeArgString(
Path));
1206 ArgStringList &CC1Args,
1207 const Twine &
Path) {
1208 CC1Args.push_back(
"-internal-externc-isystem");
1209 CC1Args.push_back(DriverArgs.MakeArgString(
Path));
1213 ArgStringList &CC1Args,
1214 const Twine &
Path) {
1215 if (llvm::sys::fs::exists(
Path))
1221 ArgStringList &CC1Args,
1223 for (
const auto &
Path : Paths) {
1224 CC1Args.push_back(
"-internal-isystem");
1225 CC1Args.push_back(DriverArgs.MakeArgString(
Path));
1230 const Twine &B,
const Twine &
C,
1233 llvm::sys::path::append(
Result, llvm::sys::path::Style::posix, A, B,
C,
D);
1234 return std::string(
Result);
1240 std::string MaxVersionString;
1242 llvm::sys::path::append(
Path,
"c++");
1243 for (llvm::vfs::directory_iterator LI =
getVFS().dir_begin(
Path, EC), LE;
1244 !EC && LI != LE; LI = LI.increment(EC)) {
1245 StringRef VersionText = llvm::sys::path::filename(LI->path());
1247 if (VersionText[0] ==
'v' &&
1248 !VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) {
1249 if (Version > MaxVersion) {
1250 MaxVersion = Version;
1251 MaxVersionString = std::string(VersionText);
1257 return MaxVersionString;
1261 ArgStringList &CC1Args)
const {
1271 DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ);
1275 const llvm::opt::ArgList &DriverArgs,
1276 llvm::opt::ArgStringList &CC1Args)
const {
1277 DriverArgs.ClaimAllArgs(options::OPT_stdlibxx_isystem);
1286 if (!DriverArgs.hasArg(options::OPT_nostdincxx))
1287 for (
const auto &
P :
1288 DriverArgs.getAllArgValues(options::OPT_stdlibxx_isystem))
1294 !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
1295 options::OPT_nostdlibxx);
1299 ArgStringList &CmdArgs)
const {
1300 assert(!Args.hasArg(options::OPT_nostdlibxx) &&
1301 "should not have called this");
1306 CmdArgs.push_back(
"-lc++");
1307 if (Args.hasArg(options::OPT_fexperimental_library))
1308 CmdArgs.push_back(
"-lc++experimental");
1312 CmdArgs.push_back(
"-lstdc++");
1318 ArgStringList &CmdArgs)
const {
1320 if(LibPath.length() > 0)
1321 CmdArgs.push_back(Args.MakeArgString(StringRef(
"-L") + LibPath));
1325 ArgStringList &CmdArgs)
const {
1326 CmdArgs.push_back(
"-lcc_kext");
1330 std::string &
Path)
const {
1334 bool Default = !Args.hasArgNoClaim(options::OPT_shared);
1340 Arg *A = Args.getLastArg(
1341 options::OPT_ffast_math, options::OPT_fno_fast_math,
1342 options::OPT_funsafe_math_optimizations,
1343 options::OPT_fno_unsafe_math_optimizations, options::OPT_ffp_model_EQ);
1345 if (!A || A->getOption().getID() == options::OPT_fno_fast_math ||
1346 A->getOption().getID() == options::OPT_fno_unsafe_math_optimizations)
1348 if (A && A->getOption().getID() == options::OPT_ffp_model_EQ) {
1349 StringRef Model = A->getValue();
1350 if (Model !=
"fast")
1357 if (!Args.hasFlag(options::OPT_mdaz_ftz, options::OPT_mno_daz_ftz,
Default))
1362 return (
Path !=
"crtfastmath.o");
1366 ArgStringList &CmdArgs)
const {
1369 CmdArgs.push_back(Args.MakeArgString(
Path));
1387 (SanitizerKind::CFI & ~SanitizerKind::CFIICall) |
1388 SanitizerKind::CFICastStrict | SanitizerKind::FloatDivideByZero |
1389 SanitizerKind::KCFI | SanitizerKind::UnsignedIntegerOverflow |
1390 SanitizerKind::UnsignedShiftBase | SanitizerKind::ImplicitConversion |
1391 SanitizerKind::Nullability | SanitizerKind::LocalBounds;
1392 if (
getTriple().getArch() == llvm::Triple::x86 ||
1393 getTriple().getArch() == llvm::Triple::x86_64 ||
1394 getTriple().getArch() == llvm::Triple::arm ||
1398 Res |= SanitizerKind::CFIICall;
1399 if (
getTriple().getArch() == llvm::Triple::x86_64 ||
1401 Res |= SanitizerKind::ShadowCallStack;
1403 Res |= SanitizerKind::MemTag;
1408 ArgStringList &CC1Args)
const {}
1411 ArgStringList &CC1Args)
const {}
1419 ArgStringList &CC1Args)
const {}
1423 return VersionTuple(Version);
1425 if (Version < 10000)
1426 return VersionTuple(Version / 100, Version % 100);
1428 unsigned Build = 0, Factor = 1;
1429 for (; Version > 10000; Version = Version / 10, Factor = Factor * 10)
1430 Build = Build + (Version % 10) * Factor;
1431 return VersionTuple(Version / 100, Version % 100, Build);
1436 const llvm::opt::ArgList &Args)
const {
1437 const Arg *MSCVersion = Args.getLastArg(options::OPT_fmsc_version);
1438 const Arg *MSCompatibilityVersion =
1439 Args.getLastArg(options::OPT_fms_compatibility_version);
1441 if (MSCVersion && MSCompatibilityVersion) {
1443 D->Diag(diag::err_drv_argument_not_allowed_with)
1444 << MSCVersion->getAsString(Args)
1445 << MSCompatibilityVersion->getAsString(Args);
1446 return VersionTuple();
1449 if (MSCompatibilityVersion) {
1451 if (MSVT.tryParse(MSCompatibilityVersion->getValue())) {
1453 D->Diag(diag::err_drv_invalid_value)
1454 << MSCompatibilityVersion->getAsString(Args)
1455 << MSCompatibilityVersion->getValue();
1462 unsigned Version = 0;
1463 if (StringRef(MSCVersion->getValue()).getAsInteger(10, Version)) {
1465 D->Diag(diag::err_drv_invalid_value)
1466 << MSCVersion->getAsString(Args) << MSCVersion->getValue();
1472 return VersionTuple();
1476 const llvm::opt::DerivedArgList &Args,
bool SameTripleAsHost,
1478 DerivedArgList *DAL =
new DerivedArgList(Args.getBaseArgs());
1480 bool Modified =
false;
1483 for (
auto *A : Args) {
1488 if (A->getOption().matches(options::OPT_m_Group)) {
1491 if (SameTripleAsHost ||
1492 A->getOption().matches(options::OPT_mcode_object_version_EQ))
1501 bool XOpenMPTargetNoTriple =
1502 A->getOption().matches(options::OPT_Xopenmp_target);
1504 if (A->getOption().matches(options::OPT_Xopenmp_target_EQ)) {
1509 Index = Args.getBaseArgs().MakeIndex(A->getValue(1));
1512 }
else if (XOpenMPTargetNoTriple) {
1514 Index = Args.getBaseArgs().MakeIndex(A->getValue(0));
1522 std::unique_ptr<Arg> XOpenMPTargetArg(Opts.ParseOneArg(Args, Index));
1523 if (!XOpenMPTargetArg || Index > Prev + 1) {
1524 getDriver().
Diag(diag::err_drv_invalid_Xopenmp_target_with_args)
1525 << A->getAsString(Args);
1528 if (XOpenMPTargetNoTriple && XOpenMPTargetArg &&
1529 Args.getAllArgValues(options::OPT_fopenmp_targets_EQ).size() != 1) {
1530 getDriver().
Diag(diag::err_drv_Xopenmp_target_missing_triple);
1533 XOpenMPTargetArg->setBaseArg(A);
1534 A = XOpenMPTargetArg.release();
1535 AllocatedArgs.push_back(A);
1551 const llvm::opt::DerivedArgList &Args, llvm::opt::Arg *&A,
1552 llvm::opt::DerivedArgList *DAL,
1555 unsigned ValuePos = 1;
1556 if (A->getOption().matches(options::OPT_Xarch_device) ||
1557 A->getOption().matches(options::OPT_Xarch_host))
1560 unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(ValuePos));
1561 unsigned Prev = Index;
1562 std::unique_ptr<llvm::opt::Arg> XarchArg(Opts.ParseOneArg(Args, Index));
1571 if (!XarchArg || Index > Prev + 1) {
1572 getDriver().
Diag(diag::err_drv_invalid_Xarch_argument_with_args)
1573 << A->getAsString(Args);
1579 "invalid Xarch argument: '%0', not all driver "
1580 "options can be forwared via Xarch argument");
1581 Diags.Report(DiagID) << A->getAsString(Args);
1584 XarchArg->setBaseArg(A);
1585 A = XarchArg.release();
1587 DAL->AddSynthesizedArg(A);
1589 AllocatedArgs->push_back(A);
1593 const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
1596 DerivedArgList *DAL =
new DerivedArgList(Args.getBaseArgs());
1597 bool Modified =
false;
1600 for (Arg *A : Args) {
1601 bool NeedTrans =
false;
1603 if (A->getOption().matches(options::OPT_Xarch_device)) {
1604 NeedTrans = IsDevice;
1606 }
else if (A->getOption().matches(options::OPT_Xarch_host)) {
1607 NeedTrans = !IsDevice;
1609 }
else if (A->getOption().matches(options::OPT_Xarch__) && IsDevice) {
1613 if (BoundArch.empty() || A->getValue(0) != BoundArch)
1618 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...