clang 19.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
18#include "clang/Basic/LLVM.h"
24#include "llvm/ADT/FloatingPointMode.h"
25#include "llvm/ADT/StringRef.h"
26#include "llvm/TargetParser/Triple.h"
27#include <optional>
28#include <string>
29#include <vector>
30
31namespace clang {
32
33/// In the Microsoft ABI, this controls the placement of virtual displacement
34/// members used to implement virtual inheritance.
36
37/// Shader programs run in specific pipeline stages.
38/// The order of these values matters, and must be kept in sync with the
39/// Triple Environment enum in llvm::Triple. The ordering is enforced in
40/// static_asserts in Triple.cpp and in clang/Basic/HLSLRuntime.h.
41enum class ShaderStage {
42 Pixel = 0,
43 Vertex,
45 Hull,
46 Domain,
47 Compute,
48 Library,
51 AnyHit,
53 Miss,
55 Mesh,
57 Invalid,
58};
59
60enum class PointerAuthenticationMode : unsigned {
61 None,
62 Strip,
65};
66
67/// Bitfields of LangOptions, split out from LangOptions in order to ensure that
68/// this large collection of bitfields is a trivial class type.
70 friend class CompilerInvocation;
72
73public:
75 using RoundingMode = llvm::RoundingMode;
76
79
80 // Automatic variables live on the stack, and when trivial they're usually
81 // uninitialized because it's undefined behavior to use them without
82 // initializing them.
84
86 // Default C standard behavior.
88
89 // -fwrapv
91
92 // -ftrapv
94 };
95
96 // FIXME: Unify with TUKind.
98 /// Not compiling a module interface at all.
100
101 /// Compiling a module from a module map.
103
104 /// Compiling a module header unit.
106
107 /// Compiling a C++ modules interface unit.
109 };
110
116 };
117
119
128 };
129
131
132 // Corresponds to _MSC_VER
134 MSVC2010 = 1600,
135 MSVC2012 = 1700,
136 MSVC2013 = 1800,
137 MSVC2015 = 1900,
138 MSVC2017 = 1910,
141 MSVC2019 = 1920,
145 };
146
151 // The "default" SYCL version to be used when none is specified on the
152 // frontend command line.
154 };
155
158 HLSL_2015 = 2015,
159 HLSL_2016 = 2016,
160 HLSL_2017 = 2017,
161 HLSL_2018 = 2018,
162 HLSL_2021 = 2021,
163 HLSL_202x = 2029,
164 };
165
166 /// Clang versions with different platform ABI conformance.
167 enum class ClangABI {
168 /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
169 /// (SVN r257626). This causes <1 x long long> to be passed in an
170 /// integer register instead of an SSE register on x64_64.
171 Ver3_8,
172
173 /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
174 /// (SVN r291814). This causes move operations to be ignored when
175 /// determining whether a class type can be passed or returned directly.
176 Ver4,
177
178 /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
179 /// (SVN r321711). This causes determination of whether a type is
180 /// standard-layout to ignore collisions between empty base classes
181 /// and between base classes and member subobjects, which affects
182 /// whether we reuse base class tail padding in some ABIs.
183 Ver6,
184
185 /// Attempt to be ABI-compatible with code generated by Clang 7.0.x
186 /// (SVN r338536). This causes alignof (C++) and _Alignof (C11) to be
187 /// compatible with __alignof (i.e., return the preferred alignment)
188 /// rather than returning the required alignment.
189 Ver7,
190
191 /// Attempt to be ABI-compatible with code generated by Clang 9.0.x
192 /// (SVN r351319). This causes vectors of __int128 to be passed in memory
193 /// instead of passing in multiple scalar registers on x86_64 on Linux and
194 /// NetBSD.
195 Ver9,
196
197 /// Attempt to be ABI-compatible with code generated by Clang 11.0.x
198 /// (git 2e10b7a39b93). This causes clang to pass unions with a 256-bit
199 /// vector member on the stack instead of using registers, to not properly
200 /// mangle substitutions for template names in some cases, and to mangle
201 /// declaration template arguments without a cast to the parameter type
202 /// even when that can lead to mangling collisions.
203 Ver11,
204
205 /// Attempt to be ABI-compatible with code generated by Clang 12.0.x
206 /// (git 8e464dd76bef). This causes clang to mangle lambdas within
207 /// global-scope inline variables incorrectly.
208 Ver12,
209
210 /// Attempt to be ABI-compatible with code generated by Clang 14.0.x.
211 /// This causes clang to:
212 /// - mangle dependent nested names incorrectly.
213 /// - make trivial only those defaulted copy constructors with a
214 /// parameter-type-list equivalent to the parameter-type-list of an
215 /// implicit declaration.
216 Ver14,
217
218 /// Attempt to be ABI-compatible with code generated by Clang 15.0.x.
219 /// This causes clang to:
220 /// - Reverse the implementation for DR692, DR1395 and DR1432.
221 /// - pack non-POD members of packed structs.
222 /// - consider classes with defaulted special member functions non-pod.
223 Ver15,
224
225 /// Attempt to be ABI-compatible with code generated by Clang 17.0.x.
226 /// This causes clang to revert some fixes to its implementation of the
227 /// Itanium name mangling scheme, with the consequence that overloaded
228 /// function templates are mangled the same if they differ only by:
229 /// - constraints
230 /// - whether a non-type template parameter has a deduced type
231 /// - the parameter list of a template template parameter
232 Ver17,
233
234 /// Attempt to be ABI-compatible with code generated by Clang 18.0.x.
235 /// This causes clang to revert some fixes to the mangling of lambdas
236 /// in the initializers of members of local classes.
237 Ver18,
238
239 /// Conform to the underlying platform's C and C++ ABIs as closely
240 /// as we can.
241 Latest
242 };
243
244 enum class CoreFoundationABI {
245 /// No interoperability ABI has been specified
247 /// CoreFoundation does not have any language interoperability
249 /// Interoperability with the ObjectiveC runtime
251 /// Interoperability with the latest known version of the Swift runtime
252 Swift,
253 /// Interoperability with the Swift 5.0 runtime
254 Swift5_0,
255 /// Interoperability with the Swift 4.2 runtime
256 Swift4_2,
257 /// Interoperability with the Swift 4.1 runtime
258 Swift4_1,
259 };
260
262 // Disable the floating point pragma
264
265 // Enable the floating point pragma
267
268 // Aggressively fuse FP ops (E.g. FMA) disregarding pragmas.
270
271 // Aggressively fuse FP ops and honor pragmas.
273 };
274
275 /// Possible floating point exception behavior.
277 /// Assume that floating-point exceptions are masked.
279 /// Transformations do not cause new exceptions but may hide some.
281 /// Strictly preserve the floating-point exception semantics.
283 /// Used internally to represent initial unspecified value.
285 };
286
287 /// Possible float expression evaluation method choices.
289 /// The evaluation method cannot be determined or is inconsistent for this
290 /// target.
292 /// Use the declared type for fp arithmetic.
294 /// Use the type double for fp arithmetic.
296 /// Use extended type for fp arithmetic.
298 /// Used only for FE option processing; this is only used to indicate that
299 /// the user did not specify an explicit evaluation method on the command
300 /// line and so the target should be queried for its default evaluation
301 /// method instead.
303 };
304
306
307 /// Possible exception handling behavior.
309
311 /// Permit no implicit vector bitcasts.
312 None,
313 /// Permit vector bitcasts between integer vectors with different numbers
314 /// of elements but the same total bit-width.
315 Integer,
316 /// Permit vector bitcasts between all vectors with the same total
317 /// bit-width.
318 All,
319 };
320
322 // All vector compares produce scalars except vector pixel and vector bool.
323 // The types vector pixel and vector bool return vector results.
324 Mixed,
325 // All vector compares produce vector results as in GCC.
326 GCC,
327 // All vector compares produce scalars as in XL.
328 XL,
329 // Default clang behaviour.
330 Default = Mixed,
331 };
332
334 /// No signing for any function.
335 None,
336 /// Sign the return address of functions that spill LR.
337 NonLeaf,
338 /// Sign the return address of all functions,
339 All
340 };
341
343 /// Return address signing uses APIA key.
344 AKey,
345 /// Return address signing uses APIB key.
346 BKey
347 };
348
349 enum class ThreadModelKind {
350 /// POSIX Threads.
351 POSIX,
352 /// Single Threaded Environment.
353 Single
354 };
355
356 enum class ExtendArgsKind {
357 /// Integer arguments are sign or zero extended to 32/64 bits
358 /// during default argument promotions.
361 };
362
364 /// Legacy default stream
365 Legacy,
366 /// Per-thread default stream
367 PerThread,
368 };
369
371 None,
372 /// map only explicit default visibilities to exported
373 Explicit,
374 /// map all default visibilities to exported
375 All,
376 };
377
379 /// Force hidden visibility
381 /// Force protected visibility
383 /// Force default visibility
385 /// Don't alter the visibility
386 Source,
387 };
388
390 /// Keep the IR-gen assigned visibility.
391 Keep,
392 /// Override the IR-gen assigned visibility with default visibility.
393 Default,
394 /// Override the IR-gen assigned visibility with hidden visibility.
395 Hidden,
396 /// Override the IR-gen assigned visibility with protected visibility.
397 Protected,
398 };
399
401 /// Any trailing array member is a FAM.
402 Default = 0,
403 /// Any trailing array member of undefined, 0, or 1 size is a FAM.
405 /// Any trailing array member of undefined or 0 size is a FAM.
407 /// Any trailing array member of undefined size is a FAM.
408 IncompleteOnly = 3,
409 };
410
411 /// Controls the various implementations for complex multiplication and
412 // division.
414 /// Implementation of complex division and multiplication using a call to
415 /// runtime library functions(generally the case, but the BE might
416 /// sometimes replace the library call if it knows enough about the
417 /// potential range of the inputs). Overflow and non-finite values are
418 /// handled by the library implementation. This is the default value.
420
421 /// Implementation of complex division offering an improved handling
422 /// for overflow in intermediate calculations with no special handling for
423 /// NaN and infinite values.
425
426 /// Implementation of complex division using algebraic formulas at
427 /// higher precision. Overflow is handled. Non-finite values are handled in
428 /// some cases. If the target hardware does not have native support for a
429 /// higher precision data type, an implementation for the complex operation
430 /// will be used to provide improved guards against intermediate overflow,
431 /// but overflow and underflow may still occur in some cases. NaN and
432 /// infinite values are not handled.
434
435 /// Implementation of complex division and multiplication using
436 /// algebraic formulas at source precision. No special handling to avoid
437 /// overflow. NaN and infinite values are not handled.
439
440 /// No range rule is enabled.
441 CX_None
442 };
443
444 // Define simple language options (with no accessors).
445#define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
446#define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
447#include "clang/Basic/LangOptions.def"
448
449protected:
450 // Define language options of enumeration type. These are private, and will
451 // have accessors (below).
452#define LANGOPT(Name, Bits, Default, Description)
453#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
454 LLVM_PREFERRED_TYPE(Type) \
455 unsigned Name : Bits;
456#include "clang/Basic/LangOptions.def"
457};
458
459/// Keeps track of the various options that can be
460/// enabled, which controls the dialect of C or C++ that is accepted.
462public:
463 /// The used language standard.
465
466 /// Set of enabled sanitizers.
468 /// Is at least one coverage instrumentation type enabled.
469 bool SanitizeCoverage = false;
470
471 /// Paths to files specifying which objects
472 /// (files, functions, variables) should not be instrumented.
473 std::vector<std::string> NoSanitizeFiles;
474
475 /// Paths to the XRay "always instrument" files specifying which
476 /// objects (files, functions, variables) should be imbued with the XRay
477 /// "always instrument" attribute.
478 /// WARNING: This is a deprecated field and will go away in the future.
479 std::vector<std::string> XRayAlwaysInstrumentFiles;
480
481 /// Paths to the XRay "never instrument" files specifying which
482 /// objects (files, functions, variables) should be imbued with the XRay
483 /// "never instrument" attribute.
484 /// WARNING: This is a deprecated field and will go away in the future.
485 std::vector<std::string> XRayNeverInstrumentFiles;
486
487 /// Paths to the XRay attribute list files, specifying which objects
488 /// (files, functions, variables) should be imbued with the appropriate XRay
489 /// attribute(s).
490 std::vector<std::string> XRayAttrListFiles;
491
492 /// Paths to special case list files specifying which entities
493 /// (files, functions) should or should not be instrumented.
494 std::vector<std::string> ProfileListFiles;
495
497
499
501
502 /// The name of the handler function to be called when -ftrapv is
503 /// specified.
504 ///
505 /// If none is specified, abort (GCC-compatible behaviour).
506 std::string OverflowHandler;
507
508 /// The module currently being compiled as specified by -fmodule-name.
509 std::string ModuleName;
510
511 /// The name of the current module, of which the main source file
512 /// is a part. If CompilingModule is set, we are compiling the interface
513 /// of this module, otherwise we are compiling an implementation file of
514 /// it. This starts as ModuleName in case -fmodule-name is provided and
515 /// changes during compilation to reflect the current module.
516 std::string CurrentModule;
517
518 /// The names of any features to enable in module 'requires' decls
519 /// in addition to the hard-coded list in Module.cpp and the target features.
520 ///
521 /// This list is sorted.
522 std::vector<std::string> ModuleFeatures;
523
524 /// Options for parsing comments.
526
527 /// A list of all -fno-builtin-* function names (e.g., memset).
528 std::vector<std::string> NoBuiltinFuncs;
529
530 /// A prefix map for __FILE__, __BASE_FILE__ and __builtin_FILE().
531 std::map<std::string, std::string, std::greater<std::string>> MacroPrefixMap;
532
533 /// Triples of the OpenMP targets that the host code codegen should
534 /// take into account in order to generate accurate offloading descriptors.
535 std::vector<llvm::Triple> OMPTargetTriples;
536
537 /// Name of the IR file that contains the result of the OpenMP target
538 /// host code generation.
539 std::string OMPHostIRFile;
540
541 /// The user provided compilation unit ID, if non-empty. This is used to
542 /// externalize static variables which is needed to support accessing static
543 /// device variables in host code for single source offloading languages
544 /// like CUDA/HIP.
545 std::string CUID;
546
547 /// C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
548 /// This overrides the default ABI used by the target.
549 std::optional<TargetCXXABI::Kind> CXXABI;
550
551 /// Indicates whether the front-end is explicitly told that the
552 /// input is a header file (i.e. -x c-header).
553 bool IsHeaderFile = false;
554
555 /// The default stream kind used for HIP kernel launching.
557
558 /// The seed used by the randomize structure layout feature.
559 std::string RandstructSeed;
560
561 /// Indicates whether to use target's platform-specific file separator when
562 /// __FILE__ macro is used and when concatenating filename with directory or
563 /// to use build environment environment's platform-specific file separator.
564 ///
565 /// The plaform-specific path separator is the backslash(\‍) for Windows and
566 /// forward slash (/) elsewhere.
568
569 // Indicates whether we should keep all nullptr checks for pointers
570 // received as a result of a standard operator new (-fcheck-new)
571 bool CheckNew = false;
572
573 // In OpenACC mode, contains a user provided override for the _OPENACC macro.
574 // This exists so that we can override the macro value and test our incomplete
575 // implementation on real-world examples.
577
578 LangOptions();
579
580 /// Set language defaults for the given input language and
581 /// language standard in the given LangOptions object.
582 ///
583 /// \param Opts - The LangOptions object to set up.
584 /// \param Lang - The input language.
585 /// \param T - The target triple.
586 /// \param Includes - If the language requires extra headers to be implicitly
587 /// included, they will be appended to this list.
588 /// \param LangStd - The input language standard.
589 static void
590 setLangDefaults(LangOptions &Opts, Language Lang, const llvm::Triple &T,
591 std::vector<std::string> &Includes,
593
594 // Define accessors/mutators for language options of enumeration type.
595#define LANGOPT(Name, Bits, Default, Description)
596#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
597 Type get##Name() const { return static_cast<Type>(Name); } \
598 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
599#include "clang/Basic/LangOptions.def"
600
601 /// Are we compiling a module?
602 bool isCompilingModule() const {
603 return getCompilingModule() != CMK_None;
604 }
605
606 /// Are we compiling a module implementation?
608 return !isCompilingModule() && !ModuleName.empty();
609 }
610
611 /// Do we need to track the owning module for a local declaration?
613 return isCompilingModule() || ModulesLocalVisibility;
614 }
615
617 return getSignedOverflowBehavior() == SOB_Defined;
618 }
619
622 !ObjCSubscriptingLegacyRuntime;
623 }
624
625 bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
626 return MSCompatibilityVersion >= MajorVersion * 100000U;
627 }
628
629 /// Reset all of the options that are not considered when building a
630 /// module.
632
633 /// Is this a libc/libm function that is no longer recognized as a
634 /// builtin because a -fno-builtin-* option has been specified?
635 bool isNoBuiltinFunc(StringRef Name) const;
636
637 /// True if any ObjC types may have non-trivial lifetime qualifiers.
639 return ObjCAutoRefCount || ObjCWeak;
640 }
641
643 return ConvergentFunctions;
644 }
645
646 /// Return the OpenCL C or C++ version as a VersionTuple.
647 VersionTuple getOpenCLVersionTuple() const;
648
649 /// Return the OpenCL version that kernel language is compatible with
650 unsigned getOpenCLCompatibleVersion() const;
651
652 /// Return the OpenCL C or C++ for OpenCL language name and version
653 /// as a string.
654 std::string getOpenCLVersionString() const;
655
656 /// Returns true if functions without prototypes or functions with an
657 /// identifier list (aka K&R C functions) are not allowed.
659 return CPlusPlus || C23 || DisableKNRFunctions;
660 }
661
662 /// Returns true if implicit function declarations are allowed in the current
663 /// language mode.
665 return !requiresStrictPrototypes() && !OpenCL;
666 }
667
668 /// Returns true if the language supports calling the 'atexit' function.
669 bool hasAtExit() const { return !(OpenMP && OpenMPIsTargetDevice); }
670
671 /// Returns true if implicit int is part of the language requirements.
672 bool isImplicitIntRequired() const { return !CPlusPlus && !C99; }
673
674 /// Returns true if implicit int is supported at all.
675 bool isImplicitIntAllowed() const { return !CPlusPlus && !C23; }
676
677 /// Check if return address signing is enabled.
678 bool hasSignReturnAddress() const {
679 return getSignReturnAddressScope() != SignReturnAddressScopeKind::None;
680 }
681
682 /// Check if return address signing uses AKey.
684 return getSignReturnAddressKey() == SignReturnAddressKeyKind::AKey;
685 }
686
687 /// Check if leaf functions are also signed.
689 return getSignReturnAddressScope() == SignReturnAddressScopeKind::All;
690 }
691
692 bool hasSjLjExceptions() const {
693 return getExceptionHandling() == ExceptionHandlingKind::SjLj;
694 }
695
696 bool hasSEHExceptions() const {
697 return getExceptionHandling() == ExceptionHandlingKind::WinEH;
698 }
699
700 bool hasDWARFExceptions() const {
701 return getExceptionHandling() == ExceptionHandlingKind::DwarfCFI;
702 }
703
704 bool hasWasmExceptions() const {
705 return getExceptionHandling() == ExceptionHandlingKind::Wasm;
706 }
707
708 bool isSYCL() const { return SYCLIsDevice || SYCLIsHost; }
709
711 return getDefaultVisibilityExportMapping() !=
713 }
714
716 return getDefaultVisibilityExportMapping() ==
718 }
719
721 return getDefaultVisibilityExportMapping() ==
723 }
724
726 return getGlobalAllocationFunctionVisibility() !=
728 }
729
731 return getGlobalAllocationFunctionVisibility() ==
733 }
734
736 return getGlobalAllocationFunctionVisibility() ==
738 }
739
741 return getGlobalAllocationFunctionVisibility() ==
743 }
744
745 /// Remap path prefix according to -fmacro-prefix-path option.
746 void remapPathPrefix(SmallVectorImpl<char> &Path) const;
747
749 return RoundingMath ? RoundingMode::Dynamic
750 : RoundingMode::NearestTiesToEven;
751 }
752
754 FPExceptionModeKind EM = getFPExceptionMode();
757 return EM;
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 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 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:
791
792 FPOptionsOverride getChangesSlow(const FPOptions &Base) const;
793
794public:
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
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#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
892 TYPE get##NAME() const { \
893 return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift); \
894 } \
895 void set##NAME(TYPE value) { \
896 Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift); \
897 }
898#include "clang/Basic/FPOptions.def"
899 LLVM_DUMP_METHOD void dump();
900};
901
902/// Represents difference between two FPOptions values.
903///
904/// The effect of language constructs changing the set of floating point options
905/// is usually a change of some FP properties while leaving others intact. This
906/// class describes such changes by keeping information about what FP options
907/// are overridden.
908///
909/// The integral set of FP options, described by the class FPOptions, may be
910/// represented as a default FP option set, defined by language standard and
911/// command line options, with the overrides introduced by pragmas.
912///
913/// The is implemented as a value of the new FPOptions plus a mask showing which
914/// fields are actually set in it.
917 FPOptions::storage_type OverrideMask = 0;
918
919public:
920 using RoundingMode = llvm::RoundingMode;
921
922 /// The type suitable for storing values of FPOptionsOverride. Must be twice
923 /// as wide as bit size of FPOption.
924 using storage_type = uint64_t;
925 static_assert(sizeof(storage_type) >= 2 * sizeof(FPOptions::storage_type),
926 "Too short type for FPOptionsOverride");
927
928 /// Bit mask selecting bits of OverrideMask in serialized representation of
929 /// FPOptionsOverride.
931 (static_cast<storage_type>(1) << FPOptions::StorageBitSize) - 1;
932
935 : Options(LO), OverrideMask(OverrideMaskBits) {}
937 : Options(FPO), OverrideMask(OverrideMaskBits) {}
939 : Options(FPO), OverrideMask(Mask) {}
940
941 bool requiresTrailingStorage() const { return OverrideMask != 0; }
942
944 setFPContractModeOverride(LangOptions::FPM_On);
945 }
946
948 setFPContractModeOverride(LangOptions::FPM_Fast);
949 }
950
952 setFPContractModeOverride(LangOptions::FPM_Off);
953 }
954
956 setAllowFPReassociateOverride(!Value);
957 setNoHonorNaNsOverride(!Value);
958 setNoHonorInfsOverride(!Value);
959 setNoSignedZeroOverride(!Value);
960 setAllowReciprocalOverride(!Value);
961 setAllowApproxFuncOverride(!Value);
962 setMathErrnoOverride(Value);
963 if (Value)
964 /* Precise mode implies fp_contract=on and disables ffast-math */
966 else
967 /* Precise mode disabled sets fp_contract=fast and enables ffast-math */
969 }
970
974 }
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 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/// Describes the kind of translation unit being processed.
1038 /// The translation unit is a complete translation unit.
1040
1041 /// The translation unit is a prefix to a translation unit, and is
1042 /// not complete.
1043 TU_Prefix,
1044
1045 /// The translation unit is a clang module.
1047
1048 /// The translation unit is a is a complete translation unit that we might
1049 /// incrementally extend later.
1051};
1052
1053} // namespace clang
1054
1055#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.
The base class of CompilerInvocation.
Helper class for holding the data necessary to invoke the compiler.
Represents difference between two FPOptions values.
Definition: LangOptions.h:915
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:947
static FPOptionsOverride getFromOpaqueInt(storage_type I)
Definition: LangOptions.h:981
bool operator!=(FPOptionsOverride other) const
Definition: LangOptions.h:1002
FPOptionsOverride(FPOptions FPO)
Definition: LangOptions.h:936
LLVM_DUMP_METHOD void dump()
void setFPPreciseEnabled(bool Value)
Definition: LangOptions.h:955
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:943
FPOptionsOverride(FPOptions FPO, FPOptions::storage_type Mask)
Definition: LangOptions.h:938
FPOptions applyOverrides(FPOptions Base)
Definition: LangOptions.h:988
bool operator==(FPOptionsOverride other) const
Definition: LangOptions.h:999
llvm::RoundingMode RoundingMode
Definition: LangOptions.h:920
static constexpr storage_type OverrideMaskBits
Bit mask selecting bits of OverrideMask in serialized representation of FPOptionsOverride.
Definition: LangOptions.h:930
storage_type getAsOpaqueInt() const
Definition: LangOptions.h:976
FPOptions applyOverrides(const LangOptions &LO)
Definition: LangOptions.h:995
uint64_t storage_type
The type suitable for storing values of FPOptionsOverride.
Definition: LangOptions.h:924
FPOptionsOverride(const LangOptions &LO)
Definition: LangOptions.h:934
bool requiresTrailingStorage() const
Definition: LangOptions.h:941
void applyChanges(FPOptionsOverride FPO)
Definition: LangOptions.h:1031
bool isFPConstrained() const
Definition: LangOptions.h:843
static constexpr storage_type FirstShift
Definition: LangOptions.h:774
FPOptionsOverride getChangesFrom(const FPOptions &Base) const
Return difference with the given option set.
Definition: LangOptions.h:1025
storage_type getAsOpaqueInt() const
Definition: LangOptions.h:878
static constexpr storage_type TotalWidth
Definition: LangOptions.h:783
LangOptions::FPExceptionModeKind getExceptionMode() const
Definition: LangOptions.h:861
FPOptions(const LangOptions &LO)
Definition: LangOptions.h:800
static constexpr storage_type FirstWidth
Definition: LangOptions.h:774
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:832
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)
Definition: LangOptions.h:879
bool allowFPContractAcrossStatement() const
Definition: LangOptions.h:836
uint32_t storage_type
Definition: LangOptions.h:766
bool operator==(FPOptions other) const
Definition: LangOptions.h:872
bool allowFPContractWithinStatement() const
Definition: LangOptions.h:829
LLVM_DUMP_METHOD void dump()
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:839
static constexpr unsigned StorageBitSize
Definition: LangOptions.h:770
llvm::RoundingMode RoundingMode
Definition: LangOptions.h:768
RoundingMode getRoundingMode() const
Definition: LangOptions.h:849
Bitfields of LangOptions, split out from LangOptions in order to ensure that this large collection of...
Definition: LangOptions.h:69
@ 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.
Definition: LangOptions.h:99
@ CMK_HeaderUnit
Compiling a module header unit.
Definition: LangOptions.h:105
@ CMK_ModuleMap
Compiling a module from a module map.
Definition: LangOptions.h:102
@ CMK_ModuleInterface
Compiling a C++ modules interface unit.
Definition: LangOptions.h:108
ComplexRangeKind
Controls the various implementations for complex multiplication and.
Definition: LangOptions.h:413
@ CX_Full
Implementation of complex division and multiplication using a call to runtime library functions(gener...
Definition: LangOptions.h:419
@ CX_Basic
Implementation of complex division and multiplication using algebraic formulas at source precision.
Definition: LangOptions.h:438
@ CX_Promoted
Implementation of complex division using algebraic formulas at higher precision.
Definition: LangOptions.h:433
@ CX_None
No range rule is enabled.
Definition: LangOptions.h:441
@ CX_Improved
Implementation of complex division offering an improved handling for overflow in intermediate calcula...
Definition: LangOptions.h:424
@ 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:75
@ 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.
FPEvalMethodKind
Possible float expression evaluation method choices.
Definition: LangOptions.h:288
@ FEM_Extended
Use extended type for fp arithmetic.
Definition: LangOptions.h:297
@ FEM_Double
Use the type double for fp arithmetic.
Definition: LangOptions.h:295
@ FEM_Indeterminable
The evaluation method cannot be determined or is inconsistent for this target.
Definition: LangOptions.h:291
@ FEM_UnsetOnCommandLine
Used only for FE option processing; this is only used to indicate that the user did not specify an ex...
Definition: LangOptions.h:302
@ FEM_Source
Use the declared type for fp arithmetic.
Definition: LangOptions.h:293
@ Integer
Permit vector bitcasts between integer vectors with different numbers of elements but the same total ...
@ All
Permit vector bitcasts between all vectors with the same total bit-width.
@ 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.
ExceptionHandlingKind
Possible exception handling behavior.
Definition: LangOptions.h:308
@ Explicit
map only explicit default visibilities to exported
@ All
map all default visibilities to exported
FPExceptionModeKind
Possible floating point exception behavior.
Definition: LangOptions.h:276
@ FPE_Default
Used internally to represent initial unspecified value.
Definition: LangOptions.h:284
@ FPE_Strict
Strictly preserve the floating-point exception semantics.
Definition: LangOptions.h:282
@ FPE_MayTrap
Transformations do not cause new exceptions but may hide some.
Definition: LangOptions.h:280
@ FPE_Ignore
Assume that floating-point exceptions are masked.
Definition: LangOptions.h:278
@ 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.
Definition: LangOptions.h:167
@ Ver6
Attempt to be ABI-compatible with code generated by Clang 6.0.x (SVN r321711).
@ Ver18
Attempt to be ABI-compatible with code generated by Clang 18.0.x.
@ Ver4
Attempt to be ABI-compatible with code generated by Clang 4.0.x (SVN r291814).
@ Ver14
Attempt to be ABI-compatible with code generated by Clang 14.0.x.
@ Ver11
Attempt to be ABI-compatible with code generated by Clang 11.0.x (git 2e10b7a39b93).
@ Ver15
Attempt to be ABI-compatible with code generated by Clang 15.0.x.
@ Ver17
Attempt to be ABI-compatible with code generated by Clang 17.0.x.
@ Ver7
Attempt to be ABI-compatible with code generated by Clang 7.0.x (SVN r338536).
@ Latest
Conform to the underlying platform's C and C++ ABIs as closely as we can.
@ Ver3_8
Attempt to be ABI-compatible with code generated by Clang 3.8.x (SVN r257626).
@ Ver12
Attempt to be ABI-compatible with code generated by Clang 12.0.x (git 8e464dd76bef).
@ Ver9
Attempt to be ABI-compatible with code generated by Clang 9.0.x (SVN r351319).
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:461
bool isSignReturnAddressWithAKey() const
Check if return address signing uses AKey.
Definition: LangOptions.h:683
void resetNonModularOptions()
Reset all of the options that are not considered when building a module.
Definition: LangOptions.cpp:25
bool hasWasmExceptions() const
Definition: LangOptions.h:704
std::optional< TargetCXXABI::Kind > CXXABI
C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
Definition: LangOptions.h:549
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:625
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
Definition: LangOptions.h:528
std::string ModuleName
The module currently being compiled as specified by -fmodule-name.
Definition: LangOptions.h:509
std::vector< std::string > XRayNeverInstrumentFiles
Paths to the XRay "never instrument" files specifying which objects (files, functions,...
Definition: LangOptions.h:485
FPExceptionModeKind getDefaultExceptionMode() const
Definition: LangOptions.h:753
bool requiresStrictPrototypes() const
Returns true if functions without prototypes or functions with an identifier list (aka K&R C function...
Definition: LangOptions.h:658
bool isImplicitIntAllowed() const
Returns true if implicit int is supported at all.
Definition: LangOptions.h:675
bool isCompilingModuleImplementation() const
Are we compiling a module implementation?
Definition: LangOptions.h:607
bool isNoBuiltinFunc(StringRef Name) const
Is this a libc/libm function that is no longer recognized as a builtin because a -fno-builtin-* optio...
Definition: LangOptions.cpp:49
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:496
CoreFoundationABI CFRuntime
Definition: LangOptions.h:498
std::string getOpenCLVersionString() const
Return the OpenCL C or C++ for OpenCL language name and version as a string.
Definition: LangOptions.cpp:79
bool hasSjLjExceptions() const
Definition: LangOptions.h:692
bool IsHeaderFile
Indicates whether the front-end is explicitly told that the input is a header file (i....
Definition: LangOptions.h:553
bool hasDefaultVisibilityExportMapping() const
Definition: LangOptions.h:710
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:467
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:525
bool isExplicitDefaultVisibilityExportMapping() const
Definition: LangOptions.h:715
std::vector< std::string > XRayAlwaysInstrumentFiles
Paths to the XRay "always instrument" files specifying which objects (files, functions,...
Definition: LangOptions.h:479
bool hasAtExit() const
Returns true if the language supports calling the 'atexit' function.
Definition: LangOptions.h:669
bool trackLocalOwningModule() const
Do we need to track the owning module for a local declaration?
Definition: LangOptions.h:612
bool isAllDefaultVisibilityExportMapping() const
Definition: LangOptions.h:720
bool isSubscriptPointerArithmetic() const
Definition: LangOptions.h:620
bool UseTargetPathSeparator
Indicates whether to use target's platform-specific file separator when FILE macro is used and when c...
Definition: LangOptions.h:567
bool isSignedOverflowDefined() const
Definition: LangOptions.h:616
bool hasDefaultGlobalAllocationFunctionVisibility() const
Definition: LangOptions.h:730
bool hasGlobalAllocationFunctionVisibility() const
Definition: LangOptions.h:725
VersionTuple getOpenCLVersionTuple() const
Return the OpenCL C or C++ version as a VersionTuple.
Definition: LangOptions.cpp:56
bool implicitFunctionsAllowed() const
Returns true if implicit function declarations are allowed in the current language mode.
Definition: LangOptions.h:664
bool hasSignReturnAddress() const
Check if return address signing is enabled.
Definition: LangOptions.h:678
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...
Definition: LangOptions.cpp:89
bool hasDWARFExceptions() const
Definition: LangOptions.h:700
bool assumeFunctionsAreConvergent() const
Definition: LangOptions.h:642
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
Definition: LangOptions.h:539
bool allowsNonTrivialObjCLifetimeQualifiers() const
True if any ObjC types may have non-trivial lifetime qualifiers.
Definition: LangOptions.h:638
std::string OverflowHandler
The name of the handler function to be called when -ftrapv is specified.
Definition: LangOptions.h:506
bool hasHiddenGlobalAllocationFunctionVisibility() const
Definition: LangOptions.h:740
std::string RandstructSeed
The seed used by the randomize structure layout feature.
Definition: LangOptions.h:559
std::map< std::string, std::string, std::greater< std::string > > MacroPrefixMap
A prefix map for FILE, BASE_FILE and __builtin_FILE().
Definition: LangOptions.h:531
std::vector< std::string > ProfileListFiles
Paths to special case list files specifying which entities (files, functions) should or should not be...
Definition: LangOptions.h:494
void remapPathPrefix(SmallVectorImpl< char > &Path) const
Remap path prefix according to -fmacro-prefix-path option.
Definition: LangOptions.cpp:73
bool hasProtectedGlobalAllocationFunctionVisibility() const
Definition: LangOptions.h:735
LangStandard::Kind LangStd
The used language standard.
Definition: LangOptions.h:464
RoundingMode getDefaultRoundingMode() const
Definition: LangOptions.h:748
bool isCompilingModule() const
Are we compiling a module?
Definition: LangOptions.h:602
bool isImplicitIntRequired() const
Returns true if implicit int is part of the language requirements.
Definition: LangOptions.h:672
bool hasSEHExceptions() const
Definition: LangOptions.h:696
std::string OpenACCMacroOverride
Definition: LangOptions.h:576
bool isSignReturnAddressScopeAll() const
Check if leaf functions are also signed.
Definition: LangOptions.h:688
bool isSYCL() const
Definition: LangOptions.h:708
std::string ObjCConstantStringClass
Definition: LangOptions.h:500
std::string CUID
The user provided compilation unit ID, if non-empty.
Definition: LangOptions.h:545
unsigned getOpenCLCompatibleVersion() const
Return the OpenCL version that kernel language is compatible with.
Definition: LangOptions.cpp:63
GPUDefaultStreamKind GPUDefaultStream
The default stream kind used for HIP kernel launching.
Definition: LangOptions.h:556
std::vector< std::string > XRayAttrListFiles
Paths to the XRay attribute list files, specifying which objects (files, functions,...
Definition: LangOptions.h:490
bool SanitizeCoverage
Is at least one coverage instrumentation type enabled.
Definition: LangOptions.h:469
std::vector< llvm::Triple > OMPTargetTriples
Triples of the OpenMP targets that the host code codegen should take into account in order to generat...
Definition: LangOptions.h:535
std::vector< std::string > NoSanitizeFiles
Paths to files specifying which objects (files, functions, variables) should not be instrumented.
Definition: LangOptions.h:473
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:516
std::vector< std::string > ModuleFeatures
The names of any features to enable in module 'requires' decls in addition to the hard-coded list in ...
Definition: LangOptions.h:522
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:28
bool isSubscriptPointerArithmetic() const
Is subscripting pointer arithmetic?
Definition: ObjCRuntime.h:356
The JSON file list parser is used to communicate input to InstallAPI.
@ OpenCL
Definition: LangStandard.h:65
@ CPlusPlus
Definition: LangStandard.h:55
Language
The language for the input, used to select and validate the language standard and possible actions.
Definition: LangStandard.h:23
@ Result
The result type of a method or function.
MSVtorDispMode
In the Microsoft ABI, this controls the placement of virtual displacement members used to implement v...
Definition: LangOptions.h:35
ShaderStage
Shader programs run in specific pipeline stages.
Definition: LangOptions.h:41
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:1036
@ TU_Incremental
The translation unit is a is a complete translation unit that we might incrementally extend later.
Definition: LangOptions.h:1049
@ TU_Complete
The translation unit is a complete translation unit.
Definition: LangOptions.h:1038
@ TU_ClangModule
The translation unit is a clang module.
Definition: LangOptions.h:1045
@ TU_Prefix
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:1042
const FunctionProtoType * T
PointerAuthenticationMode
Definition: LangOptions.h:60
@ None
The alignment was not explicit in code.
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:34
Options for controlling comment parsing.