Coverage Report

Created: 2019-07-24 05:18

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