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 // FIXME: Unify with TUKind.
118 /// Not compiling a module interface at all.
120
121 /// Compiling a module from a module map.
123
124 /// Compiling a module header unit.
126
127 /// Compiling a C++ modules interface unit.
129 };
130
137
139
149
151
152 // Corresponds to _MSC_VER
154 MSVC2010 = 1600,
155 MSVC2012 = 1700,
156 MSVC2013 = 1800,
157 MSVC2015 = 1900,
158 MSVC2017 = 1910,
161 MSVC2019 = 1920,
166 };
167
172 // The "default" SYCL version to be used when none is specified on the
173 // frontend command line.
175 };
176
179 HLSL_2015 = 2015,
180 HLSL_2016 = 2016,
181 HLSL_2017 = 2017,
182 HLSL_2018 = 2018,
183 HLSL_2021 = 2021,
184 HLSL_202x = 2028,
185 HLSL_202y = 2029,
186 };
187
188 /// Clang versions with different platform ABI conformance.
189 enum class ClangABI {
190#define ABI_VER_MAJOR_MINOR(Major, Minor) Ver##Major##_##Minor,
191#define ABI_VER_MAJOR(Major) Ver##Major,
192#define ABI_VER_LATEST(Latest) Latest
193#include "clang/Basic/ABIVersions.def"
194 };
195
196 enum class CoreFoundationABI {
197 /// No interoperability ABI has been specified
199 /// CoreFoundation does not have any language interoperability
201 /// Interoperability with the ObjectiveC runtime
203 /// Interoperability with the latest known version of the Swift runtime
205 /// Interoperability with the Swift 5.0 runtime
207 /// Interoperability with the Swift 4.2 runtime
209 /// Interoperability with the Swift 4.1 runtime
211 };
212
214 // Disable the floating point pragma
216
217 // Enable the floating point pragma
219
220 // Aggressively fuse FP ops (E.g. FMA) disregarding pragmas.
222
223 // Aggressively fuse FP ops and honor pragmas.
225 };
226
227 /// Possible floating point exception behavior.
229 /// Assume that floating-point exceptions are masked.
231 /// Transformations do not cause new exceptions but may hide some.
233 /// Strictly preserve the floating-point exception semantics.
235 /// Used internally to represent initial unspecified value.
237 };
238
239 /// Possible float expression evaluation method choices.
240 enum FPEvalMethodKind : unsigned {
241 /// Use the declared type for fp arithmetic.
243 /// Use the type double for fp arithmetic.
245 /// Use extended type for fp arithmetic.
247 /// Used only for FE option processing; this is only used to indicate that
248 /// the user did not specify an explicit evaluation method on the command
249 /// line and so the target should be queried for its default evaluation
250 /// method instead.
252 };
253
254 enum class MatrixMemoryLayout : unsigned {
255 // Use column-major layout for matrices
257 // Use row-major layout for matrices
259 };
260
262
264 /// Permit no implicit vector bitcasts.
266 /// Permit vector bitcasts between integer vectors with different numbers
267 /// of elements but the same total bit-width.
269 /// Permit vector bitcasts between all vectors with the same total
270 /// bit-width.
272 };
273
275 // All vector compares produce scalars except vector pixel and vector bool.
276 // The types vector pixel and vector bool return vector results.
278 // All vector compares produce vector results as in GCC.
280 // All vector compares produce scalars as in XL.
282 // Default clang behaviour.
284 };
285
287 /// No signing for any function.
289 /// Sign the return address of functions that spill LR.
291 /// Sign the return address of all functions,
293 };
294
296 /// Return address signing uses APIA key.
298 /// Return address signing uses APIB key.
300 };
301
302 enum class ThreadModelKind {
303 /// POSIX Threads.
305 /// Single Threaded Environment.
307 };
308
309 enum class ExtendArgsKind {
310 /// Integer arguments are sign or zero extended to 32/64 bits
311 /// during default argument promotions.
314 };
315
317 /// Legacy default stream
319 /// Per-thread default stream
321 };
322
323 /// Exclude certain code patterns from being instrumented by arithmetic
324 /// overflow sanitizers
326 /// Don't exclude any overflow patterns from sanitizers
327 None = 1 << 0,
328 /// Exclude all overflow patterns (below)
329 All = 1 << 1,
330 /// if (a + b < a)
332 /// if (a + b < a)
334 /// -1UL
336 /// while (count--)
338 };
339
342 /// map only explicit default visibilities to exported
344 /// map all default visibilities to exported
346 };
347
349 /// Force hidden visibility
351 /// Force protected visibility
353 /// Force default visibility
355 /// Don't alter the visibility
357 };
358
360 /// Keep the IR-gen assigned visibility.
362 /// Override the IR-gen assigned visibility with default visibility.
364 /// Override the IR-gen assigned visibility with hidden visibility.
366 /// Override the IR-gen assigned visibility with protected visibility.
368 };
369
371 /// Any trailing array member is a FAM.
373 /// Any trailing array member of undefined, 0, or 1 size is a FAM.
375 /// Any trailing array member of undefined or 0 size is a FAM.
377 /// Any trailing array member of undefined size is a FAM.
379 };
380
381 /// Controls the various implementations for complex multiplication and
382 // division.
384 /// Implementation of complex division and multiplication using a call to
385 /// runtime library functions(generally the case, but the BE might
386 /// sometimes replace the library call if it knows enough about the
387 /// potential range of the inputs). Overflow and non-finite values are
388 /// handled by the library implementation. This is the default value.
390
391 /// Implementation of complex division offering an improved handling
392 /// for overflow in intermediate calculations with no special handling for
393 /// NaN and infinite values.
395
396 /// Implementation of complex division using algebraic formulas at
397 /// higher precision. Overflow is handled. Non-finite values are handled in
398 /// some cases. If the target hardware does not have native support for a
399 /// higher precision data type, an implementation for the complex operation
400 /// will be used to provide improved guards against intermediate overflow,
401 /// but overflow and underflow may still occur in some cases. NaN and
402 /// infinite values are not handled.
404
405 /// Implementation of complex division and multiplication using
406 /// algebraic formulas at source precision. No special handling to avoid
407 /// overflow. NaN and infinite values are not handled.
409
410 /// No range rule is enabled.
412 };
413
414 /// Controls which variables have static destructors registered.
416 /// Register static destructors for all variables.
418 /// Register static destructors only for thread-local variables.
420 /// Don't register static destructors for any variables.
422 };
423
425 /// Use default layout rules of the target.
427 /// Use Itanium rules for bit-field layout and fundamental types alignment.
429 /// Use Microsoft C++ ABI rules for bit-field layout and fundamental types
430 /// alignment.
432 };
433
434 // Define simple language options (with no accessors).
435#define LANGOPT(Name, Bits, Default, Compatibility, Description) \
436 unsigned Name : Bits;
437#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description)
438#include "clang/Basic/LangOptions.def"
439
440protected:
441 // Define language options of enumeration type. These are private, and will
442 // have accessors (below).
443#define LANGOPT(Name, Bits, Default, Compatibility, Description)
444#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \
445 LLVM_PREFERRED_TYPE(Type) \
446 unsigned Name : Bits;
447#include "clang/Basic/LangOptions.def"
448};
449
450/// Keeps track of the various options that can be
451/// enabled, which controls the dialect of C or C++ that is accepted.
453public:
454 /// The used language standard.
456
457 /// Set of enabled sanitizers.
459 /// Is at least one coverage instrumentation type enabled.
460 bool SanitizeCoverage = false;
461 /// Set of (UBSan) sanitizers that when enabled do not cause
462 /// `__has_feature(undefined_behavior_sanitizer)` to evaluate true.
464
465 /// Paths to files specifying which objects
466 /// (files, functions, variables) should not be instrumented.
467 std::vector<std::string> NoSanitizeFiles;
468
469 /// Paths to the XRay "always instrument" files specifying which
470 /// objects (files, functions, variables) should be imbued with the XRay
471 /// "always instrument" attribute.
472 /// WARNING: This is a deprecated field and will go away in the future.
473 std::vector<std::string> XRayAlwaysInstrumentFiles;
474
475 /// Paths to the XRay "never instrument" files specifying which
476 /// objects (files, functions, variables) should be imbued with the XRay
477 /// "never instrument" attribute.
478 /// WARNING: This is a deprecated field and will go away in the future.
479 std::vector<std::string> XRayNeverInstrumentFiles;
480
481 /// Paths to the XRay attribute list files, specifying which objects
482 /// (files, functions, variables) should be imbued with the appropriate XRay
483 /// attribute(s).
484 std::vector<std::string> XRayAttrListFiles;
485
486 /// Paths to special case list files specifying which entities
487 /// (files, functions) should or should not be instrumented.
488 std::vector<std::string> ProfileListFiles;
489
491
493
495
496 /// The name of the handler function to be called when -ftrapv is
497 /// specified.
498 ///
499 /// If none is specified, abort (GCC-compatible behaviour).
500 std::string OverflowHandler;
501
502 /// The module currently being compiled as specified by -fmodule-name.
503 std::string ModuleName;
504
505 /// The name of the current module, of which the main source file
506 /// is a part. If CompilingModule is set, we are compiling the interface
507 /// of this module, otherwise we are compiling an implementation file of
508 /// it. This starts as ModuleName in case -fmodule-name is provided and
509 /// changes during compilation to reflect the current module.
510 std::string CurrentModule;
511
512 /// The names of any features to enable in module 'requires' decls
513 /// in addition to the hard-coded list in Module.cpp and the target features.
514 ///
515 /// This list is sorted.
516 std::vector<std::string> ModuleFeatures;
517
518 /// Options for parsing comments.
520
521 /// A list of all -fno-builtin-* function names (e.g., memset).
522 std::vector<std::string> NoBuiltinFuncs;
523
524 /// A prefix map for __FILE__, __BASE_FILE__ and __builtin_FILE().
525 std::map<std::string, std::string, std::greater<std::string>> MacroPrefixMap;
526
527 /// Triples of the OpenMP targets that the host code codegen should
528 /// take into account in order to generate accurate offloading descriptors.
529 std::vector<llvm::Triple> OMPTargetTriples;
530
531 /// Name of the IR file that contains the result of the OpenMP target
532 /// host code generation.
533 std::string OMPHostIRFile;
534
535 /// The user provided compilation unit ID, if non-empty. This is used to
536 /// externalize static variables which is needed to support accessing static
537 /// device variables in host code for single source offloading languages
538 /// like CUDA/HIP.
539 std::string CUID;
540
541 /// C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
542 /// This overrides the default ABI used by the target.
543 std::optional<TargetCXXABI::Kind> CXXABI;
544
545 /// Indicates whether the front-end is explicitly told that the
546 /// input is a header file (i.e. -x c-header).
547 bool IsHeaderFile = false;
548
549 /// The default stream kind used for HIP kernel launching.
551
552 /// Which overflow patterns should be excluded from sanitizer instrumentation
554
555 std::vector<std::string> OverflowPatternExclusionValues;
556
557 /// The seed used by the randomize structure layout feature.
558 std::string RandstructSeed;
559
560 /// Indicates whether to use target's platform-specific file separator when
561 /// __FILE__ macro is used and when concatenating filename with directory or
562 /// to use build environment environment's platform-specific file separator.
563 ///
564 /// The plaform-specific path separator is the backslash(\‍) for Windows and
565 /// forward slash (/) elsewhere.
567
568 // Indicates whether we should keep all nullptr checks for pointers
569 // received as a result of a standard operator new (-fcheck-new)
570 bool CheckNew = false;
571
572 /// The HLSL root signature version for dxil.
573 llvm::dxbc::RootSignatureVersion HLSLRootSigVer;
574
575 /// The HLSL root signature that will be used to overide the root signature
576 /// used for the shader entry point.
578
579 // Indicates if the wasm-opt binary must be ignored in the case of a
580 // WebAssembly target.
581 bool NoWasmOpt = false;
582
583 /// Atomic code-generation options.
584 /// These flags are set directly from the command-line options.
585 bool AtomicRemoteMemory = false;
588
589 /// Maximum number of allocation tokens (0 = target SIZE_MAX), nullopt if none
590 /// set (use target SIZE_MAX).
591 std::optional<uint64_t> AllocTokenMax;
592
593 /// The allocation token mode.
594 std::optional<llvm::AllocTokenMode> AllocTokenMode;
595
596 LangOptions();
597
598 /// Set language defaults for the given input language and
599 /// language standard in the given LangOptions object.
600 ///
601 /// \param Opts - The LangOptions object to set up.
602 /// \param Lang - The input language.
603 /// \param T - The target triple.
604 /// \param Includes - If the language requires extra headers to be implicitly
605 /// included, they will be appended to this list.
606 /// \param LangStd - The input language standard.
607 static void
608 setLangDefaults(LangOptions &Opts, Language Lang, const llvm::Triple &T,
609 std::vector<std::string> &Includes,
611
612 // Define accessors/mutators for language options of enumeration type.
613#define LANGOPT(Name, Bits, Default, Compatibility, Description)
614#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \
615 Type get##Name() const { return static_cast<Type>(Name); } \
616 void set##Name(Type Value) { \
617 assert(static_cast<unsigned>(Value) < (1u << Bits)); \
618 Name = static_cast<unsigned>(Value); \
619 }
620#include "clang/Basic/LangOptions.def"
621
622 /// Are we compiling a module?
623 bool isCompilingModule() const {
624 return getCompilingModule() != CMK_None;
625 }
626
627 /// Are we compiling a module implementation?
629 return !isCompilingModule() && !ModuleName.empty();
630 }
631
632 /// Do we need to track the owning module for a local declaration?
634 return isCompilingModule() || ModulesLocalVisibility;
635 }
636
638 return getSignedOverflowBehavior() == SOB_Defined;
639 }
640
642 return ObjCRuntime.isSubscriptPointerArithmetic() &&
643 !ObjCSubscriptingLegacyRuntime;
644 }
645
646 bool isCompatibleWithMSVC() const { return MSCompatibilityVersion > 0; }
647
648 bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
649 return MSCompatibilityVersion >= MajorVersion * 100000U;
650 }
651
659
660 /// Reset all of the options that are not considered when building a
661 /// module.
663
664 /// Is this a libc/libm function that is no longer recognized as a
665 /// builtin because a -fno-builtin-* option has been specified?
666 bool isNoBuiltinFunc(StringRef Name) const;
667
668 /// True if any ObjC types may have non-trivial lifetime qualifiers.
670 return ObjCAutoRefCount || ObjCWeak;
671 }
672
674 return ConvergentFunctions;
675 }
676
677 /// Return true if atomicrmw operations targeting allocations in private
678 /// memory are undefined.
680 // Should be false for OpenMP.
681 // TODO: Should this be true for SYCL?
682 return OpenCL || CUDA;
683 }
684
685 /// Return the OpenCL C or C++ version as a VersionTuple.
686 VersionTuple getOpenCLVersionTuple() const;
687
688 /// Return the OpenCL version that kernel language is compatible with
689 unsigned getOpenCLCompatibleVersion() const;
690
691 /// Return the OpenCL C or C++ for OpenCL language name and version
692 /// as a string.
693 std::string getOpenCLVersionString() const;
694
695 /// Returns true if functions without prototypes or functions with an
696 /// identifier list (aka K&R C functions) are not allowed.
698 return CPlusPlus || C23 || DisableKNRFunctions;
699 }
700
701 /// Returns true if implicit function declarations are allowed in the current
702 /// language mode.
704 return !requiresStrictPrototypes() && !OpenCL;
705 }
706
707 /// Returns true if the language supports calling the 'atexit' function.
708 bool hasAtExit() const { return !(OpenMP && OpenMPIsTargetDevice); }
709
710 /// Returns true if implicit int is part of the language requirements.
711 bool isImplicitIntRequired() const { return !CPlusPlus && !C99; }
712
713 /// Returns true if implicit int is supported at all.
714 bool isImplicitIntAllowed() const { return !CPlusPlus && !C23; }
715
716 /// Check if return address signing is enabled.
717 bool hasSignReturnAddress() const {
718 return getSignReturnAddressScope() != SignReturnAddressScopeKind::None;
719 }
720
721 /// Check if return address signing uses AKey.
723 return getSignReturnAddressKey() == SignReturnAddressKeyKind::AKey;
724 }
725
726 /// Check if leaf functions are also signed.
728 return getSignReturnAddressScope() == SignReturnAddressScopeKind::All;
729 }
730
731 bool isSYCL() const { return SYCLIsDevice || SYCLIsHost; }
732
734 return getDefaultVisibilityExportMapping() !=
736 }
737
739 return getDefaultVisibilityExportMapping() ==
741 }
742
744 return getDefaultVisibilityExportMapping() ==
746 }
747
749 return getGlobalAllocationFunctionVisibility() !=
751 }
752
754 return getGlobalAllocationFunctionVisibility() ==
756 }
757
759 return getGlobalAllocationFunctionVisibility() ==
761 }
762
764 return getGlobalAllocationFunctionVisibility() ==
766 }
767
768 bool allowArrayReturnTypes() const { return HLSL; }
769
770 /// Remap path prefix according to -fmacro-prefix-path option.
771 void remapPathPrefix(SmallVectorImpl<char> &Path) const;
772
774 return RoundingMath ? RoundingMode::Dynamic
775 : RoundingMode::NearestTiesToEven;
776 }
777
779 FPExceptionModeKind EM = getFPExceptionMode();
782 return EM;
783 }
784
785 /// True when compiling for an offloading target device.
786 bool isTargetDevice() const {
787 return OpenMPIsTargetDevice || CUDAIsDevice || SYCLIsDevice;
788 }
789
790 /// Returns the most applicable C standard-compliant language version code.
791 /// If none could be determined, returns \ref std::nullopt.
792 std::optional<uint32_t> getCLangStd() const;
793
794 /// Returns the most applicable C++ standard-compliant language
795 /// version code.
796 /// If none could be determined, returns \ref std::nullopt.
797 std::optional<uint32_t> getCPlusPlusLangStd() const;
798};
799
800/// Floating point control options
801class FPOptionsOverride;
803public:
804 // We start by defining the layout.
805 using storage_type = uint32_t;
806
807 using RoundingMode = llvm::RoundingMode;
808
809 static constexpr unsigned StorageBitSize = 8 * sizeof(storage_type);
810
811 // Define a fake option named "First" so that we have a PREVIOUS even for the
812 // real first option.
813 static constexpr storage_type FirstShift = 0, FirstWidth = 0;
814#define FP_OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
815 static constexpr storage_type NAME##Shift = \
816 PREVIOUS##Shift + PREVIOUS##Width; \
817 static constexpr storage_type NAME##Width = WIDTH; \
818 static constexpr storage_type NAME##Mask = ((1 << NAME##Width) - 1) \
819 << NAME##Shift;
820#include "clang/Basic/FPOptions.def"
821
822 static constexpr storage_type TotalWidth = 0
823#define FP_OPTION(NAME, TYPE, WIDTH, PREVIOUS) +WIDTH
824#include "clang/Basic/FPOptions.def"
825 ;
826 static_assert(TotalWidth <= StorageBitSize, "Too short type for FPOptions");
827
828private:
829 storage_type Value;
830
831 FPOptionsOverride getChangesSlow(const FPOptions &Base) const;
832
833public:
834 FPOptions() : Value(0) {
835 setFPContractMode(LangOptions::FPM_Off);
836 setConstRoundingMode(RoundingMode::Dynamic);
837 setSpecifiedExceptionMode(LangOptions::FPE_Default);
838 }
839 explicit FPOptions(const LangOptions &LO) {
840 Value = 0;
841 // The language fp contract option FPM_FastHonorPragmas has the same effect
842 // as FPM_Fast in frontend. For simplicity, use FPM_Fast uniformly in
843 // frontend.
844 auto LangOptContractMode = LO.getDefaultFPContractMode();
845 if (LangOptContractMode == LangOptions::FPM_FastHonorPragmas)
846 LangOptContractMode = LangOptions::FPM_Fast;
847 setFPContractMode(LangOptContractMode);
848 setRoundingMath(LO.RoundingMath);
849 setConstRoundingMode(LangOptions::RoundingMode::Dynamic);
850 setSpecifiedExceptionMode(LO.getFPExceptionMode());
851 setAllowFPReassociate(LO.AllowFPReassoc);
852 setNoHonorNaNs(LO.NoHonorNaNs);
853 setNoHonorInfs(LO.NoHonorInfs);
854 setNoSignedZero(LO.NoSignedZero);
855 setAllowReciprocal(LO.AllowRecip);
856 setAllowApproxFunc(LO.ApproxFunc);
857 if (getFPContractMode() == LangOptions::FPM_On &&
858 getRoundingMode() == llvm::RoundingMode::Dynamic &&
860 // If the FP settings are set to the "strict" model, then
861 // FENV access is set to true. (ffp-model=strict)
862 setAllowFEnvAccess(true);
863 else
864 setAllowFEnvAccess(LangOptions::FPM_Off);
865 setComplexRange(LO.getComplexRange());
866 }
867
869 return getFPContractMode() == LangOptions::FPM_On;
870 }
872 setFPContractMode(LangOptions::FPM_On);
873 }
874
876 return getFPContractMode() == LangOptions::FPM_Fast;
877 }
879 setFPContractMode(LangOptions::FPM_Fast);
880 }
881
882 bool isFPConstrained() const {
883 return getRoundingMode() != llvm::RoundingMode::NearestTiesToEven ||
885 getAllowFEnvAccess();
886 }
887
889 RoundingMode RM = getConstRoundingMode();
890 if (RM == RoundingMode::Dynamic) {
891 // C23: 7.6.2p3 If the FE_DYNAMIC mode is specified and FENV_ACCESS is
892 // "off", the translator may assume that the default rounding mode is in
893 // effect.
894 if (!getAllowFEnvAccess() && !getRoundingMath())
895 RM = RoundingMode::NearestTiesToEven;
896 }
897 return RM;
898 }
899
901 LangOptions::FPExceptionModeKind EM = getSpecifiedExceptionMode();
903 if (getAllowFEnvAccess())
905 else
907 }
908 return EM;
909 }
910
911 bool operator==(FPOptions other) const { return Value == other.Value; }
912
913 /// Return the default value of FPOptions that's used when trailing
914 /// storage isn't required.
916
917 storage_type getAsOpaqueInt() const { return Value; }
919 FPOptions Opts;
920 Opts.Value = Value;
921 return Opts;
922 }
923
924 /// Return difference with the given option set.
926
928
929 // We can define most of the accessors automatically:
930 // TODO: consider enforcing the assertion that value fits within bits
931 // statically.
932#define FP_OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
933 TYPE get##NAME() const { \
934 return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift); \
935 } \
936 void set##NAME(TYPE value) { \
937 assert(storage_type(value) < (1u << WIDTH)); \
938 Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift); \
939 }
940#include "clang/Basic/FPOptions.def"
941 LLVM_DUMP_METHOD void dump();
942};
943
944/// Represents difference between two FPOptions values.
945///
946/// The effect of language constructs changing the set of floating point options
947/// is usually a change of some FP properties while leaving others intact. This
948/// class describes such changes by keeping information about what FP options
949/// are overridden.
950///
951/// The integral set of FP options, described by the class FPOptions, may be
952/// represented as a default FP option set, defined by language standard and
953/// command line options, with the overrides introduced by pragmas.
954///
955/// The is implemented as a value of the new FPOptions plus a mask showing which
956/// fields are actually set in it.
959 FPOptions::storage_type OverrideMask = 0;
960
961public:
962 using RoundingMode = llvm::RoundingMode;
963
964 /// The type suitable for storing values of FPOptionsOverride. Must be twice
965 /// as wide as bit size of FPOption.
966 using storage_type = uint64_t;
967 static_assert(sizeof(storage_type) >= 2 * sizeof(FPOptions::storage_type),
968 "Too short type for FPOptionsOverride");
969
970 /// Bit mask selecting bits of OverrideMask in serialized representation of
971 /// FPOptionsOverride.
973 (static_cast<storage_type>(1) << FPOptions::StorageBitSize) - 1;
974
977 : Options(LO), OverrideMask(OverrideMaskBits) {}
979 : Options(FPO), OverrideMask(OverrideMaskBits) {}
981 : Options(FPO), OverrideMask(Mask) {}
982
983 bool requiresTrailingStorage() const { return OverrideMask != 0; }
984
986 setFPContractModeOverride(LangOptions::FPM_On);
987 }
988
990 setFPContractModeOverride(LangOptions::FPM_Fast);
991 }
992
994 setFPContractModeOverride(LangOptions::FPM_Off);
995 }
996
998 setAllowFPReassociateOverride(!Value);
999 setNoHonorNaNsOverride(!Value);
1000 setNoHonorInfsOverride(!Value);
1001 setNoSignedZeroOverride(!Value);
1002 setAllowReciprocalOverride(!Value);
1003 setAllowApproxFuncOverride(!Value);
1004 setMathErrnoOverride(Value);
1005 if (Value)
1006 /* Precise mode implies fp_contract=on and disables ffast-math */
1008 else
1009 /* Precise mode disabled sets fp_contract=fast and enables ffast-math */
1011 }
1012
1014
1016 return (static_cast<storage_type>(Options.getAsOpaqueInt())
1018 OverrideMask;
1019 }
1021 FPOptionsOverride Opts;
1022 Opts.OverrideMask = I & OverrideMaskBits;
1024 return Opts;
1025 }
1026
1029 FPOptions::getFromOpaqueInt((Base.getAsOpaqueInt() & ~OverrideMask) |
1030 (Options.getAsOpaqueInt() & OverrideMask));
1031 return Result;
1032 }
1033
1035 return applyOverrides(FPOptions(LO));
1036 }
1037
1038 bool operator==(FPOptionsOverride other) const {
1039 return Options == other.Options && OverrideMask == other.OverrideMask;
1040 }
1041 bool operator!=(FPOptionsOverride other) const { return !(*this == other); }
1042
1043#define FP_OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
1044 bool has##NAME##Override() const { \
1045 return OverrideMask & FPOptions::NAME##Mask; \
1046 } \
1047 TYPE get##NAME##Override() const { \
1048 assert(has##NAME##Override()); \
1049 return Options.get##NAME(); \
1050 } \
1051 void clear##NAME##Override() { \
1052 /* Clear the actual value so that we don't have spurious differences when \
1053 * testing equality. */ \
1054 Options.set##NAME(TYPE(0)); \
1055 OverrideMask &= ~FPOptions::NAME##Mask; \
1056 } \
1057 void set##NAME##Override(TYPE value) { \
1058 Options.set##NAME(value); \
1059 OverrideMask |= FPOptions::NAME##Mask; \
1060 }
1061#include "clang/Basic/FPOptions.def"
1062 LLVM_DUMP_METHOD void dump();
1063};
1066 if (Value == Base.Value)
1067 return FPOptionsOverride();
1068 return getChangesSlow(Base);
1069}
1072 *this = FPO.applyOverrides(*this);
1073}
1074
1075// The three atomic code-generation options.
1076// The canonical (positive) names are:
1077// "remote_memory", "fine_grained_memory", and "ignore_denormal_mode".
1078// In attribute or command-line parsing, a token prefixed with "no_" inverts its
1079// value.
1081 RemoteMemory, // enable remote memory.
1082 FineGrainedMemory, // enable fine-grained memory.
1083 IgnoreDenormalMode, // ignore floating-point denormals.
1085};
1087struct AtomicOptions {
1088 // Bitfields for each option.
1089 unsigned remote_memory : 1;
1091 unsigned ignore_denormal_mode : 1;
1096 AtomicOptions(const LangOptions &LO)
1097 : remote_memory(LO.AtomicRemoteMemory),
1098 fine_grained_memory(LO.AtomicFineGrainedMemory),
1099 ignore_denormal_mode(LO.AtomicIgnoreDenormalMode) {}
1101 bool getOption(AtomicOptionKind Kind) const {
1102 switch (Kind) {
1104 return remote_memory;
1106 return fine_grained_memory;
1108 return ignore_denormal_mode;
1109 }
1110 llvm_unreachable("Invalid AtomicOptionKind");
1111 }
1113 void setOption(AtomicOptionKind Kind, bool Value) {
1114 switch (Kind) {
1117 return;
1120 return;
1123 return;
1124 }
1125 llvm_unreachable("Invalid AtomicOptionKind");
1126 }
1128 LLVM_DUMP_METHOD void dump() const {
1129 llvm::errs() << "\n remote_memory: " << remote_memory
1130 << "\n fine_grained_memory: " << fine_grained_memory
1131 << "\n ignore_denormal_mode: " << ignore_denormal_mode << "\n";
1132 }
1133};
1134
1135/// Describes the kind of translation unit being processed.
1137 /// The translation unit is a complete translation unit.
1139
1140 /// The translation unit is a prefix to a translation unit, and is
1141 /// not complete.
1142 TU_Prefix,
1143
1144 /// The translation unit is a clang module.
1146
1147 /// The translation unit is a is a complete translation unit that we might
1148 /// incrementally extend later.
1150};
1151
1152} // namespace clang
1153
1154#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.
void setAllowFPContractAcrossStatement()
static FPOptionsOverride getFromOpaqueInt(storage_type I)
bool operator!=(FPOptionsOverride other) const
FPOptionsOverride(FPOptions FPO)
LLVM_DUMP_METHOD void dump()
void setFPPreciseEnabled(bool Value)
void setAllowFPContractWithinStatement()
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...
bool isSignedOverflowDefined() const
bool hasDefaultGlobalAllocationFunctionVisibility() const
bool hasGlobalAllocationFunctionVisibility() const
VersionTuple getOpenCLVersionTuple() const
Return the OpenCL C or C++ version as a VersionTuple.
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 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.
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
const FunctionProtoType * T
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:178
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.