Bug Summary

File:clang/lib/Driver/ToolChains/MinGW.cpp
Warning:line 172, column 5
Value stored to 'OutputFile' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name MinGW.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-13~++20210726100616+dead50d4427c/build-llvm/tools/clang/lib/Driver -resource-dir /usr/lib/llvm-13/lib/clang/13.0.0 -D CLANG_ROUND_TRIP_CC1_ARGS=ON -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-13~++20210726100616+dead50d4427c/build-llvm/tools/clang/lib/Driver -I /build/llvm-toolchain-snapshot-13~++20210726100616+dead50d4427c/clang/lib/Driver -I /build/llvm-toolchain-snapshot-13~++20210726100616+dead50d4427c/clang/include -I /build/llvm-toolchain-snapshot-13~++20210726100616+dead50d4427c/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-13~++20210726100616+dead50d4427c/build-llvm/include -I /build/llvm-toolchain-snapshot-13~++20210726100616+dead50d4427c/llvm/include -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-13/lib/clang/13.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-13~++20210726100616+dead50d4427c/build-llvm/tools/clang/lib/Driver -fdebug-prefix-map=/build/llvm-toolchain-snapshot-13~++20210726100616+dead50d4427c=. -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2021-07-26-235520-9401-1 -x c++ /build/llvm-toolchain-snapshot-13~++20210726100616+dead50d4427c/clang/lib/Driver/ToolChains/MinGW.cpp
1//===--- MinGW.cpp - MinGWToolChain Implementation ------------------------===//
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 "MinGW.h"
10#include "InputInfo.h"
11#include "CommonArgs.h"
12#include "clang/Config/config.h"
13#include "clang/Driver/Compilation.h"
14#include "clang/Driver/Driver.h"
15#include "clang/Driver/DriverDiagnostic.h"
16#include "clang/Driver/Options.h"
17#include "clang/Driver/SanitizerArgs.h"
18#include "llvm/Option/ArgList.h"
19#include "llvm/Support/FileSystem.h"
20#include "llvm/Support/Path.h"
21#include "llvm/Support/VirtualFileSystem.h"
22#include <system_error>
23
24using namespace clang::diag;
25using namespace clang::driver;
26using namespace clang;
27using namespace llvm::opt;
28
29/// MinGW Tools
30void tools::MinGW::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
31 const InputInfo &Output,
32 const InputInfoList &Inputs,
33 const ArgList &Args,
34 const char *LinkingOutput) const {
35 claimNoWarnArgs(Args);
36 ArgStringList CmdArgs;
37
38 if (getToolChain().getArch() == llvm::Triple::x86) {
39 CmdArgs.push_back("--32");
40 } else if (getToolChain().getArch() == llvm::Triple::x86_64) {
41 CmdArgs.push_back("--64");
42 }
43
44 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
45
46 CmdArgs.push_back("-o");
47 CmdArgs.push_back(Output.getFilename());
48
49 for (const auto &II : Inputs)
50 CmdArgs.push_back(II.getFilename());
51
52 const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
53 C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
54 Exec, CmdArgs, Inputs, Output));
55
56 if (Args.hasArg(options::OPT_gsplit_dwarf))
57 SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
58 SplitDebugName(JA, Args, Inputs[0], Output));
59}
60
61void tools::MinGW::Linker::AddLibGCC(const ArgList &Args,
62 ArgStringList &CmdArgs) const {
63 if (Args.hasArg(options::OPT_mthreads))
64 CmdArgs.push_back("-lmingwthrd");
65 CmdArgs.push_back("-lmingw32");
66
67 // Make use of compiler-rt if --rtlib option is used
68 ToolChain::RuntimeLibType RLT = getToolChain().GetRuntimeLibType(Args);
69 if (RLT == ToolChain::RLT_Libgcc) {
70 bool Static = Args.hasArg(options::OPT_static_libgcc) ||
71 Args.hasArg(options::OPT_static);
72 bool Shared = Args.hasArg(options::OPT_shared);
73 bool CXX = getToolChain().getDriver().CCCIsCXX();
74
75 if (Static || (!CXX && !Shared)) {
76 CmdArgs.push_back("-lgcc");
77 CmdArgs.push_back("-lgcc_eh");
78 } else {
79 CmdArgs.push_back("-lgcc_s");
80 CmdArgs.push_back("-lgcc");
81 }
82 } else {
83 AddRunTimeLibs(getToolChain(), getToolChain().getDriver(), CmdArgs, Args);
84 }
85
86 CmdArgs.push_back("-lmoldname");
87 CmdArgs.push_back("-lmingwex");
88 for (auto Lib : Args.getAllArgValues(options::OPT_l))
89 if (StringRef(Lib).startswith("msvcr") || StringRef(Lib).startswith("ucrt"))
90 return;
91 CmdArgs.push_back("-lmsvcrt");
92}
93
94void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,
95 const InputInfo &Output,
96 const InputInfoList &Inputs,
97 const ArgList &Args,
98 const char *LinkingOutput) const {
99 const ToolChain &TC = getToolChain();
100 const Driver &D = TC.getDriver();
101 const SanitizerArgs &Sanitize = TC.getSanitizerArgs();
102
103 ArgStringList CmdArgs;
104
105 // Silence warning for "clang -g foo.o -o foo"
106 Args.ClaimAllArgs(options::OPT_g_Group);
107 // and "clang -emit-llvm foo.o -o foo"
108 Args.ClaimAllArgs(options::OPT_emit_llvm);
109 // and for "clang -w foo.o -o foo". Other warning options are already
110 // handled somewhere else.
111 Args.ClaimAllArgs(options::OPT_w);
112
113 if (!D.SysRoot.empty())
114 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
115
116 if (Args.hasArg(options::OPT_s))
117 CmdArgs.push_back("-s");
118
119 CmdArgs.push_back("-m");
120 switch (TC.getArch()) {
121 case llvm::Triple::x86:
122 CmdArgs.push_back("i386pe");
123 break;
124 case llvm::Triple::x86_64:
125 CmdArgs.push_back("i386pep");
126 break;
127 case llvm::Triple::arm:
128 case llvm::Triple::thumb:
129 // FIXME: this is incorrect for WinCE
130 CmdArgs.push_back("thumb2pe");
131 break;
132 case llvm::Triple::aarch64:
133 CmdArgs.push_back("arm64pe");
134 break;
135 default:
136 llvm_unreachable("Unsupported target architecture.")::llvm::llvm_unreachable_internal("Unsupported target architecture."
, "/build/llvm-toolchain-snapshot-13~++20210726100616+dead50d4427c/clang/lib/Driver/ToolChains/MinGW.cpp"
, 136)
;
137 }
138
139 if (Args.hasArg(options::OPT_mwindows)) {
140 CmdArgs.push_back("--subsystem");
141 CmdArgs.push_back("windows");
142 } else if (Args.hasArg(options::OPT_mconsole)) {
143 CmdArgs.push_back("--subsystem");
144 CmdArgs.push_back("console");
145 }
146
147 if (Args.hasArg(options::OPT_mdll))
148 CmdArgs.push_back("--dll");
149 else if (Args.hasArg(options::OPT_shared))
150 CmdArgs.push_back("--shared");
151 if (Args.hasArg(options::OPT_static))
152 CmdArgs.push_back("-Bstatic");
153 else
154 CmdArgs.push_back("-Bdynamic");
155 if (Args.hasArg(options::OPT_mdll) || Args.hasArg(options::OPT_shared)) {
156 CmdArgs.push_back("-e");
157 if (TC.getArch() == llvm::Triple::x86)
158 CmdArgs.push_back("_DllMainCRTStartup@12");
159 else
160 CmdArgs.push_back("DllMainCRTStartup");
161 CmdArgs.push_back("--enable-auto-image-base");
162 }
163
164 CmdArgs.push_back("-o");
165 const char *OutputFile = Output.getFilename();
166 // GCC implicitly adds an .exe extension if it is given an output file name
167 // that lacks an extension.
168 // GCC used to do this only when the compiler itself runs on windows, but
169 // since GCC 8 it does the same when cross compiling as well.
170 if (!llvm::sys::path::has_extension(OutputFile)) {
171 CmdArgs.push_back(Args.MakeArgString(Twine(OutputFile) + ".exe"));
172 OutputFile = CmdArgs.back();
Value stored to 'OutputFile' is never read
173 } else
174 CmdArgs.push_back(OutputFile);
175
176 Args.AddAllArgs(CmdArgs, options::OPT_e);
177 // FIXME: add -N, -n flags
178 Args.AddLastArg(CmdArgs, options::OPT_r);
179 Args.AddLastArg(CmdArgs, options::OPT_s);
180 Args.AddLastArg(CmdArgs, options::OPT_t);
181 Args.AddAllArgs(CmdArgs, options::OPT_u_Group);
182 Args.AddLastArg(CmdArgs, options::OPT_Z_Flag);
183
184 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
185 if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_mdll)) {
186 CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("dllcrt2.o")));
187 } else {
188 if (Args.hasArg(options::OPT_municode))
189 CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt2u.o")));
190 else
191 CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt2.o")));
192 }
193 if (Args.hasArg(options::OPT_pg))
194 CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("gcrt2.o")));
195 CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crtbegin.o")));
196 }
197
198 Args.AddAllArgs(CmdArgs, options::OPT_L);
199 TC.AddFilePathLibArgs(Args, CmdArgs);
200
201 // Add the compiler-rt library directories if they exist to help
202 // the linker find the various sanitizer, builtin, and profiling runtimes.
203 for (const auto &LibPath : TC.getLibraryPaths()) {
204 if (TC.getVFS().exists(LibPath))
205 CmdArgs.push_back(Args.MakeArgString("-L" + LibPath));
206 }
207 auto CRTPath = TC.getCompilerRTPath();
208 if (TC.getVFS().exists(CRTPath))
209 CmdArgs.push_back(Args.MakeArgString("-L" + CRTPath));
210
211 AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
212
213 // TODO: Add profile stuff here
214
215 if (TC.ShouldLinkCXXStdlib(Args)) {
216 bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
217 !Args.hasArg(options::OPT_static);
218 if (OnlyLibstdcxxStatic)
219 CmdArgs.push_back("-Bstatic");
220 TC.AddCXXStdlibLibArgs(Args, CmdArgs);
221 if (OnlyLibstdcxxStatic)
222 CmdArgs.push_back("-Bdynamic");
223 }
224
225 bool HasWindowsApp = false;
226 for (auto Lib : Args.getAllArgValues(options::OPT_l)) {
227 if (Lib == "windowsapp") {
228 HasWindowsApp = true;
229 break;
230 }
231 }
232
233 if (!Args.hasArg(options::OPT_nostdlib)) {
234 if (!Args.hasArg(options::OPT_nodefaultlibs)) {
235 if (Args.hasArg(options::OPT_static))
236 CmdArgs.push_back("--start-group");
237
238 if (Args.hasArg(options::OPT_fstack_protector) ||
239 Args.hasArg(options::OPT_fstack_protector_strong) ||
240 Args.hasArg(options::OPT_fstack_protector_all)) {
241 CmdArgs.push_back("-lssp_nonshared");
242 CmdArgs.push_back("-lssp");
243 }
244
245 if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
246 options::OPT_fno_openmp, false)) {
247 switch (TC.getDriver().getOpenMPRuntime(Args)) {
248 case Driver::OMPRT_OMP:
249 CmdArgs.push_back("-lomp");
250 break;
251 case Driver::OMPRT_IOMP5:
252 CmdArgs.push_back("-liomp5md");
253 break;
254 case Driver::OMPRT_GOMP:
255 CmdArgs.push_back("-lgomp");
256 break;
257 case Driver::OMPRT_Unknown:
258 // Already diagnosed.
259 break;
260 }
261 }
262
263 AddLibGCC(Args, CmdArgs);
264
265 if (Args.hasArg(options::OPT_pg))
266 CmdArgs.push_back("-lgmon");
267
268 if (Args.hasArg(options::OPT_pthread))
269 CmdArgs.push_back("-lpthread");
270
271 if (Sanitize.needsAsanRt()) {
272 // MinGW always links against a shared MSVCRT.
273 CmdArgs.push_back(TC.getCompilerRTArgString(Args, "asan_dynamic",
274 ToolChain::FT_Shared));
275 CmdArgs.push_back(
276 TC.getCompilerRTArgString(Args, "asan_dynamic_runtime_thunk"));
277 CmdArgs.push_back("--require-defined");
278 CmdArgs.push_back(TC.getArch() == llvm::Triple::x86
279 ? "___asan_seh_interceptor"
280 : "__asan_seh_interceptor");
281 // Make sure the linker consider all object files from the dynamic
282 // runtime thunk.
283 CmdArgs.push_back("--whole-archive");
284 CmdArgs.push_back(
285 TC.getCompilerRTArgString(Args, "asan_dynamic_runtime_thunk"));
286 CmdArgs.push_back("--no-whole-archive");
287 }
288
289 TC.addProfileRTLibs(Args, CmdArgs);
290
291 if (!HasWindowsApp) {
292 // Add system libraries. If linking to libwindowsapp.a, that import
293 // library replaces all these and we shouldn't accidentally try to
294 // link to the normal desktop mode dlls.
295 if (Args.hasArg(options::OPT_mwindows)) {
296 CmdArgs.push_back("-lgdi32");
297 CmdArgs.push_back("-lcomdlg32");
298 }
299 CmdArgs.push_back("-ladvapi32");
300 CmdArgs.push_back("-lshell32");
301 CmdArgs.push_back("-luser32");
302 CmdArgs.push_back("-lkernel32");
303 }
304
305 if (Args.hasArg(options::OPT_static)) {
306 CmdArgs.push_back("--end-group");
307 } else {
308 AddLibGCC(Args, CmdArgs);
309 if (!HasWindowsApp)
310 CmdArgs.push_back("-lkernel32");
311 }
312 }
313
314 if (!Args.hasArg(options::OPT_nostartfiles)) {
315 // Add crtfastmath.o if available and fast math is enabled.
316 TC.addFastMathRuntimeIfAvailable(Args, CmdArgs);
317
318 CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crtend.o")));
319 }
320 }
321 const char *Exec = Args.MakeArgString(TC.GetLinkerPath());
322 C.addCommand(std::make_unique<Command>(JA, *this,
323 ResponseFileSupport::AtFileUTF8(),
324 Exec, CmdArgs, Inputs, Output));
325}
326
327// Simplified from Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple.
328static bool findGccVersion(StringRef LibDir, std::string &GccLibDir,
329 std::string &Ver) {
330 auto Version = toolchains::Generic_GCC::GCCVersion::Parse("0.0.0");
331 std::error_code EC;
332 for (llvm::sys::fs::directory_iterator LI(LibDir, EC), LE; !EC && LI != LE;
333 LI = LI.increment(EC)) {
334 StringRef VersionText = llvm::sys::path::filename(LI->path());
335 auto CandidateVersion =
336 toolchains::Generic_GCC::GCCVersion::Parse(VersionText);
337 if (CandidateVersion.Major == -1)
338 continue;
339 if (CandidateVersion <= Version)
340 continue;
341 Version = CandidateVersion;
342 Ver = std::string(VersionText);
343 GccLibDir = LI->path();
344 }
345 return Ver.size();
346}
347
348void toolchains::MinGW::findGccLibDir() {
349 llvm::SmallVector<llvm::SmallString<32>, 2> Archs;
350 Archs.emplace_back(getTriple().getArchName());
351 Archs[0] += "-w64-mingw32";
352 Archs.emplace_back("mingw32");
353 if (Arch.empty())
354 Arch = std::string(Archs[0].str());
355 // lib: Arch Linux, Ubuntu, Windows
356 // lib64: openSUSE Linux
357 for (StringRef CandidateLib : {"lib", "lib64"}) {
358 for (StringRef CandidateArch : Archs) {
359 llvm::SmallString<1024> LibDir(Base);
360 llvm::sys::path::append(LibDir, CandidateLib, "gcc", CandidateArch);
361 if (findGccVersion(LibDir, GccLibDir, Ver)) {
362 Arch = std::string(CandidateArch);
363 return;
364 }
365 }
366 }
367}
368
369llvm::ErrorOr<std::string> toolchains::MinGW::findGcc() {
370 llvm::SmallVector<llvm::SmallString<32>, 2> Gccs;
371 Gccs.emplace_back(getTriple().getArchName());
372 Gccs[0] += "-w64-mingw32-gcc";
373 Gccs.emplace_back("mingw32-gcc");
374 // Please do not add "gcc" here
375 for (StringRef CandidateGcc : Gccs)
376 if (llvm::ErrorOr<std::string> GPPName = llvm::sys::findProgramByName(CandidateGcc))
377 return GPPName;
378 return make_error_code(std::errc::no_such_file_or_directory);
379}
380
381llvm::ErrorOr<std::string> toolchains::MinGW::findClangRelativeSysroot() {
382 llvm::SmallVector<llvm::SmallString<32>, 2> Subdirs;
383 Subdirs.emplace_back(getTriple().str());
384 Subdirs.emplace_back(getTriple().getArchName());
385 Subdirs[1] += "-w64-mingw32";
386 StringRef ClangRoot =
387 llvm::sys::path::parent_path(getDriver().getInstalledDir());
388 StringRef Sep = llvm::sys::path::get_separator();
389 for (StringRef CandidateSubdir : Subdirs) {
390 if (llvm::sys::fs::is_directory(ClangRoot + Sep + CandidateSubdir)) {
391 Arch = std::string(CandidateSubdir);
392 return (ClangRoot + Sep + CandidateSubdir).str();
393 }
394 }
395 return make_error_code(std::errc::no_such_file_or_directory);
396}
397
398toolchains::MinGW::MinGW(const Driver &D, const llvm::Triple &Triple,
399 const ArgList &Args)
400 : ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args),
401 RocmInstallation(D, Triple, Args) {
402 getProgramPaths().push_back(getDriver().getInstalledDir());
403
404 if (getDriver().SysRoot.size())
405 Base = getDriver().SysRoot;
406 // Look for <clang-bin>/../<triplet>; if found, use <clang-bin>/.. as the
407 // base as it could still be a base for a gcc setup with libgcc.
408 else if (llvm::ErrorOr<std::string> TargetSubdir = findClangRelativeSysroot())
409 Base = std::string(llvm::sys::path::parent_path(TargetSubdir.get()));
410 else if (llvm::ErrorOr<std::string> GPPName = findGcc())
411 Base = std::string(llvm::sys::path::parent_path(
412 llvm::sys::path::parent_path(GPPName.get())));
413 else
414 Base = std::string(
415 llvm::sys::path::parent_path(getDriver().getInstalledDir()));
416
417 Base += llvm::sys::path::get_separator();
418 findGccLibDir();
419 // GccLibDir must precede Base/lib so that the
420 // correct crtbegin.o ,cetend.o would be found.
421 getFilePaths().push_back(GccLibDir);
422 getFilePaths().push_back(
423 (Base + Arch + llvm::sys::path::get_separator() + "lib").str());
424 getFilePaths().push_back(Base + "lib");
425 // openSUSE
426 getFilePaths().push_back(Base + Arch + "/sys-root/mingw/lib");
427
428 NativeLLVMSupport =
429 Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER"")
430 .equals_insensitive("lld");
431}
432
433bool toolchains::MinGW::IsIntegratedAssemblerDefault() const { return true; }
434
435Tool *toolchains::MinGW::getTool(Action::ActionClass AC) const {
436 switch (AC) {
437 case Action::PreprocessJobClass:
438 if (!Preprocessor)
439 Preprocessor.reset(new tools::gcc::Preprocessor(*this));
440 return Preprocessor.get();
441 case Action::CompileJobClass:
442 if (!Compiler)
443 Compiler.reset(new tools::gcc::Compiler(*this));
444 return Compiler.get();
445 default:
446 return ToolChain::getTool(AC);
447 }
448}
449
450Tool *toolchains::MinGW::buildAssembler() const {
451 return new tools::MinGW::Assembler(*this);
452}
453
454Tool *toolchains::MinGW::buildLinker() const {
455 return new tools::MinGW::Linker(*this);
456}
457
458bool toolchains::MinGW::HasNativeLLVMSupport() const {
459 return NativeLLVMSupport;
460}
461
462bool toolchains::MinGW::IsUnwindTablesDefault(const ArgList &Args) const {
463 Arg *ExceptionArg = Args.getLastArg(options::OPT_fsjlj_exceptions,
464 options::OPT_fseh_exceptions,
465 options::OPT_fdwarf_exceptions);
466 if (ExceptionArg &&
467 ExceptionArg->getOption().matches(options::OPT_fseh_exceptions))
468 return true;
469 return getArch() == llvm::Triple::x86_64 ||
470 getArch() == llvm::Triple::aarch64;
471}
472
473bool toolchains::MinGW::isPICDefault() const {
474 return getArch() == llvm::Triple::x86_64;
475}
476
477bool toolchains::MinGW::isPIEDefault() const { return false; }
478
479bool toolchains::MinGW::isPICDefaultForced() const {
480 return getArch() == llvm::Triple::x86_64;
481}
482
483llvm::ExceptionHandling
484toolchains::MinGW::GetExceptionModel(const ArgList &Args) const {
485 if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64)
486 return llvm::ExceptionHandling::WinEH;
487 return llvm::ExceptionHandling::DwarfCFI;
488}
489
490SanitizerMask toolchains::MinGW::getSupportedSanitizers() const {
491 SanitizerMask Res = ToolChain::getSupportedSanitizers();
492 Res |= SanitizerKind::Address;
493 Res |= SanitizerKind::PointerCompare;
494 Res |= SanitizerKind::PointerSubtract;
495 Res |= SanitizerKind::Vptr;
496 return Res;
497}
498
499void toolchains::MinGW::AddCudaIncludeArgs(const ArgList &DriverArgs,
500 ArgStringList &CC1Args) const {
501 CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
502}
503
504void toolchains::MinGW::AddHIPIncludeArgs(const ArgList &DriverArgs,
505 ArgStringList &CC1Args) const {
506 RocmInstallation.AddHIPIncludeArgs(DriverArgs, CC1Args);
507}
508
509void toolchains::MinGW::printVerboseInfo(raw_ostream &OS) const {
510 CudaInstallation.print(OS);
511 RocmInstallation.print(OS);
512}
513
514// Include directories for various hosts:
515
516// Windows, mingw.org
517// c:\mingw\lib\gcc\mingw32\4.8.1\include\c++
518// c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\mingw32
519// c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\backward
520// c:\mingw\include
521// c:\mingw\mingw32\include
522
523// Windows, mingw-w64 mingw-builds
524// c:\mingw32\i686-w64-mingw32\include
525// c:\mingw32\i686-w64-mingw32\include\c++
526// c:\mingw32\i686-w64-mingw32\include\c++\i686-w64-mingw32
527// c:\mingw32\i686-w64-mingw32\include\c++\backward
528
529// Windows, mingw-w64 msys2
530// c:\msys64\mingw32\include
531// c:\msys64\mingw32\i686-w64-mingw32\include
532// c:\msys64\mingw32\include\c++\4.9.2
533// c:\msys64\mingw32\include\c++\4.9.2\i686-w64-mingw32
534// c:\msys64\mingw32\include\c++\4.9.2\backward
535
536// openSUSE
537// /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include/c++
538// /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include/c++/x86_64-w64-mingw32
539// /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include/c++/backward
540// /usr/x86_64-w64-mingw32/sys-root/mingw/include
541
542// Arch Linux
543// /usr/i686-w64-mingw32/include/c++/5.1.0
544// /usr/i686-w64-mingw32/include/c++/5.1.0/i686-w64-mingw32
545// /usr/i686-w64-mingw32/include/c++/5.1.0/backward
546// /usr/i686-w64-mingw32/include
547
548// Ubuntu
549// /usr/include/c++/4.8
550// /usr/include/c++/4.8/x86_64-w64-mingw32
551// /usr/include/c++/4.8/backward
552// /usr/x86_64-w64-mingw32/include
553
554void toolchains::MinGW::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
555 ArgStringList &CC1Args) const {
556 if (DriverArgs.hasArg(options::OPT_nostdinc))
557 return;
558
559 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
560 SmallString<1024> P(getDriver().ResourceDir);
561 llvm::sys::path::append(P, "include");
562 addSystemInclude(DriverArgs, CC1Args, P.str());
563 }
564
565 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
566 return;
567
568 if (GetRuntimeLibType(DriverArgs) == ToolChain::RLT_Libgcc) {
569 // openSUSE
570 addSystemInclude(DriverArgs, CC1Args,
571 Base + Arch + "/sys-root/mingw/include");
572 }
573
574 addSystemInclude(DriverArgs, CC1Args,
575 Base + Arch + llvm::sys::path::get_separator() + "include");
576 addSystemInclude(DriverArgs, CC1Args, Base + "include");
577}
578
579void toolchains::MinGW::AddClangCXXStdlibIncludeArgs(
580 const ArgList &DriverArgs, ArgStringList &CC1Args) const {
581 if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
582 DriverArgs.hasArg(options::OPT_nostdincxx))
583 return;
584
585 StringRef Slash = llvm::sys::path::get_separator();
586
587 switch (GetCXXStdlibType(DriverArgs)) {
588 case ToolChain::CST_Libcxx:
589 addSystemInclude(DriverArgs, CC1Args, Base + Arch + Slash + "include" +
590 Slash + "c++" + Slash + "v1");
591 addSystemInclude(DriverArgs, CC1Args,
592 Base + "include" + Slash + "c++" + Slash + "v1");
593 break;
594
595 case ToolChain::CST_Libstdcxx:
596 llvm::SmallVector<llvm::SmallString<1024>, 4> CppIncludeBases;
597 CppIncludeBases.emplace_back(Base);
598 llvm::sys::path::append(CppIncludeBases[0], Arch, "include", "c++");
599 CppIncludeBases.emplace_back(Base);
600 llvm::sys::path::append(CppIncludeBases[1], Arch, "include", "c++", Ver);
601 CppIncludeBases.emplace_back(Base);
602 llvm::sys::path::append(CppIncludeBases[2], "include", "c++", Ver);
603 CppIncludeBases.emplace_back(GccLibDir);
604 llvm::sys::path::append(CppIncludeBases[3], "include", "c++");
605 for (auto &CppIncludeBase : CppIncludeBases) {
606 addSystemInclude(DriverArgs, CC1Args, CppIncludeBase);
607 CppIncludeBase += Slash;
608 addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + Arch);
609 addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + "backward");
610 }
611 break;
612 }
613}