clang 20.0.0git
MSVC.cpp
Go to the documentation of this file.
1//===-- MSVC.cpp - MSVC ToolChain Implementations -------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "MSVC.h"
10#include "CommonArgs.h"
11#include "Darwin.h"
13#include "clang/Basic/Version.h"
14#include "clang/Config/config.h"
16#include "clang/Driver/Driver.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"
31#include <cstdio>
32
33#ifdef _WIN32
34 #define WIN32_LEAN_AND_MEAN
35 #define NOGDI
36 #ifndef NOMINMAX
37 #define NOMINMAX
38 #endif
39 #include <windows.h>
40#endif
41
42using namespace clang::driver;
43using namespace clang::driver::toolchains;
44using namespace clang::driver::tools;
45using namespace clang;
46using namespace llvm::opt;
47
48static bool canExecute(llvm::vfs::FileSystem &VFS, StringRef Path) {
49 auto Status = VFS.status(Path);
50 if (!Status)
51 return false;
52 return (Status->getPermissions() & llvm::sys::fs::perms::all_exe) != 0;
53}
54
55// Try to find Exe from a Visual Studio distribution. This first tries to find
56// an installed copy of Visual Studio and, failing that, looks in the PATH,
57// making sure that whatever executable that's found is not a same-named exe
58// from clang itself to prevent clang from falling back to itself.
59static std::string FindVisualStudioExecutable(const ToolChain &TC,
60 const char *Exe) {
61 const auto &MSVC = static_cast<const toolchains::MSVCToolChain &>(TC);
62 SmallString<128> FilePath(
63 MSVC.getSubDirectoryPath(llvm::SubDirectoryType::Bin));
64 llvm::sys::path::append(FilePath, Exe);
65 return std::string(canExecute(TC.getVFS(), FilePath) ? FilePath.str() : Exe);
66}
67
69 const InputInfo &Output,
70 const InputInfoList &Inputs,
71 const ArgList &Args,
72 const char *LinkingOutput) const {
73 ArgStringList CmdArgs;
74
75 auto &TC = static_cast<const toolchains::MSVCToolChain &>(getToolChain());
76
77 assert((Output.isFilename() || Output.isNothing()) && "invalid output");
78 if (Output.isFilename())
79 CmdArgs.push_back(
80 Args.MakeArgString(std::string("-out:") + Output.getFilename()));
81
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");
86
87 if (const Arg *A = Args.getLastArg(options::OPT_fveclib)) {
88 StringRef V = A->getValue();
89 if (V == "ArmPL")
90 CmdArgs.push_back(Args.MakeArgString("--dependent-lib=amath"));
91 }
92
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");
97 }
98
99 // If the VC environment hasn't been configured (perhaps because the user
100 // did not run vcvarsall), try to build a consistent link environment. If
101 // the environment variable is set however, assume the user knows what
102 // they're doing. If the user passes /vctoolsdir or /winsdkdir, trust that
103 // over env vars.
104 if (const Arg *A = Args.getLastArg(options::OPT__SLASH_diasdkdir,
105 options::OPT__SLASH_winsysroot)) {
106 // cl.exe doesn't find the DIA SDK automatically, so this too requires
107 // explicit flags and doesn't automatically look in "DIA SDK" relative
108 // to the path we found for VCToolChainPath.
109 llvm::SmallString<128> DIAPath(A->getValue());
110 if (A->getOption().getID() == options::OPT__SLASH_winsysroot)
111 llvm::sys::path::append(DIAPath, "DIA SDK");
112
113 // The DIA SDK always uses the legacy vc arch, even in new MSVC versions.
114 llvm::sys::path::append(DIAPath, "lib",
115 llvm::archToLegacyVCArch(TC.getArch()));
116 CmdArgs.push_back(Args.MakeArgString(Twine("-libpath:") + DIAPath));
117 }
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(
122 Twine("-libpath:") +
123 TC.getSubDirectoryPath(llvm::SubDirectoryType::Lib)));
124 CmdArgs.push_back(Args.MakeArgString(
125 Twine("-libpath:") +
126 TC.getSubDirectoryPath(llvm::SubDirectoryType::Lib, "atlmfc")));
127 }
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))
134 CmdArgs.push_back(
135 Args.MakeArgString(Twine("-libpath:") + UniversalCRTLibPath));
136 }
137 std::string WindowsSdkLibPath;
138 if (TC.getWindowsSDKLibraryPath(Args, WindowsSdkLibPath))
139 CmdArgs.push_back(
140 Args.MakeArgString(std::string("-libpath:") + WindowsSdkLibPath));
141 }
142
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));
146
147 if (C.getDriver().IsFlangMode() &&
148 !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
149 addFortranRuntimeLibraryPath(TC, Args, CmdArgs);
150 addFortranRuntimeLibs(TC, Args, CmdArgs);
151
152 // Inform the MSVC linker that we're generating a console application, i.e.
153 // one with `main` as the "user-defined" entry point. The `main` function is
154 // defined in flang's runtime libraries.
155 CmdArgs.push_back("/subsystem:console");
156 }
157
158 // Add the compiler-rt library directories to libpath if they exist to help
159 // the linker find the various sanitizer, builtin, and profiling runtimes.
160 for (const auto &LibPath : TC.getLibraryPaths()) {
161 if (TC.getVFS().exists(LibPath))
162 CmdArgs.push_back(Args.MakeArgString("-libpath:" + LibPath));
163 }
164 auto CRTPath = TC.getCompilerRTPath();
165 if (TC.getVFS().exists(CRTPath))
166 CmdArgs.push_back(Args.MakeArgString("-libpath:" + CRTPath));
167
168 CmdArgs.push_back("-nologo");
169
170 if (Args.hasArg(options::OPT_g_Group, options::OPT__SLASH_Z7))
171 CmdArgs.push_back("-debug");
172
173 // If we specify /hotpatch, let the linker add padding in front of each
174 // function, like MSVC does.
175 if (Args.hasArg(options::OPT_fms_hotpatch, options::OPT__SLASH_hotpatch))
176 CmdArgs.push_back("-functionpadmin");
177
178 // Pass on /Brepro if it was passed to the compiler.
179 // Note that /Brepro maps to -mno-incremental-linker-compatible.
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");
186
187 bool DLL = Args.hasArg(options::OPT__SLASH_LD, options::OPT__SLASH_LDd,
188 options::OPT_shared);
189 if (DLL) {
190 CmdArgs.push_back(Args.MakeArgString("-dll"));
191
192 SmallString<128> ImplibName(Output.getFilename());
193 llvm::sys::path::replace_extension(ImplibName, "lib");
194 CmdArgs.push_back(Args.MakeArgString(std::string("-implib:") + ImplibName));
195 }
196
197 if (TC.getSanitizerArgs(Args).needsFuzzer()) {
198 if (!Args.hasArg(options::OPT_shared))
199 CmdArgs.push_back(
200 Args.MakeArgString(std::string("-wholearchive:") +
201 TC.getCompilerRTArgString(Args, "fuzzer")));
202 CmdArgs.push_back(Args.MakeArgString("-debug"));
203 // Prevent the linker from padding sections we use for instrumentation
204 // arrays.
205 CmdArgs.push_back(Args.MakeArgString("-incremental:no"));
206 }
207
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)) {
215 // Make sure the dynamic runtime thunk is not optimized out at link time
216 // to ensure proper SEH handling.
217 CmdArgs.push_back(Args.MakeArgString(
218 TC.getArch() == llvm::Triple::x86
219 ? "-include:___asan_seh_interceptor"
220 : "-include:__asan_seh_interceptor"));
221 // Make sure the linker consider all object files from the dynamic runtime
222 // thunk.
223 CmdArgs.push_back(Args.MakeArgString(
224 std::string("-wholearchive:") +
225 TC.getCompilerRT(Args, "asan_dynamic_runtime_thunk")));
226 } else {
227 // Make sure the linker consider all object files from the static runtime
228 // thunk.
229 CmdArgs.push_back(Args.MakeArgString(
230 std::string("-wholearchive:") +
231 TC.getCompilerRT(Args, "asan_static_runtime_thunk")));
232 }
233 }
234
235 Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
236
237 // Control Flow Guard checks
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")) {
242 // MSVC doesn't yet support the "nochecks" modifier.
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-");
250 }
251 }
252
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");
262 break;
264 CmdArgs.push_back("-defaultlib:libiomp5md.lib");
265 break;
267 break;
269 // Already diagnosed.
270 break;
271 }
272 }
273
274 // Add compiler-rt lib in case if it was explicitly
275 // specified as an argument for --rtlib option.
276 if (!Args.hasArg(options::OPT_nostdlib)) {
277 AddRunTimeLibs(TC, TC.getDriver(), CmdArgs, Args);
278 }
279
280 StringRef Linker =
281 Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER);
282 if (Linker.empty())
283 Linker = "link";
284 // We need to translate 'lld' into 'lld-link'.
285 else if (Linker.equals_insensitive("lld"))
286 Linker = "lld-link";
287
288 if (Linker == "lld-link") {
289 for (Arg *A : Args.filtered(options::OPT_vfsoverlay))
290 CmdArgs.push_back(
291 Args.MakeArgString(std::string("/vfsoverlay:") + A->getValue()));
292
293 if (C.getDriver().isUsingLTO() &&
294 Args.hasFlag(options::OPT_gsplit_dwarf, options::OPT_gno_split_dwarf,
295 false))
296 CmdArgs.push_back(Args.MakeArgString(Twine("/dwodir:") +
297 Output.getFilename() + "_dwo"));
298 }
299
300 // Add filenames, libraries, and other linker inputs.
301 for (const auto &Input : Inputs) {
302 if (Input.isFilename()) {
303 CmdArgs.push_back(Input.getFilename());
304 continue;
305 }
306
307 const Arg &A = Input.getInputArg();
308
309 // Render -l options differently for the MSVC linker.
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);
315 else
316 LinkLibArg = Args.MakeArgString(Lib + ".lib");
317 CmdArgs.push_back(LinkLibArg);
318 continue;
319 }
320
321 // Otherwise, this is some other kind of linker input option like -Wl, -z,
322 // or -L. Render it, even if MSVC doesn't understand it.
323 A.renderAsInput(Args, CmdArgs);
324 }
325
326 addHIPRuntimeLibArgs(TC, C, Args, CmdArgs);
327
328 TC.addProfileRTLibs(Args, CmdArgs);
329
330 std::vector<const char *> Environment;
331
332 // We need to special case some linker paths. In the case of the regular msvc
333 // linker, we need to use a special search algorithm.
334 llvm::SmallString<128> linkPath;
335 if (Linker.equals_insensitive("link")) {
336 // If we're using the MSVC linker, it's not sufficient to just use link
337 // from the program PATH, because other environments like GnuWin32 install
338 // their own link.exe which may come first.
339 linkPath = FindVisualStudioExecutable(TC, "link.exe");
340
341 if (!TC.FoundMSVCInstall() && !canExecute(TC.getVFS(), linkPath)) {
343 ClPath = TC.GetProgramPath("cl.exe");
344 if (canExecute(TC.getVFS(), ClPath)) {
345 linkPath = llvm::sys::path::parent_path(ClPath);
346 llvm::sys::path::append(linkPath, "link.exe");
347 if (!canExecute(TC.getVFS(), linkPath))
348 C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
349 } else {
350 C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
351 }
352 }
353
354 // Clang handles passing the proper asan libs to the linker, which goes
355 // against link.exe's /INFERASANLIBS which automatically finds asan libs.
356 if (TC.getSanitizerArgs(Args).needsAsanRt())
357 CmdArgs.push_back("/INFERASANLIBS:NO");
358
359#ifdef _WIN32
360 // When cross-compiling with VS2017 or newer, link.exe expects to have
361 // its containing bin directory at the top of PATH, followed by the
362 // native target bin directory.
363 // e.g. when compiling for x86 on an x64 host, PATH should start with:
364 // /bin/Hostx64/x86;/bin/Hostx64/x64
365 // This doesn't attempt to handle llvm::ToolsetLayout::DevDivInternal.
366 if (TC.getIsVS2017OrNewer() &&
367 llvm::Triple(llvm::sys::getProcessTriple()).getArch() != TC.getArch()) {
368 auto HostArch = llvm::Triple(llvm::sys::getProcessTriple()).getArch();
369
370 auto EnvBlockWide =
371 std::unique_ptr<wchar_t[], decltype(&FreeEnvironmentStringsW)>(
372 GetEnvironmentStringsW(), FreeEnvironmentStringsW);
373 if (!EnvBlockWide)
374 goto SkipSettingEnvironment;
375
376 size_t EnvCount = 0;
377 size_t EnvBlockLen = 0;
378 while (EnvBlockWide[EnvBlockLen] != L'\0') {
379 ++EnvCount;
380 EnvBlockLen += std::wcslen(&EnvBlockWide[EnvBlockLen]) +
381 1 /*string null-terminator*/;
382 }
383 ++EnvBlockLen; // add the block null-terminator
384
385 std::string EnvBlock;
386 if (!llvm::convertUTF16ToUTF8String(
387 llvm::ArrayRef<char>(reinterpret_cast<char *>(EnvBlockWide.get()),
388 EnvBlockLen * sizeof(EnvBlockWide[0])),
389 EnvBlock))
390 goto SkipSettingEnvironment;
391
392 Environment.reserve(EnvCount);
393
394 // Now loop over each string in the block and copy them into the
395 // environment vector, adjusting the PATH variable as needed when we
396 // find it.
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; // strlen("path=")
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)
409 : "")));
410 } else {
411 Environment.push_back(Args.MakeArgString(EnvVar));
412 }
413 Cursor += EnvVar.size() + 1 /*null-terminator*/;
414 }
415 }
416 SkipSettingEnvironment:;
417#endif
418 } else {
419 linkPath = TC.GetProgramPath(Linker.str().c_str());
420 }
421
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));
428}
429
430MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
431 const ArgList &Args)
432 : ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args),
433 RocmInstallation(D, Triple, Args) {
434 getProgramPaths().push_back(getDriver().Dir);
435
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();
447
448 // Check the command line first, that's the user explicitly telling us what to
449 // use. Check the environment next, in case we're being invoked from a VS
450 // command prompt. Failing that, just try to find the newest Visual Studio
451 // version we can and use its default VC toolchain.
452 llvm::findVCToolChainViaCommandLine(getVFS(), VCToolsDir, VCToolsVersion,
453 WinSysRoot, VCToolChainPath, VSLayout) ||
454 llvm::findVCToolChainViaEnvironment(getVFS(), VCToolChainPath,
455 VSLayout) ||
456 llvm::findVCToolChainViaSetupConfig(getVFS(), VCToolsVersion,
457 VCToolChainPath, VSLayout) ||
458 llvm::findVCToolChainViaRegistry(VCToolChainPath, VSLayout);
459}
460
462 return new tools::visualstudio::Linker(*this);
463}
464
466 if (getTriple().isOSBinFormatMachO())
467 return new tools::darwin::Assembler(*this);
468 getDriver().Diag(clang::diag::err_no_external_assembler);
469 return nullptr;
470}
471
474 // Don't emit unwind tables by default for MachO targets.
475 if (getTriple().isOSBinFormatMachO())
477
478 // All non-x86_32 Windows targets require unwind tables. However, LLVM
479 // doesn't know how to generate them for all targets, so only enable
480 // the ones that are actually implemented.
481 if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::arm ||
482 getArch() == llvm::Triple::thumb || getArch() == llvm::Triple::aarch64)
484
486}
487
489 return getArch() == llvm::Triple::x86_64 ||
490 getArch() == llvm::Triple::aarch64;
491}
492
493bool MSVCToolChain::isPIEDefault(const llvm::opt::ArgList &Args) const {
494 return false;
495}
496
498 return getArch() == llvm::Triple::x86_64 ||
499 getArch() == llvm::Triple::aarch64;
500}
501
502void MSVCToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
503 ArgStringList &CC1Args) const {
504 CudaInstallation->AddCudaIncludeArgs(DriverArgs, CC1Args);
505}
506
507void MSVCToolChain::AddHIPIncludeArgs(const ArgList &DriverArgs,
508 ArgStringList &CC1Args) const {
509 RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args);
510}
511
512void MSVCToolChain::AddHIPRuntimeLibArgs(const ArgList &Args,
513 ArgStringList &CmdArgs) const {
514 CmdArgs.append({Args.MakeArgString(StringRef("-libpath:") +
515 RocmInstallation->getLibPath()),
516 "amdhip64.lib"});
517}
518
519void MSVCToolChain::printVerboseInfo(raw_ostream &OS) const {
520 CudaInstallation->print(OS);
521 RocmInstallation->print(OS);
522}
523
524std::string
526 llvm::StringRef SubdirParent) const {
527 return llvm::getSubDirectoryPath(Type, VSLayout, VCToolChainPath, getArch(),
528 SubdirParent);
529}
530
531std::string
533 llvm::Triple::ArchType TargetArch) const {
534 return llvm::getSubDirectoryPath(Type, VSLayout, VCToolChainPath, TargetArch,
535 "");
536}
537
538// Find the most recent version of Universal CRT or Windows 10 SDK.
539// vcvarsqueryregistry.bat from Visual Studio 2015 sorts entries in the include
540// directory by name and uses the last one of the list.
541// So we compare entry names lexicographically to find the greatest one.
542// Gets the library path required to link against the Windows SDK.
544 std::string &path) const {
545 std::string sdkPath;
546 int sdkMajor = 0;
547 std::string windowsSDKIncludeVersion;
548 std::string windowsSDKLibVersion;
549
550 path.clear();
551 if (!llvm::getWindowsSDKDir(getVFS(), WinSdkDir, WinSdkVersion, WinSysRoot,
552 sdkPath, sdkMajor, windowsSDKIncludeVersion,
553 windowsSDKLibVersion))
554 return false;
555
556 llvm::SmallString<128> libPath(sdkPath);
557 llvm::sys::path::append(libPath, "Lib");
558 if (sdkMajor >= 10)
559 if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
560 WinSdkVersion.has_value())
561 windowsSDKLibVersion = *WinSdkVersion;
562 if (sdkMajor >= 8)
563 llvm::sys::path::append(libPath, windowsSDKLibVersion, "um");
564 return llvm::appendArchToWindowsSDKLibPath(sdkMajor, libPath, getArch(),
565 path);
566}
567
569 return llvm::useUniversalCRT(VSLayout, VCToolChainPath, getArch(), getVFS());
570}
571
573 std::string &Path) const {
574 std::string UniversalCRTSdkPath;
575 std::string UCRTVersion;
576
577 Path.clear();
578 if (!llvm::getUniversalCRTSdkDir(getVFS(), WinSdkDir, WinSdkVersion,
579 WinSysRoot, UniversalCRTSdkPath,
580 UCRTVersion))
581 return false;
582
583 if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
584 WinSdkVersion.has_value())
585 UCRTVersion = *WinSdkVersion;
586
587 StringRef ArchName = llvm::archToWindowsSDKArch(getArch());
588 if (ArchName.empty())
589 return false;
590
591 llvm::SmallString<128> LibPath(UniversalCRTSdkPath);
592 llvm::sys::path::append(LibPath, "Lib", UCRTVersion, "ucrt", ArchName);
593
594 Path = std::string(LibPath);
595 return true;
596}
597
598static VersionTuple getMSVCVersionFromExe(const std::string &BinDir) {
599 VersionTuple Version;
600#ifdef _WIN32
601 SmallString<128> ClExe(BinDir);
602 llvm::sys::path::append(ClExe, "cl.exe");
603
604 std::wstring ClExeWide;
605 if (!llvm::ConvertUTF8toWide(ClExe.c_str(), ClExeWide))
606 return Version;
607
608 const DWORD VersionSize = ::GetFileVersionInfoSizeW(ClExeWide.c_str(),
609 nullptr);
610 if (VersionSize == 0)
611 return Version;
612
613 SmallVector<uint8_t, 4 * 1024> VersionBlock(VersionSize);
614 if (!::GetFileVersionInfoW(ClExeWide.c_str(), 0, VersionSize,
615 VersionBlock.data()))
616 return Version;
617
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))
623 return Version;
624
625 const unsigned Major = (FileInfo->dwFileVersionMS >> 16) & 0xFFFF;
626 const unsigned Minor = (FileInfo->dwFileVersionMS ) & 0xFFFF;
627 const unsigned Micro = (FileInfo->dwFileVersionLS >> 16) & 0xFFFF;
628
629 Version = VersionTuple(Major, Minor, Micro);
630#endif
631 return Version;
632}
633
635 const ArgList &DriverArgs, ArgStringList &CC1Args,
636 const std::string &folder, const Twine &subfolder1, const Twine &subfolder2,
637 const Twine &subfolder3) const {
638 llvm::SmallString<128> path(folder);
639 llvm::sys::path::append(path, subfolder1, subfolder2, subfolder3);
640 addSystemInclude(DriverArgs, CC1Args, path);
641}
642
643void MSVCToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
644 ArgStringList &CC1Args) const {
645 if (DriverArgs.hasArg(options::OPT_nostdinc))
646 return;
647
648 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
649 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, getDriver().ResourceDir,
650 "include");
651 }
652
653 // Add %INCLUDE%-like directories from the -imsvc flag.
654 for (const auto &Path : DriverArgs.getAllArgValues(options::OPT__SLASH_imsvc))
655 addSystemInclude(DriverArgs, CC1Args, Path);
656
657 auto AddSystemIncludesFromEnv = [&](StringRef Var) -> bool {
658 if (auto Val = llvm::sys::Process::GetEnv(Var)) {
660 StringRef(*Val).split(Dirs, ";", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
661 if (!Dirs.empty()) {
662 addSystemIncludes(DriverArgs, CC1Args, Dirs);
663 return true;
664 }
665 }
666 return false;
667 };
668
669 // Add %INCLUDE%-like dirs via /external:env: flags.
670 for (const auto &Var :
671 DriverArgs.getAllArgValues(options::OPT__SLASH_external_env)) {
672 AddSystemIncludesFromEnv(Var);
673 }
674
675 // Add DIA SDK include if requested.
676 if (const Arg *A = DriverArgs.getLastArg(options::OPT__SLASH_diasdkdir,
677 options::OPT__SLASH_winsysroot)) {
678 // cl.exe doesn't find the DIA SDK automatically, so this too requires
679 // explicit flags and doesn't automatically look in "DIA SDK" relative
680 // to the path we found for VCToolChainPath.
681 llvm::SmallString<128> DIASDKPath(A->getValue());
682 if (A->getOption().getID() == options::OPT__SLASH_winsysroot)
683 llvm::sys::path::append(DIASDKPath, "DIA SDK");
684 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, std::string(DIASDKPath),
685 "include");
686 }
687
688 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
689 return;
690
691 // Honor %INCLUDE% and %EXTERNAL_INCLUDE%. It should have essential search
692 // paths set by vcvarsall.bat. Skip if the user expressly set a vctoolsdir.
693 if (!DriverArgs.getLastArg(options::OPT__SLASH_vctoolsdir,
694 options::OPT__SLASH_winsysroot)) {
695 bool Found = AddSystemIncludesFromEnv("INCLUDE");
696 Found |= AddSystemIncludesFromEnv("EXTERNAL_INCLUDE");
697 if (Found)
698 return;
699 }
700
701 // When built with access to the proper Windows APIs, try to actually find
702 // the correct include paths first.
703 if (!VCToolChainPath.empty()) {
704 addSystemInclude(DriverArgs, CC1Args,
705 getSubDirectoryPath(llvm::SubDirectoryType::Include));
707 DriverArgs, CC1Args,
708 getSubDirectoryPath(llvm::SubDirectoryType::Include, "atlmfc"));
709
710 if (useUniversalCRT()) {
711 std::string UniversalCRTSdkPath;
712 std::string UCRTVersion;
713 if (llvm::getUniversalCRTSdkDir(getVFS(), WinSdkDir, WinSdkVersion,
714 WinSysRoot, UniversalCRTSdkPath,
715 UCRTVersion)) {
716 if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
717 WinSdkVersion.has_value())
718 UCRTVersion = *WinSdkVersion;
719 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, UniversalCRTSdkPath,
720 "Include", UCRTVersion, "ucrt");
721 }
722 }
723
724 std::string WindowsSDKDir;
725 int major = 0;
726 std::string windowsSDKIncludeVersion;
727 std::string windowsSDKLibVersion;
728 if (llvm::getWindowsSDKDir(getVFS(), WinSdkDir, WinSdkVersion, WinSysRoot,
729 WindowsSDKDir, major, windowsSDKIncludeVersion,
730 windowsSDKLibVersion)) {
731 if (major >= 10)
732 if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
733 WinSdkVersion.has_value())
734 windowsSDKIncludeVersion = windowsSDKLibVersion = *WinSdkVersion;
735 if (major >= 8) {
736 // Note: windowsSDKIncludeVersion is empty for SDKs prior to v10.
737 // Anyway, llvm::sys::path::append is able to manage it.
738 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
739 "Include", windowsSDKIncludeVersion,
740 "shared");
741 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
742 "Include", windowsSDKIncludeVersion,
743 "um");
744 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
745 "Include", windowsSDKIncludeVersion,
746 "winrt");
747 if (major >= 10) {
748 llvm::VersionTuple Tuple;
749 if (!Tuple.tryParse(windowsSDKIncludeVersion) &&
750 Tuple.getSubminor().value_or(0) >= 17134) {
751 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
752 "Include", windowsSDKIncludeVersion,
753 "cppwinrt");
754 }
755 }
756 } else {
757 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
758 "Include");
759 }
760 }
761
762 return;
763 }
764
765#if defined(_WIN32)
766 // As a fallback, select default install paths.
767 // FIXME: Don't guess drives and paths like this on Windows.
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"
774 };
775 addSystemIncludes(DriverArgs, CC1Args, Paths);
776#endif
777}
778
779void MSVCToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
780 ArgStringList &CC1Args) const {
781 // FIXME: There should probably be logic here to find libc++ on Windows.
782}
783
785 const ArgList &Args) const {
786 bool IsWindowsMSVC = getTriple().isWindowsMSVCEnvironment();
787 VersionTuple MSVT = ToolChain::computeMSVCVersion(D, Args);
788 if (MSVT.empty())
789 MSVT = getTriple().getEnvironmentVersion();
790 if (MSVT.empty() && IsWindowsMSVC)
791 MSVT =
792 getMSVCVersionFromExe(getSubDirectoryPath(llvm::SubDirectoryType::Bin));
793 if (MSVT.empty() &&
794 Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
795 IsWindowsMSVC)) {
796 // -fms-compatibility-version=19.33 is default, aka 2022, 17.3
797 // NOTE: when changing this value, also update
798 // clang/docs/CommandGuide/clang.rst and clang/docs/UsersManual.rst
799 // accordingly.
800 MSVT = VersionTuple(19, 33);
801 }
802 return MSVT;
803}
804
805std::string
807 types::ID InputType) const {
808 // The MSVC version doesn't care about the architecture, even though it
809 // may look at the triple internally.
810 VersionTuple MSVT = computeMSVCVersion(/*D=*/nullptr, Args);
811 MSVT = VersionTuple(MSVT.getMajor(), MSVT.getMinor().value_or(0),
812 MSVT.getSubminor().value_or(0));
813
814 // For the rest of the triple, however, a computed architecture name may
815 // be needed.
816 llvm::Triple Triple(ToolChain::ComputeEffectiveClangTriple(Args, InputType));
817 if (Triple.getEnvironment() == llvm::Triple::MSVC) {
818 StringRef ObjFmt = Triple.getEnvironmentName().split('-').second;
819 if (ObjFmt.empty())
820 Triple.setEnvironmentName((Twine("msvc") + MSVT.getAsString()).str());
821 else
822 Triple.setEnvironmentName(
823 (Twine("msvc") + MSVT.getAsString() + Twine('-') + ObjFmt).str());
824 }
825 return Triple.getTriple();
826}
827
830 Res |= SanitizerKind::Address;
831 Res |= SanitizerKind::PointerCompare;
832 Res |= SanitizerKind::PointerSubtract;
833 Res |= SanitizerKind::Fuzzer;
834 Res |= SanitizerKind::FuzzerNoLink;
835 Res &= ~SanitizerKind::CFIMFCall;
836 return Res;
837}
838
839static void TranslateOptArg(Arg *A, llvm::opt::DerivedArgList &DAL,
840 bool SupportsForcingFramePointer,
841 const char *ExpandChar, const OptTable &Opts) {
842 assert(A->getOption().matches(options::OPT__SLASH_O));
843
844 StringRef OptStr = A->getValue();
845 for (size_t I = 0, E = OptStr.size(); I != E; ++I) {
846 const char &OptChar = *(OptStr.data() + I);
847 switch (OptChar) {
848 default:
849 break;
850 case '1':
851 case '2':
852 case 'x':
853 case 'd':
854 // Ignore /O[12xd] flags that aren't the last one on the command line.
855 // Only the last one gets expanded.
856 if (&OptChar != ExpandChar) {
857 A->claim();
858 break;
859 }
860 if (OptChar == 'd') {
861 DAL.AddFlagArg(A, Opts.getOption(options::OPT_O0));
862 } else {
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");
868 }
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));
874 }
875 break;
876 case 'b':
877 if (I + 1 != E && isdigit(OptStr[I + 1])) {
878 switch (OptStr[I + 1]) {
879 case '0':
880 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_inline));
881 break;
882 case '1':
883 DAL.AddFlagArg(A, Opts.getOption(options::OPT_finline_hint_functions));
884 break;
885 case '2':
886 case '3':
887 DAL.AddFlagArg(A, Opts.getOption(options::OPT_finline_functions));
888 break;
889 }
890 ++I;
891 }
892 break;
893 case 'g':
894 A->claim();
895 break;
896 case 'i':
897 if (I + 1 != E && OptStr[I + 1] == '-') {
898 ++I;
899 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_builtin));
900 } else {
901 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fbuiltin));
902 }
903 break;
904 case 's':
905 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O), "s");
906 break;
907 case 't':
908 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O), "3");
909 break;
910 case 'y': {
911 bool OmitFramePointer = true;
912 if (I + 1 != E && OptStr[I + 1] == '-') {
913 OmitFramePointer = false;
914 ++I;
915 }
916 if (SupportsForcingFramePointer) {
917 if (OmitFramePointer)
918 DAL.AddFlagArg(A,
919 Opts.getOption(options::OPT_fomit_frame_pointer));
920 else
921 DAL.AddFlagArg(
922 A, Opts.getOption(options::OPT_fno_omit_frame_pointer));
923 } else {
924 // Don't warn about /Oy- in x86-64 builds (where
925 // SupportsForcingFramePointer is false). The flag having no effect
926 // there is a compiler-internal optimization, and people shouldn't have
927 // to special-case their build files for x86-64 clang-cl.
928 A->claim();
929 }
930 break;
931 }
932 }
933 }
934}
935
936static void TranslateDArg(Arg *A, llvm::opt::DerivedArgList &DAL,
937 const OptTable &Opts) {
938 assert(A->getOption().matches(options::OPT_D));
939
940 StringRef Val = A->getValue();
941 size_t Hash = Val.find('#');
942 if (Hash == StringRef::npos || Hash > Val.find('=')) {
943 DAL.append(A);
944 return;
945 }
946
947 std::string NewVal = std::string(Val);
948 NewVal[Hash] = '=';
949 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_D), NewVal);
950}
951
952static void TranslatePermissive(Arg *A, llvm::opt::DerivedArgList &DAL,
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));
956}
957
958static void TranslatePermissiveMinus(Arg *A, llvm::opt::DerivedArgList &DAL,
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));
962}
963
964llvm::opt::DerivedArgList *
965MSVCToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
966 StringRef BoundArch,
967 Action::OffloadKind OFK) const {
968 DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
969 const OptTable &Opts = getDriver().getOpts();
970
971 // /Oy and /Oy- don't have an effect on X86-64
972 bool SupportsForcingFramePointer = getArch() != llvm::Triple::x86_64;
973
974 // The -O[12xd] flag actually expands to several flags. We must desugar the
975 // flags so that options embedded can be negated. For example, the '-O2' flag
976 // enables '-Oy'. Expanding '-O2' into its constituent flags allows us to
977 // correctly handle '-O2 -Oy-' where the trailing '-Oy-' disables a single
978 // aspect of '-O2'.
979 //
980 // Note that this expansion logic only applies to the *last* of '[12xd]'.
981
982 // First step is to search for the character we'd like to expand.
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') {
990 // OptChar does not expand; it's an argument to the previous char.
991 continue;
992 }
993 if (OptChar == '1' || OptChar == '2' || OptChar == 'x' || OptChar == 'd')
994 ExpandChar = OptStr.data() + I;
995 }
996 }
997
998 for (Arg *A : Args) {
999 if (A->getOption().matches(options::OPT__SLASH_O)) {
1000 // The -O flag actually takes an amalgam of other options. For example,
1001 // '/Ogyb2' is equivalent to '/Og' '/Oy' '/Ob2'.
1002 TranslateOptArg(A, *DAL, SupportsForcingFramePointer, ExpandChar, Opts);
1003 } else if (A->getOption().matches(options::OPT_D)) {
1004 // Translate -Dfoo#bar into -Dfoo=bar.
1005 TranslateDArg(A, *DAL, Opts);
1006 } else if (A->getOption().matches(options::OPT__SLASH_permissive)) {
1007 // Expand /permissive
1008 TranslatePermissive(A, *DAL, Opts);
1009 } else if (A->getOption().matches(options::OPT__SLASH_permissive_)) {
1010 // Expand /permissive-
1011 TranslatePermissiveMinus(A, *DAL, Opts);
1012 } else if (OFK != Action::OFK_HIP) {
1013 // HIP Toolchain translates input args by itself.
1014 DAL->append(A);
1015 }
1016 }
1017
1018 return DAL;
1019}
1020
1022 const ArgList &DriverArgs, ArgStringList &CC1Args,
1023 Action::OffloadKind DeviceOffloadKind) const {
1024 // MSVC STL kindly allows removing all usages of typeid by defining
1025 // _HAS_STATIC_RTTI to 0. Do so, when compiling with -fno-rtti
1026 if (DriverArgs.hasFlag(options::OPT_fno_rtti, options::OPT_frtti,
1027 /*Default=*/false))
1028 CC1Args.push_back("-D_HAS_STATIC_RTTI=0");
1029
1030 if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_marm64x))
1031 A->ignoreTargetSpecific();
1032}
#define V(N, I)
Definition: ASTContext.h:3443
const Decl * D
IndirectLocalPath & Path
Expr * E
static void TranslatePermissiveMinus(Arg *A, llvm::opt::DerivedArgList &DAL, const OptTable &Opts)
Definition: MSVC.cpp:958
static VersionTuple getMSVCVersionFromExe(const std::string &BinDir)
Definition: MSVC.cpp:598
static bool canExecute(llvm::vfs::FileSystem &VFS, StringRef Path)
Definition: MSVC.cpp:48
static std::string FindVisualStudioExecutable(const ToolChain &TC, const char *Exe)
Definition: MSVC.cpp:59
static void TranslateDArg(Arg *A, llvm::opt::DerivedArgList &DAL, const OptTable &Opts)
Definition: MSVC.cpp:936
static void TranslateOptArg(Arg *A, llvm::opt::DerivedArgList &DAL, bool SupportsForcingFramePointer, const char *ExpandChar, const OptTable &Opts)
Definition: MSVC.cpp:839
static void TranslatePermissive(Arg *A, llvm::opt::DerivedArgList &DAL, const OptTable &Opts)
Definition: MSVC.cpp:952
Defines version macros and version-related utility functions for Clang.
The base class of the type hierarchy.
Definition: Type.h:1828
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:77
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:144
const llvm::opt::OptTable & getOpts() const
Definition: Driver.h:401
@ OMPRT_IOMP5
The legacy name for the LLVM OpenMP runtime from when it was the Intel OpenMP runtime.
Definition: Driver.h:140
@ OMPRT_OMP
The LLVM OpenMP runtime.
Definition: Driver.h:130
@ OMPRT_Unknown
An unknown OpenMP runtime.
Definition: Driver.h:126
@ OMPRT_GOMP
The GNU OpenMP runtime.
Definition: Driver.h:135
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
const char * getFilename() const
Definition: InputInfo.h:83
bool isNothing() const
Definition: InputInfo.h:74
bool isFilename() const
Definition: InputInfo.h:75
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:92
virtual std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args, types::ID InputType=types::TY_INVALID) const
ComputeEffectiveClangTriple - Return the Clang triple to use for this target, which may take into acc...
Definition: ToolChain.cpp:1146
static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory to CC1 arguments.
Definition: ToolChain.cpp:1265
llvm::Triple::ArchType getArch() const
Definition: ToolChain.h:268
const Driver & getDriver() const
Definition: ToolChain.h:252
llvm::vfs::FileSystem & getVFS() const
Definition: ToolChain.cpp:153
path_list & getProgramPaths()
Definition: ToolChain.h:297
const llvm::Triple & getTriple() const
Definition: ToolChain.h:254
static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, ArrayRef< StringRef > Paths)
Utility function to add a list of system include directories to CC1.
Definition: ToolChain.cpp:1295
virtual VersionTuple computeMSVCVersion(const Driver *D, const llvm::opt::ArgList &Args) const
On Windows, returns the MSVC compatibility version.
Definition: ToolChain.cpp:1510
virtual SanitizerMask getSupportedSanitizers() const
Return sanitizers which are available in this toolchain.
Definition: ToolChain.cpp:1456
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
const ToolChain & getToolChain() const
Definition: Tool.h:52
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use system-specific CUDA includes.
Definition: MSVC.cpp:502
SanitizerMask getSupportedSanitizers() const override
Return sanitizers which are available in this toolchain.
Definition: MSVC.cpp:828
Tool * buildLinker() const override
Definition: MSVC.cpp:461
bool getUniversalCRTLibraryPath(const llvm::opt::ArgList &Args, std::string &path) const
Definition: MSVC.cpp:572
UnwindTableLevel getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override
How detailed should the unwind tables be by default.
Definition: MSVC.cpp:473
llvm::opt::DerivedArgList * TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch, Action::OffloadKind DeviceOffloadKind) const override
TranslateArgs - Create a new derived argument list for any argument translations this ToolChain may w...
Definition: MSVC.cpp:965
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition: MSVC.cpp:488
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition: MSVC.cpp:497
VersionTuple computeMSVCVersion(const Driver *D, const llvm::opt::ArgList &Args) const override
On Windows, returns the MSVC compatibility version.
Definition: MSVC.cpp:784
std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args, types::ID InputType) const override
ComputeEffectiveClangTriple - Return the Clang triple to use for this target, which may take into acc...
Definition: MSVC.cpp:806
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
Definition: MSVC.cpp:643
void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set the include paths to use for...
Definition: MSVC.cpp:779
MSVCToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition: MSVC.cpp:430
std::string getSubDirectoryPath(llvm::SubDirectoryType Type, llvm::StringRef SubdirParent="") const
Definition: MSVC.cpp:525
void printVerboseInfo(raw_ostream &OS) const override
Dispatch to the specific toolchain for verbose printing.
Definition: MSVC.cpp:519
bool isPIEDefault(const llvm::opt::ArgList &Args) const override
Test whether this toolchain defaults to PIE.
Definition: MSVC.cpp:493
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const override
Add options that need to be passed to cc1 for this target.
Definition: MSVC.cpp:1021
void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use system-specific HIP includes.
Definition: MSVC.cpp:507
Tool * buildAssembler() const override
Definition: MSVC.cpp:465
void AddHIPRuntimeLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
Add the system specific linker arguments to use for the given HIP runtime library type.
Definition: MSVC.cpp:512
bool getWindowsSDKLibraryPath(const llvm::opt::ArgList &Args, std::string &path) const
Definition: MSVC.cpp:543
void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const std::string &folder, const Twine &subfolder1, const Twine &subfolder2="", const Twine &subfolder3="") const
Definition: MSVC.cpp:634
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs,...
Definition: MSVC.cpp:68
void addHIPRuntimeLibArgs(const ToolChain &TC, Compilation &C, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
void AddRunTimeLibs(const ToolChain &TC, const Driver &D, llvm::opt::ArgStringList &CmdArgs, const llvm::opt::ArgList &Args)
void addFortranRuntimeLibraryPath(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Adds the path for the Fortran runtime libraries to CmdArgs.
void addFortranRuntimeLibs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Adds Fortran runtime libraries to CmdArgs.
The JSON file list parser is used to communicate input to InstallAPI.
static constexpr ResponseFileSupport AtFileUTF16()
Definition: Job.h:99