Coverage Report

Created: 2021-09-21 08:58

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Lex/HeaderSearchOptions.h
Line
Count
Source (jump to first uncovered line)
1
//===- HeaderSearchOptions.h ------------------------------------*- 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_LEX_HEADERSEARCHOPTIONS_H
10
#define LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
11
12
#include "clang/Basic/LLVM.h"
13
#include "llvm/ADT/CachedHashString.h"
14
#include "llvm/ADT/Hashing.h"
15
#include "llvm/ADT/SetVector.h"
16
#include "llvm/ADT/StringRef.h"
17
#include "llvm/Support/HashBuilder.h"
18
#include <cstdint>
19
#include <map>
20
#include <string>
21
#include <vector>
22
23
namespace clang {
24
25
namespace frontend {
26
27
/// IncludeDirGroup - Identifies the group an include Entry belongs to,
28
/// representing its relative positive in the search list.
29
/// \#include directives whose paths are enclosed by string quotes ("")
30
/// start searching at the Quoted group (specified by '-iquote'),
31
/// then search the Angled group, then the System group, etc.
32
enum IncludeDirGroup {
33
  /// '\#include ""' paths, added by 'gcc -iquote'.
34
  Quoted = 0,
35
36
  /// Paths for '\#include <>' added by '-I'.
37
  Angled,
38
39
  /// Like Angled, but marks header maps used when building frameworks.
40
  IndexHeaderMap,
41
42
  /// Like Angled, but marks system directories.
43
  System,
44
45
  /// Like System, but headers are implicitly wrapped in extern "C".
46
  ExternCSystem,
47
48
  /// Like System, but only used for C.
49
  CSystem,
50
51
  /// Like System, but only used for C++.
52
  CXXSystem,
53
54
  /// Like System, but only used for ObjC.
55
  ObjCSystem,
56
57
  /// Like System, but only used for ObjC++.
58
  ObjCXXSystem,
59
60
  /// Like System, but searched after the system directories.
61
  After
62
};
63
64
} // namespace frontend
65
66
/// HeaderSearchOptions - Helper class for storing options related to the
67
/// initialization of the HeaderSearch object.
68
class HeaderSearchOptions {
69
public:
70
  struct Entry {
71
    std::string Path;
72
    frontend::IncludeDirGroup Group;
73
    unsigned IsFramework : 1;
74
75
    /// IgnoreSysRoot - This is false if an absolute path should be treated
76
    /// relative to the sysroot, or true if it should always be the absolute
77
    /// path.
78
    unsigned IgnoreSysRoot : 1;
79
80
    Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework,
81
          bool ignoreSysRoot)
82
        : Path(path), Group(group), IsFramework(isFramework),
83
237k
          IgnoreSysRoot(ignoreSysRoot) {}
84
  };
85
86
  struct SystemHeaderPrefix {
87
    /// A prefix to be matched against paths in \#include directives.
88
    std::string Prefix;
89
90
    /// True if paths beginning with this prefix should be treated as system
91
    /// headers.
92
    bool IsSystemHeader;
93
94
    SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
95
8
        : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {}
96
  };
97
98
  /// If non-empty, the directory to use as a "virtual system root" for include
99
  /// paths.
100
  std::string Sysroot;
101
102
  /// User specified include entries.
103
  std::vector<Entry> UserEntries;
104
105
  /// User-specified system header prefixes.
106
  std::vector<SystemHeaderPrefix> SystemHeaderPrefixes;
107
108
  /// The directory which holds the compiler resource files (builtin includes,
109
  /// etc.).
110
  std::string ResourceDir;
111
112
  /// The directory used for the module cache.
113
  std::string ModuleCachePath;
114
115
  /// The directory used for a user build.
116
  std::string ModuleUserBuildPath;
117
118
  /// The mapping of module names to prebuilt module files.
119
  std::map<std::string, std::string, std::less<>> PrebuiltModuleFiles;
120
121
  /// The directories used to load prebuilt module files.
122
  std::vector<std::string> PrebuiltModulePaths;
123
124
  /// The module/pch container format.
125
  std::string ModuleFormat;
126
127
  /// Whether we should disable the use of the hash string within the
128
  /// module cache.
129
  ///
130
  /// Note: Only used for testing!
131
  unsigned DisableModuleHash : 1;
132
133
  /// Implicit module maps.  This option is enabld by default when
134
  /// modules is enabled.
135
  unsigned ImplicitModuleMaps : 1;
136
137
  /// Set the 'home directory' of a module map file to the current
138
  /// working directory (or the home directory of the module map file that
139
  /// contained the 'extern module' directive importing this module map file
140
  /// if any) rather than the directory containing the module map file.
141
  //
142
  /// The home directory is where we look for files named in the module map
143
  /// file.
144
  unsigned ModuleMapFileHomeIsCwd : 1;
145
146
  /// Also search for prebuilt implicit modules in the prebuilt module cache
147
  /// path.
148
  unsigned EnablePrebuiltImplicitModules : 1;
149
150
  /// The interval (in seconds) between pruning operations.
151
  ///
152
  /// This operation is expensive, because it requires Clang to walk through
153
  /// the directory structure of the module cache, stat()'ing and removing
154
  /// files.
155
  ///
156
  /// The default value is large, e.g., the operation runs once a week.
157
  unsigned ModuleCachePruneInterval = 7 * 24 * 60 * 60;
158
159
  /// The time (in seconds) after which an unused module file will be
160
  /// considered unused and will, therefore, be pruned.
161
  ///
162
  /// When the module cache is pruned, any module file that has not been
163
  /// accessed in this many seconds will be removed. The default value is
164
  /// large, e.g., a month, to avoid forcing infrequently-used modules to be
165
  /// regenerated often.
166
  unsigned ModuleCachePruneAfter = 31 * 24 * 60 * 60;
167
168
  /// The time in seconds when the build session started.
169
  ///
170
  /// This time is used by other optimizations in header search and module
171
  /// loading.
172
  uint64_t BuildSessionTimestamp = 0;
173
174
  /// The set of macro names that should be ignored for the purposes
175
  /// of computing the module hash.
176
  llvm::SmallSetVector<llvm::CachedHashString, 16> ModulesIgnoreMacros;
177
178
  /// The set of user-provided virtual filesystem overlay files.
179
  std::vector<std::string> VFSOverlayFiles;
180
181
  /// Include the compiler builtin includes.
182
  unsigned UseBuiltinIncludes : 1;
183
184
  /// Include the system standard include search directories.
185
  unsigned UseStandardSystemIncludes : 1;
186
187
  /// Include the system standard C++ library include search directories.
188
  unsigned UseStandardCXXIncludes : 1;
189
190
  /// Use libc++ instead of the default libstdc++.
191
  unsigned UseLibcxx : 1;
192
193
  /// Whether header search information should be output as for -v.
194
  unsigned Verbose : 1;
195
196
  /// If true, skip verifying input files used by modules if the
197
  /// module was already verified during this build session (see
198
  /// \c BuildSessionTimestamp).
199
  unsigned ModulesValidateOncePerBuildSession : 1;
200
201
  /// Whether to validate system input files when a module is loaded.
202
  unsigned ModulesValidateSystemHeaders : 1;
203
204
  // Whether the content of input files should be hashed and used to
205
  // validate consistency.
206
  unsigned ValidateASTInputFilesContent : 1;
207
208
  /// Whether the module includes debug information (-gmodules).
209
  unsigned UseDebugInfo : 1;
210
211
  unsigned ModulesValidateDiagnosticOptions : 1;
212
213
  unsigned ModulesHashContent : 1;
214
215
  /// Whether we should include all things that could impact the module in the
216
  /// hash.
217
  ///
218
  /// This includes things like the full header search path, and enabled
219
  /// diagnostics.
220
  unsigned ModulesStrictContextHash : 1;
221
222
  HeaderSearchOptions(StringRef _Sysroot = "/")
223
      : Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(false),
224
        ImplicitModuleMaps(false), ModuleMapFileHomeIsCwd(false),
225
        EnablePrebuiltImplicitModules(false), UseBuiltinIncludes(true),
226
        UseStandardSystemIncludes(true), UseStandardCXXIncludes(true),
227
        UseLibcxx(false), Verbose(false),
228
        ModulesValidateOncePerBuildSession(false),
229
        ModulesValidateSystemHeaders(false),
230
        ValidateASTInputFilesContent(false), UseDebugInfo(false),
231
        ModulesValidateDiagnosticOptions(true), ModulesHashContent(false),
232
204k
        ModulesStrictContextHash(false) {}
233
234
  /// AddPath - Add the \p Path path to the specified \p Group list.
235
  void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
236
218k
               bool IsFramework, bool IgnoreSysRoot) {
237
218k
    UserEntries.emplace_back(Path, Group, IsFramework, IgnoreSysRoot);
238
218k
  }
239
240
  /// AddSystemHeaderPrefix - Override whether \#include directives naming a
241
  /// path starting with \p Prefix should be considered as naming a system
242
  /// header.
243
8
  void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
244
8
    SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader);
245
8
  }
246
247
172
  void AddVFSOverlayFile(StringRef Name) {
248
172
    VFSOverlayFiles.push_back(std::string(Name));
249
172
  }
250
251
24
  void AddPrebuiltModulePath(StringRef Name) {
252
24
    PrebuiltModulePaths.push_back(std::string(Name));
253
24
  }
254
};
255
256
0
inline llvm::hash_code hash_value(const HeaderSearchOptions::Entry &E) {
257
0
  return llvm::hash_combine(E.Path, E.Group, E.IsFramework, E.IgnoreSysRoot);
258
0
}
259
260
template <typename HasherT, llvm::support::endianness Endianness>
261
inline void addHash(llvm::HashBuilderImpl<HasherT, Endianness> &HBuilder,
262
816
                    const HeaderSearchOptions::Entry &E) {
263
816
  HBuilder.add(E.Path, E.Group, E.IsFramework, E.IgnoreSysRoot);
264
816
}
265
266
inline llvm::hash_code
267
0
hash_value(const HeaderSearchOptions::SystemHeaderPrefix &SHP) {
268
0
  return llvm::hash_combine(SHP.Prefix, SHP.IsSystemHeader);
269
0
}
270
271
template <typename HasherT, llvm::support::endianness Endianness>
272
inline void addHash(llvm::HashBuilderImpl<HasherT, Endianness> &HBuilder,
273
0
                    const HeaderSearchOptions::SystemHeaderPrefix &SHP) {
274
0
  HBuilder.add(SHP.Prefix, SHP.IsSystemHeader);
275
0
}
276
277
} // namespace clang
278
279
#endif // LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H