Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:50

0001 //===- LangOptions.h - C Language Family Language Options -------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 /// \file
0010 /// Defines the clang::LangOptions interface.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_CLANG_BASIC_LANGOPTIONS_H
0015 #define LLVM_CLANG_BASIC_LANGOPTIONS_H
0016 
0017 #include "clang/Basic/CFProtectionOptions.h"
0018 #include "clang/Basic/CommentOptions.h"
0019 #include "clang/Basic/LLVM.h"
0020 #include "clang/Basic/LangStandard.h"
0021 #include "clang/Basic/ObjCRuntime.h"
0022 #include "clang/Basic/Sanitizers.h"
0023 #include "clang/Basic/TargetCXXABI.h"
0024 #include "clang/Basic/Visibility.h"
0025 #include "llvm/ADT/FloatingPointMode.h"
0026 #include "llvm/ADT/StringRef.h"
0027 #include "llvm/TargetParser/Triple.h"
0028 #include <optional>
0029 #include <string>
0030 #include <vector>
0031 
0032 namespace clang {
0033 
0034 /// In the Microsoft ABI, this controls the placement of virtual displacement
0035 /// members used to implement virtual inheritance.
0036 enum class MSVtorDispMode { Never, ForVBaseOverride, ForVFTable };
0037 
0038 /// Shader programs run in specific pipeline stages.
0039 /// The order of these values matters, and must be kept in sync with the
0040 /// Triple Environment enum in llvm::Triple. The ordering is enforced in
0041 ///  static_asserts in Triple.cpp and in clang/Basic/HLSLRuntime.h.
0042 enum class ShaderStage {
0043   Pixel = 0,
0044   Vertex,
0045   Geometry,
0046   Hull,
0047   Domain,
0048   Compute,
0049   Library,
0050   RayGeneration,
0051   Intersection,
0052   AnyHit,
0053   ClosestHit,
0054   Miss,
0055   Callable,
0056   Mesh,
0057   Amplification,
0058   Invalid,
0059 };
0060 
0061 enum class PointerAuthenticationMode : unsigned {
0062   None,
0063   Strip,
0064   SignAndStrip,
0065   SignAndAuth
0066 };
0067 
0068 /// Bitfields of LangOptions, split out from LangOptions in order to ensure that
0069 /// this large collection of bitfields is a trivial class type.
0070 class LangOptionsBase {
0071   friend class CompilerInvocation;
0072   friend class CompilerInvocationBase;
0073 
0074 public:
0075   using Visibility = clang::Visibility;
0076   using RoundingMode = llvm::RoundingMode;
0077   using CFBranchLabelSchemeKind = clang::CFBranchLabelSchemeKind;
0078 
0079   enum GCMode { NonGC, GCOnly, HybridGC };
0080   enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
0081 
0082   // Automatic variables live on the stack, and when trivial they're usually
0083   // uninitialized because it's undefined behavior to use them without
0084   // initializing them.
0085   enum class TrivialAutoVarInitKind { Uninitialized, Zero, Pattern };
0086 
0087   enum SignedOverflowBehaviorTy {
0088     // Default C standard behavior.
0089     SOB_Undefined,
0090 
0091     // -fwrapv
0092     SOB_Defined,
0093 
0094     // -ftrapv
0095     SOB_Trapping
0096   };
0097 
0098   // FIXME: Unify with TUKind.
0099   enum CompilingModuleKind {
0100     /// Not compiling a module interface at all.
0101     CMK_None,
0102 
0103     /// Compiling a module from a module map.
0104     CMK_ModuleMap,
0105 
0106     /// Compiling a module header unit.
0107     CMK_HeaderUnit,
0108 
0109     /// Compiling a C++ modules interface unit.
0110     CMK_ModuleInterface,
0111   };
0112 
0113   enum PragmaMSPointersToMembersKind {
0114     PPTMK_BestCase,
0115     PPTMK_FullGeneralitySingleInheritance,
0116     PPTMK_FullGeneralityMultipleInheritance,
0117     PPTMK_FullGeneralityVirtualInheritance
0118   };
0119 
0120   using MSVtorDispMode = clang::MSVtorDispMode;
0121 
0122   enum DefaultCallingConvention {
0123     DCC_None,
0124     DCC_CDecl,
0125     DCC_FastCall,
0126     DCC_StdCall,
0127     DCC_VectorCall,
0128     DCC_RegCall,
0129     DCC_RtdCall
0130   };
0131 
0132   enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
0133 
0134   // Corresponds to _MSC_VER
0135   enum MSVCMajorVersion {
0136     MSVC2010 = 1600,
0137     MSVC2012 = 1700,
0138     MSVC2013 = 1800,
0139     MSVC2015 = 1900,
0140     MSVC2017 = 1910,
0141     MSVC2017_5 = 1912,
0142     MSVC2017_7 = 1914,
0143     MSVC2019 = 1920,
0144     MSVC2019_5 = 1925,
0145     MSVC2019_8 = 1928,
0146     MSVC2022_3 = 1933,
0147     MSVC2022_9 = 1939,
0148   };
0149 
0150   enum SYCLMajorVersion {
0151     SYCL_None,
0152     SYCL_2017,
0153     SYCL_2020,
0154     // The "default" SYCL version to be used when none is specified on the
0155     // frontend command line.
0156     SYCL_Default = SYCL_2020
0157   };
0158 
0159   enum HLSLLangStd {
0160     HLSL_Unset = 0,
0161     HLSL_2015 = 2015,
0162     HLSL_2016 = 2016,
0163     HLSL_2017 = 2017,
0164     HLSL_2018 = 2018,
0165     HLSL_2021 = 2021,
0166     HLSL_202x = 2028,
0167     HLSL_202y = 2029,
0168   };
0169 
0170   /// Clang versions with different platform ABI conformance.
0171   enum class ClangABI {
0172     /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
0173     /// (SVN r257626). This causes <1 x long long> to be passed in an
0174     /// integer register instead of an SSE register on x64_64.
0175     Ver3_8,
0176 
0177     /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
0178     /// (SVN r291814). This causes move operations to be ignored when
0179     /// determining whether a class type can be passed or returned directly.
0180     Ver4,
0181 
0182     /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
0183     /// (SVN r321711). This causes determination of whether a type is
0184     /// standard-layout to ignore collisions between empty base classes
0185     /// and between base classes and member subobjects, which affects
0186     /// whether we reuse base class tail padding in some ABIs.
0187     Ver6,
0188 
0189     /// Attempt to be ABI-compatible with code generated by Clang 7.0.x
0190     /// (SVN r338536). This causes alignof (C++) and _Alignof (C11) to be
0191     /// compatible with __alignof (i.e., return the preferred alignment)
0192     /// rather than returning the required alignment.
0193     Ver7,
0194 
0195     /// Attempt to be ABI-compatible with code generated by Clang 9.0.x
0196     /// (SVN r351319). This causes vectors of __int128 to be passed in memory
0197     /// instead of passing in multiple scalar registers on x86_64 on Linux and
0198     /// NetBSD.
0199     Ver9,
0200 
0201     /// Attempt to be ABI-compatible with code generated by Clang 11.0.x
0202     /// (git 2e10b7a39b93). This causes clang to pass unions with a 256-bit
0203     /// vector member on the stack instead of using registers, to not properly
0204     /// mangle substitutions for template names in some cases, and to mangle
0205     /// declaration template arguments without a cast to the parameter type
0206     /// even when that can lead to mangling collisions.
0207     Ver11,
0208 
0209     /// Attempt to be ABI-compatible with code generated by Clang 12.0.x
0210     /// (git 8e464dd76bef). This causes clang to mangle lambdas within
0211     /// global-scope inline variables incorrectly.
0212     Ver12,
0213 
0214     /// Attempt to be ABI-compatible with code generated by Clang 14.0.x.
0215     /// This causes clang to:
0216     ///   - mangle dependent nested names incorrectly.
0217     ///   - make trivial only those defaulted copy constructors with a
0218     ///     parameter-type-list equivalent to the parameter-type-list of an
0219     ///     implicit declaration.
0220     Ver14,
0221 
0222     /// Attempt to be ABI-compatible with code generated by Clang 15.0.x.
0223     /// This causes clang to:
0224     ///   - Reverse the implementation for DR692, DR1395 and DR1432.
0225     ///   - pack non-POD members of packed structs.
0226     ///   - consider classes with defaulted special member functions non-pod.
0227     Ver15,
0228 
0229     /// Attempt to be ABI-compatible with code generated by Clang 17.0.x.
0230     /// This causes clang to revert some fixes to its implementation of the
0231     /// Itanium name mangling scheme, with the consequence that overloaded
0232     /// function templates are mangled the same if they differ only by:
0233     ///   - constraints
0234     ///   - whether a non-type template parameter has a deduced type
0235     ///   - the parameter list of a template template parameter
0236     Ver17,
0237 
0238     /// Attempt to be ABI-compatible with code generated by Clang 18.0.x.
0239     /// This causes clang to revert some fixes to the mangling of lambdas
0240     /// in the initializers of members of local classes.
0241     Ver18,
0242 
0243     /// Attempt to be ABI-compatible with code generated by Clang 19.0.x.
0244     /// This causes clang to:
0245     ///   - Incorrectly mangle the 'base type' substitutions of the CXX
0246     ///   construction vtable because it hasn't added 'type' as a substitution.
0247     ///   - Skip mangling enclosing class templates of member-like friend
0248     ///   function templates.
0249     ///   - Ignore empty struct arguments in C++ mode for ARM, instead of
0250     ///   passing them as if they had a size of 1 byte.
0251     Ver19,
0252 
0253     /// Conform to the underlying platform's C and C++ ABIs as closely
0254     /// as we can.
0255     Latest
0256   };
0257 
0258   enum class CoreFoundationABI {
0259     /// No interoperability ABI has been specified
0260     Unspecified,
0261     /// CoreFoundation does not have any language interoperability
0262     Standalone,
0263     /// Interoperability with the ObjectiveC runtime
0264     ObjectiveC,
0265     /// Interoperability with the latest known version of the Swift runtime
0266     Swift,
0267     /// Interoperability with the Swift 5.0 runtime
0268     Swift5_0,
0269     /// Interoperability with the Swift 4.2 runtime
0270     Swift4_2,
0271     /// Interoperability with the Swift 4.1 runtime
0272     Swift4_1,
0273   };
0274 
0275   enum FPModeKind {
0276     // Disable the floating point pragma
0277     FPM_Off,
0278 
0279     // Enable the floating point pragma
0280     FPM_On,
0281 
0282     // Aggressively fuse FP ops (E.g. FMA) disregarding pragmas.
0283     FPM_Fast,
0284 
0285     // Aggressively fuse FP ops and honor pragmas.
0286     FPM_FastHonorPragmas
0287   };
0288 
0289   /// Possible floating point exception behavior.
0290   enum FPExceptionModeKind {
0291     /// Assume that floating-point exceptions are masked.
0292     FPE_Ignore,
0293     /// Transformations do not cause new exceptions but may hide some.
0294     FPE_MayTrap,
0295     /// Strictly preserve the floating-point exception semantics.
0296     FPE_Strict,
0297     /// Used internally to represent initial unspecified value.
0298     FPE_Default
0299   };
0300 
0301   /// Possible float expression evaluation method choices.
0302   enum FPEvalMethodKind {
0303     /// The evaluation method cannot be determined or is inconsistent for this
0304     /// target.
0305     FEM_Indeterminable = -1,
0306     /// Use the declared type for fp arithmetic.
0307     FEM_Source = 0,
0308     /// Use the type double for fp arithmetic.
0309     FEM_Double = 1,
0310     /// Use extended type for fp arithmetic.
0311     FEM_Extended = 2,
0312     /// Used only for FE option processing; this is only used to indicate that
0313     /// the user did not specify an explicit evaluation method on the command
0314     /// line and so the target should be queried for its default evaluation
0315     /// method instead.
0316     FEM_UnsetOnCommandLine = 3
0317   };
0318 
0319   enum ExcessPrecisionKind { FPP_Standard, FPP_Fast, FPP_None };
0320 
0321   /// Possible exception handling behavior.
0322   enum class ExceptionHandlingKind { None, SjLj, WinEH, DwarfCFI, Wasm };
0323 
0324   enum class LaxVectorConversionKind {
0325     /// Permit no implicit vector bitcasts.
0326     None,
0327     /// Permit vector bitcasts between integer vectors with different numbers
0328     /// of elements but the same total bit-width.
0329     Integer,
0330     /// Permit vector bitcasts between all vectors with the same total
0331     /// bit-width.
0332     All,
0333   };
0334 
0335   enum class AltivecSrcCompatKind {
0336     // All vector compares produce scalars except vector pixel and vector bool.
0337     // The types vector pixel and vector bool return vector results.
0338     Mixed,
0339     // All vector compares produce vector results as in GCC.
0340     GCC,
0341     // All vector compares produce scalars as in XL.
0342     XL,
0343     // Default clang behaviour.
0344     Default = Mixed,
0345   };
0346 
0347   enum class SignReturnAddressScopeKind {
0348     /// No signing for any function.
0349     None,
0350     /// Sign the return address of functions that spill LR.
0351     NonLeaf,
0352     /// Sign the return address of all functions,
0353     All
0354   };
0355 
0356   enum class SignReturnAddressKeyKind {
0357     /// Return address signing uses APIA key.
0358     AKey,
0359     /// Return address signing uses APIB key.
0360     BKey
0361   };
0362 
0363   enum class ThreadModelKind {
0364     /// POSIX Threads.
0365     POSIX,
0366     /// Single Threaded Environment.
0367     Single
0368   };
0369 
0370   enum class ExtendArgsKind {
0371     /// Integer arguments are sign or zero extended to 32/64 bits
0372     /// during default argument promotions.
0373     ExtendTo32,
0374     ExtendTo64
0375   };
0376 
0377   enum class GPUDefaultStreamKind {
0378     /// Legacy default stream
0379     Legacy,
0380     /// Per-thread default stream
0381     PerThread,
0382   };
0383 
0384   /// Exclude certain code patterns from being instrumented by arithmetic
0385   /// overflow sanitizers
0386   enum OverflowPatternExclusionKind {
0387     /// Don't exclude any overflow patterns from sanitizers
0388     None = 1 << 0,
0389     /// Exclude all overflow patterns (below)
0390     All = 1 << 1,
0391     /// if (a + b < a)
0392     AddSignedOverflowTest = 1 << 2,
0393     /// if (a + b < a)
0394     AddUnsignedOverflowTest = 1 << 3,
0395     /// -1UL
0396     NegUnsignedConst = 1 << 4,
0397     /// while (count--)
0398     PostDecrInWhile = 1 << 5,
0399   };
0400 
0401   enum class DefaultVisiblityExportMapping {
0402     None,
0403     /// map only explicit default visibilities to exported
0404     Explicit,
0405     /// map all default visibilities to exported
0406     All,
0407   };
0408 
0409   enum class VisibilityForcedKinds {
0410     /// Force hidden visibility
0411     ForceHidden,
0412     /// Force protected visibility
0413     ForceProtected,
0414     /// Force default visibility
0415     ForceDefault,
0416     /// Don't alter the visibility
0417     Source,
0418   };
0419 
0420   enum class VisibilityFromDLLStorageClassKinds {
0421     /// Keep the IR-gen assigned visibility.
0422     Keep,
0423     /// Override the IR-gen assigned visibility with default visibility.
0424     Default,
0425     /// Override the IR-gen assigned visibility with hidden visibility.
0426     Hidden,
0427     /// Override the IR-gen assigned visibility with protected visibility.
0428     Protected,
0429   };
0430 
0431   enum class StrictFlexArraysLevelKind {
0432     /// Any trailing array member is a FAM.
0433     Default = 0,
0434     /// Any trailing array member of undefined, 0, or 1 size is a FAM.
0435     OneZeroOrIncomplete = 1,
0436     /// Any trailing array member of undefined or 0 size is a FAM.
0437     ZeroOrIncomplete = 2,
0438     /// Any trailing array member of undefined size is a FAM.
0439     IncompleteOnly = 3,
0440   };
0441 
0442   /// Controls the various implementations for complex multiplication and
0443   // division.
0444   enum ComplexRangeKind {
0445     /// Implementation of complex division and multiplication using a call to
0446     ///  runtime library functions(generally the case, but the BE might
0447     /// sometimes replace the library call if it knows enough about the
0448     /// potential range of the inputs). Overflow and non-finite values are
0449     /// handled by the library implementation. This is the default value.
0450     CX_Full,
0451 
0452     /// Implementation of complex division offering an improved handling
0453     /// for overflow in intermediate calculations with no special handling for
0454     /// NaN and infinite values.
0455     CX_Improved,
0456 
0457     /// Implementation of complex division using algebraic formulas at
0458     /// higher precision. Overflow is handled. Non-finite values are handled in
0459     /// some cases. If the target hardware does not have native support for a
0460     /// higher precision data type, an implementation for the complex operation
0461     /// will be used to provide improved guards against intermediate overflow,
0462     /// but overflow and underflow may still occur in some cases. NaN and
0463     /// infinite values are not handled.
0464     CX_Promoted,
0465 
0466     /// Implementation of complex division and multiplication using
0467     /// algebraic formulas at source precision. No special handling to avoid
0468     /// overflow. NaN and infinite values are not handled.
0469     CX_Basic,
0470 
0471     /// No range rule is enabled.
0472     CX_None
0473   };
0474 
0475   /// Controls which variables have static destructors registered.
0476   enum class RegisterStaticDestructorsKind {
0477     /// Register static destructors for all variables.
0478     All,
0479     /// Register static destructors only for thread-local variables.
0480     ThreadLocal,
0481     /// Don't register static destructors for any variables.
0482     None,
0483   };
0484 
0485   // Define simple language options (with no accessors).
0486 #define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
0487 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
0488 #include "clang/Basic/LangOptions.def"
0489 
0490 protected:
0491   // Define language options of enumeration type. These are private, and will
0492   // have accessors (below).
0493 #define LANGOPT(Name, Bits, Default, Description)
0494 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
0495   LLVM_PREFERRED_TYPE(Type) \
0496   unsigned Name : Bits;
0497 #include "clang/Basic/LangOptions.def"
0498 };
0499 
0500 /// Keeps track of the various options that can be
0501 /// enabled, which controls the dialect of C or C++ that is accepted.
0502 class LangOptions : public LangOptionsBase {
0503 public:
0504   /// The used language standard.
0505   LangStandard::Kind LangStd;
0506 
0507   /// Set of enabled sanitizers.
0508   SanitizerSet Sanitize;
0509   /// Is at least one coverage instrumentation type enabled.
0510   bool SanitizeCoverage = false;
0511 
0512   /// Paths to files specifying which objects
0513   /// (files, functions, variables) should not be instrumented.
0514   std::vector<std::string> NoSanitizeFiles;
0515 
0516   /// Paths to the XRay "always instrument" files specifying which
0517   /// objects (files, functions, variables) should be imbued with the XRay
0518   /// "always instrument" attribute.
0519   /// WARNING: This is a deprecated field and will go away in the future.
0520   std::vector<std::string> XRayAlwaysInstrumentFiles;
0521 
0522   /// Paths to the XRay "never instrument" files specifying which
0523   /// objects (files, functions, variables) should be imbued with the XRay
0524   /// "never instrument" attribute.
0525   /// WARNING: This is a deprecated field and will go away in the future.
0526   std::vector<std::string> XRayNeverInstrumentFiles;
0527 
0528   /// Paths to the XRay attribute list files, specifying which objects
0529   /// (files, functions, variables) should be imbued with the appropriate XRay
0530   /// attribute(s).
0531   std::vector<std::string> XRayAttrListFiles;
0532 
0533   /// Paths to special case list files specifying which entities
0534   /// (files, functions) should or should not be instrumented.
0535   std::vector<std::string> ProfileListFiles;
0536 
0537   clang::ObjCRuntime ObjCRuntime;
0538 
0539   CoreFoundationABI CFRuntime = CoreFoundationABI::Unspecified;
0540 
0541   std::string ObjCConstantStringClass;
0542 
0543   /// The name of the handler function to be called when -ftrapv is
0544   /// specified.
0545   ///
0546   /// If none is specified, abort (GCC-compatible behaviour).
0547   std::string OverflowHandler;
0548 
0549   /// The module currently being compiled as specified by -fmodule-name.
0550   std::string ModuleName;
0551 
0552   /// The name of the current module, of which the main source file
0553   /// is a part. If CompilingModule is set, we are compiling the interface
0554   /// of this module, otherwise we are compiling an implementation file of
0555   /// it. This starts as ModuleName in case -fmodule-name is provided and
0556   /// changes during compilation to reflect the current module.
0557   std::string CurrentModule;
0558 
0559   /// The names of any features to enable in module 'requires' decls
0560   /// in addition to the hard-coded list in Module.cpp and the target features.
0561   ///
0562   /// This list is sorted.
0563   std::vector<std::string> ModuleFeatures;
0564 
0565   /// Options for parsing comments.
0566   CommentOptions CommentOpts;
0567 
0568   /// A list of all -fno-builtin-* function names (e.g., memset).
0569   std::vector<std::string> NoBuiltinFuncs;
0570 
0571   /// A prefix map for __FILE__, __BASE_FILE__ and __builtin_FILE().
0572   std::map<std::string, std::string, std::greater<std::string>> MacroPrefixMap;
0573 
0574   /// Triples of the OpenMP targets that the host code codegen should
0575   /// take into account in order to generate accurate offloading descriptors.
0576   std::vector<llvm::Triple> OMPTargetTriples;
0577 
0578   /// Name of the IR file that contains the result of the OpenMP target
0579   /// host code generation.
0580   std::string OMPHostIRFile;
0581 
0582   /// The user provided compilation unit ID, if non-empty. This is used to
0583   /// externalize static variables which is needed to support accessing static
0584   /// device variables in host code for single source offloading languages
0585   /// like CUDA/HIP.
0586   std::string CUID;
0587 
0588   /// C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
0589   /// This overrides the default ABI used by the target.
0590   std::optional<TargetCXXABI::Kind> CXXABI;
0591 
0592   /// Indicates whether the front-end is explicitly told that the
0593   /// input is a header file (i.e. -x c-header).
0594   bool IsHeaderFile = false;
0595 
0596   /// The default stream kind used for HIP kernel launching.
0597   GPUDefaultStreamKind GPUDefaultStream;
0598 
0599   /// Which overflow patterns should be excluded from sanitizer instrumentation
0600   unsigned OverflowPatternExclusionMask = 0;
0601 
0602   std::vector<std::string> OverflowPatternExclusionValues;
0603 
0604   /// The seed used by the randomize structure layout feature.
0605   std::string RandstructSeed;
0606 
0607   /// Indicates whether to use target's platform-specific file separator when
0608   /// __FILE__ macro is used and when concatenating filename with directory or
0609   /// to use build environment environment's platform-specific file separator.
0610   ///
0611   /// The plaform-specific path separator is the backslash(\) for Windows and
0612   /// forward slash (/) elsewhere.
0613   bool UseTargetPathSeparator = false;
0614 
0615   // Indicates whether we should keep all nullptr checks for pointers
0616   // received as a result of a standard operator new (-fcheck-new)
0617   bool CheckNew = false;
0618 
0619   // In OpenACC mode, contains a user provided override for the _OPENACC macro.
0620   // This exists so that we can override the macro value and test our incomplete
0621   // implementation on real-world examples.
0622   std::string OpenACCMacroOverride;
0623 
0624   // Indicates if the wasm-opt binary must be ignored in the case of a
0625   // WebAssembly target.
0626   bool NoWasmOpt = false;
0627 
0628   LangOptions();
0629 
0630   /// Set language defaults for the given input language and
0631   /// language standard in the given LangOptions object.
0632   ///
0633   /// \param Opts - The LangOptions object to set up.
0634   /// \param Lang - The input language.
0635   /// \param T - The target triple.
0636   /// \param Includes - If the language requires extra headers to be implicitly
0637   ///                   included, they will be appended to this list.
0638   /// \param LangStd - The input language standard.
0639   static void
0640   setLangDefaults(LangOptions &Opts, Language Lang, const llvm::Triple &T,
0641                   std::vector<std::string> &Includes,
0642                   LangStandard::Kind LangStd = LangStandard::lang_unspecified);
0643 
0644   // Define accessors/mutators for language options of enumeration type.
0645 #define LANGOPT(Name, Bits, Default, Description)
0646 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
0647   Type get##Name() const { return static_cast<Type>(Name); } \
0648   void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
0649 #include "clang/Basic/LangOptions.def"
0650 
0651   /// Are we compiling a module?
0652   bool isCompilingModule() const {
0653     return getCompilingModule() != CMK_None;
0654   }
0655 
0656   /// Are we compiling a module implementation?
0657   bool isCompilingModuleImplementation() const {
0658     return !isCompilingModule() && !ModuleName.empty();
0659   }
0660 
0661   /// Do we need to track the owning module for a local declaration?
0662   bool trackLocalOwningModule() const {
0663     return isCompilingModule() || ModulesLocalVisibility;
0664   }
0665 
0666   bool isSignedOverflowDefined() const {
0667     return getSignedOverflowBehavior() == SOB_Defined;
0668   }
0669 
0670   bool isSubscriptPointerArithmetic() const {
0671     return ObjCRuntime.isSubscriptPointerArithmetic() &&
0672            !ObjCSubscriptingLegacyRuntime;
0673   }
0674 
0675   bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
0676     return MSCompatibilityVersion >= MajorVersion * 100000U;
0677   }
0678 
0679   bool isOverflowPatternExcluded(OverflowPatternExclusionKind Kind) const {
0680     if (OverflowPatternExclusionMask & OverflowPatternExclusionKind::None)
0681       return false;
0682     if (OverflowPatternExclusionMask & OverflowPatternExclusionKind::All)
0683       return true;
0684     return OverflowPatternExclusionMask & Kind;
0685   }
0686 
0687   /// Reset all of the options that are not considered when building a
0688   /// module.
0689   void resetNonModularOptions();
0690 
0691   /// Is this a libc/libm function that is no longer recognized as a
0692   /// builtin because a -fno-builtin-* option has been specified?
0693   bool isNoBuiltinFunc(StringRef Name) const;
0694 
0695   /// True if any ObjC types may have non-trivial lifetime qualifiers.
0696   bool allowsNonTrivialObjCLifetimeQualifiers() const {
0697     return ObjCAutoRefCount || ObjCWeak;
0698   }
0699 
0700   bool assumeFunctionsAreConvergent() const {
0701     return ConvergentFunctions;
0702   }
0703 
0704   /// Return true if atomicrmw operations targeting allocations in private
0705   /// memory are undefined.
0706   bool threadPrivateMemoryAtomicsAreUndefined() const {
0707     // Should be false for OpenMP.
0708     // TODO: Should this be true for SYCL?
0709     return OpenCL || CUDA;
0710   }
0711 
0712   /// Return the OpenCL C or C++ version as a VersionTuple.
0713   VersionTuple getOpenCLVersionTuple() const;
0714 
0715   /// Return the OpenCL version that kernel language is compatible with
0716   unsigned getOpenCLCompatibleVersion() const;
0717 
0718   /// Return the OpenCL C or C++ for OpenCL language name and version
0719   /// as a string.
0720   std::string getOpenCLVersionString() const;
0721 
0722   /// Returns true if functions without prototypes or functions with an
0723   /// identifier list (aka K&R C functions) are not allowed.
0724   bool requiresStrictPrototypes() const {
0725     return CPlusPlus || C23 || DisableKNRFunctions;
0726   }
0727 
0728   /// Returns true if implicit function declarations are allowed in the current
0729   /// language mode.
0730   bool implicitFunctionsAllowed() const {
0731     return !requiresStrictPrototypes() && !OpenCL;
0732   }
0733 
0734   /// Returns true if the language supports calling the 'atexit' function.
0735   bool hasAtExit() const { return !(OpenMP && OpenMPIsTargetDevice); }
0736 
0737   /// Returns true if implicit int is part of the language requirements.
0738   bool isImplicitIntRequired() const { return !CPlusPlus && !C99; }
0739 
0740   /// Returns true if implicit int is supported at all.
0741   bool isImplicitIntAllowed() const { return !CPlusPlus && !C23; }
0742 
0743   /// Check if return address signing is enabled.
0744   bool hasSignReturnAddress() const {
0745     return getSignReturnAddressScope() != SignReturnAddressScopeKind::None;
0746   }
0747 
0748   /// Check if return address signing uses AKey.
0749   bool isSignReturnAddressWithAKey() const {
0750     return getSignReturnAddressKey() == SignReturnAddressKeyKind::AKey;
0751   }
0752 
0753   /// Check if leaf functions are also signed.
0754   bool isSignReturnAddressScopeAll() const {
0755     return getSignReturnAddressScope() == SignReturnAddressScopeKind::All;
0756   }
0757 
0758   bool hasSjLjExceptions() const {
0759     return getExceptionHandling() == ExceptionHandlingKind::SjLj;
0760   }
0761 
0762   bool hasSEHExceptions() const {
0763     return getExceptionHandling() == ExceptionHandlingKind::WinEH;
0764   }
0765 
0766   bool hasDWARFExceptions() const {
0767     return getExceptionHandling() == ExceptionHandlingKind::DwarfCFI;
0768   }
0769 
0770   bool hasWasmExceptions() const {
0771     return getExceptionHandling() == ExceptionHandlingKind::Wasm;
0772   }
0773 
0774   bool isSYCL() const { return SYCLIsDevice || SYCLIsHost; }
0775 
0776   bool hasDefaultVisibilityExportMapping() const {
0777     return getDefaultVisibilityExportMapping() !=
0778            DefaultVisiblityExportMapping::None;
0779   }
0780 
0781   bool isExplicitDefaultVisibilityExportMapping() const {
0782     return getDefaultVisibilityExportMapping() ==
0783            DefaultVisiblityExportMapping::Explicit;
0784   }
0785 
0786   bool isAllDefaultVisibilityExportMapping() const {
0787     return getDefaultVisibilityExportMapping() ==
0788            DefaultVisiblityExportMapping::All;
0789   }
0790 
0791   bool hasGlobalAllocationFunctionVisibility() const {
0792     return getGlobalAllocationFunctionVisibility() !=
0793            VisibilityForcedKinds::Source;
0794   }
0795 
0796   bool hasDefaultGlobalAllocationFunctionVisibility() const {
0797     return getGlobalAllocationFunctionVisibility() ==
0798            VisibilityForcedKinds::ForceDefault;
0799   }
0800 
0801   bool hasProtectedGlobalAllocationFunctionVisibility() const {
0802     return getGlobalAllocationFunctionVisibility() ==
0803            VisibilityForcedKinds::ForceProtected;
0804   }
0805 
0806   bool hasHiddenGlobalAllocationFunctionVisibility() const {
0807     return getGlobalAllocationFunctionVisibility() ==
0808            VisibilityForcedKinds::ForceHidden;
0809   }
0810 
0811   /// Remap path prefix according to -fmacro-prefix-path option.
0812   void remapPathPrefix(SmallVectorImpl<char> &Path) const;
0813 
0814   RoundingMode getDefaultRoundingMode() const {
0815     return RoundingMath ? RoundingMode::Dynamic
0816                         : RoundingMode::NearestTiesToEven;
0817   }
0818 
0819   FPExceptionModeKind getDefaultExceptionMode() const {
0820     FPExceptionModeKind EM = getFPExceptionMode();
0821     if (EM == FPExceptionModeKind::FPE_Default)
0822       return FPExceptionModeKind::FPE_Ignore;
0823     return EM;
0824   }
0825 };
0826 
0827 /// Floating point control options
0828 class FPOptionsOverride;
0829 class FPOptions {
0830 public:
0831   // We start by defining the layout.
0832   using storage_type = uint32_t;
0833 
0834   using RoundingMode = llvm::RoundingMode;
0835 
0836   static constexpr unsigned StorageBitSize = 8 * sizeof(storage_type);
0837 
0838   // Define a fake option named "First" so that we have a PREVIOUS even for the
0839   // real first option.
0840   static constexpr storage_type FirstShift = 0, FirstWidth = 0;
0841 #define OPTION(NAME, TYPE, WIDTH, PREVIOUS)                                    \
0842   static constexpr storage_type NAME##Shift =                                  \
0843       PREVIOUS##Shift + PREVIOUS##Width;                                       \
0844   static constexpr storage_type NAME##Width = WIDTH;                           \
0845   static constexpr storage_type NAME##Mask = ((1 << NAME##Width) - 1)          \
0846                                              << NAME##Shift;
0847 #include "clang/Basic/FPOptions.def"
0848 
0849   static constexpr storage_type TotalWidth = 0
0850 #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) +WIDTH
0851 #include "clang/Basic/FPOptions.def"
0852       ;
0853   static_assert(TotalWidth <= StorageBitSize, "Too short type for FPOptions");
0854 
0855 private:
0856   storage_type Value;
0857 
0858   FPOptionsOverride getChangesSlow(const FPOptions &Base) const;
0859 
0860 public:
0861   FPOptions() : Value(0) {
0862     setFPContractMode(LangOptions::FPM_Off);
0863     setConstRoundingMode(RoundingMode::Dynamic);
0864     setSpecifiedExceptionMode(LangOptions::FPE_Default);
0865   }
0866   explicit FPOptions(const LangOptions &LO) {
0867     Value = 0;
0868     // The language fp contract option FPM_FastHonorPragmas has the same effect
0869     // as FPM_Fast in frontend. For simplicity, use FPM_Fast uniformly in
0870     // frontend.
0871     auto LangOptContractMode = LO.getDefaultFPContractMode();
0872     if (LangOptContractMode == LangOptions::FPM_FastHonorPragmas)
0873       LangOptContractMode = LangOptions::FPM_Fast;
0874     setFPContractMode(LangOptContractMode);
0875     setRoundingMath(LO.RoundingMath);
0876     setConstRoundingMode(LangOptions::RoundingMode::Dynamic);
0877     setSpecifiedExceptionMode(LO.getFPExceptionMode());
0878     setAllowFPReassociate(LO.AllowFPReassoc);
0879     setNoHonorNaNs(LO.NoHonorNaNs);
0880     setNoHonorInfs(LO.NoHonorInfs);
0881     setNoSignedZero(LO.NoSignedZero);
0882     setAllowReciprocal(LO.AllowRecip);
0883     setAllowApproxFunc(LO.ApproxFunc);
0884     if (getFPContractMode() == LangOptions::FPM_On &&
0885         getRoundingMode() == llvm::RoundingMode::Dynamic &&
0886         getExceptionMode() == LangOptions::FPE_Strict)
0887       // If the FP settings are set to the "strict" model, then
0888       // FENV access is set to true. (ffp-model=strict)
0889       setAllowFEnvAccess(true);
0890     else
0891       setAllowFEnvAccess(LangOptions::FPM_Off);
0892     setComplexRange(LO.getComplexRange());
0893   }
0894 
0895   bool allowFPContractWithinStatement() const {
0896     return getFPContractMode() == LangOptions::FPM_On;
0897   }
0898   void setAllowFPContractWithinStatement() {
0899     setFPContractMode(LangOptions::FPM_On);
0900   }
0901 
0902   bool allowFPContractAcrossStatement() const {
0903     return getFPContractMode() == LangOptions::FPM_Fast;
0904   }
0905   void setAllowFPContractAcrossStatement() {
0906     setFPContractMode(LangOptions::FPM_Fast);
0907   }
0908 
0909   bool isFPConstrained() const {
0910     return getRoundingMode() != llvm::RoundingMode::NearestTiesToEven ||
0911            getExceptionMode() != LangOptions::FPE_Ignore ||
0912            getAllowFEnvAccess();
0913   }
0914 
0915   RoundingMode getRoundingMode() const {
0916     RoundingMode RM = getConstRoundingMode();
0917     if (RM == RoundingMode::Dynamic) {
0918       // C23: 7.6.2p3  If the FE_DYNAMIC mode is specified and FENV_ACCESS is
0919       // "off", the translator may assume that the default rounding mode is in
0920       // effect.
0921       if (!getAllowFEnvAccess() && !getRoundingMath())
0922         RM = RoundingMode::NearestTiesToEven;
0923     }
0924     return RM;
0925   }
0926 
0927   LangOptions::FPExceptionModeKind getExceptionMode() const {
0928     LangOptions::FPExceptionModeKind EM = getSpecifiedExceptionMode();
0929     if (EM == LangOptions::FPExceptionModeKind::FPE_Default) {
0930       if (getAllowFEnvAccess())
0931         return LangOptions::FPExceptionModeKind::FPE_Strict;
0932       else
0933         return LangOptions::FPExceptionModeKind::FPE_Ignore;
0934     }
0935     return EM;
0936   }
0937 
0938   bool operator==(FPOptions other) const { return Value == other.Value; }
0939 
0940   /// Return the default value of FPOptions that's used when trailing
0941   /// storage isn't required.
0942   static FPOptions defaultWithoutTrailingStorage(const LangOptions &LO);
0943 
0944   storage_type getAsOpaqueInt() const { return Value; }
0945   static FPOptions getFromOpaqueInt(storage_type Value) {
0946     FPOptions Opts;
0947     Opts.Value = Value;
0948     return Opts;
0949   }
0950 
0951   /// Return difference with the given option set.
0952   FPOptionsOverride getChangesFrom(const FPOptions &Base) const;
0953 
0954   void applyChanges(FPOptionsOverride FPO);
0955 
0956   // We can define most of the accessors automatically:
0957 #define OPTION(NAME, TYPE, WIDTH, PREVIOUS)                                    \
0958   TYPE get##NAME() const {                                                     \
0959     return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift);             \
0960   }                                                                            \
0961   void set##NAME(TYPE value) {                                                 \
0962     Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift);      \
0963   }
0964 #include "clang/Basic/FPOptions.def"
0965   LLVM_DUMP_METHOD void dump();
0966 };
0967 
0968 /// Represents difference between two FPOptions values.
0969 ///
0970 /// The effect of language constructs changing the set of floating point options
0971 /// is usually a change of some FP properties while leaving others intact. This
0972 /// class describes such changes by keeping information about what FP options
0973 /// are overridden.
0974 ///
0975 /// The integral set of FP options, described by the class FPOptions, may be
0976 /// represented as a default FP option set, defined by language standard and
0977 /// command line options, with the overrides introduced by pragmas.
0978 ///
0979 /// The is implemented as a value of the new FPOptions plus a mask showing which
0980 /// fields are actually set in it.
0981 class FPOptionsOverride {
0982   FPOptions Options = FPOptions::getFromOpaqueInt(0);
0983   FPOptions::storage_type OverrideMask = 0;
0984 
0985 public:
0986   using RoundingMode = llvm::RoundingMode;
0987 
0988   /// The type suitable for storing values of FPOptionsOverride. Must be twice
0989   /// as wide as bit size of FPOption.
0990   using storage_type = uint64_t;
0991   static_assert(sizeof(storage_type) >= 2 * sizeof(FPOptions::storage_type),
0992                 "Too short type for FPOptionsOverride");
0993 
0994   /// Bit mask selecting bits of OverrideMask in serialized representation of
0995   /// FPOptionsOverride.
0996   static constexpr storage_type OverrideMaskBits =
0997       (static_cast<storage_type>(1) << FPOptions::StorageBitSize) - 1;
0998 
0999   FPOptionsOverride() {}
1000   FPOptionsOverride(const LangOptions &LO)
1001       : Options(LO), OverrideMask(OverrideMaskBits) {}
1002   FPOptionsOverride(FPOptions FPO)
1003       : Options(FPO), OverrideMask(OverrideMaskBits) {}
1004   FPOptionsOverride(FPOptions FPO, FPOptions::storage_type Mask)
1005       : Options(FPO), OverrideMask(Mask) {}
1006 
1007   bool requiresTrailingStorage() const { return OverrideMask != 0; }
1008 
1009   void setAllowFPContractWithinStatement() {
1010     setFPContractModeOverride(LangOptions::FPM_On);
1011   }
1012 
1013   void setAllowFPContractAcrossStatement() {
1014     setFPContractModeOverride(LangOptions::FPM_Fast);
1015   }
1016 
1017   void setDisallowFPContract() {
1018     setFPContractModeOverride(LangOptions::FPM_Off);
1019   }
1020 
1021   void setFPPreciseEnabled(bool Value) {
1022     setAllowFPReassociateOverride(!Value);
1023     setNoHonorNaNsOverride(!Value);
1024     setNoHonorInfsOverride(!Value);
1025     setNoSignedZeroOverride(!Value);
1026     setAllowReciprocalOverride(!Value);
1027     setAllowApproxFuncOverride(!Value);
1028     setMathErrnoOverride(Value);
1029     if (Value)
1030       /* Precise mode implies fp_contract=on and disables ffast-math */
1031       setAllowFPContractWithinStatement();
1032     else
1033       /* Precise mode disabled sets fp_contract=fast and enables ffast-math */
1034       setAllowFPContractAcrossStatement();
1035   }
1036 
1037   void setDisallowOptimizations() { setFPPreciseEnabled(true); }
1038 
1039   storage_type getAsOpaqueInt() const {
1040     return (static_cast<storage_type>(Options.getAsOpaqueInt())
1041             << FPOptions::StorageBitSize) |
1042            OverrideMask;
1043   }
1044   static FPOptionsOverride getFromOpaqueInt(storage_type I) {
1045     FPOptionsOverride Opts;
1046     Opts.OverrideMask = I & OverrideMaskBits;
1047     Opts.Options = FPOptions::getFromOpaqueInt(I >> FPOptions::StorageBitSize);
1048     return Opts;
1049   }
1050 
1051   FPOptions applyOverrides(FPOptions Base) {
1052     FPOptions Result =
1053         FPOptions::getFromOpaqueInt((Base.getAsOpaqueInt() & ~OverrideMask) |
1054                                      (Options.getAsOpaqueInt() & OverrideMask));
1055     return Result;
1056   }
1057 
1058   FPOptions applyOverrides(const LangOptions &LO) {
1059     return applyOverrides(FPOptions(LO));
1060   }
1061 
1062   bool operator==(FPOptionsOverride other) const {
1063     return Options == other.Options && OverrideMask == other.OverrideMask;
1064   }
1065   bool operator!=(FPOptionsOverride other) const { return !(*this == other); }
1066 
1067 #define OPTION(NAME, TYPE, WIDTH, PREVIOUS)                                    \
1068   bool has##NAME##Override() const {                                           \
1069     return OverrideMask & FPOptions::NAME##Mask;                               \
1070   }                                                                            \
1071   TYPE get##NAME##Override() const {                                           \
1072     assert(has##NAME##Override());                                             \
1073     return Options.get##NAME();                                                \
1074   }                                                                            \
1075   void clear##NAME##Override() {                                               \
1076     /* Clear the actual value so that we don't have spurious differences when  \
1077      * testing equality. */                                                    \
1078     Options.set##NAME(TYPE(0));                                                \
1079     OverrideMask &= ~FPOptions::NAME##Mask;                                    \
1080   }                                                                            \
1081   void set##NAME##Override(TYPE value) {                                       \
1082     Options.set##NAME(value);                                                  \
1083     OverrideMask |= FPOptions::NAME##Mask;                                     \
1084   }
1085 #include "clang/Basic/FPOptions.def"
1086   LLVM_DUMP_METHOD void dump();
1087 };
1088 
1089 inline FPOptionsOverride FPOptions::getChangesFrom(const FPOptions &Base) const {
1090   if (Value == Base.Value)
1091     return FPOptionsOverride();
1092   return getChangesSlow(Base);
1093 }
1094 
1095 inline void FPOptions::applyChanges(FPOptionsOverride FPO) {
1096   *this = FPO.applyOverrides(*this);
1097 }
1098 
1099 /// Describes the kind of translation unit being processed.
1100 enum TranslationUnitKind {
1101   /// The translation unit is a complete translation unit.
1102   TU_Complete,
1103 
1104   /// The translation unit is a prefix to a translation unit, and is
1105   /// not complete.
1106   TU_Prefix,
1107 
1108   /// The translation unit is a clang module.
1109   TU_ClangModule,
1110 
1111   /// The translation unit is a is a complete translation unit that we might
1112   /// incrementally extend later.
1113   TU_Incremental
1114 };
1115 
1116 } // namespace clang
1117 
1118 #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H