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 (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) &&
88 !
C.getDriver().IsCLMode() && !
C.getDriver().IsFlangMode()) {
89 CmdArgs.push_back(
"-defaultlib:libcmt");
90 CmdArgs.push_back(
"-defaultlib:oldnames");
98 if (
const Arg *A = Args.getLastArg(options::OPT__SLASH_diasdkdir,
99 options::OPT__SLASH_winsysroot)) {
104 if (A->getOption().getID() == options::OPT__SLASH_winsysroot)
105 llvm::sys::path::append(DIAPath,
"DIA SDK");
108 llvm::sys::path::append(DIAPath,
"lib",
109 llvm::archToLegacyVCArch(TC.getArch()));
110 CmdArgs.push_back(Args.MakeArgString(Twine(
"-libpath:") + DIAPath));
112 if (!llvm::sys::Process::GetEnv(
"LIB") ||
113 Args.getLastArg(options::OPT__SLASH_vctoolsdir,
114 options::OPT__SLASH_winsysroot)) {
115 CmdArgs.push_back(Args.MakeArgString(
117 TC.getSubDirectoryPath(llvm::SubDirectoryType::Lib)));
118 CmdArgs.push_back(Args.MakeArgString(
120 TC.getSubDirectoryPath(llvm::SubDirectoryType::Lib,
"atlmfc")));
122 if (!llvm::sys::Process::GetEnv(
"LIB") ||
123 Args.getLastArg(options::OPT__SLASH_winsdkdir,
124 options::OPT__SLASH_winsysroot)) {
125 if (TC.useUniversalCRT()) {
126 std::string UniversalCRTLibPath;
127 if (TC.getUniversalCRTLibraryPath(Args, UniversalCRTLibPath))
129 Args.MakeArgString(Twine(
"-libpath:") + UniversalCRTLibPath));
131 std::string WindowsSdkLibPath;
132 if (TC.getWindowsSDKLibraryPath(Args, WindowsSdkLibPath))
134 Args.MakeArgString(std::string(
"-libpath:") + WindowsSdkLibPath));
137 if (!
C.getDriver().IsCLMode() && Args.hasArg(options::OPT_L))
138 for (
const auto &LibPath : Args.getAllArgValues(options::OPT_L))
139 CmdArgs.push_back(Args.MakeArgString(
"-libpath:" + LibPath));
141 if (
C.getDriver().IsFlangMode()) {
148 CmdArgs.push_back(
"/subsystem:console");
153 for (
const auto &LibPath : TC.getLibraryPaths()) {
154 if (TC.getVFS().exists(LibPath))
155 CmdArgs.push_back(Args.MakeArgString(
"-libpath:" + LibPath));
157 auto CRTPath = TC.getCompilerRTPath();
158 if (TC.getVFS().exists(CRTPath))
159 CmdArgs.push_back(Args.MakeArgString(
"-libpath:" + CRTPath));
161 CmdArgs.push_back(
"-nologo");
163 if (Args.hasArg(options::OPT_g_Group, options::OPT__SLASH_Z7))
164 CmdArgs.push_back(
"-debug");
168 if (Args.hasArg(options::OPT_fms_hotpatch, options::OPT__SLASH_hotpatch))
169 CmdArgs.push_back(
"-functionpadmin");
173 bool DefaultIncrementalLinkerCompatible =
174 C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment();
175 if (!Args.hasFlag(options::OPT_mincremental_linker_compatible,
176 options::OPT_mno_incremental_linker_compatible,
177 DefaultIncrementalLinkerCompatible))
178 CmdArgs.push_back(
"-Brepro");
180 bool DLL = Args.hasArg(options::OPT__SLASH_LD, options::OPT__SLASH_LDd,
181 options::OPT_shared);
183 CmdArgs.push_back(Args.MakeArgString(
"-dll"));
186 llvm::sys::path::replace_extension(ImplibName,
"lib");
187 CmdArgs.push_back(Args.MakeArgString(std::string(
"-implib:") + ImplibName));
190 if (TC.getSanitizerArgs(Args).needsFuzzer()) {
191 if (!Args.hasArg(options::OPT_shared))
193 Args.MakeArgString(std::string(
"-wholearchive:") +
194 TC.getCompilerRTArgString(Args,
"fuzzer")));
195 CmdArgs.push_back(Args.MakeArgString(
"-debug"));
198 CmdArgs.push_back(Args.MakeArgString(
"-incremental:no"));
201 if (TC.getSanitizerArgs(Args).needsAsanRt()) {
202 CmdArgs.push_back(Args.MakeArgString(
"-debug"));
203 CmdArgs.push_back(Args.MakeArgString(
"-incremental:no"));
204 if (TC.getSanitizerArgs(Args).needsSharedRt() ||
205 Args.hasArg(options::OPT__SLASH_MD, options::OPT__SLASH_MDd)) {
206 for (
const auto &Lib : {
"asan_dynamic",
"asan_dynamic_runtime_thunk"})
207 CmdArgs.push_back(TC.getCompilerRTArgString(Args, Lib));
210 CmdArgs.push_back(Args.MakeArgString(
211 TC.getArch() == llvm::Triple::x86
212 ?
"-include:___asan_seh_interceptor"
213 :
"-include:__asan_seh_interceptor"));
216 CmdArgs.push_back(Args.MakeArgString(std::string(
"-wholearchive:") +
217 TC.getCompilerRT(Args,
"asan_dynamic_runtime_thunk")));
219 CmdArgs.push_back(TC.getCompilerRTArgString(Args,
"asan_dll_thunk"));
221 for (
const auto &Lib : {
"asan",
"asan_cxx"}) {
222 CmdArgs.push_back(TC.getCompilerRTArgString(Args, Lib));
226 CmdArgs.push_back(Args.MakeArgString(std::string(
"-wholearchive:") +
227 TC.getCompilerRT(Args, Lib)));
232 Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
235 for (
const Arg *A : Args.filtered(options::OPT__SLASH_guard)) {
236 StringRef GuardArgs = A->getValue();
237 if (GuardArgs.equals_insensitive(
"cf") ||
238 GuardArgs.equals_insensitive(
"cf,nochecks")) {
240 CmdArgs.push_back(
"-guard:cf");
241 }
else if (GuardArgs.equals_insensitive(
"cf-")) {
242 CmdArgs.push_back(
"-guard:cf-");
243 }
else if (GuardArgs.equals_insensitive(
"ehcont")) {
244 CmdArgs.push_back(
"-guard:ehcont");
245 }
else if (GuardArgs.equals_insensitive(
"ehcont-")) {
246 CmdArgs.push_back(
"-guard:ehcont-");
250 if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
251 options::OPT_fno_openmp,
false)) {
252 CmdArgs.push_back(
"-nodefaultlib:vcomp.lib");
253 CmdArgs.push_back(
"-nodefaultlib:vcompd.lib");
254 CmdArgs.push_back(Args.MakeArgString(std::string(
"-libpath:") +
255 TC.getDriver().Dir +
"/../lib"));
256 switch (TC.getDriver().getOpenMPRuntime(Args)) {
258 CmdArgs.push_back(
"-defaultlib:libomp.lib");
261 CmdArgs.push_back(
"-defaultlib:libiomp5md.lib");
273 if (!Args.hasArg(options::OPT_nostdlib)) {
278 Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER);
282 else if (
Linker.equals_insensitive(
"lld"))
285 if (
Linker ==
"lld-link") {
286 for (Arg *A : Args.filtered(options::OPT_vfsoverlay))
288 Args.MakeArgString(std::string(
"/vfsoverlay:") + A->getValue()));
290 if (
C.getDriver().isUsingLTO() &&
291 Args.hasFlag(options::OPT_gsplit_dwarf, options::OPT_gno_split_dwarf,
293 CmdArgs.push_back(Args.MakeArgString(Twine(
"/dwodir:") +
298 for (
const auto &Input : Inputs) {
299 if (Input.isFilename()) {
300 CmdArgs.push_back(Input.getFilename());
304 const Arg &A = Input.getInputArg();
307 if (A.getOption().matches(options::OPT_l)) {
308 StringRef Lib = A.getValue();
309 const char *LinkLibArg;
310 if (Lib.ends_with(
".lib"))
311 LinkLibArg = Args.MakeArgString(Lib);
313 LinkLibArg = Args.MakeArgString(Lib +
".lib");
314 CmdArgs.push_back(LinkLibArg);
320 A.renderAsInput(Args, CmdArgs);
325 TC.addProfileRTLibs(Args, CmdArgs);
327 std::vector<const char *> Environment;
332 if (
Linker.equals_insensitive(
"link")) {
338 if (!TC.FoundMSVCInstall() && !
canExecute(TC.getVFS(), linkPath)) {
340 ClPath = TC.GetProgramPath(
"cl.exe");
342 linkPath = llvm::sys::path::parent_path(ClPath);
343 llvm::sys::path::append(linkPath,
"link.exe");
345 C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
347 C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
353 if (TC.getSanitizerArgs(Args).needsAsanRt())
354 CmdArgs.push_back(
"/INFERASANLIBS:NO");
363 if (TC.getIsVS2017OrNewer() &&
364 llvm::Triple(llvm::sys::getProcessTriple()).getArch() != TC.getArch()) {
365 auto HostArch = llvm::Triple(llvm::sys::getProcessTriple()).getArch();
368 std::unique_ptr<wchar_t[], decltype(&FreeEnvironmentStringsW)>(
369 GetEnvironmentStringsW(), FreeEnvironmentStringsW);
371 goto SkipSettingEnvironment;
374 size_t EnvBlockLen = 0;
375 while (EnvBlockWide[EnvBlockLen] != L
'\0') {
377 EnvBlockLen += std::wcslen(&EnvBlockWide[EnvBlockLen]) +
382 std::string EnvBlock;
383 if (!llvm::convertUTF16ToUTF8String(
385 EnvBlockLen *
sizeof(EnvBlockWide[0])),
387 goto SkipSettingEnvironment;
389 Environment.reserve(EnvCount);
394 for (
const char *Cursor = EnvBlock.data(); *Cursor !=
'\0';) {
395 llvm::StringRef EnvVar(Cursor);
396 if (EnvVar.starts_with_insensitive(
"path=")) {
397 constexpr size_t PrefixLen = 5;
398 Environment.push_back(Args.MakeArgString(
399 EnvVar.substr(0, PrefixLen) +
400 TC.getSubDirectoryPath(llvm::SubDirectoryType::Bin) +
401 llvm::Twine(llvm::sys::EnvPathSeparator) +
402 TC.getSubDirectoryPath(llvm::SubDirectoryType::Bin, HostArch) +
403 (EnvVar.size() > PrefixLen
404 ? llvm::Twine(llvm::sys::EnvPathSeparator) +
405 EnvVar.substr(PrefixLen)
408 Environment.push_back(Args.MakeArgString(EnvVar));
410 Cursor += EnvVar.size() + 1 ;
413 SkipSettingEnvironment:;
416 linkPath = TC.GetProgramPath(
Linker.str().c_str());
419 auto LinkCmd = std::make_unique<Command>(
421 Args.MakeArgString(linkPath), CmdArgs, Inputs, Output);
422 if (!Environment.empty())
423 LinkCmd->setEnvironment(Environment);
424 C.addCommand(std::move(LinkCmd));
429 :
ToolChain(
D, Triple, Args), CudaInstallation(
D, Triple, Args),
430 RocmInstallation(
D, Triple, Args) {
433 std::optional<llvm::StringRef> VCToolsDir, VCToolsVersion;
434 if (Arg *A = Args.getLastArg(options::OPT__SLASH_vctoolsdir))
435 VCToolsDir = A->getValue();
436 if (Arg *A = Args.getLastArg(options::OPT__SLASH_vctoolsversion))
437 VCToolsVersion = A->getValue();
438 if (Arg *A = Args.getLastArg(options::OPT__SLASH_winsdkdir))
439 WinSdkDir = A->getValue();
440 if (Arg *A = Args.getLastArg(options::OPT__SLASH_winsdkversion))
441 WinSdkVersion = A->getValue();
442 if (Arg *A = Args.getLastArg(options::OPT__SLASH_winsysroot))
443 WinSysRoot = A->getValue();
449 llvm::findVCToolChainViaCommandLine(
getVFS(), VCToolsDir, VCToolsVersion,
450 WinSysRoot, VCToolChainPath, VSLayout) ||
451 llvm::findVCToolChainViaEnvironment(
getVFS(), VCToolChainPath,
453 llvm::findVCToolChainViaSetupConfig(
getVFS(), VCToolsVersion,
454 VCToolChainPath, VSLayout) ||
455 llvm::findVCToolChainViaRegistry(VCToolChainPath, VSLayout);
478 if (
getArch() == llvm::Triple::x86_64 ||
getArch() == llvm::Triple::arm ||
479 getArch() == llvm::Triple::thumb ||
getArch() == llvm::Triple::aarch64)
486 return getArch() == llvm::Triple::x86_64 ||
487 getArch() == llvm::Triple::aarch64;
495 return getArch() == llvm::Triple::x86_64 ||
496 getArch() == llvm::Triple::aarch64;
500 ArgStringList &CC1Args)
const {
501 CudaInstallation->AddCudaIncludeArgs(DriverArgs, CC1Args);
505 ArgStringList &CC1Args)
const {
506 RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args);
510 ArgStringList &CmdArgs)
const {
511 CmdArgs.append({Args.MakeArgString(StringRef(
"-libpath:") +
512 RocmInstallation->getLibPath()),
517 CudaInstallation->print(OS);
518 RocmInstallation->print(OS);
523 llvm::StringRef SubdirParent)
const {
524 return llvm::getSubDirectoryPath(
Type, VSLayout, VCToolChainPath,
getArch(),
530 llvm::Triple::ArchType TargetArch)
const {
531 return llvm::getSubDirectoryPath(
Type, VSLayout, VCToolChainPath, TargetArch,
541 std::string &path)
const {
544 std::string windowsSDKIncludeVersion;
545 std::string windowsSDKLibVersion;
548 if (!llvm::getWindowsSDKDir(
getVFS(), WinSdkDir, WinSdkVersion, WinSysRoot,
549 sdkPath, sdkMajor, windowsSDKIncludeVersion,
550 windowsSDKLibVersion))
554 llvm::sys::path::append(libPath,
"Lib");
556 if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
557 WinSdkVersion.has_value())
558 windowsSDKLibVersion = *WinSdkVersion;
560 llvm::sys::path::append(libPath, windowsSDKLibVersion,
"um");
561 return llvm::appendArchToWindowsSDKLibPath(sdkMajor, libPath,
getArch(),
566 return llvm::useUniversalCRT(VSLayout, VCToolChainPath,
getArch(),
getVFS());
570 std::string &
Path)
const {
571 std::string UniversalCRTSdkPath;
572 std::string UCRTVersion;
575 if (!llvm::getUniversalCRTSdkDir(
getVFS(), WinSdkDir, WinSdkVersion,
576 WinSysRoot, UniversalCRTSdkPath,
580 if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
581 WinSdkVersion.has_value())
582 UCRTVersion = *WinSdkVersion;
584 StringRef ArchName = llvm::archToWindowsSDKArch(
getArch());
585 if (ArchName.empty())
589 llvm::sys::path::append(LibPath,
"Lib", UCRTVersion,
"ucrt", ArchName);
591 Path = std::string(LibPath);
596 VersionTuple Version;
599 llvm::sys::path::append(ClExe,
"cl.exe");
601 std::wstring ClExeWide;
602 if (!llvm::ConvertUTF8toWide(ClExe.c_str(), ClExeWide))
605 const DWORD VersionSize = ::GetFileVersionInfoSizeW(ClExeWide.c_str(),
607 if (VersionSize == 0)
611 if (!::GetFileVersionInfoW(ClExeWide.c_str(), 0, VersionSize,
612 VersionBlock.data()))
615 VS_FIXEDFILEINFO *FileInfo =
nullptr;
616 UINT FileInfoSize = 0;
617 if (!::VerQueryValueW(VersionBlock.data(), L
"\\",
618 reinterpret_cast<LPVOID *
>(&FileInfo), &FileInfoSize) ||
619 FileInfoSize <
sizeof(*FileInfo))
622 const unsigned Major = (FileInfo->dwFileVersionMS >> 16) & 0xFFFF;
623 const unsigned Minor = (FileInfo->dwFileVersionMS ) & 0xFFFF;
624 const unsigned Micro = (FileInfo->dwFileVersionLS >> 16) & 0xFFFF;
626 Version = VersionTuple(Major, Minor, Micro);
632 const ArgList &DriverArgs, ArgStringList &CC1Args,
633 const std::string &folder,
const Twine &subfolder1,
const Twine &subfolder2,
634 const Twine &subfolder3)
const {
636 llvm::sys::path::append(path, subfolder1, subfolder2, subfolder3);
641 ArgStringList &CC1Args)
const {
642 if (DriverArgs.hasArg(options::OPT_nostdinc))
645 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
651 for (
const auto &
Path : DriverArgs.getAllArgValues(options::OPT__SLASH_imsvc))
654 auto AddSystemIncludesFromEnv = [&](StringRef Var) ->
bool {
655 if (
auto Val = llvm::sys::Process::GetEnv(Var)) {
657 StringRef(*Val).split(Dirs,
";", -1,
false);
667 for (
const auto &Var :
668 DriverArgs.getAllArgValues(options::OPT__SLASH_external_env)) {
669 AddSystemIncludesFromEnv(Var);
673 if (
const Arg *A = DriverArgs.getLastArg(options::OPT__SLASH_diasdkdir,
674 options::OPT__SLASH_winsysroot)) {
679 if (A->getOption().getID() == options::OPT__SLASH_winsysroot)
680 llvm::sys::path::append(DIASDKPath,
"DIA SDK");
685 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
690 if (!DriverArgs.getLastArg(options::OPT__SLASH_vctoolsdir,
691 options::OPT__SLASH_winsysroot)) {
692 bool Found = AddSystemIncludesFromEnv(
"INCLUDE");
693 Found |= AddSystemIncludesFromEnv(
"EXTERNAL_INCLUDE");
700 if (!VCToolChainPath.empty()) {
708 std::string UniversalCRTSdkPath;
709 std::string UCRTVersion;
710 if (llvm::getUniversalCRTSdkDir(
getVFS(), WinSdkDir, WinSdkVersion,
711 WinSysRoot, UniversalCRTSdkPath,
713 if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
714 WinSdkVersion.has_value())
715 UCRTVersion = *WinSdkVersion;
717 "Include", UCRTVersion,
"ucrt");
721 std::string WindowsSDKDir;
723 std::string windowsSDKIncludeVersion;
724 std::string windowsSDKLibVersion;
725 if (llvm::getWindowsSDKDir(
getVFS(), WinSdkDir, WinSdkVersion, WinSysRoot,
726 WindowsSDKDir, major, windowsSDKIncludeVersion,
727 windowsSDKLibVersion)) {
729 if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
730 WinSdkVersion.has_value())
731 windowsSDKIncludeVersion = windowsSDKLibVersion = *WinSdkVersion;
736 "Include", windowsSDKIncludeVersion,
739 "Include", windowsSDKIncludeVersion,
742 "Include", windowsSDKIncludeVersion,
745 llvm::VersionTuple Tuple;
746 if (!Tuple.tryParse(windowsSDKIncludeVersion) &&
747 Tuple.getSubminor().value_or(0) >= 17134) {
749 "Include", windowsSDKIncludeVersion,
765 const StringRef Paths[] = {
766 "C:/Program Files/Microsoft Visual Studio 10.0/VC/include",
767 "C:/Program Files/Microsoft Visual Studio 9.0/VC/include",
768 "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include",
769 "C:/Program Files/Microsoft Visual Studio 8/VC/include",
770 "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include"
777 ArgStringList &CC1Args)
const {
782 const ArgList &Args)
const {
783 bool IsWindowsMSVC =
getTriple().isWindowsMSVCEnvironment();
786 MSVT =
getTriple().getEnvironmentVersion();
787 if (MSVT.empty() && IsWindowsMSVC)
791 Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
797 MSVT = VersionTuple(19, 33);
808 MSVT = VersionTuple(MSVT.getMajor(), MSVT.getMinor().value_or(0),
809 MSVT.getSubminor().value_or(0));
814 if (Triple.getEnvironment() == llvm::Triple::MSVC) {
815 StringRef ObjFmt = Triple.getEnvironmentName().split(
'-').second;
817 Triple.setEnvironmentName((Twine(
"msvc") + MSVT.getAsString()).str());
819 Triple.setEnvironmentName(
820 (Twine(
"msvc") + MSVT.getAsString() + Twine(
'-') + ObjFmt).str());
822 return Triple.getTriple();
827 Res |= SanitizerKind::Address;
828 Res |= SanitizerKind::PointerCompare;
829 Res |= SanitizerKind::PointerSubtract;
830 Res |= SanitizerKind::Fuzzer;
831 Res |= SanitizerKind::FuzzerNoLink;
837 bool SupportsForcingFramePointer,
838 const char *ExpandChar,
const OptTable &Opts) {
839 assert(A->getOption().matches(options::OPT__SLASH_O));
841 StringRef OptStr = A->getValue();
842 for (
size_t I = 0,
E = OptStr.size(); I !=
E; ++I) {
843 const char &OptChar = *(OptStr.data() + I);
853 if (&OptChar != ExpandChar) {
857 if (OptChar ==
'd') {
858 DAL.AddFlagArg(A, Opts.getOption(options::OPT_O0));
860 if (OptChar ==
'1') {
861 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O),
"s");
862 }
else if (OptChar ==
'2' || OptChar ==
'x') {
863 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fbuiltin));
864 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O),
"3");
866 if (SupportsForcingFramePointer &&
867 !DAL.hasArgNoClaim(options::OPT_fno_omit_frame_pointer))
868 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fomit_frame_pointer));
869 if (OptChar ==
'1' || OptChar ==
'2')
870 DAL.AddFlagArg(A, Opts.getOption(options::OPT_ffunction_sections));
874 if (I + 1 !=
E && isdigit(OptStr[I + 1])) {
875 switch (OptStr[I + 1]) {
877 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_inline));
880 DAL.AddFlagArg(A, Opts.getOption(options::OPT_finline_hint_functions));
884 DAL.AddFlagArg(A, Opts.getOption(options::OPT_finline_functions));
894 if (I + 1 !=
E && OptStr[I + 1] ==
'-') {
896 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_builtin));
898 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fbuiltin));
902 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O),
"s");
905 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O),
"3");
908 bool OmitFramePointer =
true;
909 if (I + 1 !=
E && OptStr[I + 1] ==
'-') {
910 OmitFramePointer =
false;
913 if (SupportsForcingFramePointer) {
914 if (OmitFramePointer)
916 Opts.getOption(options::OPT_fomit_frame_pointer));
919 A, Opts.getOption(options::OPT_fno_omit_frame_pointer));
934 const OptTable &Opts) {
935 assert(A->getOption().matches(options::OPT_D));
937 StringRef Val = A->getValue();
938 size_t Hash = Val.find(
'#');
939 if (Hash == StringRef::npos || Hash > Val.find(
'=')) {
944 std::string NewVal = std::string(Val);
946 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_D), NewVal);
950 const OptTable &Opts) {
951 DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_twoPhase_));
952 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_operator_names));
956 const OptTable &Opts) {
957 DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_twoPhase));
958 DAL.AddFlagArg(A, Opts.getOption(options::OPT_foperator_names));
961llvm::opt::DerivedArgList *
965 DerivedArgList *DAL =
new DerivedArgList(Args.getBaseArgs());
969 bool SupportsForcingFramePointer =
getArch() != llvm::Triple::x86_64;
980 const char *ExpandChar =
nullptr;
981 for (Arg *A : Args.filtered(options::OPT__SLASH_O)) {
982 StringRef OptStr = A->getValue();
983 for (
size_t I = 0,
E = OptStr.size(); I !=
E; ++I) {
984 char OptChar = OptStr[I];
985 char PrevChar = I > 0 ? OptStr[I - 1] :
'0';
986 if (PrevChar ==
'b') {
990 if (OptChar ==
'1' || OptChar ==
'2' || OptChar ==
'x' || OptChar ==
'd')
991 ExpandChar = OptStr.data() + I;
995 for (Arg *A : Args) {
996 if (A->getOption().matches(options::OPT__SLASH_O)) {
999 TranslateOptArg(A, *DAL, SupportsForcingFramePointer, ExpandChar, Opts);
1000 }
else if (A->getOption().matches(options::OPT_D)) {
1003 }
else if (A->getOption().matches(options::OPT__SLASH_permissive)) {
1006 }
else if (A->getOption().matches(options::OPT__SLASH_permissive_)) {
1019 const ArgList &DriverArgs, ArgStringList &CC1Args,
1023 if (DriverArgs.hasFlag(options::OPT_fno_rtti, options::OPT_frtti,
1025 CC1Args.push_back(
"-D_HAS_STATIC_RTTI=0");
1027 if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_marm64x))
1028 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()