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