14#include "clang/Config/config.h"
20#include "llvm/ADT/StringExtras.h"
21#include "llvm/Option/Arg.h"
22#include "llvm/Option/ArgList.h"
23#include "llvm/Support/ConvertUTF.h"
24#include "llvm/Support/ErrorHandling.h"
25#include "llvm/Support/FileSystem.h"
26#include "llvm/Support/MemoryBuffer.h"
27#include "llvm/Support/Path.h"
28#include "llvm/Support/Process.h"
29#include "llvm/Support/VirtualFileSystem.h"
30#include "llvm/TargetParser/Host.h"
34 #define WIN32_LEAN_AND_MEAN
49 auto Status = VFS.status(
Path);
52 return (Status->getPermissions() & llvm::sys::fs::perms::all_exe) != 0;
63 MSVC.getSubDirectoryPath(llvm::SubDirectoryType::Bin));
64 llvm::sys::path::append(FilePath, Exe);
65 return std::string(
canExecute(TC.
getVFS(), FilePath) ? FilePath.str() : Exe);
72 const char *LinkingOutput)
const {
73 ArgStringList CmdArgs;
80 Args.MakeArgString(std::string(
"-out:") + Output.
getFilename()));
82 if (Args.hasArg(options::OPT_marm64x))
83 CmdArgs.push_back(
"-machine:arm64x");
84 else if (TC.getTriple().isWindowsArm64EC())
85 CmdArgs.push_back(
"-machine:arm64ec");
87 if (
const Arg *A = Args.getLastArg(options::OPT_fveclib)) {
88 StringRef
V = A->getValue();
90 CmdArgs.push_back(Args.MakeArgString(
"--dependent-lib=amath"));
93 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) &&
94 !
C.getDriver().IsCLMode() && !
C.getDriver().IsFlangMode()) {
95 CmdArgs.push_back(
"-defaultlib:libcmt");
96 CmdArgs.push_back(
"-defaultlib:oldnames");
104 if (
const Arg *A = Args.getLastArg(options::OPT__SLASH_diasdkdir,
105 options::OPT__SLASH_winsysroot)) {
110 if (A->getOption().getID() == options::OPT__SLASH_winsysroot)
111 llvm::sys::path::append(DIAPath,
"DIA SDK");
114 llvm::sys::path::append(DIAPath,
"lib",
115 llvm::archToLegacyVCArch(TC.getArch()));
116 CmdArgs.push_back(Args.MakeArgString(Twine(
"-libpath:") + DIAPath));
118 if (!llvm::sys::Process::GetEnv(
"LIB") ||
119 Args.getLastArg(options::OPT__SLASH_vctoolsdir,
120 options::OPT__SLASH_winsysroot)) {
121 CmdArgs.push_back(Args.MakeArgString(
123 TC.getSubDirectoryPath(llvm::SubDirectoryType::Lib)));
124 CmdArgs.push_back(Args.MakeArgString(
126 TC.getSubDirectoryPath(llvm::SubDirectoryType::Lib,
"atlmfc")));
128 if (!llvm::sys::Process::GetEnv(
"LIB") ||
129 Args.getLastArg(options::OPT__SLASH_winsdkdir,
130 options::OPT__SLASH_winsysroot)) {
131 if (TC.useUniversalCRT()) {
132 std::string UniversalCRTLibPath;
133 if (TC.getUniversalCRTLibraryPath(Args, UniversalCRTLibPath))
135 Args.MakeArgString(Twine(
"-libpath:") + UniversalCRTLibPath));
137 std::string WindowsSdkLibPath;
138 if (TC.getWindowsSDKLibraryPath(Args, WindowsSdkLibPath))
140 Args.MakeArgString(std::string(
"-libpath:") + WindowsSdkLibPath));
143 if (!
C.getDriver().IsCLMode() && Args.hasArg(options::OPT_L))
144 for (
const auto &LibPath : Args.getAllArgValues(options::OPT_L))
145 CmdArgs.push_back(Args.MakeArgString(
"-libpath:" + LibPath));
147 if (
C.getDriver().IsFlangMode() &&
148 !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
155 CmdArgs.push_back(
"/subsystem:console");
160 for (
const auto &LibPath : TC.getLibraryPaths()) {
161 if (TC.getVFS().exists(LibPath))
162 CmdArgs.push_back(Args.MakeArgString(
"-libpath:" + LibPath));
164 auto CRTPath = TC.getCompilerRTPath();
165 if (TC.getVFS().exists(CRTPath))
166 CmdArgs.push_back(Args.MakeArgString(
"-libpath:" + CRTPath));
168 CmdArgs.push_back(
"-nologo");
170 if (Args.hasArg(options::OPT_g_Group, options::OPT__SLASH_Z7))
171 CmdArgs.push_back(
"-debug");
175 if (Args.hasArg(options::OPT_fms_hotpatch, options::OPT__SLASH_hotpatch))
176 CmdArgs.push_back(
"-functionpadmin");
180 bool DefaultIncrementalLinkerCompatible =
181 C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment();
182 if (!Args.hasFlag(options::OPT_mincremental_linker_compatible,
183 options::OPT_mno_incremental_linker_compatible,
184 DefaultIncrementalLinkerCompatible))
185 CmdArgs.push_back(
"-Brepro");
187 bool DLL = Args.hasArg(options::OPT__SLASH_LD, options::OPT__SLASH_LDd,
188 options::OPT_shared);
190 CmdArgs.push_back(Args.MakeArgString(
"-dll"));
193 llvm::sys::path::replace_extension(ImplibName,
"lib");
194 CmdArgs.push_back(Args.MakeArgString(std::string(
"-implib:") + ImplibName));
197 if (TC.getSanitizerArgs(Args).needsFuzzer()) {
198 if (!Args.hasArg(options::OPT_shared))
200 Args.MakeArgString(std::string(
"-wholearchive:") +
201 TC.getCompilerRTArgString(Args,
"fuzzer")));
202 CmdArgs.push_back(Args.MakeArgString(
"-debug"));
205 CmdArgs.push_back(Args.MakeArgString(
"-incremental:no"));
208 if (TC.getSanitizerArgs(Args).needsAsanRt()) {
209 CmdArgs.push_back(Args.MakeArgString(
"-debug"));
210 CmdArgs.push_back(Args.MakeArgString(
"-incremental:no"));
211 CmdArgs.push_back(TC.getCompilerRTArgString(Args,
"asan_dynamic"));
212 auto defines = Args.getAllArgValues(options::OPT_D);
213 if (Args.hasArg(options::OPT__SLASH_MD, options::OPT__SLASH_MDd) ||
214 find(begin(defines), end(defines),
"_DLL") != end(defines)) {
217 CmdArgs.push_back(Args.MakeArgString(
218 TC.getArch() == llvm::Triple::x86
219 ?
"-include:___asan_seh_interceptor"
220 :
"-include:__asan_seh_interceptor"));
223 CmdArgs.push_back(Args.MakeArgString(
224 std::string(
"-wholearchive:") +
225 TC.getCompilerRT(Args,
"asan_dynamic_runtime_thunk")));
229 CmdArgs.push_back(Args.MakeArgString(
230 std::string(
"-wholearchive:") +
231 TC.getCompilerRT(Args,
"asan_static_runtime_thunk")));
235 Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
238 for (
const Arg *A : Args.filtered(options::OPT__SLASH_guard)) {
239 StringRef GuardArgs = A->getValue();
240 if (GuardArgs.equals_insensitive(
"cf") ||
241 GuardArgs.equals_insensitive(
"cf,nochecks")) {
243 CmdArgs.push_back(
"-guard:cf");
244 }
else if (GuardArgs.equals_insensitive(
"cf-")) {
245 CmdArgs.push_back(
"-guard:cf-");
246 }
else if (GuardArgs.equals_insensitive(
"ehcont")) {
247 CmdArgs.push_back(
"-guard:ehcont");
248 }
else if (GuardArgs.equals_insensitive(
"ehcont-")) {
249 CmdArgs.push_back(
"-guard:ehcont-");
253 if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
254 options::OPT_fno_openmp,
false)) {
255 CmdArgs.push_back(
"-nodefaultlib:vcomp.lib");
256 CmdArgs.push_back(
"-nodefaultlib:vcompd.lib");
257 CmdArgs.push_back(Args.MakeArgString(std::string(
"-libpath:") +
258 TC.getDriver().Dir +
"/../lib"));
259 switch (TC.getDriver().getOpenMPRuntime(Args)) {
261 CmdArgs.push_back(
"-defaultlib:libomp.lib");
264 CmdArgs.push_back(
"-defaultlib:libiomp5md.lib");
276 if (!Args.hasArg(options::OPT_nostdlib)) {
281 Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER);
285 else if (
Linker.equals_insensitive(
"lld"))
288 if (
Linker ==
"lld-link") {
289 for (Arg *A : Args.filtered(options::OPT_vfsoverlay))
291 Args.MakeArgString(std::string(
"/vfsoverlay:") + A->getValue()));
293 if (
C.getDriver().isUsingLTO() &&
294 Args.hasFlag(options::OPT_gsplit_dwarf, options::OPT_gno_split_dwarf,
296 CmdArgs.push_back(Args.MakeArgString(Twine(
"/dwodir:") +
301 for (
const auto &Input : Inputs) {
302 if (Input.isFilename()) {
303 CmdArgs.push_back(Input.getFilename());
307 const Arg &A = Input.getInputArg();
310 if (A.getOption().matches(options::OPT_l)) {
311 StringRef Lib = A.getValue();
312 const char *LinkLibArg;
313 if (Lib.ends_with(
".lib"))
314 LinkLibArg = Args.MakeArgString(Lib);
316 LinkLibArg = Args.MakeArgString(Lib +
".lib");
317 CmdArgs.push_back(LinkLibArg);
323 A.renderAsInput(Args, CmdArgs);
328 TC.addProfileRTLibs(Args, CmdArgs);
330 std::vector<const char *> Environment;
335 if (
Linker.equals_insensitive(
"link")) {
341 if (!TC.FoundMSVCInstall() && !
canExecute(TC.getVFS(), linkPath)) {
343 ClPath = TC.GetProgramPath(
"cl.exe");
345 linkPath = llvm::sys::path::parent_path(ClPath);
346 llvm::sys::path::append(linkPath,
"link.exe");
348 C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
350 C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
356 if (TC.getSanitizerArgs(Args).needsAsanRt())
357 CmdArgs.push_back(
"/INFERASANLIBS:NO");
366 if (TC.getIsVS2017OrNewer() &&
367 llvm::Triple(llvm::sys::getProcessTriple()).getArch() != TC.getArch()) {
368 auto HostArch = llvm::Triple(llvm::sys::getProcessTriple()).getArch();
371 std::unique_ptr<wchar_t[], decltype(&FreeEnvironmentStringsW)>(
372 GetEnvironmentStringsW(), FreeEnvironmentStringsW);
374 goto SkipSettingEnvironment;
377 size_t EnvBlockLen = 0;
378 while (EnvBlockWide[EnvBlockLen] != L
'\0') {
380 EnvBlockLen += std::wcslen(&EnvBlockWide[EnvBlockLen]) +
385 std::string EnvBlock;
386 if (!llvm::convertUTF16ToUTF8String(
388 EnvBlockLen *
sizeof(EnvBlockWide[0])),
390 goto SkipSettingEnvironment;
392 Environment.reserve(EnvCount);
397 for (
const char *Cursor = EnvBlock.data(); *Cursor !=
'\0';) {
398 llvm::StringRef EnvVar(Cursor);
399 if (EnvVar.starts_with_insensitive(
"path=")) {
400 constexpr size_t PrefixLen = 5;
401 Environment.push_back(Args.MakeArgString(
402 EnvVar.substr(0, PrefixLen) +
403 TC.getSubDirectoryPath(llvm::SubDirectoryType::Bin) +
404 llvm::Twine(llvm::sys::EnvPathSeparator) +
405 TC.getSubDirectoryPath(llvm::SubDirectoryType::Bin, HostArch) +
406 (EnvVar.size() > PrefixLen
407 ? llvm::Twine(llvm::sys::EnvPathSeparator) +
408 EnvVar.substr(PrefixLen)
411 Environment.push_back(Args.MakeArgString(EnvVar));
413 Cursor += EnvVar.size() + 1 ;
416 SkipSettingEnvironment:;
419 linkPath = TC.GetProgramPath(
Linker.str().c_str());
422 auto LinkCmd = std::make_unique<Command>(
424 Args.MakeArgString(linkPath), CmdArgs, Inputs, Output);
425 if (!Environment.empty())
426 LinkCmd->setEnvironment(Environment);
427 C.addCommand(std::move(LinkCmd));
432 :
ToolChain(
D, Triple, Args), CudaInstallation(
D, Triple, Args),
433 RocmInstallation(
D, Triple, Args) {
436 std::optional<llvm::StringRef> VCToolsDir, VCToolsVersion;
437 if (Arg *A = Args.getLastArg(options::OPT__SLASH_vctoolsdir))
438 VCToolsDir = A->getValue();
439 if (Arg *A = Args.getLastArg(options::OPT__SLASH_vctoolsversion))
440 VCToolsVersion = A->getValue();
441 if (Arg *A = Args.getLastArg(options::OPT__SLASH_winsdkdir))
442 WinSdkDir = A->getValue();
443 if (Arg *A = Args.getLastArg(options::OPT__SLASH_winsdkversion))
444 WinSdkVersion = A->getValue();
445 if (Arg *A = Args.getLastArg(options::OPT__SLASH_winsysroot))
446 WinSysRoot = A->getValue();
452 llvm::findVCToolChainViaCommandLine(
getVFS(), VCToolsDir, VCToolsVersion,
453 WinSysRoot, VCToolChainPath, VSLayout) ||
454 llvm::findVCToolChainViaEnvironment(
getVFS(), VCToolChainPath,
456 llvm::findVCToolChainViaSetupConfig(
getVFS(), VCToolsVersion,
457 VCToolChainPath, VSLayout) ||
458 llvm::findVCToolChainViaRegistry(VCToolChainPath, VSLayout);
481 if (
getArch() == llvm::Triple::x86_64 ||
getArch() == llvm::Triple::arm ||
482 getArch() == llvm::Triple::thumb ||
getArch() == llvm::Triple::aarch64)
489 return getArch() == llvm::Triple::x86_64 ||
490 getArch() == llvm::Triple::aarch64;
498 return getArch() == llvm::Triple::x86_64 ||
499 getArch() == llvm::Triple::aarch64;
503 ArgStringList &CC1Args)
const {
504 CudaInstallation->AddCudaIncludeArgs(DriverArgs, CC1Args);
508 ArgStringList &CC1Args)
const {
509 RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args);
513 ArgStringList &CmdArgs)
const {
514 CmdArgs.append({Args.MakeArgString(StringRef(
"-libpath:") +
515 RocmInstallation->getLibPath()),
520 CudaInstallation->print(OS);
521 RocmInstallation->print(OS);
526 llvm::StringRef SubdirParent)
const {
527 return llvm::getSubDirectoryPath(
Type, VSLayout, VCToolChainPath,
getArch(),
533 llvm::Triple::ArchType TargetArch)
const {
534 return llvm::getSubDirectoryPath(
Type, VSLayout, VCToolChainPath, TargetArch,
544 std::string &path)
const {
547 std::string windowsSDKIncludeVersion;
548 std::string windowsSDKLibVersion;
551 if (!llvm::getWindowsSDKDir(
getVFS(), WinSdkDir, WinSdkVersion, WinSysRoot,
552 sdkPath, sdkMajor, windowsSDKIncludeVersion,
553 windowsSDKLibVersion))
557 llvm::sys::path::append(libPath,
"Lib");
559 if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
560 WinSdkVersion.has_value())
561 windowsSDKLibVersion = *WinSdkVersion;
563 llvm::sys::path::append(libPath, windowsSDKLibVersion,
"um");
564 return llvm::appendArchToWindowsSDKLibPath(sdkMajor, libPath,
getArch(),
569 return llvm::useUniversalCRT(VSLayout, VCToolChainPath,
getArch(),
getVFS());
573 std::string &
Path)
const {
574 std::string UniversalCRTSdkPath;
575 std::string UCRTVersion;
578 if (!llvm::getUniversalCRTSdkDir(
getVFS(), WinSdkDir, WinSdkVersion,
579 WinSysRoot, UniversalCRTSdkPath,
583 if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
584 WinSdkVersion.has_value())
585 UCRTVersion = *WinSdkVersion;
587 StringRef ArchName = llvm::archToWindowsSDKArch(
getArch());
588 if (ArchName.empty())
592 llvm::sys::path::append(LibPath,
"Lib", UCRTVersion,
"ucrt", ArchName);
594 Path = std::string(LibPath);
599 VersionTuple Version;
602 llvm::sys::path::append(ClExe,
"cl.exe");
604 std::wstring ClExeWide;
605 if (!llvm::ConvertUTF8toWide(ClExe.c_str(), ClExeWide))
608 const DWORD VersionSize = ::GetFileVersionInfoSizeW(ClExeWide.c_str(),
610 if (VersionSize == 0)
614 if (!::GetFileVersionInfoW(ClExeWide.c_str(), 0, VersionSize,
615 VersionBlock.data()))
618 VS_FIXEDFILEINFO *FileInfo =
nullptr;
619 UINT FileInfoSize = 0;
620 if (!::VerQueryValueW(VersionBlock.data(), L
"\\",
621 reinterpret_cast<LPVOID *
>(&FileInfo), &FileInfoSize) ||
622 FileInfoSize <
sizeof(*FileInfo))
625 const unsigned Major = (FileInfo->dwFileVersionMS >> 16) & 0xFFFF;
626 const unsigned Minor = (FileInfo->dwFileVersionMS ) & 0xFFFF;
627 const unsigned Micro = (FileInfo->dwFileVersionLS >> 16) & 0xFFFF;
629 Version = VersionTuple(Major, Minor, Micro);
635 const ArgList &DriverArgs, ArgStringList &CC1Args,
636 const std::string &folder,
const Twine &subfolder1,
const Twine &subfolder2,
637 const Twine &subfolder3)
const {
639 llvm::sys::path::append(path, subfolder1, subfolder2, subfolder3);
644 ArgStringList &CC1Args)
const {
645 if (DriverArgs.hasArg(options::OPT_nostdinc))
648 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
654 for (
const auto &
Path : DriverArgs.getAllArgValues(options::OPT__SLASH_imsvc))
657 auto AddSystemIncludesFromEnv = [&](StringRef Var) ->
bool {
658 if (
auto Val = llvm::sys::Process::GetEnv(Var)) {
660 StringRef(*Val).split(Dirs,
";", -1,
false);
670 for (
const auto &Var :
671 DriverArgs.getAllArgValues(options::OPT__SLASH_external_env)) {
672 AddSystemIncludesFromEnv(Var);
676 if (
const Arg *A = DriverArgs.getLastArg(options::OPT__SLASH_diasdkdir,
677 options::OPT__SLASH_winsysroot)) {
682 if (A->getOption().getID() == options::OPT__SLASH_winsysroot)
683 llvm::sys::path::append(DIASDKPath,
"DIA SDK");
688 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
693 if (!DriverArgs.getLastArg(options::OPT__SLASH_vctoolsdir,
694 options::OPT__SLASH_winsysroot)) {
695 bool Found = AddSystemIncludesFromEnv(
"INCLUDE");
696 Found |= AddSystemIncludesFromEnv(
"EXTERNAL_INCLUDE");
703 if (!VCToolChainPath.empty()) {
711 std::string UniversalCRTSdkPath;
712 std::string UCRTVersion;
713 if (llvm::getUniversalCRTSdkDir(
getVFS(), WinSdkDir, WinSdkVersion,
714 WinSysRoot, UniversalCRTSdkPath,
716 if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
717 WinSdkVersion.has_value())
718 UCRTVersion = *WinSdkVersion;
720 "Include", UCRTVersion,
"ucrt");
724 std::string WindowsSDKDir;
726 std::string windowsSDKIncludeVersion;
727 std::string windowsSDKLibVersion;
728 if (llvm::getWindowsSDKDir(
getVFS(), WinSdkDir, WinSdkVersion, WinSysRoot,
729 WindowsSDKDir, major, windowsSDKIncludeVersion,
730 windowsSDKLibVersion)) {
732 if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
733 WinSdkVersion.has_value())
734 windowsSDKIncludeVersion = windowsSDKLibVersion = *WinSdkVersion;
739 "Include", windowsSDKIncludeVersion,
742 "Include", windowsSDKIncludeVersion,
745 "Include", windowsSDKIncludeVersion,
748 llvm::VersionTuple Tuple;
749 if (!Tuple.tryParse(windowsSDKIncludeVersion) &&
750 Tuple.getSubminor().value_or(0) >= 17134) {
752 "Include", windowsSDKIncludeVersion,
768 const StringRef Paths[] = {
769 "C:/Program Files/Microsoft Visual Studio 10.0/VC/include",
770 "C:/Program Files/Microsoft Visual Studio 9.0/VC/include",
771 "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include",
772 "C:/Program Files/Microsoft Visual Studio 8/VC/include",
773 "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include"
780 ArgStringList &CC1Args)
const {
785 const ArgList &Args)
const {
786 bool IsWindowsMSVC =
getTriple().isWindowsMSVCEnvironment();
789 MSVT =
getTriple().getEnvironmentVersion();
790 if (MSVT.empty() && IsWindowsMSVC)
794 Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
800 MSVT = VersionTuple(19, 33);
811 MSVT = VersionTuple(MSVT.getMajor(), MSVT.getMinor().value_or(0),
812 MSVT.getSubminor().value_or(0));
817 if (Triple.getEnvironment() == llvm::Triple::MSVC) {
818 StringRef ObjFmt = Triple.getEnvironmentName().split(
'-').second;
820 Triple.setEnvironmentName((Twine(
"msvc") + MSVT.getAsString()).str());
822 Triple.setEnvironmentName(
823 (Twine(
"msvc") + MSVT.getAsString() + Twine(
'-') + ObjFmt).str());
825 return Triple.getTriple();
830 Res |= SanitizerKind::Address;
831 Res |= SanitizerKind::PointerCompare;
832 Res |= SanitizerKind::PointerSubtract;
833 Res |= SanitizerKind::Fuzzer;
834 Res |= SanitizerKind::FuzzerNoLink;
840 bool SupportsForcingFramePointer,
841 const char *ExpandChar,
const OptTable &Opts) {
842 assert(A->getOption().matches(options::OPT__SLASH_O));
844 StringRef OptStr = A->getValue();
845 for (
size_t I = 0,
E = OptStr.size(); I !=
E; ++I) {
846 const char &OptChar = *(OptStr.data() + I);
856 if (&OptChar != ExpandChar) {
860 if (OptChar ==
'd') {
861 DAL.AddFlagArg(A, Opts.getOption(options::OPT_O0));
863 if (OptChar ==
'1') {
864 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O),
"s");
865 }
else if (OptChar ==
'2' || OptChar ==
'x') {
866 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fbuiltin));
867 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O),
"3");
869 if (SupportsForcingFramePointer &&
870 !DAL.hasArgNoClaim(options::OPT_fno_omit_frame_pointer))
871 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fomit_frame_pointer));
872 if (OptChar ==
'1' || OptChar ==
'2')
873 DAL.AddFlagArg(A, Opts.getOption(options::OPT_ffunction_sections));
877 if (I + 1 !=
E && isdigit(OptStr[I + 1])) {
878 switch (OptStr[I + 1]) {
880 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_inline));
883 DAL.AddFlagArg(A, Opts.getOption(options::OPT_finline_hint_functions));
887 DAL.AddFlagArg(A, Opts.getOption(options::OPT_finline_functions));
897 if (I + 1 !=
E && OptStr[I + 1] ==
'-') {
899 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_builtin));
901 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fbuiltin));
905 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O),
"s");
908 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O),
"3");
911 bool OmitFramePointer =
true;
912 if (I + 1 !=
E && OptStr[I + 1] ==
'-') {
913 OmitFramePointer =
false;
916 if (SupportsForcingFramePointer) {
917 if (OmitFramePointer)
919 Opts.getOption(options::OPT_fomit_frame_pointer));
922 A, Opts.getOption(options::OPT_fno_omit_frame_pointer));
937 const OptTable &Opts) {
938 assert(A->getOption().matches(options::OPT_D));
940 StringRef Val = A->getValue();
941 size_t Hash = Val.find(
'#');
942 if (Hash == StringRef::npos || Hash > Val.find(
'=')) {
947 std::string NewVal = std::string(Val);
949 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_D), NewVal);
953 const OptTable &Opts) {
954 DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_twoPhase_));
955 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_operator_names));
959 const OptTable &Opts) {
960 DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_twoPhase));
961 DAL.AddFlagArg(A, Opts.getOption(options::OPT_foperator_names));
964llvm::opt::DerivedArgList *
968 DerivedArgList *DAL =
new DerivedArgList(Args.getBaseArgs());
972 bool SupportsForcingFramePointer =
getArch() != llvm::Triple::x86_64;
983 const char *ExpandChar =
nullptr;
984 for (Arg *A : Args.filtered(options::OPT__SLASH_O)) {
985 StringRef OptStr = A->getValue();
986 for (
size_t I = 0,
E = OptStr.size(); I !=
E; ++I) {
987 char OptChar = OptStr[I];
988 char PrevChar = I > 0 ? OptStr[I - 1] :
'0';
989 if (PrevChar ==
'b') {
993 if (OptChar ==
'1' || OptChar ==
'2' || OptChar ==
'x' || OptChar ==
'd')
994 ExpandChar = OptStr.data() + I;
998 for (Arg *A : Args) {
999 if (A->getOption().matches(options::OPT__SLASH_O)) {
1002 TranslateOptArg(A, *DAL, SupportsForcingFramePointer, ExpandChar, Opts);
1003 }
else if (A->getOption().matches(options::OPT_D)) {
1006 }
else if (A->getOption().matches(options::OPT__SLASH_permissive)) {
1009 }
else if (A->getOption().matches(options::OPT__SLASH_permissive_)) {
1022 const ArgList &DriverArgs, ArgStringList &CC1Args,
1026 if (DriverArgs.hasFlag(options::OPT_fno_rtti, options::OPT_frtti,
1028 CC1Args.push_back(
"-D_HAS_STATIC_RTTI=0");
1030 if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_marm64x))
1031 A->ignoreTargetSpecific();
static void TranslatePermissiveMinus(Arg *A, llvm::opt::DerivedArgList &DAL, const OptTable &Opts)
static VersionTuple getMSVCVersionFromExe(const std::string &BinDir)
static bool canExecute(llvm::vfs::FileSystem &VFS, StringRef Path)
static std::string FindVisualStudioExecutable(const ToolChain &TC, const char *Exe)
static void TranslateDArg(Arg *A, llvm::opt::DerivedArgList &DAL, const OptTable &Opts)
static void TranslateOptArg(Arg *A, llvm::opt::DerivedArgList &DAL, bool SupportsForcingFramePointer, const char *ExpandChar, const OptTable &Opts)
static void TranslatePermissive(Arg *A, llvm::opt::DerivedArgList &DAL, const OptTable &Opts)
Defines version macros and version-related utility functions for Clang.
The base class of the type hierarchy.
Compilation - A set of tasks to perform for a single driver invocation.
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
DiagnosticBuilder Diag(unsigned DiagID) const
const llvm::opt::OptTable & getOpts() const
@ OMPRT_IOMP5
The legacy name for the LLVM OpenMP runtime from when it was the Intel OpenMP runtime.
@ OMPRT_OMP
The LLVM OpenMP runtime.
@ OMPRT_Unknown
An unknown OpenMP runtime.
@ OMPRT_GOMP
The GNU OpenMP runtime.
The JSON file list parser is used to communicate input to InstallAPI.
static constexpr ResponseFileSupport AtFileUTF16()