Coverage Report

Created: 2020-02-15 09:57

/Users/buildslave/jenkins/workspace/coverage/llvm-project/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
// 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
/// \file
10
/// Defines the clang::LangOptions interface.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_BASIC_LANGOPTIONS_H
15
#define LLVM_CLANG_BASIC_LANGOPTIONS_H
16
17
#include "clang/Basic/CommentOptions.h"
18
#include "clang/Basic/LLVM.h"
19
#include "clang/Basic/ObjCRuntime.h"
20
#include "clang/Basic/Sanitizers.h"
21
#include "clang/Basic/Visibility.h"
22
#include "llvm/ADT/StringRef.h"
23
#include "llvm/ADT/Triple.h"
24
#include <string>
25
#include <vector>
26
27
namespace clang {
28
29
/// Bitfields of LangOptions, split out from LangOptions in order to ensure that
30
/// this large collection of bitfields is a trivial class type.
31
class LangOptionsBase {
32
public:
33
  // Define simple language options (with no accessors).
34
#define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
35
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
36
#include "clang/Basic/LangOptions.def"
37
38
protected:
39
  // Define language options of enumeration type. These are private, and will
40
  // have accessors (below).
41
#define LANGOPT(Name, Bits, Default, Description)
42
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
43
  unsigned Name : Bits;
44
#include "clang/Basic/LangOptions.def"
45
};
46
47
/// In the Microsoft ABI, this controls the placement of virtual displacement
48
/// members used to implement virtual inheritance.
49
enum class MSVtorDispMode { Never, ForVBaseOverride, ForVFTable };
50
51
/// Keeps track of the various options that can be
52
/// enabled, which controls the dialect of C or C++ that is accepted.
53
class LangOptions : public LangOptionsBase {
54
public:
55
  using Visibility = clang::Visibility;
56
57
  enum GCMode { NonGC, GCOnly, HybridGC };
58
  enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
59
60
  // Automatic variables live on the stack, and when trivial they're usually
61
  // uninitialized because it's undefined behavior to use them without
62
  // initializing them.
63
  enum class TrivialAutoVarInitKind { Uninitialized, Zero, Pattern };
64
65
  enum SignedOverflowBehaviorTy {
66
    // Default C standard behavior.
67
    SOB_Undefined,
68
69
    // -fwrapv
70
    SOB_Defined,
71
72
    // -ftrapv
73
    SOB_Trapping
74
  };
75
76
  // FIXME: Unify with TUKind.
77
  enum CompilingModuleKind {
78
    /// Not compiling a module interface at all.
79
    CMK_None,
80
81
    /// Compiling a module from a module map.
82
    CMK_ModuleMap,
83
84
    /// Compiling a module from a list of header files.
85
    CMK_HeaderModule,
86
87
    /// Compiling a C++ modules TS module interface unit.
88
    CMK_ModuleInterface,
89
  };
90
91
  enum PragmaMSPointersToMembersKind {
92
    PPTMK_BestCase,
93
    PPTMK_FullGeneralitySingleInheritance,
94
    PPTMK_FullGeneralityMultipleInheritance,
95
    PPTMK_FullGeneralityVirtualInheritance
96
  };
97
98
  using MSVtorDispMode = clang::MSVtorDispMode;
99
100
  enum DefaultCallingConvention {
101
    DCC_None,
102
    DCC_CDecl,
103
    DCC_FastCall,
104
    DCC_StdCall,
105
    DCC_VectorCall,
106
    DCC_RegCall
107
  };
108
109
  enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
110
111
  // Corresponds to _MSC_VER
112
  enum MSVCMajorVersion {
113
    MSVC2010 = 1600,
114
    MSVC2012 = 1700,
115
    MSVC2013 = 1800,
116
    MSVC2015 = 1900,
117
    MSVC2017 = 1910,
118
    MSVC2017_5 = 1912,
119
    MSVC2017_7 = 1914,
120
  };
121
122
  /// Clang versions with different platform ABI conformance.
123
  enum class ClangABI {
124
    /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
125
    /// (SVN r257626). This causes <1 x long long> to be passed in an
126
    /// integer register instead of an SSE register on x64_64.
127
    Ver3_8,
128
129
    /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
130
    /// (SVN r291814). This causes move operations to be ignored when
131
    /// determining whether a class type can be passed or returned directly.
132
    Ver4,
133
134
    /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
135
    /// (SVN r321711). This causes determination of whether a type is
136
    /// standard-layout to ignore collisions between empty base classes
137
    /// and between base classes and member subobjects, which affects
138
    /// whether we reuse base class tail padding in some ABIs.
139
    Ver6,
140
141
    /// Attempt to be ABI-compatible with code generated by Clang 7.0.x
142
    /// (SVN r338536). This causes alignof (C++) and _Alignof (C11) to be
143
    /// compatible with __alignof (i.e., return the preferred alignment)
144
    /// rather than returning the required alignment.
145
    Ver7,
146
147
    /// Attempt to be ABI-compatible with code generated by Clang 9.0.x
148
    /// (SVN r351319). This causes vectors of __int128 to be passed in memory
149
    /// instead of passing in multiple scalar registers on x86_64 on Linux and
150
    /// NetBSD.
151
    Ver9,
152
153
    /// Conform to the underlying platform's C and C++ ABIs as closely
154
    /// as we can.
155
    Latest
156
  };
157
158
  enum class CoreFoundationABI {
159
    /// No interoperability ABI has been specified
160
    Unspecified,
161
    /// CoreFoundation does not have any language interoperability
162
    Standalone,
163
    /// Interoperability with the ObjectiveC runtime
164
    ObjectiveC,
165
    /// Interoperability with the latest known version of the Swift runtime
166
    Swift,
167
    /// Interoperability with the Swift 5.0 runtime
168
    Swift5_0,
169
    /// Interoperability with the Swift 4.2 runtime
170
    Swift4_2,
171
    /// Interoperability with the Swift 4.1 runtime
172
    Swift4_1,
173
  };
174
175
  enum FPContractModeKind {
176
    // Form fused FP ops only where result will not be affected.
177
    FPC_Off,
178
179
    // Form fused FP ops according to FP_CONTRACT rules.
180
    FPC_On,
181
182
    // Aggressively fuse FP ops (E.g. FMA).
183
    FPC_Fast
184
  };
185
186
  // TODO: merge FEnvAccessModeKind and FPContractModeKind
187
  enum FEnvAccessModeKind {
188
    FEA_Off,
189
190
    FEA_On
191
  };
192
193
  // Values of the following enumerations correspond to metadata arguments
194
  // specified for constrained floating-point intrinsics:
195
  // http://llvm.org/docs/LangRef.html#constrained-floating-point-intrinsics.
196
197
  /// Possible rounding modes.
198
  enum FPRoundingModeKind {
199
    /// Rounding to nearest, corresponds to "round.tonearest".
200
    FPR_ToNearest,
201
    /// Rounding toward -Inf, corresponds to "round.downward".
202
    FPR_Downward,
203
    /// Rounding toward +Inf, corresponds to "round.upward".
204
    FPR_Upward,
205
    /// Rounding toward zero, corresponds to "round.towardzero".
206
    FPR_TowardZero,
207
    /// Is determined by runtime environment, corresponds to "round.dynamic".
208
    FPR_Dynamic
209
  };
210
211
  /// Possible floating point exception behavior.
212
  enum FPExceptionModeKind {
213
    /// Assume that floating-point exceptions are masked.
214
    FPE_Ignore,
215
    /// Transformations do not cause new exceptions but may hide some.
216
    FPE_MayTrap,
217
    /// Strictly preserve the floating-point exception semantics.
218
    FPE_Strict
219
  };
220
221
  enum class LaxVectorConversionKind {
222
    /// Permit no implicit vector bitcasts.
223
    None,
224
    /// Permit vector bitcasts between integer vectors with different numbers
225
    /// of elements but the same total bit-width.
226
    Integer,
227
    /// Permit vector bitcasts between all vectors with the same total
228
    /// bit-width.
229
    All,
230
  };
231
232
public:
233
  /// Set of enabled sanitizers.
234
  SanitizerSet Sanitize;
235
236
  /// Paths to blacklist files specifying which objects
237
  /// (files, functions, variables) should not be instrumented.
238
  std::vector<std::string> SanitizerBlacklistFiles;
239
240
  /// Paths to the XRay "always instrument" files specifying which
241
  /// objects (files, functions, variables) should be imbued with the XRay
242
  /// "always instrument" attribute.
243
  /// WARNING: This is a deprecated field and will go away in the future.
244
  std::vector<std::string> XRayAlwaysInstrumentFiles;
245
246
  /// Paths to the XRay "never instrument" files specifying which
247
  /// objects (files, functions, variables) should be imbued with the XRay
248
  /// "never instrument" attribute.
249
  /// WARNING: This is a deprecated field and will go away in the future.
250
  std::vector<std::string> XRayNeverInstrumentFiles;
251
252
  /// Paths to the XRay attribute list files, specifying which objects
253
  /// (files, functions, variables) should be imbued with the appropriate XRay
254
  /// attribute(s).
255
  std::vector<std::string> XRayAttrListFiles;
256
257
  clang::ObjCRuntime ObjCRuntime;
258
259
  CoreFoundationABI CFRuntime = CoreFoundationABI::Unspecified;
260
261
  std::string ObjCConstantStringClass;
262
263
  /// The name of the handler function to be called when -ftrapv is
264
  /// specified.
265
  ///
266
  /// If none is specified, abort (GCC-compatible behaviour).
267
  std::string OverflowHandler;
268
269
  /// The module currently being compiled as specified by -fmodule-name.
270
  std::string ModuleName;
271
272
  /// The name of the current module, of which the main source file
273
  /// is a part. If CompilingModule is set, we are compiling the interface
274
  /// of this module, otherwise we are compiling an implementation file of
275
  /// it. This starts as ModuleName in case -fmodule-name is provided and
276
  /// changes during compilation to reflect the current module.
277
  std::string CurrentModule;
278
279
  /// The names of any features to enable in module 'requires' decls
280
  /// in addition to the hard-coded list in Module.cpp and the target features.
281
  ///
282
  /// This list is sorted.
283
  std::vector<std::string> ModuleFeatures;
284
285
  /// Options for parsing comments.
286
  CommentOptions CommentOpts;
287
288
  /// A list of all -fno-builtin-* function names (e.g., memset).
289
  std::vector<std::string> NoBuiltinFuncs;
290
291
  /// Triples of the OpenMP targets that the host code codegen should
292
  /// take into account in order to generate accurate offloading descriptors.
293
  std::vector<llvm::Triple> OMPTargetTriples;
294
295
  /// Name of the IR file that contains the result of the OpenMP target
296
  /// host code generation.
297
  std::string OMPHostIRFile;
298
299
  /// Indicates whether the front-end is explicitly told that the
300
  /// input is a header file (i.e. -x c-header).
301
  bool IsHeaderFile = false;
302
303
  LangOptions();
304
305
  // Define accessors/mutators for language options of enumeration type.
306
#define LANGOPT(Name, Bits, Default, Description)
307
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
308
112M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getLaxVectorConversions() const
Line
Count
Source
308
1.24M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getCompilingModule() const
Line
Count
Source
308
88.5M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getMSPointerToMemberRepresentationMethod() const
Line
Count
Source
308
82.0k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getDefaultCallingConv() const
Line
Count
Source
308
6.22M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getDefaultFPContractMode() const
Line
Count
Source
308
96.2k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getFPRoundingMode() const
Line
Count
Source
308
343k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getFPExceptionMode() const
Line
Count
Source
308
343k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getAddressSpaceMapMangling() const
Line
Count
Source
308
89.5k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getGC() const
Line
Count
Source
308
7.33M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getValueVisibilityMode() const
Line
Count
Source
308
658k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getTypeVisibilityMode() const
Line
Count
Source
308
192k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getStackProtector() const
Line
Count
Source
308
732k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getTrivialAutoVarInit() const
Line
Count
Source
308
192k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getSignedOverflowBehavior() const
Line
Count
Source
308
281k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getVtorDispMode() const
Line
Count
Source
308
1.09M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getClangABICompat() const
Line
Count
Source
308
4.75M
  Type get##Name() const { return static_cast<Type>(Name); } \
309
63.3M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setLaxVectorConversions(clang::LangOptions::LaxVectorConversionKind)
Line
Count
Source
309
3.93M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setCompilingModule(clang::LangOptions::CompilingModuleKind)
Line
Count
Source
309
3.98M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setMSPointerToMemberRepresentationMethod(clang::LangOptions::PragmaMSPointersToMembersKind)
Line
Count
Source
309
3.93M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setDefaultCallingConv(clang::LangOptions::DefaultCallingConvention)
Line
Count
Source
309
3.93M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setDefaultFPContractMode(clang::LangOptions::FPContractModeKind)
Line
Count
Source
309
3.93M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setFPRoundingMode(clang::LangOptions::FPRoundingModeKind)
Line
Count
Source
309
3.98M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setFPExceptionMode(clang::LangOptions::FPExceptionModeKind)
Line
Count
Source
309
3.98M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setAddressSpaceMapMangling(clang::LangOptions::AddrSpaceMapMangling)
Line
Count
Source
309
3.93M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setGC(clang::LangOptions::GCMode)
Line
Count
Source
309
3.93M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setValueVisibilityMode(clang::Visibility)
Line
Count
Source
309
3.98M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setTypeVisibilityMode(clang::Visibility)
Line
Count
Source
309
3.98M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setStackProtector(clang::LangOptions::StackProtectorMode)
Line
Count
Source
309
3.98M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setTrivialAutoVarInit(clang::LangOptions::TrivialAutoVarInitKind)
Line
Count
Source
309
3.93M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setSignedOverflowBehavior(clang::LangOptions::SignedOverflowBehaviorTy)
Line
Count
Source
309
3.93M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setVtorDispMode(clang::MSVtorDispMode)
Line
Count
Source
309
3.98M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setClangABICompat(clang::LangOptions::ClangABI)
Line
Count
Source
309
3.93M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
310
#include "clang/Basic/LangOptions.def"
311
312
  /// Are we compiling a module interface (.cppm or module map)?
313
88.4M
  bool isCompilingModule() const {
314
88.4M
    return getCompilingModule() != CMK_None;
315
88.4M
  }
316
317
  /// Do we need to track the owning module for a local declaration?
318
68.5M
  bool trackLocalOwningModule() const {
319
68.5M
    return isCompilingModule() || 
ModulesLocalVisibility54.9M
;
320
68.5M
  }
321
322
59.8k
  bool isSignedOverflowDefined() const {
323
59.8k
    return getSignedOverflowBehavior() == SOB_Defined;
324
59.8k
  }
325
326
583
  bool isSubscriptPointerArithmetic() const {
327
583
    return ObjCRuntime.isSubscriptPointerArithmetic() &&
328
583
           
!ObjCSubscriptingLegacyRuntime17
;
329
583
  }
330
331
52.3k
  bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
332
52.3k
    return MSCompatibilityVersion >= MajorVersion * 100000U;
333
52.3k
  }
334
335
  /// Reset all of the options that are not considered when building a
336
  /// module.
337
  void resetNonModularOptions();
338
339
  /// Is this a libc/libm function that is no longer recognized as a
340
  /// builtin because a -fno-builtin-* option has been specified?
341
  bool isNoBuiltinFunc(StringRef Name) const;
342
343
  /// True if any ObjC types may have non-trivial lifetime qualifiers.
344
5.12M
  bool allowsNonTrivialObjCLifetimeQualifiers() const {
345
5.12M
    return ObjCAutoRefCount || 
ObjCWeak5.08M
;
346
5.12M
  }
347
348
576k
  bool assumeFunctionsAreConvergent() const {
349
576k
    return ConvergentFunctions;
350
576k
  }
351
352
  /// Return the OpenCL C or C++ version as a VersionTuple.
353
  VersionTuple getOpenCLVersionTuple() const;
354
};
355
356
/// Floating point control options
357
class FPOptions {
358
public:
359
  FPOptions() : fp_contract(LangOptions::FPC_Off),
360
                fenv_access(LangOptions::FEA_Off),
361
                rounding(LangOptions::FPR_ToNearest),
362
                exceptions(LangOptions::FPE_Ignore)
363
392k
        {}
364
365
  // Used for serializing.
366
  explicit FPOptions(unsigned I)
367
      : fp_contract(static_cast<LangOptions::FPContractModeKind>(I & 3)),
368
        fenv_access(static_cast<LangOptions::FEnvAccessModeKind>((I >> 2) & 1)),
369
        rounding(static_cast<LangOptions::FPRoundingModeKind>((I >> 3) & 7)),
370
        exceptions(static_cast<LangOptions::FPExceptionModeKind>((I >> 6) & 3))
371
1.85M
        {}
372
373
  explicit FPOptions(const LangOptions &LangOpts)
374
      : fp_contract(LangOpts.getDefaultFPContractMode()),
375
        fenv_access(LangOptions::FEA_Off),
376
        rounding(LangOptions::FPR_ToNearest),
377
        exceptions(LangOptions::FPE_Ignore)
378
54.2k
        {}
379
  // FIXME: Use getDefaultFEnvAccessMode() when available.
380
381
4.33k
  bool allowFPContractWithinStatement() const {
382
4.33k
    return fp_contract == LangOptions::FPC_On;
383
4.33k
  }
384
385
6.10k
  bool allowFPContractAcrossStatement() const {
386
6.10k
    return fp_contract == LangOptions::FPC_Fast;
387
6.10k
  }
388
389
21
  void setAllowFPContractWithinStatement() {
390
21
    fp_contract = LangOptions::FPC_On;
391
21
  }
392
393
6
  void setAllowFPContractAcrossStatement() {
394
6
    fp_contract = LangOptions::FPC_Fast;
395
6
  }
396
397
8
  void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
398
399
0
  bool allowFEnvAccess() const {
400
0
    return fenv_access == LangOptions::FEA_On;
401
0
  }
402
403
1
  void setAllowFEnvAccess() {
404
1
    fenv_access = LangOptions::FEA_On;
405
1
  }
406
407
2
  void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; }
408
409
0
  LangOptions::FPRoundingModeKind getRoundingMode() const {
410
0
    return static_cast<LangOptions::FPRoundingModeKind>(rounding);
411
0
  }
412
413
0
  void setRoundingMode(LangOptions::FPRoundingModeKind RM) {
414
0
    rounding = RM;
415
0
  }
416
417
0
  LangOptions::FPExceptionModeKind getExceptionMode() const {
418
0
    return static_cast<LangOptions::FPExceptionModeKind>(exceptions);
419
0
  }
420
421
0
  void setExceptionMode(LangOptions::FPExceptionModeKind EM) {
422
0
    exceptions = EM;
423
0
  }
424
425
0
  bool isFPConstrained() const {
426
0
    return getRoundingMode() != LangOptions::FPR_ToNearest ||
427
0
           getExceptionMode() != LangOptions::FPE_Ignore ||
428
0
           allowFEnvAccess();
429
0
  }
430
431
  /// Used to serialize this.
432
8.25M
  unsigned getInt() const {
433
8.25M
    return fp_contract | (fenv_access << 2) | (rounding << 3)
434
8.25M
        | (exceptions << 6);
435
8.25M
  }
436
437
private:
438
  /// Adjust BinaryOperatorBitfields::FPFeatures and
439
  /// CXXOperatorCallExprBitfields::FPFeatures to match the total bit-field size
440
  /// of these fields.
441
  unsigned fp_contract : 2;
442
  unsigned fenv_access : 1;
443
  unsigned rounding : 3;
444
  unsigned exceptions : 2;
445
};
446
447
/// Describes the kind of translation unit being processed.
448
enum TranslationUnitKind {
449
  /// The translation unit is a complete translation unit.
450
  TU_Complete,
451
452
  /// The translation unit is a prefix to a translation unit, and is
453
  /// not complete.
454
  TU_Prefix,
455
456
  /// The translation unit is a module.
457
  TU_Module
458
};
459
460
} // namespace clang
461
462
#endif // LLVM_CLANG_BASIC_LANGOPTIONS_H