clang 17.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_nostdlib, options::OPT_nostartfiles) &&
83 !C.getDriver().IsCLMode() && !C.getDriver().IsFlangMode()) {
84 CmdArgs.push_back("-defaultlib:libcmt");
85 CmdArgs.push_back("-defaultlib:oldnames");
86 }
87
88 // If the VC environment hasn't been configured (perhaps because the user
89 // did not run vcvarsall), try to build a consistent link environment. If
90 // the environment variable is set however, assume the user knows what
91 // they're doing. If the user passes /vctoolsdir or /winsdkdir, trust that
92 // over env vars.
93 if (const Arg *A = Args.getLastArg(options::OPT__SLASH_diasdkdir,
94 options::OPT__SLASH_winsysroot)) {
95 // cl.exe doesn't find the DIA SDK automatically, so this too requires
96 // explicit flags and doesn't automatically look in "DIA SDK" relative
97 // to the path we found for VCToolChainPath.
98 llvm::SmallString<128> DIAPath(A->getValue());
99 if (A->getOption().getID() == options::OPT__SLASH_winsysroot)
100 llvm::sys::path::append(DIAPath, "DIA SDK");
101
102 // The DIA SDK always uses the legacy vc arch, even in new MSVC versions.
103 llvm::sys::path::append(DIAPath, "lib",
104 llvm::archToLegacyVCArch(TC.getArch()));
105 CmdArgs.push_back(Args.MakeArgString(Twine("-libpath:") + DIAPath));
106 }
107 if (!llvm::sys::Process::GetEnv("LIB") ||
108 Args.getLastArg(options::OPT__SLASH_vctoolsdir,
109 options::OPT__SLASH_winsysroot)) {
110 CmdArgs.push_back(Args.MakeArgString(
111 Twine("-libpath:") +
112 TC.getSubDirectoryPath(llvm::SubDirectoryType::Lib)));
113 CmdArgs.push_back(Args.MakeArgString(
114 Twine("-libpath:") +
115 TC.getSubDirectoryPath(llvm::SubDirectoryType::Lib, "atlmfc")));
116 }
117 if (!llvm::sys::Process::GetEnv("LIB") ||
118 Args.getLastArg(options::OPT__SLASH_winsdkdir,
119 options::OPT__SLASH_winsysroot)) {
120 if (TC.useUniversalCRT()) {
121 std::string UniversalCRTLibPath;
122 if (TC.getUniversalCRTLibraryPath(Args, UniversalCRTLibPath))
123 CmdArgs.push_back(
124 Args.MakeArgString(Twine("-libpath:") + UniversalCRTLibPath));
125 }
126 std::string WindowsSdkLibPath;
127 if (TC.getWindowsSDKLibraryPath(Args, WindowsSdkLibPath))
128 CmdArgs.push_back(
129 Args.MakeArgString(std::string("-libpath:") + WindowsSdkLibPath));
130 }
131
132 if (C.getDriver().IsFlangMode()) {
133 addFortranRuntimeLibraryPath(TC, Args, CmdArgs);
134 addFortranRuntimeLibs(TC, CmdArgs);
135
136 // Inform the MSVC linker that we're generating a console application, i.e.
137 // one with `main` as the "user-defined" entry point. The `main` function is
138 // defined in flang's runtime libraries.
139 CmdArgs.push_back("/subsystem:console");
140 }
141
142 // Add the compiler-rt library directories to libpath if they exist to help
143 // the linker find the various sanitizer, builtin, and profiling runtimes.
144 for (const auto &LibPath : TC.getLibraryPaths()) {
145 if (TC.getVFS().exists(LibPath))
146 CmdArgs.push_back(Args.MakeArgString("-libpath:" + LibPath));
147 }
148 auto CRTPath = TC.getCompilerRTPath();
149 if (TC.getVFS().exists(CRTPath))
150 CmdArgs.push_back(Args.MakeArgString("-libpath:" + CRTPath));
151
152 if (!C.getDriver().IsCLMode() && Args.hasArg(options::OPT_L))
153 for (const auto &LibPath : Args.getAllArgValues(options::OPT_L))
154 CmdArgs.push_back(Args.MakeArgString("-libpath:" + LibPath));
155
156 CmdArgs.push_back("-nologo");
157
158 if (Args.hasArg(options::OPT_g_Group, options::OPT__SLASH_Z7))
159 CmdArgs.push_back("-debug");
160
161 // If we specify /hotpatch, let the linker add padding in front of each
162 // function, like MSVC does.
163 if (Args.hasArg(options::OPT_fms_hotpatch, options::OPT__SLASH_hotpatch))
164 CmdArgs.push_back("-functionpadmin");
165
166 // Pass on /Brepro if it was passed to the compiler.
167 // Note that /Brepro maps to -mno-incremental-linker-compatible.
168 bool DefaultIncrementalLinkerCompatible =
169 C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment();
170 if (!Args.hasFlag(options::OPT_mincremental_linker_compatible,
171 options::OPT_mno_incremental_linker_compatible,
172 DefaultIncrementalLinkerCompatible))
173 CmdArgs.push_back("-Brepro");
174
175 bool DLL = Args.hasArg(options::OPT__SLASH_LD, options::OPT__SLASH_LDd,
176 options::OPT_shared);
177 if (DLL) {
178 CmdArgs.push_back(Args.MakeArgString("-dll"));
179
180 SmallString<128> ImplibName(Output.getFilename());
181 llvm::sys::path::replace_extension(ImplibName, "lib");
182 CmdArgs.push_back(Args.MakeArgString(std::string("-implib:") + ImplibName));
183 }
184
185 if (TC.getSanitizerArgs(Args).needsFuzzer()) {
186 if (!Args.hasArg(options::OPT_shared))
187 CmdArgs.push_back(
188 Args.MakeArgString(std::string("-wholearchive:") +
189 TC.getCompilerRTArgString(Args, "fuzzer")));
190 CmdArgs.push_back(Args.MakeArgString("-debug"));
191 // Prevent the linker from padding sections we use for instrumentation
192 // arrays.
193 CmdArgs.push_back(Args.MakeArgString("-incremental:no"));
194 }
195
196 if (TC.getSanitizerArgs(Args).needsAsanRt()) {
197 CmdArgs.push_back(Args.MakeArgString("-debug"));
198 CmdArgs.push_back(Args.MakeArgString("-incremental:no"));
199 if (TC.getSanitizerArgs(Args).needsSharedRt() ||
200 Args.hasArg(options::OPT__SLASH_MD, options::OPT__SLASH_MDd)) {
201 for (const auto &Lib : {"asan_dynamic", "asan_dynamic_runtime_thunk"})
202 CmdArgs.push_back(TC.getCompilerRTArgString(Args, Lib));
203 // Make sure the dynamic runtime thunk is not optimized out at link time
204 // to ensure proper SEH handling.
205 CmdArgs.push_back(Args.MakeArgString(
206 TC.getArch() == llvm::Triple::x86
207 ? "-include:___asan_seh_interceptor"
208 : "-include:__asan_seh_interceptor"));
209 // Make sure the linker consider all object files from the dynamic runtime
210 // thunk.
211 CmdArgs.push_back(Args.MakeArgString(std::string("-wholearchive:") +
212 TC.getCompilerRT(Args, "asan_dynamic_runtime_thunk")));
213 } else if (DLL) {
214 CmdArgs.push_back(TC.getCompilerRTArgString(Args, "asan_dll_thunk"));
215 } else {
216 for (const auto &Lib : {"asan", "asan_cxx"}) {
217 CmdArgs.push_back(TC.getCompilerRTArgString(Args, Lib));
218 // Make sure the linker consider all object files from the static lib.
219 // This is necessary because instrumented dlls need access to all the
220 // interface exported by the static lib in the main executable.
221 CmdArgs.push_back(Args.MakeArgString(std::string("-wholearchive:") +
222 TC.getCompilerRT(Args, Lib)));
223 }
224 }
225 }
226
227 Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
228
229 // Control Flow Guard checks
230 if (Arg *A = Args.getLastArg(options::OPT__SLASH_guard)) {
231 StringRef GuardArgs = A->getValue();
232 if (GuardArgs.equals_insensitive("cf") ||
233 GuardArgs.equals_insensitive("cf,nochecks")) {
234 // MSVC doesn't yet support the "nochecks" modifier.
235 CmdArgs.push_back("-guard:cf");
236 } else if (GuardArgs.equals_insensitive("cf-")) {
237 CmdArgs.push_back("-guard:cf-");
238 } else if (GuardArgs.equals_insensitive("ehcont")) {
239 CmdArgs.push_back("-guard:ehcont");
240 } else if (GuardArgs.equals_insensitive("ehcont-")) {
241 CmdArgs.push_back("-guard:ehcont-");
242 }
243 }
244
245 if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
246 options::OPT_fno_openmp, false)) {
247 CmdArgs.push_back("-nodefaultlib:vcomp.lib");
248 CmdArgs.push_back("-nodefaultlib:vcompd.lib");
249 CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") +
250 TC.getDriver().Dir + "/../lib"));
251 switch (TC.getDriver().getOpenMPRuntime(Args)) {
253 CmdArgs.push_back("-defaultlib:libomp.lib");
254 break;
256 CmdArgs.push_back("-defaultlib:libiomp5md.lib");
257 break;
259 break;
261 // Already diagnosed.
262 break;
263 }
264 }
265
266 // Add compiler-rt lib in case if it was explicitly
267 // specified as an argument for --rtlib option.
268 if (!Args.hasArg(options::OPT_nostdlib)) {
269 AddRunTimeLibs(TC, TC.getDriver(), CmdArgs, Args);
270 }
271
272 // Add filenames, libraries, and other linker inputs.
273 for (const auto &Input : Inputs) {
274 if (Input.isFilename()) {
275 CmdArgs.push_back(Input.getFilename());
276 continue;
277 }
278
279 const Arg &A = Input.getInputArg();
280
281 // Render -l options differently for the MSVC linker.
282 if (A.getOption().matches(options::OPT_l)) {
283 StringRef Lib = A.getValue();
284 const char *LinkLibArg;
285 if (Lib.endswith(".lib"))
286 LinkLibArg = Args.MakeArgString(Lib);
287 else
288 LinkLibArg = Args.MakeArgString(Lib + ".lib");
289 CmdArgs.push_back(LinkLibArg);
290 continue;
291 }
292
293 // Otherwise, this is some other kind of linker input option like -Wl, -z,
294 // or -L. Render it, even if MSVC doesn't understand it.
295 A.renderAsInput(Args, CmdArgs);
296 }
297
298 addHIPRuntimeLibArgs(TC, Args, CmdArgs);
299
300 TC.addProfileRTLibs(Args, CmdArgs);
301
302 std::vector<const char *> Environment;
303
304 // We need to special case some linker paths. In the case of lld, we need to
305 // translate 'lld' into 'lld-link', and in the case of the regular msvc
306 // linker, we need to use a special search algorithm.
307 llvm::SmallString<128> linkPath;
308 StringRef Linker
309 = Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER);
310 if (Linker.empty())
311 Linker = "link";
312 if (Linker.equals_insensitive("lld"))
313 Linker = "lld-link";
314
315 if (Linker == "lld-link")
316 for (Arg *A : Args.filtered(options::OPT_vfsoverlay))
317 CmdArgs.push_back(
318 Args.MakeArgString(std::string("/vfsoverlay:") + A->getValue()));
319
320 if (Linker.equals_insensitive("link")) {
321 // If we're using the MSVC linker, it's not sufficient to just use link
322 // from the program PATH, because other environments like GnuWin32 install
323 // their own link.exe which may come first.
324 linkPath = FindVisualStudioExecutable(TC, "link.exe");
325
326 if (!TC.FoundMSVCInstall() && !canExecute(TC.getVFS(), linkPath)) {
328 ClPath = TC.GetProgramPath("cl.exe");
329 if (canExecute(TC.getVFS(), ClPath)) {
330 linkPath = llvm::sys::path::parent_path(ClPath);
331 llvm::sys::path::append(linkPath, "link.exe");
332 if (!canExecute(TC.getVFS(), linkPath))
333 C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
334 } else {
335 C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
336 }
337 }
338
339 // Clang handles passing the proper asan libs to the linker, which goes
340 // against link.exe's /INFERASANLIBS which automatically finds asan libs.
341 if (TC.getSanitizerArgs(Args).needsAsanRt())
342 CmdArgs.push_back("/INFERASANLIBS:NO");
343
344#ifdef _WIN32
345 // When cross-compiling with VS2017 or newer, link.exe expects to have
346 // its containing bin directory at the top of PATH, followed by the
347 // native target bin directory.
348 // e.g. when compiling for x86 on an x64 host, PATH should start with:
349 // /bin/Hostx64/x86;/bin/Hostx64/x64
350 // This doesn't attempt to handle llvm::ToolsetLayout::DevDivInternal.
351 if (TC.getIsVS2017OrNewer() &&
352 llvm::Triple(llvm::sys::getProcessTriple()).getArch() != TC.getArch()) {
353 auto HostArch = llvm::Triple(llvm::sys::getProcessTriple()).getArch();
354
355 auto EnvBlockWide =
356 std::unique_ptr<wchar_t[], decltype(&FreeEnvironmentStringsW)>(
357 GetEnvironmentStringsW(), FreeEnvironmentStringsW);
358 if (!EnvBlockWide)
359 goto SkipSettingEnvironment;
360
361 size_t EnvCount = 0;
362 size_t EnvBlockLen = 0;
363 while (EnvBlockWide[EnvBlockLen] != L'\0') {
364 ++EnvCount;
365 EnvBlockLen += std::wcslen(&EnvBlockWide[EnvBlockLen]) +
366 1 /*string null-terminator*/;
367 }
368 ++EnvBlockLen; // add the block null-terminator
369
370 std::string EnvBlock;
371 if (!llvm::convertUTF16ToUTF8String(
372 llvm::ArrayRef<char>(reinterpret_cast<char *>(EnvBlockWide.get()),
373 EnvBlockLen * sizeof(EnvBlockWide[0])),
374 EnvBlock))
375 goto SkipSettingEnvironment;
376
377 Environment.reserve(EnvCount);
378
379 // Now loop over each string in the block and copy them into the
380 // environment vector, adjusting the PATH variable as needed when we
381 // find it.
382 for (const char *Cursor = EnvBlock.data(); *Cursor != '\0';) {
383 llvm::StringRef EnvVar(Cursor);
384 if (EnvVar.startswith_insensitive("path=")) {
385 constexpr size_t PrefixLen = 5; // strlen("path=")
386 Environment.push_back(Args.MakeArgString(
387 EnvVar.substr(0, PrefixLen) +
388 TC.getSubDirectoryPath(llvm::SubDirectoryType::Bin) +
389 llvm::Twine(llvm::sys::EnvPathSeparator) +
390 TC.getSubDirectoryPath(llvm::SubDirectoryType::Bin, HostArch) +
391 (EnvVar.size() > PrefixLen
392 ? llvm::Twine(llvm::sys::EnvPathSeparator) +
393 EnvVar.substr(PrefixLen)
394 : "")));
395 } else {
396 Environment.push_back(Args.MakeArgString(EnvVar));
397 }
398 Cursor += EnvVar.size() + 1 /*null-terminator*/;
399 }
400 }
401 SkipSettingEnvironment:;
402#endif
403 } else {
404 linkPath = TC.GetProgramPath(Linker.str().c_str());
405 }
406
407 auto LinkCmd = std::make_unique<Command>(
409 Args.MakeArgString(linkPath), CmdArgs, Inputs, Output);
410 if (!Environment.empty())
411 LinkCmd->setEnvironment(Environment);
412 C.addCommand(std::move(LinkCmd));
413}
414
415MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
416 const ArgList &Args)
417 : ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args),
418 RocmInstallation(D, Triple, Args) {
419 getProgramPaths().push_back(getDriver().getInstalledDir());
420 if (getDriver().getInstalledDir() != getDriver().Dir)
421 getProgramPaths().push_back(getDriver().Dir);
422
423 std::optional<llvm::StringRef> VCToolsDir, VCToolsVersion;
424 if (Arg *A = Args.getLastArg(options::OPT__SLASH_vctoolsdir))
425 VCToolsDir = A->getValue();
426 if (Arg *A = Args.getLastArg(options::OPT__SLASH_vctoolsversion))
427 VCToolsVersion = A->getValue();
428 if (Arg *A = Args.getLastArg(options::OPT__SLASH_winsdkdir))
429 WinSdkDir = A->getValue();
430 if (Arg *A = Args.getLastArg(options::OPT__SLASH_winsdkversion))
431 WinSdkVersion = A->getValue();
432 if (Arg *A = Args.getLastArg(options::OPT__SLASH_winsysroot))
433 WinSysRoot = A->getValue();
434
435 // Check the command line first, that's the user explicitly telling us what to
436 // use. Check the environment next, in case we're being invoked from a VS
437 // command prompt. Failing that, just try to find the newest Visual Studio
438 // version we can and use its default VC toolchain.
439 llvm::findVCToolChainViaCommandLine(getVFS(), VCToolsDir, VCToolsVersion,
440 WinSysRoot, VCToolChainPath, VSLayout) ||
441 llvm::findVCToolChainViaEnvironment(getVFS(), VCToolChainPath,
442 VSLayout) ||
443 llvm::findVCToolChainViaSetupConfig(getVFS(), VCToolsVersion,
444 VCToolChainPath, VSLayout) ||
445 llvm::findVCToolChainViaRegistry(VCToolChainPath, VSLayout);
446}
447
449 return new tools::visualstudio::Linker(*this);
450}
451
453 if (getTriple().isOSBinFormatMachO())
454 return new tools::darwin::Assembler(*this);
455 getDriver().Diag(clang::diag::err_no_external_assembler);
456 return nullptr;
457}
458
460 return true;
461}
462
465 // Don't emit unwind tables by default for MachO targets.
466 if (getTriple().isOSBinFormatMachO())
468
469 // All non-x86_32 Windows targets require unwind tables. However, LLVM
470 // doesn't know how to generate them for all targets, so only enable
471 // the ones that are actually implemented.
472 if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::arm ||
473 getArch() == llvm::Triple::thumb || getArch() == llvm::Triple::aarch64)
475
477}
478
480 return getArch() == llvm::Triple::x86_64 ||
481 getArch() == llvm::Triple::aarch64;
482}
483
484bool MSVCToolChain::isPIEDefault(const llvm::opt::ArgList &Args) const {
485 return false;
486}
487
489 return getArch() == llvm::Triple::x86_64 ||
490 getArch() == llvm::Triple::aarch64;
491}
492
493void MSVCToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
494 ArgStringList &CC1Args) const {
495 CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
496}
497
498void MSVCToolChain::AddHIPIncludeArgs(const ArgList &DriverArgs,
499 ArgStringList &CC1Args) const {
500 RocmInstallation.AddHIPIncludeArgs(DriverArgs, CC1Args);
501}
502
503void MSVCToolChain::AddHIPRuntimeLibArgs(const ArgList &Args,
504 ArgStringList &CmdArgs) const {
505 CmdArgs.append({Args.MakeArgString(StringRef("-libpath:") +
506 RocmInstallation.getLibPath()),
507 "amdhip64.lib"});
508}
509
510void MSVCToolChain::printVerboseInfo(raw_ostream &OS) const {
511 CudaInstallation.print(OS);
512 RocmInstallation.print(OS);
513}
514
515std::string
517 llvm::StringRef SubdirParent) const {
518 return llvm::getSubDirectoryPath(Type, VSLayout, VCToolChainPath, getArch(),
519 SubdirParent);
520}
521
522std::string
524 llvm::Triple::ArchType TargetArch) const {
525 return llvm::getSubDirectoryPath(Type, VSLayout, VCToolChainPath, TargetArch,
526 "");
527}
528
529// Find the most recent version of Universal CRT or Windows 10 SDK.
530// vcvarsqueryregistry.bat from Visual Studio 2015 sorts entries in the include
531// directory by name and uses the last one of the list.
532// So we compare entry names lexicographically to find the greatest one.
533// Gets the library path required to link against the Windows SDK.
535 std::string &path) const {
536 std::string sdkPath;
537 int sdkMajor = 0;
538 std::string windowsSDKIncludeVersion;
539 std::string windowsSDKLibVersion;
540
541 path.clear();
542 if (!llvm::getWindowsSDKDir(getVFS(), WinSdkDir, WinSdkVersion, WinSysRoot,
543 sdkPath, sdkMajor, windowsSDKIncludeVersion,
544 windowsSDKLibVersion))
545 return false;
546
547 llvm::SmallString<128> libPath(sdkPath);
548 llvm::sys::path::append(libPath, "Lib");
549 if (sdkMajor >= 10)
550 if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
551 WinSdkVersion.has_value())
552 windowsSDKLibVersion = *WinSdkVersion;
553 if (sdkMajor >= 8)
554 llvm::sys::path::append(libPath, windowsSDKLibVersion, "um");
555 return llvm::appendArchToWindowsSDKLibPath(sdkMajor, libPath, getArch(),
556 path);
557}
558
560 return llvm::useUniversalCRT(VSLayout, VCToolChainPath, getArch(), getVFS());
561}
562
564 std::string &Path) const {
565 std::string UniversalCRTSdkPath;
566 std::string UCRTVersion;
567
568 Path.clear();
569 if (!llvm::getUniversalCRTSdkDir(getVFS(), WinSdkDir, WinSdkVersion,
570 WinSysRoot, UniversalCRTSdkPath,
571 UCRTVersion))
572 return false;
573
574 if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
575 WinSdkVersion.has_value())
576 UCRTVersion = *WinSdkVersion;
577
578 StringRef ArchName = llvm::archToWindowsSDKArch(getArch());
579 if (ArchName.empty())
580 return false;
581
582 llvm::SmallString<128> LibPath(UniversalCRTSdkPath);
583 llvm::sys::path::append(LibPath, "Lib", UCRTVersion, "ucrt", ArchName);
584
585 Path = std::string(LibPath.str());
586 return true;
587}
588
589static VersionTuple getMSVCVersionFromExe(const std::string &BinDir) {
590 VersionTuple Version;
591#ifdef _WIN32
592 SmallString<128> ClExe(BinDir);
593 llvm::sys::path::append(ClExe, "cl.exe");
594
595 std::wstring ClExeWide;
596 if (!llvm::ConvertUTF8toWide(ClExe.c_str(), ClExeWide))
597 return Version;
598
599 const DWORD VersionSize = ::GetFileVersionInfoSizeW(ClExeWide.c_str(),
600 nullptr);
601 if (VersionSize == 0)
602 return Version;
603
604 SmallVector<uint8_t, 4 * 1024> VersionBlock(VersionSize);
605 if (!::GetFileVersionInfoW(ClExeWide.c_str(), 0, VersionSize,
606 VersionBlock.data()))
607 return Version;
608
609 VS_FIXEDFILEINFO *FileInfo = nullptr;
610 UINT FileInfoSize = 0;
611 if (!::VerQueryValueW(VersionBlock.data(), L"\\",
612 reinterpret_cast<LPVOID *>(&FileInfo), &FileInfoSize) ||
613 FileInfoSize < sizeof(*FileInfo))
614 return Version;
615
616 const unsigned Major = (FileInfo->dwFileVersionMS >> 16) & 0xFFFF;
617 const unsigned Minor = (FileInfo->dwFileVersionMS ) & 0xFFFF;
618 const unsigned Micro = (FileInfo->dwFileVersionLS >> 16) & 0xFFFF;
619
620 Version = VersionTuple(Major, Minor, Micro);
621#endif
622 return Version;
623}
624
626 const ArgList &DriverArgs, ArgStringList &CC1Args,
627 const std::string &folder, const Twine &subfolder1, const Twine &subfolder2,
628 const Twine &subfolder3) const {
629 llvm::SmallString<128> path(folder);
630 llvm::sys::path::append(path, subfolder1, subfolder2, subfolder3);
631 addSystemInclude(DriverArgs, CC1Args, path);
632}
633
634void MSVCToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
635 ArgStringList &CC1Args) const {
636 if (DriverArgs.hasArg(options::OPT_nostdinc))
637 return;
638
639 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
640 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, getDriver().ResourceDir,
641 "include");
642 }
643
644 // Add %INCLUDE%-like directories from the -imsvc flag.
645 for (const auto &Path : DriverArgs.getAllArgValues(options::OPT__SLASH_imsvc))
646 addSystemInclude(DriverArgs, CC1Args, Path);
647
648 auto AddSystemIncludesFromEnv = [&](StringRef Var) -> bool {
649 if (auto Val = llvm::sys::Process::GetEnv(Var)) {
651 StringRef(*Val).split(Dirs, ";", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
652 if (!Dirs.empty()) {
653 addSystemIncludes(DriverArgs, CC1Args, Dirs);
654 return true;
655 }
656 }
657 return false;
658 };
659
660 // Add %INCLUDE%-like dirs via /external:env: flags.
661 for (const auto &Var :
662 DriverArgs.getAllArgValues(options::OPT__SLASH_external_env)) {
663 AddSystemIncludesFromEnv(Var);
664 }
665
666 // Add DIA SDK include if requested.
667 if (const Arg *A = DriverArgs.getLastArg(options::OPT__SLASH_diasdkdir,
668 options::OPT__SLASH_winsysroot)) {
669 // cl.exe doesn't find the DIA SDK automatically, so this too requires
670 // explicit flags and doesn't automatically look in "DIA SDK" relative
671 // to the path we found for VCToolChainPath.
672 llvm::SmallString<128> DIASDKPath(A->getValue());
673 if (A->getOption().getID() == options::OPT__SLASH_winsysroot)
674 llvm::sys::path::append(DIASDKPath, "DIA SDK");
675 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, std::string(DIASDKPath),
676 "include");
677 }
678
679 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
680 return;
681
682 // Honor %INCLUDE% and %EXTERNAL_INCLUDE%. It should have essential search
683 // paths set by vcvarsall.bat. Skip if the user expressly set a vctoolsdir.
684 if (!DriverArgs.getLastArg(options::OPT__SLASH_vctoolsdir,
685 options::OPT__SLASH_winsysroot)) {
686 bool Found = AddSystemIncludesFromEnv("INCLUDE");
687 Found |= AddSystemIncludesFromEnv("EXTERNAL_INCLUDE");
688 if (Found)
689 return;
690 }
691
692 // When built with access to the proper Windows APIs, try to actually find
693 // the correct include paths first.
694 if (!VCToolChainPath.empty()) {
695 addSystemInclude(DriverArgs, CC1Args,
696 getSubDirectoryPath(llvm::SubDirectoryType::Include));
698 DriverArgs, CC1Args,
699 getSubDirectoryPath(llvm::SubDirectoryType::Include, "atlmfc"));
700
701 if (useUniversalCRT()) {
702 std::string UniversalCRTSdkPath;
703 std::string UCRTVersion;
704 if (llvm::getUniversalCRTSdkDir(getVFS(), WinSdkDir, WinSdkVersion,
705 WinSysRoot, UniversalCRTSdkPath,
706 UCRTVersion)) {
707 if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
708 WinSdkVersion.has_value())
709 UCRTVersion = *WinSdkVersion;
710 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, UniversalCRTSdkPath,
711 "Include", UCRTVersion, "ucrt");
712 }
713 }
714
715 std::string WindowsSDKDir;
716 int major = 0;
717 std::string windowsSDKIncludeVersion;
718 std::string windowsSDKLibVersion;
719 if (llvm::getWindowsSDKDir(getVFS(), WinSdkDir, WinSdkVersion, WinSysRoot,
720 WindowsSDKDir, major, windowsSDKIncludeVersion,
721 windowsSDKLibVersion)) {
722 if (major >= 10)
723 if (!(WinSdkDir.has_value() || WinSysRoot.has_value()) &&
724 WinSdkVersion.has_value())
725 windowsSDKIncludeVersion = windowsSDKLibVersion = *WinSdkVersion;
726 if (major >= 8) {
727 // Note: windowsSDKIncludeVersion is empty for SDKs prior to v10.
728 // Anyway, llvm::sys::path::append is able to manage it.
729 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
730 "Include", windowsSDKIncludeVersion,
731 "shared");
732 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
733 "Include", windowsSDKIncludeVersion,
734 "um");
735 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
736 "Include", windowsSDKIncludeVersion,
737 "winrt");
738 if (major >= 10) {
739 llvm::VersionTuple Tuple;
740 if (!Tuple.tryParse(windowsSDKIncludeVersion) &&
741 Tuple.getSubminor().value_or(0) >= 17134) {
742 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
743 "Include", windowsSDKIncludeVersion,
744 "cppwinrt");
745 }
746 }
747 } else {
748 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
749 "Include");
750 }
751 }
752
753 return;
754 }
755
756#if defined(_WIN32)
757 // As a fallback, select default install paths.
758 // FIXME: Don't guess drives and paths like this on Windows.
759 const StringRef Paths[] = {
760 "C:/Program Files/Microsoft Visual Studio 10.0/VC/include",
761 "C:/Program Files/Microsoft Visual Studio 9.0/VC/include",
762 "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include",
763 "C:/Program Files/Microsoft Visual Studio 8/VC/include",
764 "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include"
765 };
766 addSystemIncludes(DriverArgs, CC1Args, Paths);
767#endif
768}
769
770void MSVCToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
771 ArgStringList &CC1Args) const {
772 // FIXME: There should probably be logic here to find libc++ on Windows.
773}
774
776 const ArgList &Args) const {
777 bool IsWindowsMSVC = getTriple().isWindowsMSVCEnvironment();
778 VersionTuple MSVT = ToolChain::computeMSVCVersion(D, Args);
779 if (MSVT.empty())
780 MSVT = getTriple().getEnvironmentVersion();
781 if (MSVT.empty() && IsWindowsMSVC)
782 MSVT =
783 getMSVCVersionFromExe(getSubDirectoryPath(llvm::SubDirectoryType::Bin));
784 if (MSVT.empty() &&
785 Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
786 IsWindowsMSVC)) {
787 // -fms-compatibility-version=19.20 is default, aka 2019, 16.x
788 MSVT = VersionTuple(19, 20);
789 }
790 return MSVT;
791}
792
793std::string
795 types::ID InputType) const {
796 // The MSVC version doesn't care about the architecture, even though it
797 // may look at the triple internally.
798 VersionTuple MSVT = computeMSVCVersion(/*D=*/nullptr, Args);
799 MSVT = VersionTuple(MSVT.getMajor(), MSVT.getMinor().value_or(0),
800 MSVT.getSubminor().value_or(0));
801
802 // For the rest of the triple, however, a computed architecture name may
803 // be needed.
804 llvm::Triple Triple(ToolChain::ComputeEffectiveClangTriple(Args, InputType));
805 if (Triple.getEnvironment() == llvm::Triple::MSVC) {
806 StringRef ObjFmt = Triple.getEnvironmentName().split('-').second;
807 if (ObjFmt.empty())
808 Triple.setEnvironmentName((Twine("msvc") + MSVT.getAsString()).str());
809 else
810 Triple.setEnvironmentName(
811 (Twine("msvc") + MSVT.getAsString() + Twine('-') + ObjFmt).str());
812 }
813 return Triple.getTriple();
814}
815
818 Res |= SanitizerKind::Address;
819 Res |= SanitizerKind::PointerCompare;
820 Res |= SanitizerKind::PointerSubtract;
821 Res |= SanitizerKind::Fuzzer;
822 Res |= SanitizerKind::FuzzerNoLink;
823 Res &= ~SanitizerKind::CFIMFCall;
824 return Res;
825}
826
827static void TranslateOptArg(Arg *A, llvm::opt::DerivedArgList &DAL,
828 bool SupportsForcingFramePointer,
829 const char *ExpandChar, const OptTable &Opts) {
830 assert(A->getOption().matches(options::OPT__SLASH_O));
831
832 StringRef OptStr = A->getValue();
833 for (size_t I = 0, E = OptStr.size(); I != E; ++I) {
834 const char &OptChar = *(OptStr.data() + I);
835 switch (OptChar) {
836 default:
837 break;
838 case '1':
839 case '2':
840 case 'x':
841 case 'd':
842 // Ignore /O[12xd] flags that aren't the last one on the command line.
843 // Only the last one gets expanded.
844 if (&OptChar != ExpandChar) {
845 A->claim();
846 break;
847 }
848 if (OptChar == 'd') {
849 DAL.AddFlagArg(A, Opts.getOption(options::OPT_O0));
850 } else {
851 if (OptChar == '1') {
852 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O), "s");
853 } else if (OptChar == '2' || OptChar == 'x') {
854 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fbuiltin));
855 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O), "2");
856 }
857 if (SupportsForcingFramePointer &&
858 !DAL.hasArgNoClaim(options::OPT_fno_omit_frame_pointer))
859 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fomit_frame_pointer));
860 if (OptChar == '1' || OptChar == '2')
861 DAL.AddFlagArg(A, Opts.getOption(options::OPT_ffunction_sections));
862 }
863 break;
864 case 'b':
865 if (I + 1 != E && isdigit(OptStr[I + 1])) {
866 switch (OptStr[I + 1]) {
867 case '0':
868 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_inline));
869 break;
870 case '1':
871 DAL.AddFlagArg(A, Opts.getOption(options::OPT_finline_hint_functions));
872 break;
873 case '2':
874 DAL.AddFlagArg(A, Opts.getOption(options::OPT_finline_functions));
875 break;
876 }
877 ++I;
878 }
879 break;
880 case 'g':
881 A->claim();
882 break;
883 case 'i':
884 if (I + 1 != E && OptStr[I + 1] == '-') {
885 ++I;
886 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_builtin));
887 } else {
888 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fbuiltin));
889 }
890 break;
891 case 's':
892 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O), "s");
893 break;
894 case 't':
895 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O), "2");
896 break;
897 case 'y': {
898 bool OmitFramePointer = true;
899 if (I + 1 != E && OptStr[I + 1] == '-') {
900 OmitFramePointer = false;
901 ++I;
902 }
903 if (SupportsForcingFramePointer) {
904 if (OmitFramePointer)
905 DAL.AddFlagArg(A,
906 Opts.getOption(options::OPT_fomit_frame_pointer));
907 else
908 DAL.AddFlagArg(
909 A, Opts.getOption(options::OPT_fno_omit_frame_pointer));
910 } else {
911 // Don't warn about /Oy- in x86-64 builds (where
912 // SupportsForcingFramePointer is false). The flag having no effect
913 // there is a compiler-internal optimization, and people shouldn't have
914 // to special-case their build files for x86-64 clang-cl.
915 A->claim();
916 }
917 break;
918 }
919 }
920 }
921}
922
923static void TranslateDArg(Arg *A, llvm::opt::DerivedArgList &DAL,
924 const OptTable &Opts) {
925 assert(A->getOption().matches(options::OPT_D));
926
927 StringRef Val = A->getValue();
928 size_t Hash = Val.find('#');
929 if (Hash == StringRef::npos || Hash > Val.find('=')) {
930 DAL.append(A);
931 return;
932 }
933
934 std::string NewVal = std::string(Val);
935 NewVal[Hash] = '=';
936 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_D), NewVal);
937}
938
939static void TranslatePermissive(Arg *A, llvm::opt::DerivedArgList &DAL,
940 const OptTable &Opts) {
941 DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_twoPhase_));
942 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_operator_names));
943}
944
945static void TranslatePermissiveMinus(Arg *A, llvm::opt::DerivedArgList &DAL,
946 const OptTable &Opts) {
947 DAL.AddFlagArg(A, Opts.getOption(options::OPT__SLASH_Zc_twoPhase));
948 DAL.AddFlagArg(A, Opts.getOption(options::OPT_foperator_names));
949}
950
951llvm::opt::DerivedArgList *
952MSVCToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
953 StringRef BoundArch,
954 Action::OffloadKind OFK) const {
955 DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
956 const OptTable &Opts = getDriver().getOpts();
957
958 // /Oy and /Oy- don't have an effect on X86-64
959 bool SupportsForcingFramePointer = getArch() != llvm::Triple::x86_64;
960
961 // The -O[12xd] flag actually expands to several flags. We must desugar the
962 // flags so that options embedded can be negated. For example, the '-O2' flag
963 // enables '-Oy'. Expanding '-O2' into its constituent flags allows us to
964 // correctly handle '-O2 -Oy-' where the trailing '-Oy-' disables a single
965 // aspect of '-O2'.
966 //
967 // Note that this expansion logic only applies to the *last* of '[12xd]'.
968
969 // First step is to search for the character we'd like to expand.
970 const char *ExpandChar = nullptr;
971 for (Arg *A : Args.filtered(options::OPT__SLASH_O)) {
972 StringRef OptStr = A->getValue();
973 for (size_t I = 0, E = OptStr.size(); I != E; ++I) {
974 char OptChar = OptStr[I];
975 char PrevChar = I > 0 ? OptStr[I - 1] : '0';
976 if (PrevChar == 'b') {
977 // OptChar does not expand; it's an argument to the previous char.
978 continue;
979 }
980 if (OptChar == '1' || OptChar == '2' || OptChar == 'x' || OptChar == 'd')
981 ExpandChar = OptStr.data() + I;
982 }
983 }
984
985 for (Arg *A : Args) {
986 if (A->getOption().matches(options::OPT__SLASH_O)) {
987 // The -O flag actually takes an amalgam of other options. For example,
988 // '/Ogyb2' is equivalent to '/Og' '/Oy' '/Ob2'.
989 TranslateOptArg(A, *DAL, SupportsForcingFramePointer, ExpandChar, Opts);
990 } else if (A->getOption().matches(options::OPT_D)) {
991 // Translate -Dfoo#bar into -Dfoo=bar.
992 TranslateDArg(A, *DAL, Opts);
993 } else if (A->getOption().matches(options::OPT__SLASH_permissive)) {
994 // Expand /permissive
995 TranslatePermissive(A, *DAL, Opts);
996 } else if (A->getOption().matches(options::OPT__SLASH_permissive_)) {
997 // Expand /permissive-
998 TranslatePermissiveMinus(A, *DAL, Opts);
999 } else if (OFK != Action::OFK_HIP) {
1000 // HIP Toolchain translates input args by itself.
1001 DAL->append(A);
1002 }
1003 }
1004
1005 return DAL;
1006}
1007
1009 const ArgList &DriverArgs, ArgStringList &CC1Args,
1010 Action::OffloadKind DeviceOffloadKind) const {
1011 // MSVC STL kindly allows removing all usages of typeid by defining
1012 // _HAS_STATIC_RTTI to 0. Do so, when compiling with -fno-rtti
1013 if (DriverArgs.hasFlag(options::OPT_fno_rtti, options::OPT_frtti,
1014 /*Default=*/false))
1015 CC1Args.push_back("-D_HAS_STATIC_RTTI=0");
1016}
llvm::raw_ostream & OS
Definition: Logger.cpp:24
static void TranslatePermissiveMinus(Arg *A, llvm::opt::DerivedArgList &DAL, const OptTable &Opts)
Definition: MSVC.cpp:945
static VersionTuple getMSVCVersionFromExe(const std::string &BinDir)
Definition: MSVC.cpp:589
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:923
static void TranslateOptArg(Arg *A, llvm::opt::DerivedArgList &DAL, bool SupportsForcingFramePointer, const char *ExpandChar, const OptTable &Opts)
Definition: MSVC.cpp:827
static void TranslatePermissive(Arg *A, llvm::opt::DerivedArgList &DAL, const OptTable &Opts)
Definition: MSVC.cpp:939
Defines version macros and version-related utility functions for Clang.
The base class of the type hierarchy.
Definition: Type.h:1566
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition: Cuda.cpp:278
void print(raw_ostream &OS) const
Print information about the detected CUDA installation.
Definition: Cuda.cpp:319
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:388
@ 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
StringRef getLibPath() const
Get the detected Rocm library path.
Definition: ROCm.h:199
void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition: AMDGPU.cpp:493
void print(raw_ostream &OS) const
Print information about the detected ROCm installation.
Definition: AMDGPU.cpp:487
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:91
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:850
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:969
llvm::Triple::ArchType getArch() const
Definition: ToolChain.h:252
const Driver & getDriver() const
Definition: ToolChain.h:236
llvm::vfs::FileSystem & getVFS() const
Definition: ToolChain.cpp:127
path_list & getProgramPaths()
Definition: ToolChain.h:281
const llvm::Triple & getTriple() const
Definition: ToolChain.h:238
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:999
virtual VersionTuple computeMSVCVersion(const Driver *D, const llvm::opt::ArgList &Args) const
On Windows, returns the MSVC compatibility version.
Definition: ToolChain.cpp:1197
virtual SanitizerMask getSupportedSanitizers() const
Return sanitizers which are available in this toolchain.
Definition: ToolChain.cpp:1144
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:493
SanitizerMask getSupportedSanitizers() const override
Return sanitizers which are available in this toolchain.
Definition: MSVC.cpp:816
Tool * buildLinker() const override
Definition: MSVC.cpp:448
bool getUniversalCRTLibraryPath(const llvm::opt::ArgList &Args, std::string &path) const
Definition: MSVC.cpp:563
UnwindTableLevel getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override
How detailed should the unwind tables be by default.
Definition: MSVC.cpp:464
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:952
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition: MSVC.cpp:479
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition: MSVC.cpp:488
VersionTuple computeMSVCVersion(const Driver *D, const llvm::opt::ArgList &Args) const override
On Windows, returns the MSVC compatibility version.
Definition: MSVC.cpp:775
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:794
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:634
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:770
MSVCToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition: MSVC.cpp:415
std::string getSubDirectoryPath(llvm::SubDirectoryType Type, llvm::StringRef SubdirParent="") const
Definition: MSVC.cpp:516
void printVerboseInfo(raw_ostream &OS) const override
Dispatch to the specific toolchain for verbose printing.
Definition: MSVC.cpp:510
bool isPIEDefault(const llvm::opt::ArgList &Args) const override
Test whether this toolchain defaults to PIE.
Definition: MSVC.cpp:484
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:1008
void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use system-specific HIP includes.
Definition: MSVC.cpp:498
Tool * buildAssembler() const override
Definition: MSVC.cpp:452
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:503
bool IsIntegratedAssemblerDefault() const override
IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as by default.
Definition: MSVC.cpp:459
bool getWindowsSDKLibraryPath(const llvm::opt::ArgList &Args, std::string &path) const
Definition: MSVC.cpp:534
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:625
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 AddRunTimeLibs(const ToolChain &TC, const Driver &D, llvm::opt::ArgStringList &CmdArgs, const llvm::opt::ArgList &Args)
void addHIPRuntimeLibArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
void addFortranRuntimeLibs(const ToolChain &TC, llvm::opt::ArgStringList &CmdArgs)
Adds Fortran runtime libraries to CmdArgs.
Definition: CommonArgs.cpp:873
void addFortranRuntimeLibraryPath(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Adds the path for the Fortran runtime libraries to CmdArgs.
@ C
Languages that the frontend can parse and compile.
static constexpr ResponseFileSupport AtFileUTF16()
Definition: Job.h:99