clang 23.0.0git
LangOptions.h
Go to the documentation of this file.
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
19#include "clang/Basic/LLVM.h"
25#include "llvm/ADT/FloatingPointMode.h"
26#include "llvm/ADT/StringRef.h"
27#include "llvm/BinaryFormat/DXContainer.h"
28#include "llvm/Support/AllocToken.h"
29#include "llvm/TargetParser/Triple.h"
30#include <optional>
31#include <string>
32#include <vector>
33
34namespace clang {
35
36/// In the Microsoft ABI, this controls the placement of virtual displacement
37/// members used to implement virtual inheritance.
39
40/// Shader programs run in specific pipeline stages.
41/// The order of these values matters, and must be kept in sync with the
42/// Triple Environment enum in llvm::Triple. The ordering is enforced in
43/// static_asserts in Triple.cpp and in clang/Basic/HLSLRuntime.h.
62
69
70/// Bitfields of LangOptions, split out from LangOptions in order to ensure that
71/// this large collection of bitfields is a trivial class type.
73 friend class CompilerInvocation;
75
76public:
78 using RoundingMode = llvm::RoundingMode;
80
81 /// For ASTs produced with different option value, signifies their level of
82 /// compatibility.
83 enum class CompatibilityKind {
84 /// Does affect the construction of the AST in a way that does prevent
85 /// module interoperability.
87 /// Does affect the construction of the AST in a way that doesn't prevent
88 /// interoperability (that is, the value can be different between an
89 /// explicit module and the user of that module).
91 /// Does not affect the construction of the AST in any way (that is, the
92 /// value can be different between an implicit module and the user of that
93 /// module).
95 };
96
99
100 // Automatic variables live on the stack, and when trivial they're usually
101 // uninitialized because it's undefined behavior to use them without
102 // initializing them.
104
106 // Default C standard behavior.
108
109 // -fwrapv
111
112 // -ftrapv
114 };
115
116 // Used by __attribute__((overflow_behavior())) to describe overflow behavior
117 // on a per-type basis.
119 // Default C standard behavior (type dependent).
121
122 // __attribute__((overflow_behavior("wrap")))
124
125 // __attribute__((overflow_behavior("trap")))
127
128 // Signed types defined as wrapping via -fwrapv can still be instrumented
129 // by sanitizers (PR82432). This field is needed to disambiguate canonical
130 // wrapping type behaviors from -fwrapv behaviors.
131 // -fwrapv
133 };
134
135 // FIXME: Unify with TUKind.
137 /// Not compiling a module interface at all.
139
140 /// Compiling a module from a module map.
142
143 /// Compiling a module header unit.
145
146 /// Compiling a C++ modules interface unit.
148 };
149
156
158
168
170
171 // Corresponds to _MSC_VER
173 MSVC2010 = 1600,
174 MSVC2012 = 1700,
175 MSVC2013 = 1800,
176 MSVC2015 = 1900,
177 MSVC2017 = 1910,
181 MSVC2019 = 1920,
186 };
187
192 // The "default" SYCL version to be used when none is specified on the
193 // frontend command line.
195 };
196
199 HLSL_2015 = 2015,
200 HLSL_2016 = 2016,
201 HLSL_2017 = 2017,
202 HLSL_2018 = 2018,
203 HLSL_2021 = 2021,
204 HLSL_202x = 2028,
205 HLSL_202y = 2029,
206 };
207
208 /// Clang versions with different platform ABI conformance.
209 enum class ClangABI {
210#define ABI_VER_MAJOR_MINOR(Major, Minor) Ver##Major##_##Minor,
211#define ABI_VER_MAJOR(Major) Ver##Major,
212#define ABI_VER_LATEST(Latest) Latest
213#include "clang/Basic/ABIVersions.def"
214 };
215
216 enum class CoreFoundationABI {
217 /// No interoperability ABI has been specified
219 /// CoreFoundation does not have any language interoperability
221 /// Interoperability with the ObjectiveC runtime
223 /// Interoperability with the latest known version of the Swift runtime
225 /// Interoperability with the Swift 5.0 runtime
227 /// Interoperability with the Swift 4.2 runtime
229 /// Interoperability with the Swift 4.1 runtime
231 };
232
234 // Disable the floating point pragma
236
237 // Enable the floating point pragma
239
240 // Aggressively fuse FP ops (E.g. FMA) disregarding pragmas.
242
243 // Aggressively fuse FP ops and honor pragmas.
245 };
246
247 /// Possible floating point exception behavior.
249 /// Assume that floating-point exceptions are masked.
251 /// Transformations do not cause new exceptions but may hide some.
253 /// Strictly preserve the floating-point exception semantics.
255 /// Used internally to represent initial unspecified value.
257 };
258
259 /// Possible float expression evaluation method choices.
260 enum FPEvalMethodKind : unsigned {
261 /// Use the declared type for fp arithmetic.
263 /// Use the type double for fp arithmetic.
265 /// Use extended type for fp arithmetic.
267 /// Used only for FE option processing; this is only used to indicate that
268 /// the user did not specify an explicit evaluation method on the command
269 /// line and so the target should be queried for its default evaluation
270 /// method instead.
272 };
273
274 enum class MatrixMemoryLayout : unsigned {
275 // Use column-major layout for matrices
277 // Use row-major layout for matrices
279 };
280
282
284 /// Permit no implicit vector bitcasts.
286 /// Permit vector bitcasts between integer vectors with different numbers
287 /// of elements but the same total bit-width.
289 /// Permit vector bitcasts between all vectors with the same total
290 /// bit-width.
292 };
293
295 // All vector compares produce scalars except vector pixel and vector bool.
296 // The types vector pixel and vector bool return vector results.
298 // All vector compares produce vector results as in GCC.
300 // All vector compares produce scalars as in XL.
302 // Default clang behaviour.
304 };
305
307 /// No signing for any function.
309 /// Sign the return address of functions that spill LR.
311 /// Sign the return address of all functions,
313 };
314
316 /// Return address signing uses APIA key.
318 /// Return address signing uses APIB key.
320 };
321
322 enum class ThreadModelKind {
323 /// POSIX Threads.
325 /// Single Threaded Environment.
327 };
328
329 enum class ExtendArgsKind {
330 /// Integer arguments are sign or zero extended to 32/64 bits
331 /// during default argument promotions.
334 };
335
337 /// Legacy default stream
339 /// Per-thread default stream
341 };
342
343 /// Exclude certain code patterns from being instrumented by arithmetic
344 /// overflow sanitizers
346 /// Don't exclude any overflow patterns from sanitizers
347 None = 1 << 0,
348 /// Exclude all overflow patterns (below)
349 All = 1 << 1,
350 /// if (a + b < a)
352 /// if (a + b < a)
354 /// -1UL
356 /// while (count--)
358 };
359
362 /// map only explicit default visibilities to exported
364 /// map all default visibilities to exported
366 };
367
369 /// Force hidden visibility
371 /// Force protected visibility
373 /// Force default visibility
375 /// Don't alter the visibility
377 };
378
380 /// Keep the IR-gen assigned visibility.
382 /// Override the IR-gen assigned visibility with default visibility.
384 /// Override the IR-gen assigned visibility with hidden visibility.
386 /// Override the IR-gen assigned visibility with protected visibility.
388 };
389
391 /// Any trailing array member is a FAM.
393 /// Any trailing array member of undefined, 0, or 1 size is a FAM.
395 /// Any trailing array member of undefined or 0 size is a FAM.
397 /// Any trailing array member of undefined size is a FAM.
399 };
400
401 /// Controls the various implementations for complex multiplication and
402 // division.
404 /// Implementation of complex division and multiplication using a call to
405 /// runtime library functions(generally the case, but the BE might
406 /// sometimes replace the library call if it knows enough about the
407 /// potential range of the inputs). Overflow and non-finite values are
408 /// handled by the library implementation. This is the default value.
410
411 /// Implementation of complex division offering an improved handling
412 /// for overflow in intermediate calculations with no special handling for
413 /// NaN and infinite values.
415
416 /// Implementation of complex division using algebraic formulas at
417 /// higher precision. Overflow is handled. Non-finite values are handled in
418 /// some cases. If the target hardware does not have native support for a
419 /// higher precision data type, an implementation for the complex operation
420 /// will be used to provide improved guards against intermediate overflow,
421 /// but overflow and underflow may still occur in some cases. NaN and
422 /// infinite values are not handled.
424
425 /// Implementation of complex division and multiplication using
426 /// algebraic formulas at source precision. No special handling to avoid
427 /// overflow. NaN and infinite values are not handled.
429
430 /// No range rule is enabled.
432 };
433
434 /// Controls which variables have static destructors registered.
436 /// Register static destructors for all variables.
438 /// Register static destructors only for thread-local variables.
440 /// Don't register static destructors for any variables.
442 };
443
445 /// Use default layout rules of the target.
447 /// Use Itanium rules for bit-field layout and fundamental types alignment.
449 /// Use Microsoft C++ ABI rules for bit-field layout and fundamental types
450 /// alignment.
452 };
453
454 // Define simple language options (with no accessors).
455#define LANGOPT(Name, Bits, Default, Compatibility, Description) \
456 unsigned Name : Bits;
457#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description)
458#include "clang/Basic/LangOptions.def"
459
460protected:
461 // Define language options of enumeration type. These are private, and will
462 // have accessors (below).
463#define LANGOPT(Name, Bits, Default, Compatibility, Description)
464#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \
465 LLVM_PREFERRED_TYPE(Type) \
466 unsigned Name : Bits;
467#include "clang/Basic/LangOptions.def"
468};
469
470/// Keeps track of the various options that can be
471/// enabled, which controls the dialect of C or C++ that is accepted.
473public:
474 /// The used language standard.
476
477 /// Set of enabled sanitizers.
479 /// Is at least one coverage instrumentation type enabled.
480 bool SanitizeCoverage = false;
481 /// Set of (UBSan) sanitizers that when enabled do not cause
482 /// `__has_feature(undefined_behavior_sanitizer)` to evaluate true.
484
485 /// Paths to files specifying which objects
486 /// (files, functions, variables) should not be instrumented.
487 std::vector<std::string> NoSanitizeFiles;
488
489 /// Paths to the XRay "always instrument" files specifying which
490 /// objects (files, functions, variables) should be imbued with the XRay
491 /// "always instrument" attribute.
492 /// WARNING: This is a deprecated field and will go away in the future.
493 std::vector<std::string> XRayAlwaysInstrumentFiles;
494
495 /// Paths to the XRay "never instrument" files specifying which
496 /// objects (files, functions, variables) should be imbued with the XRay
497 /// "never instrument" attribute.
498 /// WARNING: This is a deprecated field and will go away in the future.
499 std::vector<std::string> XRayNeverInstrumentFiles;
500
501 /// Paths to the XRay attribute list files, specifying which objects
502 /// (files, functions, variables) should be imbued with the appropriate XRay
503 /// attribute(s).
504 std::vector<std::string> XRayAttrListFiles;
505
506 /// Paths to special case list files specifying which entities
507 /// (files, functions) should or should not be instrumented.
508 std::vector<std::string> ProfileListFiles;
509
511
513
520
521 /// The name of the handler function to be called when -ftrapv is
522 /// specified.
523 ///
524 /// If none is specified, abort (GCC-compatible behaviour).
525 std::string OverflowHandler;
526
527 /// The module currently being compiled as specified by -fmodule-name.
528 std::string ModuleName;
529
530 /// The name of the current module, of which the main source file
531 /// is a part. If CompilingModule is set, we are compiling the interface
532 /// of this module, otherwise we are compiling an implementation file of
533 /// it. This starts as ModuleName in case -fmodule-name is provided and
534 /// changes during compilation to reflect the current module.
535 std::string CurrentModule;
536
537 /// The names of any features to enable in module 'requires' decls
538 /// in addition to the hard-coded list in Module.cpp and the target features.
539 ///
540 /// This list is sorted.
541 std::vector<std::string> ModuleFeatures;
542
543 /// Options for parsing comments.
545
546 /// A list of all -fno-builtin-* function names (e.g., memset).
547 std::vector<std::string> NoBuiltinFuncs;
548
549 /// A prefix map for __FILE__, __BASE_FILE__ and __builtin_FILE().
550 std::map<std::string, std::string, std::greater<std::string>> MacroPrefixMap;
551
552 /// Triples of the OpenMP targets that the host code codegen should
553 /// take into account in order to generate accurate offloading descriptors.
554 std::vector<llvm::Triple> OMPTargetTriples;
555
556 /// Name of the IR file that contains the result of the OpenMP target
557 /// host code generation.
558 std::string OMPHostIRFile;
559
560 /// The user provided compilation unit ID, if non-empty. This is used to
561 /// externalize static variables which is needed to support accessing static
562 /// device variables in host code for single source offloading languages
563 /// like CUDA/HIP.
564 std::string CUID;
565
566 /// C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
567 /// This overrides the default ABI used by the target.
568 std::optional<TargetCXXABI::Kind> CXXABI;
569
570 /// Indicates whether the front-end is explicitly told that the
571 /// input is a header file (i.e. -x c-header).
572 bool IsHeaderFile = false;
573
574 /// The default stream kind used for HIP kernel launching.
576
577 /// Which overflow patterns should be excluded from sanitizer instrumentation
579
580 std::vector<std::string> OverflowPatternExclusionValues;
581
582 /// The seed used by the randomize structure layout feature.
583 std::string RandstructSeed;
584
585 /// Indicates whether to use target's platform-specific file separator when
586 /// __FILE__ macro is used and when concatenating filename with directory or
587 /// to use build environment environment's platform-specific file separator.
588 ///
589 /// The plaform-specific path separator is the backslash(\‍) for Windows and
590 /// forward slash (/) elsewhere.
592
593 // Indicates whether we should keep all nullptr checks for pointers
594 // received as a result of a standard operator new (-fcheck-new)
595 bool CheckNew = false;
596
597 /// The HLSL root signature version for dxil.
598 llvm::dxbc::RootSignatureVersion HLSLRootSigVer;
599
600 /// The HLSL root signature that will be used to overide the root signature
601 /// used for the shader entry point.
603
604 // Indicates if the wasm-opt binary must be ignored in the case of a
605 // WebAssembly target.
606 bool NoWasmOpt = false;
607
608 /// Atomic code-generation options.
609 /// These flags are set directly from the command-line options.
610 bool AtomicRemoteMemory = false;
613
614 /// Maximum number of allocation tokens (0 = target SIZE_MAX), nullopt if none
615 /// set (use target SIZE_MAX).
616 std::optional<uint64_t> AllocTokenMax;
617
618 /// The allocation token mode.
619 std::optional<llvm::AllocTokenMode> AllocTokenMode;
620
621 LangOptions();
622
623 /// Set language defaults for the given input language and
624 /// language standard in the given LangOptions object.
625 ///
626 /// \param Opts - The LangOptions object to set up.
627 /// \param Lang - The input language.
628 /// \param T - The target triple.
629 /// \param Includes - If the language requires extra headers to be implicitly
630 /// included, they will be appended to this list.
631 /// \param LangStd - The input language standard.
632 static void
633 setLangDefaults(LangOptions &Opts, Language Lang, const llvm::Triple &T,
634 std::vector<std::string> &Includes,
636
637 // Define accessors/mutators for language options of enumeration type.
638#define LANGOPT(Name, Bits, Default, Compatibility, Description)
639#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \
640 Type get##Name() const { return static_cast<Type>(Name); } \
641 void set##Name(Type Value) { \
642 assert(static_cast<unsigned>(Value) < (1u << Bits)); \
643 Name = static_cast<unsigned>(Value); \
644 }
645#include "clang/Basic/LangOptions.def"
646
647 /// Are we compiling a module?
648 bool isCompilingModule() const {
649 return getCompilingModule() != CMK_None;
650 }
651
652 /// Are we compiling a module implementation?
654 return !isCompilingModule() && !ModuleName.empty();
655 }
656
657 /// Do we need to track the owning module for a local declaration?
659 return isCompilingModule() || ModulesLocalVisibility;
660 }
661
663 return getSignedOverflowBehavior() == SOB_Defined;
664 }
665
667 return ObjCRuntime.isSubscriptPointerArithmetic() &&
668 !ObjCSubscriptingLegacyRuntime;
669 }
670
671 bool isCompatibleWithMSVC() const { return MSCompatibilityVersion > 0; }
672
673 bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
674 return MSCompatibilityVersion >= MajorVersion * 100000U;
675 }
676
684
685 /// Reset all of the options that are not considered when building a
686 /// module.
688
689 /// Is this a libc/libm function that is no longer recognized as a
690 /// builtin because a -fno-builtin-* option has been specified?
691 bool isNoBuiltinFunc(StringRef Name) const;
692
693 /// True if any ObjC types may have non-trivial lifetime qualifiers.
695 return ObjCAutoRefCount || ObjCWeak;
696 }
697
699 return ConvergentFunctions;
700 }
701
702 /// Return true if atomicrmw operations targeting allocations in private
703 /// memory are undefined.
705 // Should be false for OpenMP.
706 // TODO: Should this be true for SYCL?
707 return OpenCL || CUDA;
708 }
709
710 /// Return the OpenCL C or C++ version as a VersionTuple.
711 VersionTuple getOpenCLVersionTuple() const;
712
713 /// Return the OpenCL version that kernel language is compatible with
714 unsigned getOpenCLCompatibleVersion() const;
715
716 /// Return the OpenCL C or C++ for OpenCL language name and version
717 /// as a string.
718 std::string getOpenCLVersionString() const;
719
720 /// Returns true if functions without prototypes or functions with an
721 /// identifier list (aka K&R C functions) are not allowed.
723 return CPlusPlus || C23 || DisableKNRFunctions;
724 }
725
726 /// Returns true if implicit function declarations are allowed in the current
727 /// language mode.
729 return !requiresStrictPrototypes() && !OpenCL;
730 }
731
732 /// Returns true if the language supports calling the 'atexit' function.
733 bool hasAtExit() const { return !(OpenMP && OpenMPIsTargetDevice); }
734
735 /// Returns true if implicit int is part of the language requirements.
736 bool isImplicitIntRequired() const { return !CPlusPlus && !C99; }
737
738 /// Returns true if implicit int is supported at all.
739 bool isImplicitIntAllowed() const { return !CPlusPlus && !C23; }
740
741 /// Check if return address signing is enabled.
742 bool hasSignReturnAddress() const {
743 return getSignReturnAddressScope() != SignReturnAddressScopeKind::None;
744 }
745
746 /// Check if return address signing uses AKey.
748 return getSignReturnAddressKey() == SignReturnAddressKeyKind::AKey;
749 }
750
751 /// Check if leaf functions are also signed.
753 return getSignReturnAddressScope() == SignReturnAddressScopeKind::All;
754 }
755
756 bool isSYCL() const { return SYCLIsDevice || SYCLIsHost; }
757
759 return getDefaultVisibilityExportMapping() !=
761 }
762
764 return getDefaultVisibilityExportMapping() ==
766 }
767
769 return getDefaultVisibilityExportMapping() ==
771 }
772
774 return getGlobalAllocationFunctionVisibility() !=
776 }
777
779 return getGlobalAllocationFunctionVisibility() ==
781 }
782
784 return getGlobalAllocationFunctionVisibility() ==
786 }
787
789 return getGlobalAllocationFunctionVisibility() ==
791 }
792
793 bool allowArrayReturnTypes() const { return HLSL; }
794
795 /// Remap path prefix according to -fmacro-prefix-path option.
796 void remapPathPrefix(SmallVectorImpl<char> &Path) const;
797
799 return RoundingMath ? RoundingMode::Dynamic
800 : RoundingMode::NearestTiesToEven;
801 }
802
804 FPExceptionModeKind EM = getFPExceptionMode();
807 return EM;
808 }
809
810 /// True when compiling for an offloading target device.
811 bool isTargetDevice() const {
812 return OpenMPIsTargetDevice || CUDAIsDevice || SYCLIsDevice;
813 }
814
815 /// Returns the most applicable C standard-compliant language version code.
816 /// If none could be determined, returns \ref std::nullopt.
817 std::optional<uint32_t> getCLangStd() const;
818
819 /// Returns the most applicable C++ standard-compliant language
820 /// version code.
821 /// If none could be determined, returns \ref std::nullopt.
822 std::optional<uint32_t> getCPlusPlusLangStd() const;
823};
824
825/// Floating point control options
826class FPOptionsOverride;
828public:
829 // We start by defining the layout.
830 using storage_type = uint32_t;
831
832 using RoundingMode = llvm::RoundingMode;
833
834 static constexpr unsigned StorageBitSize = 8 * sizeof(storage_type);
835
836 // Define a fake option named "First" so that we have a PREVIOUS even for the
837 // real first option.
838 static constexpr storage_type FirstShift = 0, FirstWidth = 0;
839#define FP_OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
840 static constexpr storage_type NAME##Shift = \
841 PREVIOUS##Shift + PREVIOUS##Width; \
842 static constexpr storage_type NAME##Width = WIDTH; \
843 static constexpr storage_type NAME##Mask = ((1 << NAME##Width) - 1) \
844 << NAME##Shift;
845#include "clang/Basic/FPOptions.def"
846
847 static constexpr storage_type TotalWidth = 0
848#define FP_OPTION(NAME, TYPE, WIDTH, PREVIOUS) +WIDTH
849#include "clang/Basic/FPOptions.def"
850 ;
851 static_assert(TotalWidth <= StorageBitSize, "Too short type for FPOptions");
852
853private:
854 storage_type Value;
855
856 FPOptionsOverride getChangesSlow(const FPOptions &Base) const;
857
858public:
859 FPOptions() : Value(0) {
860 setFPContractMode(LangOptions::FPM_Off);
861 setConstRoundingMode(RoundingMode::Dynamic);
862 setSpecifiedExceptionMode(LangOptions::FPE_Default);
863 }
864 explicit FPOptions(const LangOptions &LO) {
865 Value = 0;
866 // The language fp contract option FPM_FastHonorPragmas has the same effect
867 // as FPM_Fast in frontend. For simplicity, use FPM_Fast uniformly in
868 // frontend.
869 auto LangOptContractMode = LO.getDefaultFPContractMode();
870 if (LangOptContractMode == LangOptions::FPM_FastHonorPragmas)
871 LangOptContractMode = LangOptions::FPM_Fast;
872 setFPContractMode(LangOptContractMode);
873 setRoundingMath(LO.RoundingMath);
874 setConstRoundingMode(LangOptions::RoundingMode::Dynamic);
875 setSpecifiedExceptionMode(LO.getFPExceptionMode());
876 setAllowFPReassociate(LO.AllowFPReassoc);
877 setNoHonorNaNs(LO.NoHonorNaNs);
878 setNoHonorInfs(LO.NoHonorInfs);
879 setNoSignedZero(LO.NoSignedZero);
880 setAllowReciprocal(LO.AllowRecip);
881 setAllowApproxFunc(LO.ApproxFunc);
882 if (getFPContractMode() == LangOptions::FPM_On &&
883 getRoundingMode() == llvm::RoundingMode::Dynamic &&
885 // If the FP settings are set to the "strict" model, then
886 // FENV access is set to true. (ffp-model=strict)
887 setAllowFEnvAccess(true);
888 else
889 setAllowFEnvAccess(LangOptions::FPM_Off);
890 setComplexRange(LO.getComplexRange());
891 }
892
894 return getFPContractMode() == LangOptions::FPM_On;
895 }
897 setFPContractMode(LangOptions::FPM_On);
898 }
899
901 return getFPContractMode() == LangOptions::FPM_Fast;
902 }
904 setFPContractMode(LangOptions::FPM_Fast);
905 }
906
907 bool isFPConstrained() const {
908 return getRoundingMode() != llvm::RoundingMode::NearestTiesToEven ||
910 getAllowFEnvAccess();
911 }
912
914 RoundingMode RM = getConstRoundingMode();
915 if (RM == RoundingMode::Dynamic) {
916 // C23: 7.6.2p3 If the FE_DYNAMIC mode is specified and FENV_ACCESS is
917 // "off", the translator may assume that the default rounding mode is in
918 // effect.
919 if (!getAllowFEnvAccess() && !getRoundingMath())
920 RM = RoundingMode::NearestTiesToEven;
921 }
922 return RM;
923 }
924
926 LangOptions::FPExceptionModeKind EM = getSpecifiedExceptionMode();
928 if (getAllowFEnvAccess())
930 else
932 }
933 return EM;
934 }
935
936 bool operator==(FPOptions other) const { return Value == other.Value; }
937
938 /// Return the default value of FPOptions that's used when trailing
939 /// storage isn't required.
941
942 storage_type getAsOpaqueInt() const { return Value; }
944 FPOptions Opts;
945 Opts.Value = Value;
946 return Opts;
947 }
948
949 /// Return difference with the given option set.
951
953
954 // We can define most of the accessors automatically:
955 // TODO: consider enforcing the assertion that value fits within bits
956 // statically.
957#define FP_OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
958 TYPE get##NAME() const { \
959 return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift); \
960 } \
961 void set##NAME(TYPE value) { \
962 assert(storage_type(value) < (1u << WIDTH)); \
963 Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift); \
964 }
965#include "clang/Basic/FPOptions.def"
966 LLVM_DUMP_METHOD void dump();
967};
968
969/// Represents difference between two FPOptions values.
970///
971/// The effect of language constructs changing the set of floating point options
972/// is usually a change of some FP properties while leaving others intact. This
973/// class describes such changes by keeping information about what FP options
974/// are overridden.
975///
976/// The integral set of FP options, described by the class FPOptions, may be
977/// represented as a default FP option set, defined by language standard and
978/// command line options, with the overrides introduced by pragmas.
979///
980/// The is implemented as a value of the new FPOptions plus a mask showing which
981/// fields are actually set in it.
984 FPOptions::storage_type OverrideMask = 0;
985
986public:
987 using RoundingMode = llvm::RoundingMode;
988
989 /// The type suitable for storing values of FPOptionsOverride. Must be twice
990 /// as wide as bit size of FPOption.
991 using storage_type = uint64_t;
992 static_assert(sizeof(storage_type) >= 2 * sizeof(FPOptions::storage_type),
993 "Too short type for FPOptionsOverride");
994
995 /// Bit mask selecting bits of OverrideMask in serialized representation of
996 /// FPOptionsOverride.
998 (static_cast<storage_type>(1) << FPOptions::StorageBitSize) - 1;
999
1002 : Options(LO), OverrideMask(OverrideMaskBits) {}
1004 : Options(FPO), OverrideMask(OverrideMaskBits) {}
1006 : Options(FPO), OverrideMask(Mask) {}
1007
1008 bool requiresTrailingStorage() const { return OverrideMask != 0; }
1009
1011 setFPContractModeOverride(LangOptions::FPM_On);
1012 }
1013
1015 setFPContractModeOverride(LangOptions::FPM_Fast);
1016 }
1017
1019 setFPContractModeOverride(LangOptions::FPM_Off);
1020 }
1021
1023 setAllowFPReassociateOverride(!Value);
1024 setNoHonorNaNsOverride(!Value);
1025 setNoHonorInfsOverride(!Value);
1026 setNoSignedZeroOverride(!Value);
1027 setAllowReciprocalOverride(!Value);
1028 setAllowApproxFuncOverride(!Value);
1029 setMathErrnoOverride(Value);
1030 if (Value)
1031 /* Precise mode implies fp_contract=on and disables ffast-math */
1033 else
1034 /* Precise mode disabled sets fp_contract=fast and enables ffast-math */
1036 }
1037
1039
1041 return (static_cast<storage_type>(Options.getAsOpaqueInt())
1043 OverrideMask;
1044 }
1046 FPOptionsOverride Opts;
1047 Opts.OverrideMask = I & OverrideMaskBits;
1049 return Opts;
1050 }
1051
1054 FPOptions::getFromOpaqueInt((Base.getAsOpaqueInt() & ~OverrideMask) |
1055 (Options.getAsOpaqueInt() & OverrideMask));
1056 return Result;
1057 }
1058
1060 return applyOverrides(FPOptions(LO));
1061 }
1062
1063 bool operator==(FPOptionsOverride other) const {
1064 return Options == other.Options && OverrideMask == other.OverrideMask;
1065 }
1066 bool operator!=(FPOptionsOverride other) const { return !(*this == other); }
1067
1068#define FP_OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
1069 bool has##NAME##Override() const { \
1070 return OverrideMask & FPOptions::NAME##Mask; \
1071 } \
1072 TYPE get##NAME##Override() const { \
1073 assert(has##NAME##Override()); \
1074 return Options.get##NAME(); \
1075 } \
1076 void clear##NAME##Override() { \
1077 /* Clear the actual value so that we don't have spurious differences when \
1078 * testing equality. */ \
1079 Options.set##NAME(TYPE(0)); \
1080 OverrideMask &= ~FPOptions::NAME##Mask; \
1081 } \
1082 void set##NAME##Override(TYPE value) { \
1083 Options.set##NAME(value); \
1084 OverrideMask |= FPOptions::NAME##Mask; \
1085 }
1086#include "clang/Basic/FPOptions.def"
1087 LLVM_DUMP_METHOD void dump();
1088};
1091 if (Value == Base.Value)
1092 return FPOptionsOverride();
1093 return getChangesSlow(Base);
1094}
1097 *this = FPO.applyOverrides(*this);
1098}
1099
1100// The three atomic code-generation options.
1101// The canonical (positive) names are:
1102// "remote_memory", "fine_grained_memory", and "ignore_denormal_mode".
1103// In attribute or command-line parsing, a token prefixed with "no_" inverts its
1104// value.
1106 RemoteMemory, // enable remote memory.
1107 FineGrainedMemory, // enable fine-grained memory.
1108 IgnoreDenormalMode, // ignore floating-point denormals.
1110};
1112struct AtomicOptions {
1113 // Bitfields for each option.
1114 unsigned remote_memory : 1;
1116 unsigned ignore_denormal_mode : 1;
1121 AtomicOptions(const LangOptions &LO)
1122 : remote_memory(LO.AtomicRemoteMemory),
1123 fine_grained_memory(LO.AtomicFineGrainedMemory),
1124 ignore_denormal_mode(LO.AtomicIgnoreDenormalMode) {}
1126 bool getOption(AtomicOptionKind Kind) const {
1127 switch (Kind) {
1129 return remote_memory;
1131 return fine_grained_memory;
1133 return ignore_denormal_mode;
1134 }
1135 llvm_unreachable("Invalid AtomicOptionKind");
1136 }
1138 void setOption(AtomicOptionKind Kind, bool Value) {
1139 switch (Kind) {
1142 return;
1145 return;
1148 return;
1149 }
1150 llvm_unreachable("Invalid AtomicOptionKind");
1151 }
1153 LLVM_DUMP_METHOD void dump() const {
1154 llvm::errs() << "\n remote_memory: " << remote_memory
1155 << "\n fine_grained_memory: " << fine_grained_memory
1156 << "\n ignore_denormal_mode: " << ignore_denormal_mode << "\n";
1157 }
1158};
1159
1160/// Describes the kind of translation unit being processed.
1162 /// The translation unit is a complete translation unit.
1164
1165 /// The translation unit is a prefix to a translation unit, and is
1166 /// not complete.
1167 TU_Prefix,
1168
1169 /// The translation unit is a clang module.
1171
1172 /// The translation unit is a is a complete translation unit that we might
1173 /// incrementally extend later.
1175};
1176
1177} // namespace clang
1178
1179#endif // LLVM_CLANG_BASIC_LANGOPTIONS_H
Defines the clang::CommentOptions interface.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines types useful for describing an Objective-C runtime.
Defines the clang::SanitizerKind enum.
Defines the TargetCXXABI class, which abstracts details of the C++ ABI that we're targeting.
Defines the clang::Visibility enumeration and various utility functions.
Represents difference between two FPOptions values.
static FPOptionsOverride getFromOpaqueInt(storage_type I)
bool operator!=(FPOptionsOverride other) const
FPOptionsOverride(FPOptions FPO)
LLVM_DUMP_METHOD void dump()
void setFPPreciseEnabled(bool Value)
FPOptionsOverride(FPOptions FPO, FPOptions::storage_type Mask)
FPOptions applyOverrides(FPOptions Base)
bool operator==(FPOptionsOverride other) const
llvm::RoundingMode RoundingMode
static constexpr storage_type OverrideMaskBits
Bit mask selecting bits of OverrideMask in serialized representation of FPOptionsOverride.
storage_type getAsOpaqueInt() const
FPOptions applyOverrides(const LangOptions &LO)
uint64_t storage_type
The type suitable for storing values of FPOptionsOverride.
FPOptionsOverride(const LangOptions &LO)
bool requiresTrailingStorage() const
void applyChanges(FPOptionsOverride FPO)
bool isFPConstrained() const
static constexpr storage_type FirstShift
FPOptionsOverride getChangesFrom(const FPOptions &Base) const
Return difference with the given option set.
storage_type getAsOpaqueInt() const
static constexpr storage_type TotalWidth
LangOptions::FPExceptionModeKind getExceptionMode() const
FPOptions(const LangOptions &LO)
static constexpr storage_type FirstWidth
void setAllowFPContractWithinStatement()
static FPOptions defaultWithoutTrailingStorage(const LangOptions &LO)
Return the default value of FPOptions that's used when trailing storage isn't required.
static FPOptions getFromOpaqueInt(storage_type Value)
bool allowFPContractAcrossStatement() const
uint32_t storage_type
bool operator==(FPOptions other) const
bool allowFPContractWithinStatement() const
LLVM_DUMP_METHOD void dump()
void setAllowFPContractAcrossStatement()
static constexpr unsigned StorageBitSize
llvm::RoundingMode RoundingMode
RoundingMode getRoundingMode() const
Bitfields of LangOptions, split out from LangOptions in order to ensure that this large collection of...
Definition LangOptions.h:72
FPEvalMethodKind
Possible float expression evaluation method choices.
@ FEM_Extended
Use extended type for fp arithmetic.
@ FEM_Double
Use the type double for fp arithmetic.
@ FEM_UnsetOnCommandLine
Used only for FE option processing; this is only used to indicate that the user did not specify an ex...
@ FEM_Source
Use the declared type for fp arithmetic.
@ NonLeaf
Sign the return address of functions that spill LR.
@ All
Sign the return address of all functions,.
@ CMK_None
Not compiling a module interface at all.
@ CMK_HeaderUnit
Compiling a module header unit.
@ CMK_ModuleMap
Compiling a module from a module map.
@ CMK_ModuleInterface
Compiling a C++ modules interface unit.
ComplexRangeKind
Controls the various implementations for complex multiplication and.
@ CX_Full
Implementation of complex division and multiplication using a call to runtime library functions(gener...
@ CX_Basic
Implementation of complex division and multiplication using algebraic formulas at source precision.
@ CX_Promoted
Implementation of complex division using algebraic formulas at higher precision.
@ CX_None
No range rule is enabled.
@ CX_Improved
Implementation of complex division offering an improved handling for overflow in intermediate calcula...
@ Swift5_0
Interoperability with the Swift 5.0 runtime.
@ ObjectiveC
Interoperability with the ObjectiveC runtime.
@ Standalone
CoreFoundation does not have any language interoperability.
@ Unspecified
No interoperability ABI has been specified.
@ Swift
Interoperability with the latest known version of the Swift runtime.
@ Swift4_2
Interoperability with the Swift 4.2 runtime.
@ Swift4_1
Interoperability with the Swift 4.1 runtime.
llvm::RoundingMode RoundingMode
Definition LangOptions.h:78
clang::MSVtorDispMode MSVtorDispMode
@ PerThread
Per-thread default stream.
@ ForceProtected
Force protected visibility.
@ BKey
Return address signing uses APIB key.
@ AKey
Return address signing uses APIA key.
@ ExtendTo32
Integer arguments are sign or zero extended to 32/64 bits during default argument promotions.
@ Single
Single Threaded Environment.
@ Integer
Permit vector bitcasts between integer vectors with different numbers of elements but the same total ...
@ ZeroOrIncomplete
Any trailing array member of undefined or 0 size is a FAM.
@ OneZeroOrIncomplete
Any trailing array member of undefined, 0, or 1 size is a FAM.
@ IncompleteOnly
Any trailing array member of undefined size is a FAM.
@ Microsoft
Use Microsoft C++ ABI rules for bit-field layout and fundamental types alignment.
@ Itanium
Use Itanium rules for bit-field layout and fundamental types alignment.
friend class CompilerInvocationBase
Definition LangOptions.h:74
OverflowPatternExclusionKind
Exclude certain code patterns from being instrumented by arithmetic overflow sanitizers.
@ None
Don't exclude any overflow patterns from sanitizers.
@ AddUnsignedOverflowTest
if (a + b < a)
@ All
Exclude all overflow patterns (below)
@ AddSignedOverflowTest
if (a + b < a)
@ PostDecrInWhile
while (count–)
clang::Visibility Visibility
Definition LangOptions.h:77
@ Explicit
map only explicit default visibilities to exported
@ All
map all default visibilities to exported
CompatibilityKind
For ASTs produced with different option value, signifies their level of compatibility.
Definition LangOptions.h:83
@ NotCompatible
Does affect the construction of the AST in a way that does prevent module interoperability.
Definition LangOptions.h:86
@ Compatible
Does affect the construction of the AST in a way that doesn't prevent interoperability (that is,...
Definition LangOptions.h:90
@ Benign
Does not affect the construction of the AST in any way (that is, the value can be different between a...
Definition LangOptions.h:94
FPExceptionModeKind
Possible floating point exception behavior.
@ FPE_Default
Used internally to represent initial unspecified value.
@ FPE_Strict
Strictly preserve the floating-point exception semantics.
@ FPE_MayTrap
Transformations do not cause new exceptions but may hide some.
@ FPE_Ignore
Assume that floating-point exceptions are masked.
clang::CFBranchLabelSchemeKind CFBranchLabelSchemeKind
Definition LangOptions.h:79
friend class CompilerInvocation
Definition LangOptions.h:73
@ Protected
Override the IR-gen assigned visibility with protected visibility.
@ Hidden
Override the IR-gen assigned visibility with hidden visibility.
ClangABI
Clang versions with different platform ABI conformance.
RegisterStaticDestructorsKind
Controls which variables have static destructors registered.
@ ThreadLocal
Register static destructors only for thread-local variables.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
SanitizerSet UBSanFeatureIgnoredSanitize
Set of (UBSan) sanitizers that when enabled do not cause __has_feature(undefined_behavior_sanitizer) ...
bool isSignReturnAddressWithAKey() const
Check if return address signing uses AKey.
void resetNonModularOptions()
Reset all of the options that are not considered when building a module.
std::vector< std::string > OverflowPatternExclusionValues
std::optional< TargetCXXABI::Kind > CXXABI
C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
std::string ModuleName
The module currently being compiled as specified by -fmodule-name.
std::vector< std::string > XRayNeverInstrumentFiles
Paths to the XRay "never instrument" files specifying which objects (files, functions,...
FPExceptionModeKind getDefaultExceptionMode() const
bool requiresStrictPrototypes() const
Returns true if functions without prototypes or functions with an identifier list (aka K&R C function...
bool isImplicitIntAllowed() const
Returns true if implicit int is supported at all.
bool isCompilingModuleImplementation() const
Are we compiling a module implementation?
bool isNoBuiltinFunc(StringRef Name) const
Is this a libc/libm function that is no longer recognized as a builtin because a -fno-builtin-* optio...
clang::ObjCRuntime ObjCRuntime
CoreFoundationABI CFRuntime
std::string getOpenCLVersionString() const
Return the OpenCL C or C++ for OpenCL language name and version as a string.
unsigned OverflowPatternExclusionMask
Which overflow patterns should be excluded from sanitizer instrumentation.
bool IsHeaderFile
Indicates whether the front-end is explicitly told that the input is a header file (i....
bool hasDefaultVisibilityExportMapping() const
SanitizerSet Sanitize
Set of enabled sanitizers.
std::optional< llvm::AllocTokenMode > AllocTokenMode
The allocation token mode.
CommentOptions CommentOpts
Options for parsing comments.
bool isExplicitDefaultVisibilityExportMapping() const
std::vector< std::string > XRayAlwaysInstrumentFiles
Paths to the XRay "always instrument" files specifying which objects (files, functions,...
bool hasAtExit() const
Returns true if the language supports calling the 'atexit' function.
bool trackLocalOwningModule() const
Do we need to track the owning module for a local declaration?
bool isAllDefaultVisibilityExportMapping() const
bool isSubscriptPointerArithmetic() const
bool UseTargetPathSeparator
Indicates whether to use target's platform-specific file separator when FILE macro is used and when c...
std::string ObjCConstantIntegerNumberClass
bool isSignedOverflowDefined() const
bool hasDefaultGlobalAllocationFunctionVisibility() const
bool hasGlobalAllocationFunctionVisibility() const
VersionTuple getOpenCLVersionTuple() const
Return the OpenCL C or C++ version as a VersionTuple.
std::string ObjCConstantDoubleNumberClass
bool implicitFunctionsAllowed() const
Returns true if implicit function declarations are allowed in the current language mode.
bool hasSignReturnAddress() const
Check if return address signing is enabled.
static void setLangDefaults(LangOptions &Opts, Language Lang, const llvm::Triple &T, std::vector< std::string > &Includes, LangStandard::Kind LangStd=LangStandard::lang_unspecified)
Set language defaults for the given input language and language standard in the given LangOptions obj...
bool isCompatibleWithMSVC() const
bool assumeFunctionsAreConvergent() const
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
bool allowsNonTrivialObjCLifetimeQualifiers() const
True if any ObjC types may have non-trivial lifetime qualifiers.
bool isOverflowPatternExcluded(OverflowPatternExclusionKind Kind) const
bool allowArrayReturnTypes() const
std::string OverflowHandler
The name of the handler function to be called when -ftrapv is specified.
std::string HLSLRootSigOverride
The HLSL root signature that will be used to overide the root signature used for the shader entry poi...
bool hasHiddenGlobalAllocationFunctionVisibility() const
std::string RandstructSeed
The seed used by the randomize structure layout feature.
std::map< std::string, std::string, std::greater< std::string > > MacroPrefixMap
A prefix map for FILE, BASE_FILE and __builtin_FILE().
std::vector< std::string > ProfileListFiles
Paths to special case list files specifying which entities (files, functions) should or should not be...
void remapPathPrefix(SmallVectorImpl< char > &Path) const
Remap path prefix according to -fmacro-prefix-path option.
bool isTargetDevice() const
True when compiling for an offloading target device.
std::optional< uint64_t > AllocTokenMax
Maximum number of allocation tokens (0 = target SIZE_MAX), nullopt if none set (use target SIZE_MAX).
bool hasProtectedGlobalAllocationFunctionVisibility() const
std::optional< uint32_t > getCPlusPlusLangStd() const
Returns the most applicable C++ standard-compliant language version code.
LangStandard::Kind LangStd
The used language standard.
llvm::dxbc::RootSignatureVersion HLSLRootSigVer
The HLSL root signature version for dxil.
std::optional< uint32_t > getCLangStd() const
Returns the most applicable C standard-compliant language version code.
RoundingMode getDefaultRoundingMode() const
bool isCompilingModule() const
Are we compiling a module?
bool isImplicitIntRequired() const
Returns true if implicit int is part of the language requirements.
bool isSignReturnAddressScopeAll() const
Check if leaf functions are also signed.
bool isSYCL() const
std::string ObjCConstantArrayClass
std::string ObjCConstantStringClass
std::string CUID
The user provided compilation unit ID, if non-empty.
unsigned getOpenCLCompatibleVersion() const
Return the OpenCL version that kernel language is compatible with.
std::string ObjCConstantDictionaryClass
std::string ObjCConstantFloatNumberClass
GPUDefaultStreamKind GPUDefaultStream
The default stream kind used for HIP kernel launching.
bool AtomicRemoteMemory
Atomic code-generation options.
bool threadPrivateMemoryAtomicsAreUndefined() const
Return true if atomicrmw operations targeting allocations in private memory are undefined.
std::vector< std::string > XRayAttrListFiles
Paths to the XRay attribute list files, specifying which objects (files, functions,...
bool SanitizeCoverage
Is at least one coverage instrumentation type enabled.
std::vector< llvm::Triple > OMPTargetTriples
Triples of the OpenMP targets that the host code codegen should take into account in order to generat...
std::vector< std::string > NoSanitizeFiles
Paths to files specifying which objects (files, functions, variables) should not be instrumented.
std::string CurrentModule
The name of the current module, of which the main source file is a part.
std::vector< std::string > ModuleFeatures
The names of any features to enable in module 'requires' decls in addition to the hard-coded list in ...
The basic abstraction for the target Objective-C runtime.
Definition ObjCRuntime.h:28
The JSON file list parser is used to communicate input to InstallAPI.
@ CPlusPlus
Language
The language for the input, used to select and validate the language standard and possible actions.
@ Result
The result type of a method or function.
Definition TypeBase.h:905
MSVtorDispMode
In the Microsoft ABI, this controls the placement of virtual displacement members used to implement v...
Definition LangOptions.h:38
ShaderStage
Shader programs run in specific pipeline stages.
Definition LangOptions.h:44
TranslationUnitKind
Describes the kind of translation unit being processed.
@ TU_Incremental
The translation unit is a is a complete translation unit that we might incrementally extend later.
@ TU_Complete
The translation unit is a complete translation unit.
@ TU_ClangModule
The translation unit is a clang module.
@ TU_Prefix
The translation unit is a prefix to a translation unit, and is not complete.
PointerAuthenticationMode
Definition LangOptions.h:63
@ None
The alignment was not explicit in code.
Definition ASTContext.h:179
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition Visibility.h:34
void setOption(AtomicOptionKind Kind, bool Value)
LLVM_DUMP_METHOD void dump() const
unsigned ignore_denormal_mode
bool getOption(AtomicOptionKind Kind) const
Options for controlling comment parsing.