Coverage Report

Created: 2020-02-15 09:57

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