Coverage Report

Created: 2018-11-16 02:38

/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
    /// Attempt to be ABI-compatible with code generated by Clang 7.0.x
128
    /// (SVN r338536). This causes alignof (C++) and _Alignof (C11) to be
129
    /// compatible with __alignof (i.e., return the preferred alignment)
130
    /// rather than returning the required alignment.
131
    Ver7,
132
133
    /// Conform to the underlying platform's C and C++ ABIs as closely
134
    /// as we can.
135
    Latest
136
  };
137
138
  enum class CoreFoundationABI {
139
    /// No interoperability ABI has been specified
140
    Unspecified,
141
    /// CoreFoundation does not have any language interoperability
142
    Standalone,
143
    /// Interoperability with the ObjectiveC runtime
144
    ObjectiveC,
145
    /// Interoperability with the latest known version of the Swift runtime
146
    Swift,
147
    /// Interoperability with the Swift 5.0 runtime
148
    Swift5_0,
149
    /// Interoperability with the Swift 4.2 runtime
150
    Swift4_2,
151
    /// Interoperability with the Swift 4.1 runtime
152
    Swift4_1,
153
  };
154
155
  enum FPContractModeKind {
156
    // Form fused FP ops only where result will not be affected.
157
    FPC_Off,
158
159
    // Form fused FP ops according to FP_CONTRACT rules.
160
    FPC_On,
161
162
    // Aggressively fuse FP ops (E.g. FMA).
163
    FPC_Fast
164
  };
165
166
  // TODO: merge FEnvAccessModeKind and FPContractModeKind
167
  enum FEnvAccessModeKind {
168
    FEA_Off,
169
170
    FEA_On
171
  };
172
173
174
public:
175
  /// Set of enabled sanitizers.
176
  SanitizerSet Sanitize;
177
178
  /// Paths to blacklist files specifying which objects
179
  /// (files, functions, variables) should not be instrumented.
180
  std::vector<std::string> SanitizerBlacklistFiles;
181
182
  /// Paths to the XRay "always instrument" files specifying which
183
  /// objects (files, functions, variables) should be imbued with the XRay
184
  /// "always instrument" attribute.
185
  /// WARNING: This is a deprecated field and will go away in the future.
186
  std::vector<std::string> XRayAlwaysInstrumentFiles;
187
188
  /// Paths to the XRay "never instrument" files specifying which
189
  /// objects (files, functions, variables) should be imbued with the XRay
190
  /// "never instrument" attribute.
191
  /// WARNING: This is a deprecated field and will go away in the future.
192
  std::vector<std::string> XRayNeverInstrumentFiles;
193
194
  /// Paths to the XRay attribute list files, specifying which objects
195
  /// (files, functions, variables) should be imbued with the appropriate XRay
196
  /// attribute(s).
197
  std::vector<std::string> XRayAttrListFiles;
198
199
  clang::ObjCRuntime ObjCRuntime;
200
201
  CoreFoundationABI CFRuntime = CoreFoundationABI::Unspecified;
202
203
  std::string ObjCConstantStringClass;
204
205
  /// The name of the handler function to be called when -ftrapv is
206
  /// specified.
207
  ///
208
  /// If none is specified, abort (GCC-compatible behaviour).
209
  std::string OverflowHandler;
210
211
  /// The module currently being compiled as speficied by -fmodule-name.
212
  std::string ModuleName;
213
214
  /// The name of the current module, of which the main source file
215
  /// is a part. If CompilingModule is set, we are compiling the interface
216
  /// of this module, otherwise we are compiling an implementation file of
217
  /// it. This starts as ModuleName in case -fmodule-name is provided and
218
  /// changes during compilation to reflect the current module.
219
  std::string CurrentModule;
220
221
  /// The names of any features to enable in module 'requires' decls
222
  /// in addition to the hard-coded list in Module.cpp and the target features.
223
  ///
224
  /// This list is sorted.
225
  std::vector<std::string> ModuleFeatures;
226
227
  /// Options for parsing comments.
228
  CommentOptions CommentOpts;
229
230
  /// A list of all -fno-builtin-* function names (e.g., memset).
231
  std::vector<std::string> NoBuiltinFuncs;
232
233
  /// Triples of the OpenMP targets that the host code codegen should
234
  /// take into account in order to generate accurate offloading descriptors.
235
  std::vector<llvm::Triple> OMPTargetTriples;
236
237
  /// Name of the IR file that contains the result of the OpenMP target
238
  /// host code generation.
239
  std::string OMPHostIRFile;
240
241
  /// Indicates whether the front-end is explicitly told that the
242
  /// input is a header file (i.e. -x c-header).
243
  bool IsHeaderFile = false;
244
245
  LangOptions();
246
247
  // Define accessors/mutators for language options of enumeration type.
248
#define LANGOPT(Name, Bits, Default, Description)
249
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
250
68.1M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getCompilingModule() const
Line
Count
Source
250
42.2M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getMSPointerToMemberRepresentationMethod() const
Line
Count
Source
250
51.4k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getDefaultCallingConv() const
Line
Count
Source
250
4.55M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getDefaultFPContractMode() const
Line
Count
Source
250
72.4k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getAddressSpaceMapMangling() const
Line
Count
Source
250
51.5k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getGC() const
Line
Count
Source
250
12.9M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getValueVisibilityMode() const
Line
Count
Source
250
1.16M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getTypeVisibilityMode() const
Line
Count
Source
250
874k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getStackProtector() const
Line
Count
Source
250
929k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getSignedOverflowBehavior() const
Line
Count
Source
250
563k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getClangABICompat() const
Line
Count
Source
250
4.74M
  Type get##Name() const { return static_cast<Type>(Name); } \
251
11.7M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setCompilingModule(clang::LangOptions::CompilingModuleKind)
Line
Count
Source
251
1.09M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setMSPointerToMemberRepresentationMethod(clang::LangOptions::PragmaMSPointersToMembersKind)
Line
Count
Source
251
1.05M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setDefaultCallingConv(clang::LangOptions::DefaultCallingConvention)
Line
Count
Source
251
1.05M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setDefaultFPContractMode(clang::LangOptions::FPContractModeKind)
Line
Count
Source
251
1.05M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setAddressSpaceMapMangling(clang::LangOptions::AddrSpaceMapMangling)
Line
Count
Source
251
1.05M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setGC(clang::LangOptions::GCMode)
Line
Count
Source
251
1.05M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setValueVisibilityMode(clang::Visibility)
Line
Count
Source
251
1.08M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setTypeVisibilityMode(clang::Visibility)
Line
Count
Source
251
1.08M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setStackProtector(clang::LangOptions::StackProtectorMode)
Line
Count
Source
251
1.08M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setSignedOverflowBehavior(clang::LangOptions::SignedOverflowBehaviorTy)
Line
Count
Source
251
1.05M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setClangABICompat(clang::LangOptions::ClangABI)
Line
Count
Source
251
1.05M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
252
#include "clang/Basic/LangOptions.def"
253
254
  /// Are we compiling a module interface (.cppm or module map)?
255
42.2M
  bool isCompilingModule() const {
256
42.2M
    return getCompilingModule() != CMK_None;
257
42.2M
  }
258
259
  /// Do we need to track the owning module for a local declaration?
260
41.5M
  bool trackLocalOwningModule() const {
261
41.5M
    return isCompilingModule() || 
ModulesLocalVisibility41.3M
||
ModulesTS41.3M
;
262
41.5M
  }
263
264
258k
  bool isSignedOverflowDefined() const {
265
258k
    return getSignedOverflowBehavior() == SOB_Defined;
266
258k
  }
267
268
263
  bool isSubscriptPointerArithmetic() const {
269
263
    return ObjCRuntime.isSubscriptPointerArithmetic() &&
270
263
           
!ObjCSubscriptingLegacyRuntime11
;
271
263
  }
272
273
44.6k
  bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
274
44.6k
    return MSCompatibilityVersion >= MajorVersion * 10000000U;
275
44.6k
  }
276
277
  /// Reset all of the options that are not considered when building a
278
  /// module.
279
  void resetNonModularOptions();
280
281
  /// Is this a libc/libm function that is no longer recognized as a
282
  /// builtin because a -fno-builtin-* option has been specified?
283
  bool isNoBuiltinFunc(StringRef Name) const;
284
285
  /// True if any ObjC types may have non-trivial lifetime qualifiers.
286
6.97M
  bool allowsNonTrivialObjCLifetimeQualifiers() const {
287
6.97M
    return ObjCAutoRefCount || 
ObjCWeak6.97M
;
288
6.97M
  }
289
290
1.32M
  bool assumeFunctionsAreConvergent() const {
291
1.32M
    return (CUDA && 
CUDAIsDevice889
) ||
OpenCL1.32M
;
292
1.32M
  }
293
294
  /// Return the OpenCL C or C++ version as a VersionTuple.
295
  VersionTuple getOpenCLVersionTuple() const;
296
};
297
298
/// Floating point control options
299
0
class FPOptions {
300
public:
301
  FPOptions() : fp_contract(LangOptions::FPC_Off),
302
689k
                fenv_access(LangOptions::FEA_Off) {}
303
304
  // Used for serializing.
305
  explicit FPOptions(unsigned I)
306
      : fp_contract(static_cast<LangOptions::FPContractModeKind>(I & 3)),
307
        fenv_access(static_cast<LangOptions::FEnvAccessModeKind>((I >> 2) & 1))
308
1.75M
        {}
309
310
  explicit FPOptions(const LangOptions &LangOpts)
311
      : fp_contract(LangOpts.getDefaultFPContractMode()),
312
37.8k
        fenv_access(LangOptions::FEA_Off) {}
313
  // FIXME: Use getDefaultFEnvAccessMode() when available.
314
315
35.1k
  bool allowFPContractWithinStatement() const {
316
35.1k
    return fp_contract == LangOptions::FPC_On;
317
35.1k
  }
318
319
46.2k
  bool allowFPContractAcrossStatement() const {
320
46.2k
    return fp_contract == LangOptions::FPC_Fast;
321
46.2k
  }
322
323
17
  void setAllowFPContractWithinStatement() {
324
17
    fp_contract = LangOptions::FPC_On;
325
17
  }
326
327
6
  void setAllowFPContractAcrossStatement() {
328
6
    fp_contract = LangOptions::FPC_Fast;
329
6
  }
330
331
74
  void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
332
333
  bool allowFEnvAccess() const {
334
    return fenv_access == LangOptions::FEA_On;
335
  }
336
337
1
  void setAllowFEnvAccess() {
338
1
    fenv_access = LangOptions::FEA_On;
339
1
  }
340
341
2
  void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; }
342
343
  /// Used to serialize this.
344
6.95M
  unsigned getInt() const { return fp_contract | (fenv_access << 2); }
345
346
private:
347
  /// Adjust BinaryOperator::FPFeatures to match the total bit-field size
348
  /// of these two.
349
  unsigned fp_contract : 2;
350
  unsigned fenv_access : 1;
351
};
352
353
/// Describes the kind of translation unit being processed.
354
enum TranslationUnitKind {
355
  /// The translation unit is a complete translation unit.
356
  TU_Complete,
357
358
  /// The translation unit is a prefix to a translation unit, and is
359
  /// not complete.
360
  TU_Prefix,
361
362
  /// The translation unit is a module.
363
  TU_Module
364
};
365
366
} // namespace clang
367
368
#endif // LLVM_CLANG_BASIC_LANGOPTIONS_H