Coverage Report

Created: 2018-09-21 05:35

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Basic/LangOptions.h
Line
Count
Source (jump to first uncovered line)
1
//===- LangOptions.h - C Language Family Language Options -------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
/// \file
11
/// Defines the clang::LangOptions interface.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CLANG_BASIC_LANGOPTIONS_H
16
#define LLVM_CLANG_BASIC_LANGOPTIONS_H
17
18
#include "clang/Basic/CommentOptions.h"
19
#include "clang/Basic/LLVM.h"
20
#include "clang/Basic/ObjCRuntime.h"
21
#include "clang/Basic/Sanitizers.h"
22
#include "clang/Basic/Visibility.h"
23
#include "llvm/ADT/StringRef.h"
24
#include "llvm/ADT/Triple.h"
25
#include <string>
26
#include <vector>
27
28
namespace clang {
29
30
/// Bitfields of LangOptions, split out from LangOptions in order to ensure that
31
/// this large collection of bitfields is a trivial class type.
32
class LangOptionsBase {
33
public:
34
  // Define simple language options (with no accessors).
35
#define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
36
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
37
#include "clang/Basic/LangOptions.def"
38
39
protected:
40
  // Define language options of enumeration type. These are private, and will
41
  // have accessors (below).
42
#define LANGOPT(Name, Bits, Default, Description)
43
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
44
  unsigned Name : Bits;
45
#include "clang/Basic/LangOptions.def"
46
};
47
48
/// Keeps track of the various options that can be
49
/// enabled, which controls the dialect of C or C++ that is accepted.
50
class LangOptions : public LangOptionsBase {
51
public:
52
  using Visibility = clang::Visibility;
53
54
  enum GCMode { NonGC, GCOnly, HybridGC };
55
  enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
56
57
  enum SignedOverflowBehaviorTy {
58
    // Default C standard behavior.
59
    SOB_Undefined,
60
61
    // -fwrapv
62
    SOB_Defined,
63
64
    // -ftrapv
65
    SOB_Trapping
66
  };
67
68
  // FIXME: Unify with TUKind.
69
  enum CompilingModuleKind {
70
    /// Not compiling a module interface at all.
71
    CMK_None,
72
73
    /// Compiling a module from a module map.
74
    CMK_ModuleMap,
75
76
    /// Compiling a module from a list of header files.
77
    CMK_HeaderModule,
78
79
    /// Compiling a C++ modules TS module interface unit.
80
    CMK_ModuleInterface,
81
  };
82
83
  enum PragmaMSPointersToMembersKind {
84
    PPTMK_BestCase,
85
    PPTMK_FullGeneralitySingleInheritance,
86
    PPTMK_FullGeneralityMultipleInheritance,
87
    PPTMK_FullGeneralityVirtualInheritance
88
  };
89
90
  enum DefaultCallingConvention {
91
    DCC_None,
92
    DCC_CDecl,
93
    DCC_FastCall,
94
    DCC_StdCall,
95
    DCC_VectorCall,
96
    DCC_RegCall
97
  };
98
99
  enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
100
101
  enum MSVCMajorVersion {
102
    MSVC2010 = 16,
103
    MSVC2012 = 17,
104
    MSVC2013 = 18,
105
    MSVC2015 = 19
106
  };
107
108
  /// Clang versions with different platform ABI conformance.
109
  enum class ClangABI {
110
    /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
111
    /// (SVN r257626). This causes <1 x long long> to be passed in an
112
    /// integer register instead of an SSE register on x64_64.
113
    Ver3_8,
114
115
    /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
116
    /// (SVN r291814). This causes move operations to be ignored when
117
    /// determining whether a class type can be passed or returned directly.
118
    Ver4,
119
120
    /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
121
    /// (SVN r321711). This causes determination of whether a type is
122
    /// standard-layout to ignore collisions between empty base classes
123
    /// and between base classes and member subobjects, which affects
124
    /// whether we reuse base class tail padding in some ABIs.
125
    Ver6,
126
127
    /// Conform to the underlying platform's C and C++ ABIs as closely
128
    /// as we can.
129
    Latest
130
  };
131
132
  enum FPContractModeKind {
133
    // Form fused FP ops only where result will not be affected.
134
    FPC_Off,
135
136
    // Form fused FP ops according to FP_CONTRACT rules.
137
    FPC_On,
138
139
    // Aggressively fuse FP ops (E.g. FMA).
140
    FPC_Fast
141
  };
142
143
  // TODO: merge FEnvAccessModeKind and FPContractModeKind
144
  enum FEnvAccessModeKind {
145
    FEA_Off,
146
147
    FEA_On
148
  };
149
150
151
public:
152
  /// Set of enabled sanitizers.
153
  SanitizerSet Sanitize;
154
155
  /// Paths to blacklist files specifying which objects
156
  /// (files, functions, variables) should not be instrumented.
157
  std::vector<std::string> SanitizerBlacklistFiles;
158
159
  /// Paths to the XRay "always instrument" files specifying which
160
  /// objects (files, functions, variables) should be imbued with the XRay
161
  /// "always instrument" attribute.
162
  /// WARNING: This is a deprecated field and will go away in the future.
163
  std::vector<std::string> XRayAlwaysInstrumentFiles;
164
165
  /// Paths to the XRay "never instrument" files specifying which
166
  /// objects (files, functions, variables) should be imbued with the XRay
167
  /// "never instrument" attribute.
168
  /// WARNING: This is a deprecated field and will go away in the future.
169
  std::vector<std::string> XRayNeverInstrumentFiles;
170
171
  /// Paths to the XRay attribute list files, specifying which objects
172
  /// (files, functions, variables) should be imbued with the appropriate XRay
173
  /// attribute(s).
174
  std::vector<std::string> XRayAttrListFiles;
175
176
  clang::ObjCRuntime ObjCRuntime;
177
178
  std::string ObjCConstantStringClass;
179
180
  /// The name of the handler function to be called when -ftrapv is
181
  /// specified.
182
  ///
183
  /// If none is specified, abort (GCC-compatible behaviour).
184
  std::string OverflowHandler;
185
186
  /// The module currently being compiled as speficied by -fmodule-name.
187
  std::string ModuleName;
188
189
  /// The name of the current module, of which the main source file
190
  /// is a part. If CompilingModule is set, we are compiling the interface
191
  /// of this module, otherwise we are compiling an implementation file of
192
  /// it. This starts as ModuleName in case -fmodule-name is provided and
193
  /// changes during compilation to reflect the current module.
194
  std::string CurrentModule;
195
196
  /// The names of any features to enable in module 'requires' decls
197
  /// in addition to the hard-coded list in Module.cpp and the target features.
198
  ///
199
  /// This list is sorted.
200
  std::vector<std::string> ModuleFeatures;
201
202
  /// Options for parsing comments.
203
  CommentOptions CommentOpts;
204
205
  /// A list of all -fno-builtin-* function names (e.g., memset).
206
  std::vector<std::string> NoBuiltinFuncs;
207
208
  /// Triples of the OpenMP targets that the host code codegen should
209
  /// take into account in order to generate accurate offloading descriptors.
210
  std::vector<llvm::Triple> OMPTargetTriples;
211
212
  /// Name of the IR file that contains the result of the OpenMP target
213
  /// host code generation.
214
  std::string OMPHostIRFile;
215
216
  /// Indicates whether the front-end is explicitly told that the
217
  /// input is a header file (i.e. -x c-header).
218
  bool IsHeaderFile = false;
219
220
  LangOptions();
221
222
  // Define accessors/mutators for language options of enumeration type.
223
#define LANGOPT(Name, Bits, Default, Description)
224
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
225
67.8M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getCompilingModule() const
Line
Count
Source
225
42.0M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getMSPointerToMemberRepresentationMethod() const
Line
Count
Source
225
50.9k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getDefaultCallingConv() const
Line
Count
Source
225
4.51M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getDefaultFPContractMode() const
Line
Count
Source
225
71.7k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getAddressSpaceMapMangling() const
Line
Count
Source
225
51.1k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getGC() const
Line
Count
Source
225
12.8M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getValueVisibilityMode() const
Line
Count
Source
225
1.16M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getTypeVisibilityMode() const
Line
Count
Source
225
868k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getStackProtector() const
Line
Count
Source
225
921k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getSignedOverflowBehavior() const
Line
Count
Source
225
560k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getClangABICompat() const
Line
Count
Source
225
4.73M
  Type get##Name() const { return static_cast<Type>(Name); } \
226
11.7M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setCompilingModule(clang::LangOptions::CompilingModuleKind)
Line
Count
Source
226
1.09M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setMSPointerToMemberRepresentationMethod(clang::LangOptions::PragmaMSPointersToMembersKind)
Line
Count
Source
226
1.05M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setDefaultCallingConv(clang::LangOptions::DefaultCallingConvention)
Line
Count
Source
226
1.05M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setDefaultFPContractMode(clang::LangOptions::FPContractModeKind)
Line
Count
Source
226
1.05M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setAddressSpaceMapMangling(clang::LangOptions::AddrSpaceMapMangling)
Line
Count
Source
226
1.05M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setGC(clang::LangOptions::GCMode)
Line
Count
Source
226
1.05M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setValueVisibilityMode(clang::Visibility)
Line
Count
Source
226
1.08M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setTypeVisibilityMode(clang::Visibility)
Line
Count
Source
226
1.08M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setStackProtector(clang::LangOptions::StackProtectorMode)
Line
Count
Source
226
1.08M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setSignedOverflowBehavior(clang::LangOptions::SignedOverflowBehaviorTy)
Line
Count
Source
226
1.05M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setClangABICompat(clang::LangOptions::ClangABI)
Line
Count
Source
226
1.05M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
227
#include "clang/Basic/LangOptions.def"
228
229
  /// Are we compiling a module interface (.cppm or module map)?
230
42.0M
  bool isCompilingModule() const {
231
42.0M
    return getCompilingModule() != CMK_None;
232
42.0M
  }
233
234
  /// Do we need to track the owning module for a local declaration?
235
41.4M
  bool trackLocalOwningModule() const {
236
41.4M
    return isCompilingModule() || 
ModulesLocalVisibility41.1M
||
ModulesTS41.1M
;
237
41.4M
  }
238
239
258k
  bool isSignedOverflowDefined() const {
240
258k
    return getSignedOverflowBehavior() == SOB_Defined;
241
258k
  }
242
243
272
  bool isSubscriptPointerArithmetic() const {
244
272
    return ObjCRuntime.isSubscriptPointerArithmetic() &&
245
272
           
!ObjCSubscriptingLegacyRuntime11
;
246
272
  }
247
248
42.5k
  bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
249
42.5k
    return MSCompatibilityVersion >= MajorVersion * 10000000U;
250
42.5k
  }
251
252
  /// Reset all of the options that are not considered when building a
253
  /// module.
254
  void resetNonModularOptions();
255
256
  /// Is this a libc/libm function that is no longer recognized as a
257
  /// builtin because a -fno-builtin-* option has been specified?
258
  bool isNoBuiltinFunc(StringRef Name) const;
259
260
  /// True if any ObjC types may have non-trivial lifetime qualifiers.
261
6.93M
  bool allowsNonTrivialObjCLifetimeQualifiers() const {
262
6.93M
    return ObjCAutoRefCount || 
ObjCWeak6.92M
;
263
6.93M
  }
264
265
1.32M
  bool assumeFunctionsAreConvergent() const {
266
1.32M
    return (CUDA && 
CUDAIsDevice625
) ||
OpenCL1.32M
;
267
1.32M
  }
268
269
  /// Return the OpenCL C or C++ version as a VersionTuple.
270
  VersionTuple getOpenCLVersionTuple() const;
271
};
272
273
/// Floating point control options
274
0
class FPOptions {
275
public:
276
  FPOptions() : fp_contract(LangOptions::FPC_Off), 
277
679k
                fenv_access(LangOptions::FEA_Off) {}
278
279
  // Used for serializing.
280
  explicit FPOptions(unsigned I)
281
      : fp_contract(static_cast<LangOptions::FPContractModeKind>(I & 3)),
282
        fenv_access(static_cast<LangOptions::FEnvAccessModeKind>((I >> 2) & 1))
283
1.73M
        {}
284
285
  explicit FPOptions(const LangOptions &LangOpts)
286
      : fp_contract(LangOpts.getDefaultFPContractMode()),
287
37.4k
        fenv_access(LangOptions::FEA_Off) {}
288
  // FIXME: Use getDefaultFEnvAccessMode() when available.
289
290
35.0k
  bool allowFPContractWithinStatement() const {
291
35.0k
    return fp_contract == LangOptions::FPC_On;
292
35.0k
  }
293
294
46.1k
  bool allowFPContractAcrossStatement() const {
295
46.1k
    return fp_contract == LangOptions::FPC_Fast;
296
46.1k
  }
297
298
17
  void setAllowFPContractWithinStatement() {
299
17
    fp_contract = LangOptions::FPC_On;
300
17
  }
301
302
6
  void setAllowFPContractAcrossStatement() {
303
6
    fp_contract = LangOptions::FPC_Fast;
304
6
  }
305
306
74
  void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
307
308
  bool allowFEnvAccess() const {
309
    return fenv_access == LangOptions::FEA_On;
310
  }
311
312
1
  void setAllowFEnvAccess() {
313
1
    fenv_access = LangOptions::FEA_On;
314
1
  }
315
316
2
  void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; }
317
318
  /// Used to serialize this.
319
6.83M
  unsigned getInt() const { return fp_contract | (fenv_access << 2); }
320
321
private:
322
  /// Adjust BinaryOperator::FPFeatures to match the total bit-field size 
323
  /// of these two.
324
  unsigned fp_contract : 2;
325
  unsigned fenv_access : 1;
326
};
327
328
/// Describes the kind of translation unit being processed.
329
enum TranslationUnitKind {
330
  /// The translation unit is a complete translation unit.
331
  TU_Complete,
332
333
  /// The translation unit is a prefix to a translation unit, and is
334
  /// not complete.
335
  TU_Prefix,
336
337
  /// The translation unit is a module.
338
  TU_Module
339
};
340
341
} // namespace clang
342
343
#endif // LLVM_CLANG_BASIC_LANGOPTIONS_H