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/LangStandard.h"
20 #include "clang/Basic/ObjCRuntime.h"
21 #include "clang/Basic/Sanitizers.h"
22 #include "clang/Basic/TargetCXXABI.h"
23 #include "clang/Basic/Visibility.h"
24 #include "llvm/ADT/FloatingPointMode.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/ADT/Triple.h"
27 #include <string>
28 #include <vector>
29 
30 namespace clang {
31 
32 /// Bitfields of LangOptions, split out from LangOptions in order to ensure that
33 /// this large collection of bitfields is a trivial class type.
34 class LangOptionsBase {
35   friend class CompilerInvocation;
36 
37 public:
38   // Define simple language options (with no accessors).
39 #define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
40 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
41 #include "clang/Basic/LangOptions.def"
42 
43 protected:
44   // Define language options of enumeration type. These are private, and will
45   // have accessors (below).
46 #define LANGOPT(Name, Bits, Default, Description)
47 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
48   unsigned Name : Bits;
49 #include "clang/Basic/LangOptions.def"
50 };
51 
52 /// In the Microsoft ABI, this controls the placement of virtual displacement
53 /// members used to implement virtual inheritance.
54 enum class MSVtorDispMode { Never, ForVBaseOverride, ForVFTable };
55 
56 /// Keeps track of the various options that can be
57 /// enabled, which controls the dialect of C or C++ that is accepted.
58 class LangOptions : public LangOptionsBase {
59 public:
60   using Visibility = clang::Visibility;
61   using RoundingMode = llvm::RoundingMode;
62 
63   enum GCMode { NonGC, GCOnly, HybridGC };
64   enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
65 
66   // Automatic variables live on the stack, and when trivial they're usually
67   // uninitialized because it's undefined behavior to use them without
68   // initializing them.
69   enum class TrivialAutoVarInitKind { Uninitialized, Zero, Pattern };
70 
71   enum SignedOverflowBehaviorTy {
72     // Default C standard behavior.
73     SOB_Undefined,
74 
75     // -fwrapv
76     SOB_Defined,
77 
78     // -ftrapv
79     SOB_Trapping
80   };
81 
82   // FIXME: Unify with TUKind.
83   enum CompilingModuleKind {
84     /// Not compiling a module interface at all.
85     CMK_None,
86 
87     /// Compiling a module from a module map.
88     CMK_ModuleMap,
89 
90     /// Compiling a module from a list of header files.
91     CMK_HeaderModule,
92 
93     /// Compiling a C++ modules TS module interface unit.
94     CMK_ModuleInterface,
95   };
96 
97   enum PragmaMSPointersToMembersKind {
98     PPTMK_BestCase,
99     PPTMK_FullGeneralitySingleInheritance,
100     PPTMK_FullGeneralityMultipleInheritance,
101     PPTMK_FullGeneralityVirtualInheritance
102   };
103 
104   using MSVtorDispMode = clang::MSVtorDispMode;
105 
106   enum DefaultCallingConvention {
107     DCC_None,
108     DCC_CDecl,
109     DCC_FastCall,
110     DCC_StdCall,
111     DCC_VectorCall,
112     DCC_RegCall
113   };
114 
115   enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
116 
117   // Corresponds to _MSC_VER
118   enum MSVCMajorVersion {
119     MSVC2010 = 1600,
120     MSVC2012 = 1700,
121     MSVC2013 = 1800,
122     MSVC2015 = 1900,
123     MSVC2017 = 1910,
124     MSVC2017_5 = 1912,
125     MSVC2017_7 = 1914,
126     MSVC2019 = 1920,
127     MSVC2019_8 = 1928,
128   };
129 
130   enum SYCLMajorVersion {
131     SYCL_None,
132     SYCL_2017,
133     SYCL_2020,
134     // The "default" SYCL version to be used when none is specified on the
135     // frontend command line.
136     SYCL_Default = SYCL_2020
137   };
138 
139   /// Clang versions with different platform ABI conformance.
140   enum class ClangABI {
141     /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
142     /// (SVN r257626). This causes <1 x long long> to be passed in an
143     /// integer register instead of an SSE register on x64_64.
144     Ver3_8,
145 
146     /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
147     /// (SVN r291814). This causes move operations to be ignored when
148     /// determining whether a class type can be passed or returned directly.
149     Ver4,
150 
151     /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
152     /// (SVN r321711). This causes determination of whether a type is
153     /// standard-layout to ignore collisions between empty base classes
154     /// and between base classes and member subobjects, which affects
155     /// whether we reuse base class tail padding in some ABIs.
156     Ver6,
157 
158     /// Attempt to be ABI-compatible with code generated by Clang 7.0.x
159     /// (SVN r338536). This causes alignof (C++) and _Alignof (C11) to be
160     /// compatible with __alignof (i.e., return the preferred alignment)
161     /// rather than returning the required alignment.
162     Ver7,
163 
164     /// Attempt to be ABI-compatible with code generated by Clang 9.0.x
165     /// (SVN r351319). This causes vectors of __int128 to be passed in memory
166     /// instead of passing in multiple scalar registers on x86_64 on Linux and
167     /// NetBSD.
168     Ver9,
169 
170     /// Attempt to be ABI-compatible with code generated by Clang 11.0.x
171     /// (git 2e10b7a39b93). This causes clang to pass unions with a 256-bit
172     /// vector member on the stack instead of using registers, to not properly
173     /// mangle substitutions for template names in some cases, and to mangle
174     /// declaration template arguments without a cast to the parameter type
175     /// even when that can lead to mangling collisions.
176     Ver11,
177 
178     /// Attempt to be ABI-compatible with code generated by Clang 12.0.x
179     /// (git 8e464dd76bef). This causes clang to mangle lambdas within
180     /// global-scope inline variables incorrectly.
181     Ver12,
182 
183     /// Conform to the underlying platform's C and C++ ABIs as closely
184     /// as we can.
185     Latest
186   };
187 
188   enum class CoreFoundationABI {
189     /// No interoperability ABI has been specified
190     Unspecified,
191     /// CoreFoundation does not have any language interoperability
192     Standalone,
193     /// Interoperability with the ObjectiveC runtime
194     ObjectiveC,
195     /// Interoperability with the latest known version of the Swift runtime
196     Swift,
197     /// Interoperability with the Swift 5.0 runtime
198     Swift5_0,
199     /// Interoperability with the Swift 4.2 runtime
200     Swift4_2,
201     /// Interoperability with the Swift 4.1 runtime
202     Swift4_1,
203   };
204 
205   enum FPModeKind {
206     // Disable the floating point pragma
207     FPM_Off,
208 
209     // Enable the floating point pragma
210     FPM_On,
211 
212     // Aggressively fuse FP ops (E.g. FMA) disregarding pragmas.
213     FPM_Fast,
214 
215     // Aggressively fuse FP ops and honor pragmas.
216     FPM_FastHonorPragmas
217   };
218 
219   /// Alias for RoundingMode::NearestTiesToEven.
220   static constexpr unsigned FPR_ToNearest =
221       static_cast<unsigned>(llvm::RoundingMode::NearestTiesToEven);
222 
223   /// Possible floating point exception behavior.
224   enum FPExceptionModeKind {
225     /// Assume that floating-point exceptions are masked.
226     FPE_Ignore,
227     /// Transformations do not cause new exceptions but may hide some.
228     FPE_MayTrap,
229     /// Strictly preserve the floating-point exception semantics.
230     FPE_Strict
231   };
232 
233   /// Possible exception handling behavior.
234   enum class ExceptionHandlingKind { None, SjLj, WinEH, DwarfCFI, Wasm };
235 
236   enum class LaxVectorConversionKind {
237     /// Permit no implicit vector bitcasts.
238     None,
239     /// Permit vector bitcasts between integer vectors with different numbers
240     /// of elements but the same total bit-width.
241     Integer,
242     /// Permit vector bitcasts between all vectors with the same total
243     /// bit-width.
244     All,
245   };
246 
247   enum class AltivecSrcCompatKind {
248     // All vector compares produce scalars except vector pixel and vector bool.
249     // The types vector pixel and vector bool return vector results.
250     Mixed,
251     // All vector compares produce vector results as in GCC.
252     GCC,
253     // All vector compares produce scalars as in XL.
254     XL,
255     // Default clang behaviour.
256     Default = Mixed,
257   };
258 
259   enum class SignReturnAddressScopeKind {
260     /// No signing for any function.
261     None,
262     /// Sign the return address of functions that spill LR.
263     NonLeaf,
264     /// Sign the return address of all functions,
265     All
266   };
267 
268   enum class SignReturnAddressKeyKind {
269     /// Return address signing uses APIA key.
270     AKey,
271     /// Return address signing uses APIB key.
272     BKey
273   };
274 
275   enum class ThreadModelKind {
276     /// POSIX Threads.
277     POSIX,
278     /// Single Threaded Environment.
279     Single
280   };
281 
282   enum class ExtendArgsKind {
283     /// Integer arguments are sign or zero extended to 32/64 bits
284     /// during default argument promotions.
285     ExtendTo32,
286     ExtendTo64
287   };
288 
289 public:
290   /// The used language standard.
291   LangStandard::Kind LangStd;
292 
293   /// Set of enabled sanitizers.
294   SanitizerSet Sanitize;
295   /// Is at least one coverage instrumentation type enabled.
296   bool SanitizeCoverage = false;
297 
298   /// Paths to files specifying which objects
299   /// (files, functions, variables) should not be instrumented.
300   std::vector<std::string> NoSanitizeFiles;
301 
302   /// Paths to the XRay "always instrument" files specifying which
303   /// objects (files, functions, variables) should be imbued with the XRay
304   /// "always instrument" attribute.
305   /// WARNING: This is a deprecated field and will go away in the future.
306   std::vector<std::string> XRayAlwaysInstrumentFiles;
307 
308   /// Paths to the XRay "never instrument" files specifying which
309   /// objects (files, functions, variables) should be imbued with the XRay
310   /// "never instrument" attribute.
311   /// WARNING: This is a deprecated field and will go away in the future.
312   std::vector<std::string> XRayNeverInstrumentFiles;
313 
314   /// Paths to the XRay attribute list files, specifying which objects
315   /// (files, functions, variables) should be imbued with the appropriate XRay
316   /// attribute(s).
317   std::vector<std::string> XRayAttrListFiles;
318 
319   /// Paths to special case list files specifying which entities
320   /// (files, functions) should or should not be instrumented.
321   std::vector<std::string> ProfileListFiles;
322 
323   clang::ObjCRuntime ObjCRuntime;
324 
325   CoreFoundationABI CFRuntime = CoreFoundationABI::Unspecified;
326 
327   std::string ObjCConstantStringClass;
328 
329   /// The name of the handler function to be called when -ftrapv is
330   /// specified.
331   ///
332   /// If none is specified, abort (GCC-compatible behaviour).
333   std::string OverflowHandler;
334 
335   /// The module currently being compiled as specified by -fmodule-name.
336   std::string ModuleName;
337 
338   /// The name of the current module, of which the main source file
339   /// is a part. If CompilingModule is set, we are compiling the interface
340   /// of this module, otherwise we are compiling an implementation file of
341   /// it. This starts as ModuleName in case -fmodule-name is provided and
342   /// changes during compilation to reflect the current module.
343   std::string CurrentModule;
344 
345   /// The names of any features to enable in module 'requires' decls
346   /// in addition to the hard-coded list in Module.cpp and the target features.
347   ///
348   /// This list is sorted.
349   std::vector<std::string> ModuleFeatures;
350 
351   /// Options for parsing comments.
352   CommentOptions CommentOpts;
353 
354   /// A list of all -fno-builtin-* function names (e.g., memset).
355   std::vector<std::string> NoBuiltinFuncs;
356 
357   /// A prefix map for __FILE__, __BASE_FILE__ and __builtin_FILE().
358   std::map<std::string, std::string, std::greater<std::string>> MacroPrefixMap;
359 
360   /// Triples of the OpenMP targets that the host code codegen should
361   /// take into account in order to generate accurate offloading descriptors.
362   std::vector<llvm::Triple> OMPTargetTriples;
363 
364   /// Name of the IR file that contains the result of the OpenMP target
365   /// host code generation.
366   std::string OMPHostIRFile;
367 
368   /// The user provided compilation unit ID, if non-empty. This is used to
369   /// externalize static variables which is needed to support accessing static
370   /// device variables in host code for single source offloading languages
371   /// like CUDA/HIP.
372   std::string CUID;
373 
374   /// C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
375   /// This overrides the default ABI used by the target.
376   llvm::Optional<TargetCXXABI::Kind> CXXABI;
377 
378   /// Indicates whether the front-end is explicitly told that the
379   /// input is a header file (i.e. -x c-header).
380   bool IsHeaderFile = false;
381 
382   LangOptions();
383 
384   // Define accessors/mutators for language options of enumeration type.
385 #define LANGOPT(Name, Bits, Default, Description)
386 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
387   Type get##Name() const { return static_cast<Type>(Name); } \
388   void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
389 #include "clang/Basic/LangOptions.def"
390 
391   /// Are we compiling a module interface (.cppm or module map)?
392   bool isCompilingModule() const {
393     return getCompilingModule() != CMK_None;
394   }
395 
396   /// Do we need to track the owning module for a local declaration?
397   bool trackLocalOwningModule() const {
398     return isCompilingModule() || ModulesLocalVisibility;
399   }
400 
401   bool isSignedOverflowDefined() const {
402     return getSignedOverflowBehavior() == SOB_Defined;
403   }
404 
405   bool isSubscriptPointerArithmetic() const {
406     return ObjCRuntime.isSubscriptPointerArithmetic() &&
407            !ObjCSubscriptingLegacyRuntime;
408   }
409 
410   bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
411     return MSCompatibilityVersion >= MajorVersion * 100000U;
412   }
413 
414   /// Reset all of the options that are not considered when building a
415   /// module.
416   void resetNonModularOptions();
417 
418   /// Is this a libc/libm function that is no longer recognized as a
419   /// builtin because a -fno-builtin-* option has been specified?
420   bool isNoBuiltinFunc(StringRef Name) const;
421 
422   /// True if any ObjC types may have non-trivial lifetime qualifiers.
423   bool allowsNonTrivialObjCLifetimeQualifiers() const {
424     return ObjCAutoRefCount || ObjCWeak;
425   }
426 
427   bool assumeFunctionsAreConvergent() const {
428     return ConvergentFunctions;
429   }
430 
431   /// Return the OpenCL C or C++ version as a VersionTuple.
432   VersionTuple getOpenCLVersionTuple() const;
433 
434   /// Check if return address signing is enabled.
435   bool hasSignReturnAddress() const {
436     return getSignReturnAddressScope() != SignReturnAddressScopeKind::None;
437   }
438 
439   /// Check if return address signing uses AKey.
440   bool isSignReturnAddressWithAKey() const {
441     return getSignReturnAddressKey() == SignReturnAddressKeyKind::AKey;
442   }
443 
444   /// Check if leaf functions are also signed.
445   bool isSignReturnAddressScopeAll() const {
446     return getSignReturnAddressScope() == SignReturnAddressScopeKind::All;
447   }
448 
449   bool hasSjLjExceptions() const {
450     return getExceptionHandling() == ExceptionHandlingKind::SjLj;
451   }
452 
453   bool hasSEHExceptions() const {
454     return getExceptionHandling() == ExceptionHandlingKind::WinEH;
455   }
456 
457   bool hasDWARFExceptions() const {
458     return getExceptionHandling() == ExceptionHandlingKind::DwarfCFI;
459   }
460 
461   bool hasWasmExceptions() const {
462     return getExceptionHandling() == ExceptionHandlingKind::Wasm;
463   }
464 
465   bool isSYCL() const { return SYCLIsDevice || SYCLIsHost; }
466 
467   /// Remap path prefix according to -fmacro-prefix-path option.
468   void remapPathPrefix(SmallString<256> &Path) const;
469 };
470 
471 /// Floating point control options
472 class FPOptionsOverride;
473 class FPOptions {
474 public:
475   // We start by defining the layout.
476   using storage_type = uint16_t;
477 
478   using RoundingMode = llvm::RoundingMode;
479 
480   static constexpr unsigned StorageBitSize = 8 * sizeof(storage_type);
481 
482   // Define a fake option named "First" so that we have a PREVIOUS even for the
483   // real first option.
484   static constexpr storage_type FirstShift = 0, FirstWidth = 0;
485 #define OPTION(NAME, TYPE, WIDTH, PREVIOUS)                                    \
486   static constexpr storage_type NAME##Shift =                                  \
487       PREVIOUS##Shift + PREVIOUS##Width;                                       \
488   static constexpr storage_type NAME##Width = WIDTH;                           \
489   static constexpr storage_type NAME##Mask = ((1 << NAME##Width) - 1)          \
490                                              << NAME##Shift;
491 #include "clang/Basic/FPOptions.def"
492 
493   static constexpr storage_type TotalWidth = 0
494 #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) +WIDTH
495 #include "clang/Basic/FPOptions.def"
496       ;
497   static_assert(TotalWidth <= StorageBitSize, "Too short type for FPOptions");
498 
499 private:
500   storage_type Value;
501 
502 public:
503   FPOptions() : Value(0) {
504     setFPContractMode(LangOptions::FPM_Off);
505     setRoundingMode(static_cast<RoundingMode>(LangOptions::FPR_ToNearest));
506     setFPExceptionMode(LangOptions::FPE_Ignore);
507   }
508   explicit FPOptions(const LangOptions &LO) {
509     Value = 0;
510     // The language fp contract option FPM_FastHonorPragmas has the same effect
511     // as FPM_Fast in frontend. For simplicity, use FPM_Fast uniformly in
512     // frontend.
513     auto LangOptContractMode = LO.getDefaultFPContractMode();
514     if (LangOptContractMode == LangOptions::FPM_FastHonorPragmas)
515       LangOptContractMode = LangOptions::FPM_Fast;
516     setFPContractMode(LangOptContractMode);
517     setRoundingMode(LO.getFPRoundingMode());
518     setFPExceptionMode(LO.getFPExceptionMode());
519     setAllowFPReassociate(LO.AllowFPReassoc);
520     setNoHonorNaNs(LO.NoHonorNaNs);
521     setNoHonorInfs(LO.NoHonorInfs);
522     setNoSignedZero(LO.NoSignedZero);
523     setAllowReciprocal(LO.AllowRecip);
524     setAllowApproxFunc(LO.ApproxFunc);
525     if (getFPContractMode() == LangOptions::FPM_On &&
526         getRoundingMode() == llvm::RoundingMode::Dynamic &&
527         getFPExceptionMode() == LangOptions::FPE_Strict)
528       // If the FP settings are set to the "strict" model, then
529       // FENV access is set to true. (ffp-model=strict)
530       setAllowFEnvAccess(true);
531     else
532       setAllowFEnvAccess(LangOptions::FPM_Off);
533   }
534 
535   bool allowFPContractWithinStatement() const {
536     return getFPContractMode() == LangOptions::FPM_On;
537   }
538   void setAllowFPContractWithinStatement() {
539     setFPContractMode(LangOptions::FPM_On);
540   }
541 
542   bool allowFPContractAcrossStatement() const {
543     return getFPContractMode() == LangOptions::FPM_Fast;
544   }
545   void setAllowFPContractAcrossStatement() {
546     setFPContractMode(LangOptions::FPM_Fast);
547   }
548 
549   bool isFPConstrained() const {
550     return getRoundingMode() != llvm::RoundingMode::NearestTiesToEven ||
551            getFPExceptionMode() != LangOptions::FPE_Ignore ||
552            getAllowFEnvAccess();
553   }
554 
555   bool operator==(FPOptions other) const { return Value == other.Value; }
556 
557   /// Return the default value of FPOptions that's used when trailing
558   /// storage isn't required.
559   static FPOptions defaultWithoutTrailingStorage(const LangOptions &LO);
560 
561   storage_type getAsOpaqueInt() const { return Value; }
562   static FPOptions getFromOpaqueInt(storage_type Value) {
563     FPOptions Opts;
564     Opts.Value = Value;
565     return Opts;
566   }
567 
568   // We can define most of the accessors automatically:
569 #define OPTION(NAME, TYPE, WIDTH, PREVIOUS)                                    \
570   TYPE get##NAME() const {                                                     \
571     return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift);             \
572   }                                                                            \
573   void set##NAME(TYPE value) {                                                 \
574     Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift);      \
575   }
576 #include "clang/Basic/FPOptions.def"
577   LLVM_DUMP_METHOD void dump();
578 };
579 
580 /// Represents difference between two FPOptions values.
581 ///
582 /// The effect of language constructs changing the set of floating point options
583 /// is usually a change of some FP properties while leaving others intact. This
584 /// class describes such changes by keeping information about what FP options
585 /// are overridden.
586 ///
587 /// The integral set of FP options, described by the class FPOptions, may be
588 /// represented as a default FP option set, defined by language standard and
589 /// command line options, with the overrides introduced by pragmas.
590 ///
591 /// The is implemented as a value of the new FPOptions plus a mask showing which
592 /// fields are actually set in it.
593 class FPOptionsOverride {
594   FPOptions Options = FPOptions::getFromOpaqueInt(0);
595   FPOptions::storage_type OverrideMask = 0;
596 
597 public:
598   using RoundingMode = llvm::RoundingMode;
599 
600   /// The type suitable for storing values of FPOptionsOverride. Must be twice
601   /// as wide as bit size of FPOption.
602   using storage_type = uint32_t;
603   static_assert(sizeof(storage_type) >= 2 * sizeof(FPOptions::storage_type),
604                 "Too short type for FPOptionsOverride");
605 
606   /// Bit mask selecting bits of OverrideMask in serialized representation of
607   /// FPOptionsOverride.
608   static constexpr storage_type OverrideMaskBits =
609       (static_cast<storage_type>(1) << FPOptions::StorageBitSize) - 1;
610 
611   FPOptionsOverride() {}
612   FPOptionsOverride(const LangOptions &LO)
613       : Options(LO), OverrideMask(OverrideMaskBits) {}
614   FPOptionsOverride(FPOptions FPO)
615       : Options(FPO), OverrideMask(OverrideMaskBits) {}
616 
617   bool requiresTrailingStorage() const { return OverrideMask != 0; }
618 
619   void setAllowFPContractWithinStatement() {
620     setFPContractModeOverride(LangOptions::FPM_On);
621   }
622 
623   void setAllowFPContractAcrossStatement() {
624     setFPContractModeOverride(LangOptions::FPM_Fast);
625   }
626 
627   void setDisallowFPContract() {
628     setFPContractModeOverride(LangOptions::FPM_Off);
629   }
630 
631   void setFPPreciseEnabled(bool Value) {
632     setAllowFPReassociateOverride(!Value);
633     setNoHonorNaNsOverride(!Value);
634     setNoHonorInfsOverride(!Value);
635     setNoSignedZeroOverride(!Value);
636     setAllowReciprocalOverride(!Value);
637     setAllowApproxFuncOverride(!Value);
638     if (Value)
639       /* Precise mode implies fp_contract=on and disables ffast-math */
640       setAllowFPContractWithinStatement();
641     else
642       /* Precise mode disabled sets fp_contract=fast and enables ffast-math */
643       setAllowFPContractAcrossStatement();
644   }
645 
646   storage_type getAsOpaqueInt() const {
647     return (static_cast<storage_type>(Options.getAsOpaqueInt())
648             << FPOptions::StorageBitSize) |
649            OverrideMask;
650   }
651   static FPOptionsOverride getFromOpaqueInt(storage_type I) {
652     FPOptionsOverride Opts;
653     Opts.OverrideMask = I & OverrideMaskBits;
654     Opts.Options = FPOptions::getFromOpaqueInt(I >> FPOptions::StorageBitSize);
655     return Opts;
656   }
657 
658   FPOptions applyOverrides(FPOptions Base) {
659     FPOptions Result =
660         FPOptions::getFromOpaqueInt((Base.getAsOpaqueInt() & ~OverrideMask) |
661                                      (Options.getAsOpaqueInt() & OverrideMask));
662     return Result;
663   }
664 
665   FPOptions applyOverrides(const LangOptions &LO) {
666     return applyOverrides(FPOptions(LO));
667   }
668 
669   bool operator==(FPOptionsOverride other) const {
670     return Options == other.Options && OverrideMask == other.OverrideMask;
671   }
672   bool operator!=(FPOptionsOverride other) const { return !(*this == other); }
673 
674 #define OPTION(NAME, TYPE, WIDTH, PREVIOUS)                                    \
675   bool has##NAME##Override() const {                                           \
676     return OverrideMask & FPOptions::NAME##Mask;                               \
677   }                                                                            \
678   TYPE get##NAME##Override() const {                                           \
679     assert(has##NAME##Override());                                             \
680     return Options.get##NAME();                                                \
681   }                                                                            \
682   void clear##NAME##Override() {                                               \
683     /* Clear the actual value so that we don't have spurious differences when  \
684      * testing equality. */                                                    \
685     Options.set##NAME(TYPE(0));                                                \
686     OverrideMask &= ~FPOptions::NAME##Mask;                                    \
687   }                                                                            \
688   void set##NAME##Override(TYPE value) {                                       \
689     Options.set##NAME(value);                                                  \
690     OverrideMask |= FPOptions::NAME##Mask;                                     \
691   }
692 #include "clang/Basic/FPOptions.def"
693   LLVM_DUMP_METHOD void dump();
694 };
695 
696 /// Describes the kind of translation unit being processed.
697 enum TranslationUnitKind {
698   /// The translation unit is a complete translation unit.
699   TU_Complete,
700 
701   /// The translation unit is a prefix to a translation unit, and is
702   /// not complete.
703   TU_Prefix,
704 
705   /// The translation unit is a module.
706   TU_Module,
707 
708   /// The translation unit is a is a complete translation unit that we might
709   /// incrementally extend later.
710   TU_Incremental
711 };
712 
713 } // namespace clang
714 
715 #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H
716