Coverage Report

Created: 2020-09-22 08:39

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Driver/ToolChains/MSVC.h
Line
Count
Source (jump to first uncovered line)
1
//===--- MSVC.h - MSVC ToolChain Implementations ----------------*- C++ -*-===//
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
#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H
10
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H
11
12
#include "AMDGPU.h"
13
#include "Cuda.h"
14
#include "clang/Basic/DebugInfoOptions.h"
15
#include "clang/Driver/Compilation.h"
16
#include "clang/Driver/Tool.h"
17
#include "clang/Driver/ToolChain.h"
18
19
namespace clang {
20
namespace driver {
21
namespace tools {
22
23
/// Visual studio tools.
24
namespace visualstudio {
25
class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
26
public:
27
365
  Linker(const ToolChain &TC) : Tool("visualstudio::Linker", "linker", TC) {}
28
29
365
  bool hasIntegratedCPP() const override { return false; }
30
0
  bool isLinkJob() const override { return true; }
31
32
  void ConstructJob(Compilation &C, const JobAction &JA,
33
                    const InputInfo &Output, const InputInfoList &Inputs,
34
                    const llvm::opt::ArgList &TCArgs,
35
                    const char *LinkingOutput) const override;
36
};
37
38
class LLVM_LIBRARY_VISIBILITY Compiler : public Tool {
39
public:
40
  Compiler(const ToolChain &TC)
41
15
      : Tool("visualstudio::Compiler", "compiler", TC) {}
42
43
0
  bool hasIntegratedAssembler() const override { return true; }
44
0
  bool hasIntegratedCPP() const override { return true; }
45
0
  bool isLinkJob() const override { return false; }
46
47
  void ConstructJob(Compilation &C, const JobAction &JA,
48
                    const InputInfo &Output, const InputInfoList &Inputs,
49
                    const llvm::opt::ArgList &TCArgs,
50
                    const char *LinkingOutput) const override;
51
52
  std::unique_ptr<Command> GetCommand(Compilation &C, const JobAction &JA,
53
                                      const InputInfo &Output,
54
                                      const InputInfoList &Inputs,
55
                                      const llvm::opt::ArgList &TCArgs,
56
                                      const char *LinkingOutput) const;
57
};
58
} // end namespace visualstudio
59
60
} // end namespace tools
61
62
namespace toolchains {
63
64
class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
65
public:
66
  MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
67
                const llvm::opt::ArgList &Args);
68
69
  llvm::opt::DerivedArgList *
70
  TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
71
                Action::OffloadKind DeviceOffloadKind) const override;
72
73
  bool IsIntegratedAssemblerDefault() const override;
74
  bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
75
  bool isPICDefault() const override;
76
  bool isPIEDefault() const override;
77
  bool isPICDefaultForced() const override;
78
79
  /// Set CodeView as the default debug info format for non-MachO binary
80
  /// formats, and to DWARF otherwise. Users can use -gcodeview and -gdwarf to
81
  /// override the default.
82
4
  codegenoptions::DebugInfoFormat getDefaultDebugFormat() const override {
83
1
    return getTriple().isOSBinFormatMachO() ? codegenoptions::DIF_DWARF
84
3
                                            : codegenoptions::DIF_CodeView;
85
4
  }
86
87
  /// Set the debugger tuning to "default", since we're definitely not tuning
88
  /// for GDB.
89
7.65k
  llvm::DebuggerKind getDefaultDebuggerTuning() const override {
90
7.65k
    return llvm::DebuggerKind::Default;
91
7.65k
  }
92
93
  enum class SubDirectoryType {
94
    Bin,
95
    Include,
96
    Lib,
97
  };
98
  std::string getSubDirectoryPath(SubDirectoryType Type,
99
                                  llvm::StringRef SubdirParent,
100
                                  llvm::Triple::ArchType TargetArch) const;
101
102
  // Convenience overload.
103
  // Uses the current target arch.
104
  std::string getSubDirectoryPath(SubDirectoryType Type,
105
17.1k
                                  llvm::StringRef SubdirParent = "") const {
106
17.1k
    return getSubDirectoryPath(Type, SubdirParent, getArch());
107
17.1k
  }
108
109
  enum class ToolsetLayout {
110
    OlderVS,
111
    VS2017OrNewer,
112
    DevDivInternal,
113
  };
114
0
  bool getIsVS2017OrNewer() const { return VSLayout == ToolsetLayout::VS2017OrNewer; }
115
116
  void
117
  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
118
                            llvm::opt::ArgStringList &CC1Args) const override;
119
  void AddClangCXXStdlibIncludeArgs(
120
      const llvm::opt::ArgList &DriverArgs,
121
      llvm::opt::ArgStringList &CC1Args) const override;
122
123
  void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
124
                          llvm::opt::ArgStringList &CC1Args) const override;
125
126
  void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
127
                         llvm::opt::ArgStringList &CC1Args) const override;
128
129
  bool getWindowsSDKLibraryPath(std::string &path) const;
130
  /// Check if Universal CRT should be used if available
131
  bool getUniversalCRTLibraryPath(std::string &path) const;
132
  bool useUniversalCRT() const;
133
  VersionTuple
134
  computeMSVCVersion(const Driver *D,
135
                     const llvm::opt::ArgList &Args) const override;
136
137
  std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
138
                                          types::ID InputType) const override;
139
  SanitizerMask getSupportedSanitizers() const override;
140
141
  void printVerboseInfo(raw_ostream &OS) const override;
142
143
362
  bool FoundMSVCInstall() const { return !VCToolChainPath.empty(); }
144
145
protected:
146
  void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
147
                                     llvm::opt::ArgStringList &CC1Args,
148
                                     const std::string &folder,
149
                                     const Twine &subfolder1,
150
                                     const Twine &subfolder2 = "",
151
                                     const Twine &subfolder3 = "") const;
152
153
  Tool *buildLinker() const override;
154
  Tool *buildAssembler() const override;
155
private:
156
  std::string VCToolChainPath;
157
  ToolsetLayout VSLayout = ToolsetLayout::OlderVS;
158
  CudaInstallationDetector CudaInstallation;
159
  RocmInstallationDetector RocmInstallation;
160
};
161
162
} // end namespace toolchains
163
} // end namespace driver
164
} // end namespace clang
165
166
#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H