Thanks to visit codestin.com
Credit goes to clang.llvm.org

clang 22.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/TargetParser/Triple.h"
29#include <optional>
30#include <string>
31#include <vector>
32
33namespace clang {
34
35/// In the Microsoft ABI, this controls the placement of virtual displacement
36/// members used to implement virtual inheritance.
38
39/// Shader programs run in specific pipeline stages.
40/// The order of these values matters, and must be kept in sync with the
41/// Triple Environment enum in llvm::Triple. The ordering is enforced in
42/// static_asserts in Triple.cpp and in clang/Basic/HLSLRuntime.h.
61
68
69/// Bitfields of LangOptions, split out from LangOptions in order to ensure that
70/// this large collection of bitfields is a trivial class type.
72 friend class CompilerInvocation;
74
75public:
77 using RoundingMode = llvm::RoundingMode;
79
80 /// For ASTs produced with different option value, signifies their level of
81 /// compatibility.
82 enum class CompatibilityKind {
83 /// Does affect the construction of the AST in a way that does prevent
84 /// module interoperability.
86 /// Does affect the construction of the AST in a way that doesn't prevent
87 /// interoperability (that is, the value can be different between an
88 /// explicit module and the user of that module).
90 /// Does not affect the construction of the AST in any way (that is, the
91 /// value can be different between an implicit module and the user of that
92 /// module).
94 };
95
98
99 // Automatic variables live on the stack, and when trivial they're usually
100 // uninitialized because it's undefined behavior to use them without
101 // initializing them.
103
105 // Default C standard behavior.
107
108 // -fwrapv
110
111 // -ftrapv
113 };
114
115 // FIXME: Unify with TUKind.
117 /// Not compiling a module interface at all.
119
120 /// Compiling a module from a module map.
122
123 /// Compiling a module header unit.
125
126 /// Compiling a C++ modules interface unit.
128 };
129
136
138
148
150
151 // Corresponds to _MSC_VER
153 MSVC2010 = 1600,
154 MSVC2012 = 1700,
155 MSVC2013 = 1800,
156 MSVC2015 = 1900,
157 MSVC2017 = 1910,
160 MSVC2019 = 1920,
165 };
166
171 // The "default" SYCL version to be used when none is specified on the
172 // frontend command line.
174 };
175
178 HLSL_2015 = 2015,
179 HLSL_2016 = 2016,
180 HLSL_2017 = 2017,
181 HLSL_2018 = 2018,
182 HLSL_2021 = 2021,
183 HLSL_202x = 2028,
184 HLSL_202y = 2029,
185 };
186
187 /// Clang versions with different platform ABI conformance.
188 enum class ClangABI {
189#define ABI_VER_MAJOR_MINOR(Major, Minor) Ver##Major##_##Minor,
190#define ABI_VER_MAJOR(Major) Ver##Major,
191#define ABI_VER_LATEST(Latest) Latest
192#include "clang/Basic/ABIVersions.def"
193 };
194
195 enum class CoreFoundationABI {
196 /// No interoperability ABI has been specified
198 /// CoreFoundation does not have any language interoperability
200 /// Interoperability with the ObjectiveC runtime
202 /// Interoperability with the latest known version of the Swift runtime
204 /// Interoperability with the Swift 5.0 runtime
206 /// Interoperability with the Swift 4.2 runtime
208 /// Interoperability with the Swift 4.1 runtime
210 };
211
213 // Disable the floating point pragma
215
216 // Enable the floating point pragma
218
219 // Aggressively fuse FP ops (E.g. FMA) disregarding pragmas.
221
222 // Aggressively fuse FP ops and honor pragmas.
224 };
225
226 /// Possible floating point exception behavior.
228 /// Assume that floating-point exceptions are masked.
230 /// Transformations do not cause new exceptions but may hide some.
232 /// Strictly preserve the floating-point exception semantics.
234 /// Used internally to represent initial unspecified value.
236 };
237
238 /// Possible float expression evaluation method choices.
239 enum FPEvalMethodKind : unsigned {
240 /// Use the declared type for fp arithmetic.
242 /// Use the type double for fp arithmetic.
244 /// Use extended type for fp arithmetic.
246 /// Used only for FE option processing; this is only used to indicate that
247 /// the user did not specify an explicit evaluation method on the command
248 /// line and so the target should be queried for its default evaluation
249 /// method instead.
251 };
252
254
256 /// Permit no implicit vector bitcasts.
258 /// Permit vector bitcasts between integer vectors with different numbers
259 /// of elements but the same total bit-width.
261 /// Permit vector bitcasts between all vectors with the same total
262 /// bit-width.
264 };
265
267 // All vector compares produce scalars except vector pixel and vector bool.
268 // The types vector pixel and vector bool return vector results.
270 // All vector compares produce vector results as in GCC.
272 // All vector compares produce scalars as in XL.
274 // Default clang behaviour.
276 };
277
279 /// No signing for any function.
281 /// Sign the return address of functions that spill LR.
283 /// Sign the return address of all functions,
285 };
286
288 /// Return address signing uses APIA key.
290 /// Return address signing uses APIB key.
292 };
293
294 enum class ThreadModelKind {
295 /// POSIX Threads.
297 /// Single Threaded Environment.
299 };
300
301 enum class ExtendArgsKind {
302 /// Integer arguments are sign or zero extended to 32/64 bits
303 /// during default argument promotions.
306 };
307
309 /// Legacy default stream
311 /// Per-thread default stream
313 };
314
315 /// Exclude certain code patterns from being instrumented by arithmetic
316 /// overflow sanitizers
318 /// Don't exclude any overflow patterns from sanitizers
319 None = 1 << 0,
320 /// Exclude all overflow patterns (below)
321 All = 1 << 1,
322 /// if (a + b < a)
324 /// if (a + b < a)
326 /// -1UL
328 /// while (count--)
330 };
331
334 /// map only explicit default visibilities to exported
336 /// map all default visibilities to exported
338 };
339
341 /// Force hidden visibility
343 /// Force protected visibility
345 /// Force default visibility
347 /// Don't alter the visibility
349 };
350
352 /// Keep the IR-gen assigned visibility.
354 /// Override the IR-gen assigned visibility with default visibility.
356 /// Override the IR-gen assigned visibility with hidden visibility.
358 /// Override the IR-gen assigned visibility with protected visibility.
360 };
361
363 /// Any trailing array member is a FAM.
365 /// Any trailing array member of undefined, 0, or 1 size is a FAM.
367 /// Any trailing array member of undefined or 0 size is a FAM.
369 /// Any trailing array member of undefined size is a FAM.
371 };
372
373 /// Controls the various implementations for complex multiplication and
374 // division.
376 /// Implementation of complex division and multiplication using a call to
377 /// runtime library functions(generally the case, but the BE might
378 /// sometimes replace the library call if it knows enough about the
379 /// potential range of the inputs). Overflow and non-finite values are
380 /// handled by the library implementation. This is the default value.
382
383 /// Implementation of complex division offering an improved handling
384 /// for overflow in intermediate calculations with no special handling for
385 /// NaN and infinite values.
387
388 /// Implementation of complex division using algebraic formulas at
389 /// higher precision. Overflow is handled. Non-finite values are handled in
390 /// some cases. If the target hardware does not have native support for a
391 /// higher precision data type, an implementation for the complex operation
392 /// will be used to provide improved guards against intermediate overflow,
393 /// but overflow and underflow may still occur in some cases. NaN and
394 /// infinite values are not handled.
396
397 /// Implementation of complex division and multiplication using
398 /// algebraic formulas at source precision. No special handling to avoid
399 /// overflow. NaN and infinite values are not handled.
401
402 /// No range rule is enabled.
404 };
405
406 /// Controls which variables have static destructors registered.
408 /// Register static destructors for all variables.
410 /// Register static destructors only for thread-local variables.
412 /// Don't register static destructors for any variables.
414 };
415
416 // Define simple language options (with no accessors).
417#define LANGOPT(Name, Bits, Default, Compatibility, Description) \
418 unsigned Name : Bits;
419#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description)
420#include "clang/Basic/LangOptions.def"
421
422protected:
423 // Define language options of enumeration type. These are private, and will
424 // have accessors (below).
425#define LANGOPT(Name, Bits, Default, Compatibility, Description)
426#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \
427 LLVM_PREFERRED_TYPE(Type) \
428 unsigned Name : Bits;
429#include "clang/Basic/LangOptions.def"
430};
431
432/// Keeps track of the various options that can be
433/// enabled, which controls the dialect of C or C++ that is accepted.
435public:
436 /// The used language standard.
438
439 /// Set of enabled sanitizers.
441 /// Is at least one coverage instrumentation type enabled.
442 bool SanitizeCoverage = false;
443
444 /// Paths to files specifying which objects
445 /// (files, functions, variables) should not be instrumented.
446 std::vector<std::string> NoSanitizeFiles;
447
448 /// Paths to the XRay "always instrument" files specifying which
449 /// objects (files, functions, variables) should be imbued with the XRay
450 /// "always instrument" attribute.
451 /// WARNING: This is a deprecated field and will go away in the future.
452 std::vector<std::string> XRayAlwaysInstrumentFiles;
453
454 /// Paths to the XRay "never instrument" files specifying which
455 /// objects (files, functions, variables) should be imbued with the XRay
456 /// "never instrument" attribute.
457 /// WARNING: This is a deprecated field and will go away in the future.
458 std::vector<std::string> XRayNeverInstrumentFiles;
459
460 /// Paths to the XRay attribute list files, specifying which objects
461 /// (files, functions, variables) should be imbued with the appropriate XRay
462 /// attribute(s).
463 std::vector<std::string> XRayAttrListFiles;
464
465 /// Paths to special case list files specifying which entities
466 /// (files, functions) should or should not be instrumented.
467 std::vector<std::string> ProfileListFiles;
468
470
472
474
475 /// The name of the handler function to be called when -ftrapv is
476 /// specified.
477 ///
478 /// If none is specified, abort (GCC-compatible behaviour).
479 std::string OverflowHandler;
480
481 /// The module currently being compiled as specified by -fmodule-name.
482 std::string ModuleName;
483
484 /// The name of the current module, of which the main source file
485 /// is a part. If CompilingModule is set, we are compiling the interface
486 /// of this module, otherwise we are compiling an implementation file of
487 /// it. This starts as ModuleName in case -fmodule-name is provided and
488 /// changes during compilation to reflect the current module.
489 std::string CurrentModule;
490
491 /// The names of any features to enable in module 'requires' decls
492 /// in addition to the hard-coded list in Module.cpp and the target features.
493 ///
494 /// This list is sorted.
495 std::vector<std::string> ModuleFeatures;
496
497 /// Options for parsing comments.
499
500 /// A list of all -fno-builtin-* function names (e.g., memset).
501 std::vector<std::string> NoBuiltinFuncs;
502
503 /// A prefix map for __FILE__, __BASE_FILE__ and __builtin_FILE().
504 std::map<std::string, std::string, std::greater<std::string>> MacroPrefixMap;
505
506 /// Triples of the OpenMP targets that the host code codegen should
507 /// take into account in order to generate accurate offloading descriptors.
508 std::vector<llvm::Triple> OMPTargetTriples;
509
510 /// Name of the IR file that contains the result of the OpenMP target
511 /// host code generation.
512 std::string OMPHostIRFile;
513
514 /// The user provided compilation unit ID, if non-empty. This is used to
515 /// externalize static variables which is needed to support accessing static
516 /// device variables in host code for single source offloading languages
517 /// like CUDA/HIP.
518 std::string CUID;
519
520 /// C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
521 /// This overrides the default ABI used by the target.
522 std::optional<TargetCXXABI::Kind> CXXABI;
523
524 /// Indicates whether the front-end is explicitly told that the
525 /// input is a header file (i.e. -x c-header).
526 bool IsHeaderFile = false;
527
528 /// The default stream kind used for HIP kernel launching.
530
531 /// Which overflow patterns should be excluded from sanitizer instrumentation
533
534 std::vector<std::string> OverflowPatternExclusionValues;
535
536 /// The seed used by the randomize structure layout feature.
537 std::string RandstructSeed;
538
539 /// Indicates whether to use target's platform-specific file separator when
540 /// __FILE__ macro is used and when concatenating filename with directory or
541 /// to use build environment environment's platform-specific file separator.
542 ///
543 /// The plaform-specific path separator is the backslash(\‍) for Windows and
544 /// forward slash (/) elsewhere.
546
547 // Indicates whether we should keep all nullptr checks for pointers
548 // received as a result of a standard operator new (-fcheck-new)
549 bool CheckNew = false;
550
551 /// The HLSL root signature version for dxil.
552 llvm::dxbc::RootSignatureVersion HLSLRootSigVer;
553
554 /// The HLSL root signature that will be used to overide the root signature
555 /// used for the shader entry point.
557
558 // Indicates if the wasm-opt binary must be ignored in the case of a
559 // WebAssembly target.
560 bool NoWasmOpt = false;
561
562 /// Atomic code-generation options.
563 /// These flags are set directly from the command-line options.
564 bool AtomicRemoteMemory = false;
567
568 LangOptions();
569
570 /// Set language defaults for the given input language and
571 /// language standard in the given LangOptions object.
572 ///
573 /// \param Opts - The LangOptions object to set up.
574 /// \param Lang - The input language.
575 /// \param T - The target triple.
576 /// \param Includes - If the language requires extra headers to be implicitly
577 /// included, they will be appended to this list.
578 /// \param LangStd - The input language standard.
579 static void
580 setLangDefaults(LangOptions &Opts, Language Lang, const llvm::Triple &T,
581 std::vector<std::string> &Includes,
583
584 // Define accessors/mutators for language options of enumeration type.
585#define LANGOPT(Name, Bits, Default, Compatibility, Description)
586#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \
587 Type get##Name() const { return static_cast<Type>(Name); } \
588 void set##Name(Type Value) { \
589 assert(static_cast<unsigned>(Value) < (1u << Bits)); \
590 Name = static_cast<unsigned>(Value); \
591 }
592#include "clang/Basic/LangOptions.def"
593
594 /// Are we compiling a module?
595 bool isCompilingModule() const {
596 return getCompilingModule() != CMK_None;
597 }
598
599 /// Are we compiling a module implementation?
601 return !isCompilingModule() && !ModuleName.empty();
602 }
603
604 /// Do we need to track the owning module for a local declaration?
606 return isCompilingModule() || ModulesLocalVisibility;
607 }
608
610 return getSignedOverflowBehavior() == SOB_Defined;
611 }
612
614 return ObjCRuntime.isSubscriptPointerArithmetic() &&
615 !ObjCSubscriptingLegacyRuntime;
616 }
617
618 bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
619 return MSCompatibilityVersion >= MajorVersion * 100000U;
620 }
621
629
630 /// Reset all of the options that are not considered when building a
631 /// module.
633
634 /// Is this a libc/libm function that is no longer recognized as a
635 /// builtin because a -fno-builtin-* option has been specified?
636 bool isNoBuiltinFunc(StringRef Name) const;
637
638 /// True if any ObjC types may have non-trivial lifetime qualifiers.
640 return ObjCAutoRefCount || ObjCWeak;
641 }
642
644 return ConvergentFunctions;
645 }
646
647 /// Return true if atomicrmw operations targeting allocations in private
648 /// memory are undefined.
650 // Should be false for OpenMP.
651 // TODO: Should this be true for SYCL?
652 return OpenCL || CUDA;
653 }
654
655 /// Return the OpenCL C or C++ version as a VersionTuple.
656 VersionTuple getOpenCLVersionTuple() const;
657
658 /// Return the OpenCL version that kernel language is compatible with
659 unsigned getOpenCLCompatibleVersion() const;
660
661 /// Return the OpenCL C or C++ for OpenCL language name and version
662 /// as a string.
663 std::string getOpenCLVersionString() const;
664
665 /// Returns true if functions without prototypes or functions with an
666 /// identifier list (aka K&R C functions) are not allowed.
668 return CPlusPlus || C23 || DisableKNRFunctions;
669 }
670
671 /// Returns true if implicit function declarations are allowed in the current
672 /// language mode.
674 return !requiresStrictPrototypes() && !OpenCL;
675 }
676
677 /// Returns true if the language supports calling the 'atexit' function.
678 bool hasAtExit() const { return !(OpenMP && OpenMPIsTargetDevice); }
679
680 /// Returns true if implicit int is part of the language requirements.
681 bool isImplicitIntRequired() const { return !CPlusPlus && !C99; }
682
683 /// Returns true if implicit int is supported at all.
684 bool isImplicitIntAllowed() const { return !CPlusPlus && !C23; }
685
686 /// Check if return address signing is enabled.
687 bool hasSignReturnAddress() const {
688 return getSignReturnAddressScope() != SignReturnAddressScopeKind::None;
689 }
690
691 /// Check if return address signing uses AKey.
693 return getSignReturnAddressKey() == SignReturnAddressKeyKind::AKey;
694 }
695
696 /// Check if leaf functions are also signed.
698 return getSignReturnAddressScope() == SignReturnAddressScopeKind::All;
699 }
700
701 bool isSYCL() const { return SYCLIsDevice || SYCLIsHost; }
702
704 return getDefaultVisibilityExportMapping() !=
706 }
707
709 return getDefaultVisibilityExportMapping() ==
711 }
712
714 return getDefaultVisibilityExportMapping() ==
716 }
717
719 return getGlobalAllocationFunctionVisibility() !=
721 }
722
724 return getGlobalAllocationFunctionVisibility() ==
726 }
727
729 return getGlobalAllocationFunctionVisibility() ==
731 }
732
734 return getGlobalAllocationFunctionVisibility() ==
736 }
737
738 bool allowArrayReturnTypes() const { return HLSL; }
739
740 /// Remap path prefix according to -fmacro-prefix-path option.
741 void remapPathPrefix(SmallVectorImpl<char> &Path) const;
742
744 return RoundingMath ? RoundingMode::Dynamic
745 : RoundingMode::NearestTiesToEven;
746 }
747
749 FPExceptionModeKind EM = getFPExceptionMode();
752 return EM;
753 }
754
755 /// True when compiling for an offloading target device.
756 bool isTargetDevice() const {
757 return OpenMPIsTargetDevice || CUDAIsDevice || SYCLIsDevice;
758 }
759};
760
761/// Floating point control options
762class FPOptionsOverride;
764public:
765 // We start by defining the layout.
766 using storage_type = uint32_t;
767
768 using RoundingMode = llvm::RoundingMode;
769
770 static constexpr unsigned StorageBitSize = 8 * sizeof(storage_type);
771
772 // Define a fake option named "First" so that we have a PREVIOUS even for the
773 // real first option.
774 static constexpr storage_type FirstShift = 0, FirstWidth = 0;
775#define FP_OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
776 static constexpr storage_type NAME##Shift = \
777 PREVIOUS##Shift + PREVIOUS##Width; \
778 static constexpr storage_type NAME##Width = WIDTH; \
779 static constexpr storage_type NAME##Mask = ((1 << NAME##Width) - 1) \
780 << NAME##Shift;
781#include "clang/Basic/FPOptions.def"
782
783 static constexpr storage_type TotalWidth = 0
784#define FP_OPTION(NAME, TYPE, WIDTH, PREVIOUS) +WIDTH
785#include "clang/Basic/FPOptions.def"
786 ;
787 static_assert(TotalWidth <= StorageBitSize, "Too short type for FPOptions");
788
789private:
790 storage_type Value;
791
792 FPOptionsOverride getChangesSlow(const FPOptions &Base) const;
793
794public:
795 FPOptions() : Value(0) {
796 setFPContractMode(LangOptions::FPM_Off);
797 setConstRoundingMode(RoundingMode::Dynamic);
798 setSpecifiedExceptionMode(LangOptions::FPE_Default);
799 }
800 explicit FPOptions(const LangOptions &LO) {
801 Value = 0;
802 // The language fp contract option FPM_FastHonorPragmas has the same effect
803 // as FPM_Fast in frontend. For simplicity, use FPM_Fast uniformly in
804 // frontend.
805 auto LangOptContractMode = LO.getDefaultFPContractMode();
806 if (LangOptContractMode == LangOptions::FPM_FastHonorPragmas)
807 LangOptContractMode = LangOptions::FPM_Fast;
808 setFPContractMode(LangOptContractMode);
809 setRoundingMath(LO.RoundingMath);
810 setConstRoundingMode(LangOptions::RoundingMode::Dynamic);
811 setSpecifiedExceptionMode(LO.getFPExceptionMode());
812 setAllowFPReassociate(LO.AllowFPReassoc);
813 setNoHonorNaNs(LO.NoHonorNaNs);
814 setNoHonorInfs(LO.NoHonorInfs);
815 setNoSignedZero(LO.NoSignedZero);
816 setAllowReciprocal(LO.AllowRecip);
817 setAllowApproxFunc(LO.ApproxFunc);
818 if (getFPContractMode() == LangOptions::FPM_On &&
819 getRoundingMode() == llvm::RoundingMode::Dynamic &&
821 // If the FP settings are set to the "strict" model, then
822 // FENV access is set to true. (ffp-model=strict)
823 setAllowFEnvAccess(true);
824 else
825 setAllowFEnvAccess(LangOptions::FPM_Off);
826 setComplexRange(LO.getComplexRange());
827 }
828
830 return getFPContractMode() == LangOptions::FPM_On;
831 }
833 setFPContractMode(LangOptions::FPM_On);
834 }
835
837 return getFPContractMode() == LangOptions::FPM_Fast;
838 }
840 setFPContractMode(LangOptions::FPM_Fast);
841 }
842
843 bool isFPConstrained() const {
844 return getRoundingMode() != llvm::RoundingMode::NearestTiesToEven ||
846 getAllowFEnvAccess();
847 }
848
850 RoundingMode RM = getConstRoundingMode();
851 if (RM == RoundingMode::Dynamic) {
852 // C23: 7.6.2p3 If the FE_DYNAMIC mode is specified and FENV_ACCESS is
853 // "off", the translator may assume that the default rounding mode is in
854 // effect.
855 if (!getAllowFEnvAccess() && !getRoundingMath())
856 RM = RoundingMode::NearestTiesToEven;
857 }
858 return RM;
859 }
860
862 LangOptions::FPExceptionModeKind EM = getSpecifiedExceptionMode();
864 if (getAllowFEnvAccess())
866 else
868 }
869 return EM;
870 }
871
872 bool operator==(FPOptions other) const { return Value == other.Value; }
873
874 /// Return the default value of FPOptions that's used when trailing
875 /// storage isn't required.
877
878 storage_type getAsOpaqueInt() const { return Value; }
880 FPOptions Opts;
881 Opts.Value = Value;
882 return Opts;
883 }
884
885 /// Return difference with the given option set.
887
889
890 // We can define most of the accessors automatically:
891 // TODO: consider enforcing the assertion that value fits within bits
892 // statically.
893#define FP_OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
894 TYPE get##NAME() const { \
895 return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift); \
896 } \
897 void set##NAME(TYPE value) { \
898 assert(storage_type(value) < (1u << WIDTH)); \
899 Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift); \
900 }
901#include "clang/Basic/FPOptions.def"
902 LLVM_DUMP_METHOD void dump();
903};
904
905/// Represents difference between two FPOptions values.
906///
907/// The effect of language constructs changing the set of floating point options
908/// is usually a change of some FP properties while leaving others intact. This
909/// class describes such changes by keeping information about what FP options
910/// are overridden.
911///
912/// The integral set of FP options, described by the class FPOptions, may be
913/// represented as a default FP option set, defined by language standard and
914/// command line options, with the overrides introduced by pragmas.
915///
916/// The is implemented as a value of the new FPOptions plus a mask showing which
917/// fields are actually set in it.
920 FPOptions::storage_type OverrideMask = 0;
921
922public:
923 using RoundingMode = llvm::RoundingMode;
924
925 /// The type suitable for storing values of FPOptionsOverride. Must be twice
926 /// as wide as bit size of FPOption.
927 using storage_type = uint64_t;
928 static_assert(sizeof(storage_type) >= 2 * sizeof(FPOptions::storage_type),
929 "Too short type for FPOptionsOverride");
930
931 /// Bit mask selecting bits of OverrideMask in serialized representation of
932 /// FPOptionsOverride.
934 (static_cast<storage_type>(1) << FPOptions::StorageBitSize) - 1;
935
938 : Options(LO), OverrideMask(OverrideMaskBits) {}
940 : Options(FPO), OverrideMask(OverrideMaskBits) {}
942 : Options(FPO), OverrideMask(Mask) {}
943
944 bool requiresTrailingStorage() const { return OverrideMask != 0; }
945
947 setFPContractModeOverride(LangOptions::FPM_On);
948 }
949
951 setFPContractModeOverride(LangOptions::FPM_Fast);
952 }
953
955 setFPContractModeOverride(LangOptions::FPM_Off);
956 }
957
959 setAllowFPReassociateOverride(!Value);
960 setNoHonorNaNsOverride(!Value);
961 setNoHonorInfsOverride(!Value);
962 setNoSignedZeroOverride(!Value);
963 setAllowReciprocalOverride(!Value);
964 setAllowApproxFuncOverride(!Value);
965 setMathErrnoOverride(Value);
966 if (Value)
967 /* Precise mode implies fp_contract=on and disables ffast-math */
969 else
970 /* Precise mode disabled sets fp_contract=fast and enables ffast-math */
972 }
973
975
977 return (static_cast<storage_type>(Options.getAsOpaqueInt())
979 OverrideMask;
980 }
983 Opts.OverrideMask = I & OverrideMaskBits;
985 return Opts;
986 }
987
990 FPOptions::getFromOpaqueInt((Base.getAsOpaqueInt() & ~OverrideMask) |
991 (Options.getAsOpaqueInt() & OverrideMask));
992 return Result;
993 }
994
996 return applyOverrides(FPOptions(LO));
997 }
998
999 bool operator==(FPOptionsOverride other) const {
1000 return Options == other.Options && OverrideMask == other.OverrideMask;
1001 }
1002 bool operator!=(FPOptionsOverride other) const { return !(*this == other); }
1003
1004#define FP_OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
1005 bool has##NAME##Override() const { \
1006 return OverrideMask & FPOptions::NAME##Mask; \
1007 } \
1008 TYPE get##NAME##Override() const { \
1009 assert(has##NAME##Override()); \
1010 return Options.get##NAME(); \
1011 } \
1012 void clear##NAME##Override() { \
1013 /* Clear the actual value so that we don't have spurious differences when \
1014 * testing equality. */ \
1015 Options.set##NAME(TYPE(0)); \
1016 OverrideMask &= ~FPOptions::NAME##Mask; \
1017 } \
1018 void set##NAME##Override(TYPE value) { \
1019 Options.set##NAME(value); \
1020 OverrideMask |= FPOptions::NAME##Mask; \
1021 }
1022#include "clang/Basic/FPOptions.def"
1023 LLVM_DUMP_METHOD void dump();
1024};
1027 if (Value == Base.Value)
1028 return FPOptionsOverride();
1029 return getChangesSlow(Base);
1030}
1033 *this = FPO.applyOverrides(*this);
1034}
1035
1036// The three atomic code-generation options.
1037// The canonical (positive) names are:
1038// "remote_memory", "fine_grained_memory", and "ignore_denormal_mode".
1039// In attribute or command-line parsing, a token prefixed with "no_" inverts its
1040// value.
1042 RemoteMemory, // enable remote memory.
1043 FineGrainedMemory, // enable fine-grained memory.
1044 IgnoreDenormalMode, // ignore floating-point denormals.
1046};
1048struct AtomicOptions {
1049 // Bitfields for each option.
1050 unsigned remote_memory : 1;
1052 unsigned ignore_denormal_mode : 1;
1057 AtomicOptions(const LangOptions &LO)
1058 : remote_memory(LO.AtomicRemoteMemory),
1059 fine_grained_memory(LO.AtomicFineGrainedMemory),
1060 ignore_denormal_mode(LO.AtomicIgnoreDenormalMode) {}
1062 bool getOption(AtomicOptionKind Kind) const {
1063 switch (Kind) {
1065 return remote_memory;
1067 return fine_grained_memory;
1069 return ignore_denormal_mode;
1070 }
1071 llvm_unreachable("Invalid AtomicOptionKind");
1072 }
1074 void setOption(AtomicOptionKind Kind, bool Value) {
1075 switch (Kind) {
1078 return;
1081 return;
1084 return;
1085 }
1086 llvm_unreachable("Invalid AtomicOptionKind");
1087 }
1089 LLVM_DUMP_METHOD void dump() const {
1090 llvm::errs() << "\n remote_memory: " << remote_memory
1091 << "\n fine_grained_memory: " << fine_grained_memory
1092 << "\n ignore_denormal_mode: " << ignore_denormal_mode << "\n";
1093 }
1094};
1095
1096/// Describes the kind of translation unit being processed.
1098 /// The translation unit is a complete translation unit.
1100
1101 /// The translation unit is a prefix to a translation unit, and is
1102 /// not complete.
1103 TU_Prefix,
1104
1105 /// The translation unit is a clang module.
1107
1108 /// The translation unit is a is a complete translation unit that we might
1109 /// incrementally extend later.
1111};
1112
1113} // namespace clang
1114
1115#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:71
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:77
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.
friend class CompilerInvocationBase
Definition LangOptions.h:73
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:76
@ 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:82
@ NotCompatible
Does affect the construction of the AST in a way that does prevent module interoperability.
Definition LangOptions.h:85
@ Compatible
Does affect the construction of the AST in a way that doesn't prevent interoperability (that is,...
Definition LangOptions.h:89
@ Benign
Does not affect the construction of the AST in any way (that is, the value can be different between a...
Definition LangOptions.h:93
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:78
friend class CompilerInvocation
Definition LangOptions.h:72
@ 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...
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.
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 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.
bool hasProtectedGlobalAllocationFunctionVisibility() const
LangStandard::Kind LangStd
The used language standard.
llvm::dxbc::RootSignatureVersion HLSLRootSigVer
The HLSL root signature version for dxil.
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:37
ShaderStage
Shader programs run in specific pipeline stages.
Definition LangOptions.h:43
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:62
@ 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.