Coverage Report

Created: 2020-09-22 08:39

/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/FloatingPointMode.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
/// In the Microsoft ABI, this controls the placement of virtual displacement
49
/// members used to implement virtual inheritance.
50
enum class MSVtorDispMode { Never, ForVBaseOverride, ForVFTable };
51
52
/// Keeps track of the various options that can be
53
/// enabled, which controls the dialect of C or C++ that is accepted.
54
class LangOptions : public LangOptionsBase {
55
public:
56
  using Visibility = clang::Visibility;
57
  using RoundingMode = llvm::RoundingMode;
58
59
  enum GCMode { NonGC, GCOnly, HybridGC };
60
  enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
61
62
  // Automatic variables live on the stack, and when trivial they're usually
63
  // uninitialized because it's undefined behavior to use them without
64
  // initializing them.
65
  enum class TrivialAutoVarInitKind { Uninitialized, Zero, Pattern };
66
67
  enum SignedOverflowBehaviorTy {
68
    // Default C standard behavior.
69
    SOB_Undefined,
70
71
    // -fwrapv
72
    SOB_Defined,
73
74
    // -ftrapv
75
    SOB_Trapping
76
  };
77
78
  // FIXME: Unify with TUKind.
79
  enum CompilingModuleKind {
80
    /// Not compiling a module interface at all.
81
    CMK_None,
82
83
    /// Compiling a module from a module map.
84
    CMK_ModuleMap,
85
86
    /// Compiling a module from a list of header files.
87
    CMK_HeaderModule,
88
89
    /// Compiling a C++ modules TS module interface unit.
90
    CMK_ModuleInterface,
91
  };
92
93
  enum PragmaMSPointersToMembersKind {
94
    PPTMK_BestCase,
95
    PPTMK_FullGeneralitySingleInheritance,
96
    PPTMK_FullGeneralityMultipleInheritance,
97
    PPTMK_FullGeneralityVirtualInheritance
98
  };
99
100
  using MSVtorDispMode = clang::MSVtorDispMode;
101
102
  enum DefaultCallingConvention {
103
    DCC_None,
104
    DCC_CDecl,
105
    DCC_FastCall,
106
    DCC_StdCall,
107
    DCC_VectorCall,
108
    DCC_RegCall
109
  };
110
111
  enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
112
113
  // Corresponds to _MSC_VER
114
  enum MSVCMajorVersion {
115
    MSVC2010 = 1600,
116
    MSVC2012 = 1700,
117
    MSVC2013 = 1800,
118
    MSVC2015 = 1900,
119
    MSVC2017 = 1910,
120
    MSVC2017_5 = 1912,
121
    MSVC2017_7 = 1914,
122
    MSVC2019 = 1920,
123
  };
124
125
  /// Clang versions with different platform ABI conformance.
126
  enum class ClangABI {
127
    /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
128
    /// (SVN r257626). This causes <1 x long long> to be passed in an
129
    /// integer register instead of an SSE register on x64_64.
130
    Ver3_8,
131
132
    /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
133
    /// (SVN r291814). This causes move operations to be ignored when
134
    /// determining whether a class type can be passed or returned directly.
135
    Ver4,
136
137
    /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
138
    /// (SVN r321711). This causes determination of whether a type is
139
    /// standard-layout to ignore collisions between empty base classes
140
    /// and between base classes and member subobjects, which affects
141
    /// whether we reuse base class tail padding in some ABIs.
142
    Ver6,
143
144
    /// Attempt to be ABI-compatible with code generated by Clang 7.0.x
145
    /// (SVN r338536). This causes alignof (C++) and _Alignof (C11) to be
146
    /// compatible with __alignof (i.e., return the preferred alignment)
147
    /// rather than returning the required alignment.
148
    Ver7,
149
150
    /// Attempt to be ABI-compatible with code generated by Clang 9.0.x
151
    /// (SVN r351319). This causes vectors of __int128 to be passed in memory
152
    /// instead of passing in multiple scalar registers on x86_64 on Linux and
153
    /// NetBSD.
154
    Ver9,
155
156
    /// Conform to the underlying platform's C and C++ ABIs as closely
157
    /// as we can.
158
    Latest
159
  };
160
161
  enum class CoreFoundationABI {
162
    /// No interoperability ABI has been specified
163
    Unspecified,
164
    /// CoreFoundation does not have any language interoperability
165
    Standalone,
166
    /// Interoperability with the ObjectiveC runtime
167
    ObjectiveC,
168
    /// Interoperability with the latest known version of the Swift runtime
169
    Swift,
170
    /// Interoperability with the Swift 5.0 runtime
171
    Swift5_0,
172
    /// Interoperability with the Swift 4.2 runtime
173
    Swift4_2,
174
    /// Interoperability with the Swift 4.1 runtime
175
    Swift4_1,
176
  };
177
178
  enum FPModeKind {
179
    // Disable the floating point pragma
180
    FPM_Off,
181
182
    // Enable the floating point pragma
183
    FPM_On,
184
185
    // Aggressively fuse FP ops (E.g. FMA).
186
    FPM_Fast
187
  };
188
189
  /// Alias for RoundingMode::NearestTiesToEven.
190
  static constexpr unsigned FPR_ToNearest =
191
      static_cast<unsigned>(llvm::RoundingMode::NearestTiesToEven);
192
193
  /// Possible floating point exception behavior.
194
  enum FPExceptionModeKind {
195
    /// Assume that floating-point exceptions are masked.
196
    FPE_Ignore,
197
    /// Transformations do not cause new exceptions but may hide some.
198
    FPE_MayTrap,
199
    /// Strictly preserve the floating-point exception semantics.
200
    FPE_Strict
201
  };
202
203
  enum class LaxVectorConversionKind {
204
    /// Permit no implicit vector bitcasts.
205
    None,
206
    /// Permit vector bitcasts between integer vectors with different numbers
207
    /// of elements but the same total bit-width.
208
    Integer,
209
    /// Permit vector bitcasts between all vectors with the same total
210
    /// bit-width.
211
    All,
212
  };
213
214
  enum class SignReturnAddressScopeKind {
215
    /// No signing for any function.
216
    None,
217
    /// Sign the return address of functions that spill LR.
218
    NonLeaf,
219
    /// Sign the return address of all functions,
220
    All
221
  };
222
223
  enum class SignReturnAddressKeyKind {
224
    /// Return address signing uses APIA key.
225
    AKey,
226
    /// Return address signing uses APIB key.
227
    BKey
228
  };
229
230
public:
231
  /// Set of enabled sanitizers.
232
  SanitizerSet Sanitize;
233
234
  /// Paths to blacklist files specifying which objects
235
  /// (files, functions, variables) should not be instrumented.
236
  std::vector<std::string> SanitizerBlacklistFiles;
237
238
  /// Paths to the XRay "always instrument" files specifying which
239
  /// objects (files, functions, variables) should be imbued with the XRay
240
  /// "always instrument" attribute.
241
  /// WARNING: This is a deprecated field and will go away in the future.
242
  std::vector<std::string> XRayAlwaysInstrumentFiles;
243
244
  /// Paths to the XRay "never instrument" files specifying which
245
  /// objects (files, functions, variables) should be imbued with the XRay
246
  /// "never instrument" attribute.
247
  /// WARNING: This is a deprecated field and will go away in the future.
248
  std::vector<std::string> XRayNeverInstrumentFiles;
249
250
  /// Paths to the XRay attribute list files, specifying which objects
251
  /// (files, functions, variables) should be imbued with the appropriate XRay
252
  /// attribute(s).
253
  std::vector<std::string> XRayAttrListFiles;
254
255
  clang::ObjCRuntime ObjCRuntime;
256
257
  CoreFoundationABI CFRuntime = CoreFoundationABI::Unspecified;
258
259
  std::string ObjCConstantStringClass;
260
261
  /// The name of the handler function to be called when -ftrapv is
262
  /// specified.
263
  ///
264
  /// If none is specified, abort (GCC-compatible behaviour).
265
  std::string OverflowHandler;
266
267
  /// The module currently being compiled as specified by -fmodule-name.
268
  std::string ModuleName;
269
270
  /// The name of the current module, of which the main source file
271
  /// is a part. If CompilingModule is set, we are compiling the interface
272
  /// of this module, otherwise we are compiling an implementation file of
273
  /// it. This starts as ModuleName in case -fmodule-name is provided and
274
  /// changes during compilation to reflect the current module.
275
  std::string CurrentModule;
276
277
  /// The names of any features to enable in module 'requires' decls
278
  /// in addition to the hard-coded list in Module.cpp and the target features.
279
  ///
280
  /// This list is sorted.
281
  std::vector<std::string> ModuleFeatures;
282
283
  /// Options for parsing comments.
284
  CommentOptions CommentOpts;
285
286
  /// A list of all -fno-builtin-* function names (e.g., memset).
287
  std::vector<std::string> NoBuiltinFuncs;
288
289
  /// Triples of the OpenMP targets that the host code codegen should
290
  /// take into account in order to generate accurate offloading descriptors.
291
  std::vector<llvm::Triple> OMPTargetTriples;
292
293
  /// Name of the IR file that contains the result of the OpenMP target
294
  /// host code generation.
295
  std::string OMPHostIRFile;
296
297
  /// Indicates whether the front-end is explicitly told that the
298
  /// input is a header file (i.e. -x c-header).
299
  bool IsHeaderFile = false;
300
301
  LangOptions();
302
303
  // Define accessors/mutators for language options of enumeration type.
304
#define LANGOPT(Name, Bits, Default, Description)
305
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
306
159M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getLaxVectorConversions() const
Line
Count
Source
306
1.39M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getCompilingModule() const
Line
Count
Source
306
118M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getMSPointerToMemberRepresentationMethod() const
Line
Count
Source
306
105k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getDefaultCallingConv() const
Line
Count
Source
306
13.6M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getDefaultFPContractMode() const
Line
Count
Source
306
2.29M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getFPRoundingMode() const
Line
Count
Source
306
2.56M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getFPExceptionMode() const
Line
Count
Source
306
2.88M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getAddressSpaceMapMangling() const
Line
Count
Source
306
113k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getGC() const
Line
Count
Source
306
8.52M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getValueVisibilityMode() const
Line
Count
Source
306
821k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getTypeVisibilityMode() const
Line
Count
Source
306
199k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getStackProtector() const
Line
Count
Source
306
931k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getTrivialAutoVarInit() const
Line
Count
Source
306
223k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getSignedOverflowBehavior() const
Line
Count
Source
306
347k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getVtorDispMode() const
Line
Count
Source
306
1.23M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getClangABICompat() const
Line
Count
Source
306
4.98M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getSignReturnAddressScope() const
Line
Count
Source
306
97.0k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getSignReturnAddressKey() const
Line
Count
Source
306
84.4k
  Type get##Name() const { return static_cast<Type>(Name); } \
307
75.2M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setLaxVectorConversions(clang::LangOptions::LaxVectorConversionKind)
Line
Count
Source
307
4.15M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setCompilingModule(clang::LangOptions::CompilingModuleKind)
Line
Count
Source
307
4.22M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setMSPointerToMemberRepresentationMethod(clang::LangOptions::PragmaMSPointersToMembersKind)
Line
Count
Source
307
4.15M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setDefaultCallingConv(clang::LangOptions::DefaultCallingConvention)
Line
Count
Source
307
4.15M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setDefaultFPContractMode(clang::LangOptions::FPModeKind)
Line
Count
Source
307
4.15M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setFPRoundingMode(llvm::RoundingMode)
Line
Count
Source
307
4.22M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setFPExceptionMode(clang::LangOptions::FPExceptionModeKind)
Line
Count
Source
307
4.22M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setAddressSpaceMapMangling(clang::LangOptions::AddrSpaceMapMangling)
Line
Count
Source
307
4.15M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setGC(clang::LangOptions::GCMode)
Line
Count
Source
307
4.15M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setValueVisibilityMode(clang::Visibility)
Line
Count
Source
307
4.22M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setTypeVisibilityMode(clang::Visibility)
Line
Count
Source
307
4.22M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setStackProtector(clang::LangOptions::StackProtectorMode)
Line
Count
Source
307
4.22M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setTrivialAutoVarInit(clang::LangOptions::TrivialAutoVarInitKind)
Line
Count
Source
307
4.15M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setSignedOverflowBehavior(clang::LangOptions::SignedOverflowBehaviorTy)
Line
Count
Source
307
4.15M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setVtorDispMode(clang::MSVtorDispMode)
Line
Count
Source
307
4.22M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setClangABICompat(clang::LangOptions::ClangABI)
Line
Count
Source
307
4.15M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setSignReturnAddressScope(clang::LangOptions::SignReturnAddressScopeKind)
Line
Count
Source
307
4.15M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setSignReturnAddressKey(clang::LangOptions::SignReturnAddressKeyKind)
Line
Count
Source
307
4.15M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
308
#include "clang/Basic/LangOptions.def"
309
310
  /// Are we compiling a module interface (.cppm or module map)?
311
118M
  bool isCompilingModule() const {
312
118M
    return getCompilingModule() != CMK_None;
313
118M
  }
314
315
  /// Do we need to track the owning module for a local declaration?
316
98.7M
  bool trackLocalOwningModule() const {
317
98.7M
    return isCompilingModule() || 
ModulesLocalVisibility87.8M
;
318
98.7M
  }
319
320
67.6k
  bool isSignedOverflowDefined() const {
321
67.6k
    return getSignedOverflowBehavior() == SOB_Defined;
322
67.6k
  }
323
324
591
  bool isSubscriptPointerArithmetic() const {
325
591
    return ObjCRuntime.isSubscriptPointerArithmetic() &&
326
17
           !ObjCSubscriptingLegacyRuntime;
327
591
  }
328
329
77.5k
  bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
330
77.5k
    return MSCompatibilityVersion >= MajorVersion * 100000U;
331
77.5k
  }
332
333
  /// Reset all of the options that are not considered when building a
334
  /// module.
335
  void resetNonModularOptions();
336
337
  /// Is this a libc/libm function that is no longer recognized as a
338
  /// builtin because a -fno-builtin-* option has been specified?
339
  bool isNoBuiltinFunc(StringRef Name) const;
340
341
  /// True if any ObjC types may have non-trivial lifetime qualifiers.
342
6.26M
  bool allowsNonTrivialObjCLifetimeQualifiers() const {
343
6.26M
    return ObjCAutoRefCount || 
ObjCWeak6.23M
;
344
6.26M
  }
345
346
637k
  bool assumeFunctionsAreConvergent() const {
347
637k
    return ConvergentFunctions;
348
637k
  }
349
350
  /// Return the OpenCL C or C++ version as a VersionTuple.
351
  VersionTuple getOpenCLVersionTuple() const;
352
353
  /// Check if return address signing is enabled.
354
2.27k
  bool hasSignReturnAddress() const {
355
2.27k
    return getSignReturnAddressScope() != SignReturnAddressScopeKind::None;
356
2.27k
  }
357
358
  /// Check if return address signing uses AKey.
359
27
  bool isSignReturnAddressWithAKey() const {
360
27
    return getSignReturnAddressKey() == SignReturnAddressKeyKind::AKey;
361
27
  }
362
363
  /// Check if leaf functions are also signed.
364
27
  bool isSignReturnAddressScopeAll() const {
365
27
    return getSignReturnAddressScope() == SignReturnAddressScopeKind::All;
366
27
  }
367
};
368
369
/// Floating point control options
370
class FPOptionsOverride;
371
class FPOptions {
372
public:
373
  // We start by defining the layout.
374
  using storage_type = uint16_t;
375
376
  using RoundingMode = llvm::RoundingMode;
377
378
  static constexpr unsigned StorageBitSize = 8 * sizeof(storage_type);
379
380
  // Define a fake option named "First" so that we have a PREVIOUS even for the
381
  // real first option.
382
  static constexpr storage_type FirstShift = 0, FirstWidth = 0;
383
#define OPTION(NAME, TYPE, WIDTH, PREVIOUS)                                    \
384
  static constexpr storage_type NAME##Shift =                                  \
385
      PREVIOUS##Shift + PREVIOUS##Width;                                       \
386
  static constexpr storage_type NAME##Width = WIDTH;                           \
387
  static constexpr storage_type NAME##Mask = ((1 << NAME##Width) - 1)          \
388
                                             << NAME##Shift;
389
#include "clang/Basic/FPOptions.def"
390
391
  static constexpr storage_type TotalWidth = 0
392
#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) +WIDTH
393
#include "clang/Basic/FPOptions.def"
394
      ;
395
  static_assert(TotalWidth <= StorageBitSize, "Too short type for FPOptions");
396
397
private:
398
  storage_type Value;
399
400
public:
401
76.0M
  FPOptions() : Value(0) {
402
76.0M
    setFPContractMode(LangOptions::FPM_Off);
403
76.0M
    setRoundingMode(static_cast<RoundingMode>(LangOptions::FPR_ToNearest));
404
76.0M
    setFPExceptionMode(LangOptions::FPE_Ignore);
405
76.0M
  }
406
2.26M
  explicit FPOptions(const LangOptions &LO) {
407
2.26M
    Value = 0;
408
2.26M
    setFPContractMode(LO.getDefaultFPContractMode());
409
2.26M
    setRoundingMode(LO.getFPRoundingMode());
410
2.26M
    setFPExceptionMode(LO.getFPExceptionMode());
411
2.26M
    setAllowFEnvAccess(LangOptions::FPM_Off);
412
2.26M
    setAllowFPReassociate(LO.AllowFPReassoc);
413
2.26M
    setNoHonorNaNs(LO.NoHonorNaNs);
414
2.26M
    setNoHonorInfs(LO.NoHonorInfs);
415
2.26M
    setNoSignedZero(LO.NoSignedZero);
416
2.26M
    setAllowReciprocal(LO.AllowRecip);
417
2.26M
    setAllowApproxFunc(LO.ApproxFunc);
418
2.26M
  }
419
420
5.61k
  bool allowFPContractWithinStatement() const {
421
5.61k
    return getFPContractMode() == LangOptions::FPM_On;
422
5.61k
  }
423
0
  void setAllowFPContractWithinStatement() {
424
0
    setFPContractMode(LangOptions::FPM_On);
425
0
  }
426
427
288k
  bool allowFPContractAcrossStatement() const {
428
288k
    return getFPContractMode() == LangOptions::FPM_Fast;
429
288k
  }
430
0
  void setAllowFPContractAcrossStatement() {
431
0
    setFPContractMode(LangOptions::FPM_Fast);
432
0
  }
433
434
3.73M
  bool isFPConstrained() const {
435
3.73M
    return getRoundingMode() != llvm::RoundingMode::NearestTiesToEven ||
436
3.73M
           getFPExceptionMode() != LangOptions::FPE_Ignore ||
437
3.64M
           getAllowFEnvAccess();
438
3.73M
  }
439
440
27.5M
  bool operator==(FPOptions other) const { return Value == other.Value; }
441
442
  /// Return the default value of FPOptions that's used when trailing
443
  /// storage isn't required.
444
  static FPOptions defaultWithoutTrailingStorage(const LangOptions &LO);
445
446
2.98M
  storage_type getAsOpaqueInt() const { return Value; }
447
75.6M
  static FPOptions getFromOpaqueInt(storage_type Value) {
448
75.6M
    FPOptions Opts;
449
75.6M
    Opts.Value = Value;
450
75.6M
    return Opts;
451
75.6M
  }
452
453
  // We can define most of the accessors automatically:
454
#define OPTION(NAME, TYPE, WIDTH, PREVIOUS)                                    \
455
13.1M
  TYPE get##NAME() const {                                                     \
456
13.1M
    return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift);             \
457
13.1M
  }                                                                            \
clang::FPOptions::getFPContractMode() const
Line
Count
Source
455
294k
  TYPE get##NAME() const {                                                     \
456
294k
    return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift);             \
457
294k
  }                                                                            \
clang::FPOptions::getRoundingMode() const
Line
Count
Source
455
3.73M
  TYPE get##NAME() const {                                                     \
456
3.73M
    return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift);             \
457
3.73M
  }                                                                            \
clang::FPOptions::getFPExceptionMode() const
Line
Count
Source
455
3.73M
  TYPE get##NAME() const {                                                     \
456
3.73M
    return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift);             \
457
3.73M
  }                                                                            \
clang::FPOptions::getAllowFEnvAccess() const
Line
Count
Source
455
3.64M
  TYPE get##NAME() const {                                                     \
456
3.64M
    return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift);             \
457
3.64M
  }                                                                            \
clang::FPOptions::getAllowFPReassociate() const
Line
Count
Source
455
289k
  TYPE get##NAME() const {                                                     \
456
289k
    return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift);             \
457
289k
  }                                                                            \
clang::FPOptions::getNoHonorNaNs() const
Line
Count
Source
455
289k
  TYPE get##NAME() const {                                                     \
456
289k
    return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift);             \
457
289k
  }                                                                            \
clang::FPOptions::getNoHonorInfs() const
Line
Count
Source
455
289k
  TYPE get##NAME() const {                                                     \
456
289k
    return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift);             \
457
289k
  }                                                                            \
clang::FPOptions::getNoSignedZero() const
Line
Count
Source
455
289k
  TYPE get##NAME() const {                                                     \
456
289k
    return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift);             \
457
289k
  }                                                                            \
clang::FPOptions::getAllowReciprocal() const
Line
Count
Source
455
289k
  TYPE get##NAME() const {                                                     \
456
289k
    return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift);             \
457
289k
  }                                                                            \
clang::FPOptions::getAllowApproxFunc() const
Line
Count
Source
455
289k
  TYPE get##NAME() const {                                                     \
456
289k
    return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift);             \
457
289k
  }                                                                            \
458
250M
  void set##NAME(TYPE value) {                                                 \
459
250M
    Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift);      \
460
250M
  }
clang::FPOptions::setFPContractMode(clang::LangOptions::FPModeKind)
Line
Count
Source
458
78.3M
  void set##NAME(TYPE value) {                                                 \
459
78.3M
    Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift);      \
460
78.3M
  }
clang::FPOptions::setRoundingMode(llvm::RoundingMode)
Line
Count
Source
458
78.3M
  void set##NAME(TYPE value) {                                                 \
459
78.3M
    Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift);      \
460
78.3M
  }
clang::FPOptions::setFPExceptionMode(clang::LangOptions::FPExceptionModeKind)
Line
Count
Source
458
78.3M
  void set##NAME(TYPE value) {                                                 \
459
78.3M
    Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift);      \
460
78.3M
  }
clang::FPOptions::setAllowFEnvAccess(bool)
Line
Count
Source
458
2.26M
  void set##NAME(TYPE value) {                                                 \
459
2.26M
    Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift);      \
460
2.26M
  }
clang::FPOptions::setAllowFPReassociate(bool)
Line
Count
Source
458
2.26M
  void set##NAME(TYPE value) {                                                 \
459
2.26M
    Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift);      \
460
2.26M
  }
clang::FPOptions::setNoHonorNaNs(bool)
Line
Count
Source
458
2.26M
  void set##NAME(TYPE value) {                                                 \
459
2.26M
    Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift);      \
460
2.26M
  }
clang::FPOptions::setNoHonorInfs(bool)
Line
Count
Source
458
2.26M
  void set##NAME(TYPE value) {                                                 \
459
2.26M
    Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift);      \
460
2.26M
  }
clang::FPOptions::setNoSignedZero(bool)
Line
Count
Source
458
2.26M
  void set##NAME(TYPE value) {                                                 \
459
2.26M
    Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift);      \
460
2.26M
  }
clang::FPOptions::setAllowReciprocal(bool)
Line
Count
Source
458
2.26M
  void set##NAME(TYPE value) {                                                 \
459
2.26M
    Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift);      \
460
2.26M
  }
clang::FPOptions::setAllowApproxFunc(bool)
Line
Count
Source
458
2.26M
  void set##NAME(TYPE value) {                                                 \
459
2.26M
    Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift);      \
460
2.26M
  }
461
#include "clang/Basic/FPOptions.def"
462
  LLVM_DUMP_METHOD void dump();
463
};
464
465
/// Represents difference between two FPOptions values.
466
///
467
/// The effect of language constructs changing the set of floating point options
468
/// is usually a change of some FP properties while leaving others intact. This
469
/// class describes such changes by keeping information about what FP options
470
/// are overridden.
471
///
472
/// The integral set of FP options, described by the class FPOptions, may be
473
/// represented as a default FP option set, defined by language standard and
474
/// command line options, with the overrides introduced by pragmas.
475
///
476
/// The is implemented as a value of the new FPOptions plus a mask showing which
477
/// fields are actually set in it.
478
class FPOptionsOverride {
479
  FPOptions Options = FPOptions::getFromOpaqueInt(0);
480
  FPOptions::storage_type OverrideMask = 0;
481
482
public:
483
  using RoundingMode = llvm::RoundingMode;
484
485
  /// The type suitable for storing values of FPOptionsOverride. Must be twice
486
  /// as wide as bit size of FPOption.
487
  using storage_type = uint32_t;
488
  static_assert(sizeof(storage_type) >= 2 * sizeof(FPOptions::storage_type),
489
                "Too short type for FPOptionsOverride");
490
491
  /// Bit mask selecting bits of OverrideMask in serialized representation of
492
  /// FPOptionsOverride.
493
  static constexpr storage_type OverrideMaskBits =
494
      (static_cast<storage_type>(1) << FPOptions::StorageBitSize) - 1;
495
496
74.1M
  FPOptionsOverride() {}
497
  FPOptionsOverride(const LangOptions &LO)
498
0
      : Options(LO), OverrideMask(OverrideMaskBits) {}
499
  FPOptionsOverride(FPOptions FPO)
500
0
      : Options(FPO), OverrideMask(OverrideMaskBits) {}
501
502
77.1M
  bool requiresTrailingStorage() const { return OverrideMask != 0; }
503
504
64
  void setAllowFPContractWithinStatement() {
505
64
    setFPContractModeOverride(LangOptions::FPM_On);
506
64
  }
507
508
50
  void setAllowFPContractAcrossStatement() {
509
50
    setFPContractModeOverride(LangOptions::FPM_Fast);
510
50
  }
511
512
10
  void setDisallowFPContract() {
513
10
    setFPContractModeOverride(LangOptions::FPM_Off);
514
10
  }
515
516
77
  void setFPPreciseEnabled(bool Value) {
517
77
    setAllowFPReassociateOverride(!Value);
518
77
    setNoHonorNaNsOverride(!Value);
519
77
    setNoHonorInfsOverride(!Value);
520
77
    setNoSignedZeroOverride(!Value);
521
77
    setAllowReciprocalOverride(!Value);
522
77
    setAllowApproxFuncOverride(!Value);
523
77
    if (Value)
524
      /* Precise mode implies fp_contract=on and disables ffast-math */
525
33
      setAllowFPContractWithinStatement();
526
44
    else
527
      /* Precise mode disabled sets fp_contract=fast and enables ffast-math */
528
44
      setAllowFPContractAcrossStatement();
529
77
  }
530
531
8.25k
  storage_type getAsOpaqueInt() const {
532
8.25k
    return (static_cast<storage_type>(Options.getAsOpaqueInt())
533
8.25k
            << FPOptions::StorageBitSize) |
534
8.25k
           OverrideMask;
535
8.25k
  }
536
7.64k
  static FPOptionsOverride getFromOpaqueInt(storage_type I) {
537
7.64k
    FPOptionsOverride Opts;
538
7.64k
    Opts.OverrideMask = I & OverrideMaskBits;
539
7.64k
    Opts.Options = FPOptions::getFromOpaqueInt(I >> FPOptions::StorageBitSize);
540
7.64k
    return Opts;
541
7.64k
  }
542
543
1.49M
  FPOptions applyOverrides(FPOptions Base) {
544
1.49M
    FPOptions Result =
545
1.49M
        FPOptions::getFromOpaqueInt((Base.getAsOpaqueInt() & ~OverrideMask) |
546
1.49M
                                     (Options.getAsOpaqueInt() & OverrideMask));
547
1.49M
    return Result;
548
1.49M
  }
549
550
1.49M
  FPOptions applyOverrides(const LangOptions &LO) {
551
1.49M
    return applyOverrides(FPOptions(LO));
552
1.49M
  }
553
554
27.5M
  bool operator==(FPOptionsOverride other) const {
555
27.5M
    return Options == other.Options && 
OverrideMask == other.OverrideMask27.5M
;
556
27.5M
  }
557
27.5M
  bool operator!=(FPOptionsOverride other) const { return !(*this == other); }
558
559
#define OPTION(NAME, TYPE, WIDTH, PREVIOUS)                                    \
560
506
  bool has##NAME##Override() const {                                           \
561
506
    return OverrideMask & FPOptions::NAME##Mask;                               \
562
506
  }                                                                            \
clang::FPOptionsOverride::hasFPContractModeOverride() const
Line
Count
Source
560
70
  bool has##NAME##Override() const {                                           \
561
70
    return OverrideMask & FPOptions::NAME##Mask;                               \
562
70
  }                                                                            \
clang::FPOptionsOverride::hasRoundingModeOverride() const
Line
Count
Source
560
68
  bool has##NAME##Override() const {                                           \
561
68
    return OverrideMask & FPOptions::NAME##Mask;                               \
562
68
  }                                                                            \
clang::FPOptionsOverride::hasFPExceptionModeOverride() const
Line
Count
Source
560
46
  bool has##NAME##Override() const {                                           \
561
46
    return OverrideMask & FPOptions::NAME##Mask;                               \
562
46
  }                                                                            \
clang::FPOptionsOverride::hasAllowFEnvAccessOverride() const
Line
Count
Source
560
46
  bool has##NAME##Override() const {                                           \
561
46
    return OverrideMask & FPOptions::NAME##Mask;                               \
562
46
  }                                                                            \
clang::FPOptionsOverride::hasAllowFPReassociateOverride() const
Line
Count
Source
560
46
  bool has##NAME##Override() const {                                           \
561
46
    return OverrideMask & FPOptions::NAME##Mask;                               \
562
46
  }                                                                            \
clang::FPOptionsOverride::hasNoHonorNaNsOverride() const
Line
Count
Source
560
46
  bool has##NAME##Override() const {                                           \
561
46
    return OverrideMask & FPOptions::NAME##Mask;                               \
562
46
  }                                                                            \
clang::FPOptionsOverride::hasNoHonorInfsOverride() const
Line
Count
Source
560
46
  bool has##NAME##Override() const {                                           \
561
46
    return OverrideMask & FPOptions::NAME##Mask;                               \
562
46
  }                                                                            \
clang::FPOptionsOverride::hasNoSignedZeroOverride() const
Line
Count
Source
560
46
  bool has##NAME##Override() const {                                           \
561
46
    return OverrideMask & FPOptions::NAME##Mask;                               \
562
46
  }                                                                            \
clang::FPOptionsOverride::hasAllowReciprocalOverride() const
Line
Count
Source
560
46
  bool has##NAME##Override() const {                                           \
561
46
    return OverrideMask & FPOptions::NAME##Mask;                               \
562
46
  }                                                                            \
clang::FPOptionsOverride::hasAllowApproxFuncOverride() const
Line
Count
Source
560
46
  bool has##NAME##Override() const {                                           \
561
46
    return OverrideMask & FPOptions::NAME##Mask;                               \
562
46
  }                                                                            \
563
46
  TYPE get##NAME##Override() const {                                           \
564
46
    assert(has##NAME##Override());                                             \
565
46
    return Options.get##NAME();                                                \
566
46
  }                                                                            \
clang::FPOptionsOverride::getFPContractModeOverride() const
Line
Count
Source
563
24
  TYPE get##NAME##Override() const {                                           \
564
24
    assert(has##NAME##Override());                                             \
565
24
    return Options.get##NAME();                                                \
566
24
  }                                                                            \
clang::FPOptionsOverride::getRoundingModeOverride() const
Line
Count
Source
563
22
  TYPE get##NAME##Override() const {                                           \
564
22
    assert(has##NAME##Override());                                             \
565
22
    return Options.get##NAME();                                                \
566
22
  }                                                                            \
Unexecuted instantiation: clang::FPOptionsOverride::getFPExceptionModeOverride() const
Unexecuted instantiation: clang::FPOptionsOverride::getAllowFEnvAccessOverride() const
Unexecuted instantiation: clang::FPOptionsOverride::getAllowFPReassociateOverride() const
Unexecuted instantiation: clang::FPOptionsOverride::getNoHonorNaNsOverride() const
Unexecuted instantiation: clang::FPOptionsOverride::getNoHonorInfsOverride() const
Unexecuted instantiation: clang::FPOptionsOverride::getNoSignedZeroOverride() const
Unexecuted instantiation: clang::FPOptionsOverride::getAllowReciprocalOverride() const
Unexecuted instantiation: clang::FPOptionsOverride::getAllowApproxFuncOverride() const
567
0
  void clear##NAME##Override() {                                               \
568
0
    /* Clear the actual value so that we don't have spurious differences when  \
569
0
     * testing equality. */                                                    \
570
0
    Options.set##NAME(TYPE(0));                                                \
571
0
    OverrideMask &= ~FPOptions::NAME##Mask;                                    \
572
0
  }                                                                            \
Unexecuted instantiation: clang::FPOptionsOverride::clearFPContractModeOverride()
Unexecuted instantiation: clang::FPOptionsOverride::clearRoundingModeOverride()
Unexecuted instantiation: clang::FPOptionsOverride::clearFPExceptionModeOverride()
Unexecuted instantiation: clang::FPOptionsOverride::clearAllowFEnvAccessOverride()
Unexecuted instantiation: clang::FPOptionsOverride::clearAllowFPReassociateOverride()
Unexecuted instantiation: clang::FPOptionsOverride::clearNoHonorNaNsOverride()
Unexecuted instantiation: clang::FPOptionsOverride::clearNoHonorInfsOverride()
Unexecuted instantiation: clang::FPOptionsOverride::clearNoSignedZeroOverride()
Unexecuted instantiation: clang::FPOptionsOverride::clearAllowReciprocalOverride()
Unexecuted instantiation: clang::FPOptionsOverride::clearAllowApproxFuncOverride()
573
664
  void set##NAME##Override(TYPE value) {                                       \
574
664
    Options.set##NAME(value);                                                  \
575
664
    OverrideMask |= FPOptions::NAME##Mask;                                     \
576
664
  }
clang::FPOptionsOverride::setFPContractModeOverride(clang::LangOptions::FPModeKind)
Line
Count
Source
573
124
  void set##NAME##Override(TYPE value) {                                       \
574
124
    Options.set##NAME(value);                                                  \
575
124
    OverrideMask |= FPOptions::NAME##Mask;                                     \
576
124
  }
clang::FPOptionsOverride::setRoundingModeOverride(llvm::RoundingMode)
Line
Count
Source
573
12
  void set##NAME##Override(TYPE value) {                                       \
574
12
    Options.set##NAME(value);                                                  \
575
12
    OverrideMask |= FPOptions::NAME##Mask;                                     \
576
12
  }
clang::FPOptionsOverride::setFPExceptionModeOverride(clang::LangOptions::FPExceptionModeKind)
Line
Count
Source
573
54
  void set##NAME##Override(TYPE value) {                                       \
574
54
    Options.set##NAME(value);                                                  \
575
54
    OverrideMask |= FPOptions::NAME##Mask;                                     \
576
54
  }
clang::FPOptionsOverride::setAllowFEnvAccessOverride(bool)
Line
Count
Source
573
2
  void set##NAME##Override(TYPE value) {                                       \
574
2
    Options.set##NAME(value);                                                  \
575
2
    OverrideMask |= FPOptions::NAME##Mask;                                     \
576
2
  }
clang::FPOptionsOverride::setAllowFPReassociateOverride(bool)
Line
Count
Source
573
87
  void set##NAME##Override(TYPE value) {                                       \
574
87
    Options.set##NAME(value);                                                  \
575
87
    OverrideMask |= FPOptions::NAME##Mask;                                     \
576
87
  }
clang::FPOptionsOverride::setNoHonorNaNsOverride(bool)
Line
Count
Source
573
77
  void set##NAME##Override(TYPE value) {                                       \
574
77
    Options.set##NAME(value);                                                  \
575
77
    OverrideMask |= FPOptions::NAME##Mask;                                     \
576
77
  }
clang::FPOptionsOverride::setNoHonorInfsOverride(bool)
Line
Count
Source
573
77
  void set##NAME##Override(TYPE value) {                                       \
574
77
    Options.set##NAME(value);                                                  \
575
77
    OverrideMask |= FPOptions::NAME##Mask;                                     \
576
77
  }
clang::FPOptionsOverride::setNoSignedZeroOverride(bool)
Line
Count
Source
573
77
  void set##NAME##Override(TYPE value) {                                       \
574
77
    Options.set##NAME(value);                                                  \
575
77
    OverrideMask |= FPOptions::NAME##Mask;                                     \
576
77
  }
clang::FPOptionsOverride::setAllowReciprocalOverride(bool)
Line
Count
Source
573
77
  void set##NAME##Override(TYPE value) {                                       \
574
77
    Options.set##NAME(value);                                                  \
575
77
    OverrideMask |= FPOptions::NAME##Mask;                                     \
576
77
  }
clang::FPOptionsOverride::setAllowApproxFuncOverride(bool)
Line
Count
Source
573
77
  void set##NAME##Override(TYPE value) {                                       \
574
77
    Options.set##NAME(value);                                                  \
575
77
    OverrideMask |= FPOptions::NAME##Mask;                                     \
576
77
  }
577
#include "clang/Basic/FPOptions.def"
578
  LLVM_DUMP_METHOD void dump();
579
};
580
581
/// Describes the kind of translation unit being processed.
582
enum TranslationUnitKind {
583
  /// The translation unit is a complete translation unit.
584
  TU_Complete,
585
586
  /// The translation unit is a prefix to a translation unit, and is
587
  /// not complete.
588
  TU_Prefix,
589
590
  /// The translation unit is a module.
591
  TU_Module
592
};
593
594
} // namespace clang
595
596
#endif // LLVM_CLANG_BASIC_LANGOPTIONS_H