clang 20.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 // Indicates if the wasm-opt binary must be ignored in the case of a
579 // WebAssembly target.
580 bool NoWasmOpt = false;
581
582 LangOptions();
583
584 /// Set language defaults for the given input language and
585 /// language standard in the given LangOptions object.
586 ///
587 /// \param Opts - The LangOptions object to set up.
588 /// \param Lang - The input language.
589 /// \param T - The target triple.
590 /// \param Includes - If the language requires extra headers to be implicitly
591 /// included, they will be appended to this list.
592 /// \param LangStd - The input language standard.
593 static void
594 setLangDefaults(LangOptions &Opts, Language Lang, const llvm::Triple &T,
595 std::vector<std::string> &Includes,
597
598 // Define accessors/mutators for language options of enumeration type.
599#define LANGOPT(Name, Bits, Default, Description)
600#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
601 Type get##Name() const { return static_cast<Type>(Name); } \
602 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
603#include "clang/Basic/LangOptions.def"
604
605 /// Are we compiling a module?
606 bool isCompilingModule() const {
607 return getCompilingModule() != CMK_None;
608 }
609
610 /// Are we compiling a module implementation?
612 return !isCompilingModule() && !ModuleName.empty();
613 }
614
615 /// Do we need to track the owning module for a local declaration?
617 return isCompilingModule() || ModulesLocalVisibility;
618 }
619
621 return getSignedOverflowBehavior() == SOB_Defined;
622 }
623
626 !ObjCSubscriptingLegacyRuntime;
627 }
628
629 bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
630 return MSCompatibilityVersion >= MajorVersion * 100000U;
631 }
632
633 /// Reset all of the options that are not considered when building a
634 /// module.
636
637 /// Is this a libc/libm function that is no longer recognized as a
638 /// builtin because a -fno-builtin-* option has been specified?
639 bool isNoBuiltinFunc(StringRef Name) const;
640
641 /// True if any ObjC types may have non-trivial lifetime qualifiers.
643 return ObjCAutoRefCount || ObjCWeak;
644 }
645
647 return ConvergentFunctions;
648 }
649
650 /// Return the OpenCL C or C++ version as a VersionTuple.
651 VersionTuple getOpenCLVersionTuple() const;
652
653 /// Return the OpenCL version that kernel language is compatible with
654 unsigned getOpenCLCompatibleVersion() const;
655
656 /// Return the OpenCL C or C++ for OpenCL language name and version
657 /// as a string.
658 std::string getOpenCLVersionString() const;
659
660 /// Returns true if functions without prototypes or functions with an
661 /// identifier list (aka K&R C functions) are not allowed.
663 return CPlusPlus || C23 || DisableKNRFunctions;
664 }
665
666 /// Returns true if implicit function declarations are allowed in the current
667 /// language mode.
669 return !requiresStrictPrototypes() && !OpenCL;
670 }
671
672 /// Returns true if the language supports calling the 'atexit' function.
673 bool hasAtExit() const { return !(OpenMP && OpenMPIsTargetDevice); }
674
675 /// Returns true if implicit int is part of the language requirements.
676 bool isImplicitIntRequired() const { return !CPlusPlus && !C99; }
677
678 /// Returns true if implicit int is supported at all.
679 bool isImplicitIntAllowed() const { return !CPlusPlus && !C23; }
680
681 /// Check if return address signing is enabled.
682 bool hasSignReturnAddress() const {
683 return getSignReturnAddressScope() != SignReturnAddressScopeKind::None;
684 }
685
686 /// Check if return address signing uses AKey.
688 return getSignReturnAddressKey() == SignReturnAddressKeyKind::AKey;
689 }
690
691 /// Check if leaf functions are also signed.
693 return getSignReturnAddressScope() == SignReturnAddressScopeKind::All;
694 }
695
696 bool hasSjLjExceptions() const {
697 return getExceptionHandling() == ExceptionHandlingKind::SjLj;
698 }
699
700 bool hasSEHExceptions() const {
701 return getExceptionHandling() == ExceptionHandlingKind::WinEH;
702 }
703
704 bool hasDWARFExceptions() const {
705 return getExceptionHandling() == ExceptionHandlingKind::DwarfCFI;
706 }
707
708 bool hasWasmExceptions() const {
709 return getExceptionHandling() == ExceptionHandlingKind::Wasm;
710 }
711
712 bool isSYCL() const { return SYCLIsDevice || SYCLIsHost; }
713
715 return getDefaultVisibilityExportMapping() !=
717 }
718
720 return getDefaultVisibilityExportMapping() ==
722 }
723
725 return getDefaultVisibilityExportMapping() ==
727 }
728
730 return getGlobalAllocationFunctionVisibility() !=
732 }
733
735 return getGlobalAllocationFunctionVisibility() ==
737 }
738
740 return getGlobalAllocationFunctionVisibility() ==
742 }
743
745 return getGlobalAllocationFunctionVisibility() ==
747 }
748
749 /// Remap path prefix according to -fmacro-prefix-path option.
751
753 return RoundingMath ? RoundingMode::Dynamic
754 : RoundingMode::NearestTiesToEven;
755 }
756
758 FPExceptionModeKind EM = getFPExceptionMode();
761 return EM;
762 }
763};
764
765/// Floating point control options
766class FPOptionsOverride;
768public:
769 // We start by defining the layout.
770 using storage_type = uint32_t;
771
772 using RoundingMode = llvm::RoundingMode;
773
774 static constexpr unsigned StorageBitSize = 8 * sizeof(storage_type);
775
776 // Define a fake option named "First" so that we have a PREVIOUS even for the
777 // real first option.
778 static constexpr storage_type FirstShift = 0, FirstWidth = 0;
779#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
780 static constexpr storage_type NAME##Shift = \
781 PREVIOUS##Shift + PREVIOUS##Width; \
782 static constexpr storage_type NAME##Width = WIDTH; \
783 static constexpr storage_type NAME##Mask = ((1 << NAME##Width) - 1) \
784 << NAME##Shift;
785#include "clang/Basic/FPOptions.def"
786
787 static constexpr storage_type TotalWidth = 0
788#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) +WIDTH
789#include "clang/Basic/FPOptions.def"
790 ;
791 static_assert(TotalWidth <= StorageBitSize, "Too short type for FPOptions");
792
793private:
795
796 FPOptionsOverride getChangesSlow(const FPOptions &Base) const;
797
798public:
800 setFPContractMode(LangOptions::FPM_Off);
801 setConstRoundingMode(RoundingMode::Dynamic);
802 setSpecifiedExceptionMode(LangOptions::FPE_Default);
803 }
804 explicit FPOptions(const LangOptions &LO) {
805 Value = 0;
806 // The language fp contract option FPM_FastHonorPragmas has the same effect
807 // as FPM_Fast in frontend. For simplicity, use FPM_Fast uniformly in
808 // frontend.
809 auto LangOptContractMode = LO.getDefaultFPContractMode();
810 if (LangOptContractMode == LangOptions::FPM_FastHonorPragmas)
811 LangOptContractMode = LangOptions::FPM_Fast;
812 setFPContractMode(LangOptContractMode);
813 setRoundingMath(LO.RoundingMath);
814 setConstRoundingMode(LangOptions::RoundingMode::Dynamic);
815 setSpecifiedExceptionMode(LO.getFPExceptionMode());
816 setAllowFPReassociate(LO.AllowFPReassoc);
817 setNoHonorNaNs(LO.NoHonorNaNs);
818 setNoHonorInfs(LO.NoHonorInfs);
819 setNoSignedZero(LO.NoSignedZero);
820 setAllowReciprocal(LO.AllowRecip);
821 setAllowApproxFunc(LO.ApproxFunc);
822 if (getFPContractMode() == LangOptions::FPM_On &&
823 getRoundingMode() == llvm::RoundingMode::Dynamic &&
825 // If the FP settings are set to the "strict" model, then
826 // FENV access is set to true. (ffp-model=strict)
827 setAllowFEnvAccess(true);
828 else
829 setAllowFEnvAccess(LangOptions::FPM_Off);
830 setComplexRange(LO.getComplexRange());
831 }
832
834 return getFPContractMode() == LangOptions::FPM_On;
835 }
837 setFPContractMode(LangOptions::FPM_On);
838 }
839
841 return getFPContractMode() == LangOptions::FPM_Fast;
842 }
844 setFPContractMode(LangOptions::FPM_Fast);
845 }
846
847 bool isFPConstrained() const {
848 return getRoundingMode() != llvm::RoundingMode::NearestTiesToEven ||
850 getAllowFEnvAccess();
851 }
852
854 RoundingMode RM = getConstRoundingMode();
855 if (RM == RoundingMode::Dynamic) {
856 // C23: 7.6.2p3 If the FE_DYNAMIC mode is specified and FENV_ACCESS is
857 // "off", the translator may assume that the default rounding mode is in
858 // effect.
859 if (!getAllowFEnvAccess() && !getRoundingMath())
860 RM = RoundingMode::NearestTiesToEven;
861 }
862 return RM;
863 }
864
866 LangOptions::FPExceptionModeKind EM = getSpecifiedExceptionMode();
868 if (getAllowFEnvAccess())
870 else
872 }
873 return EM;
874 }
875
876 bool operator==(FPOptions other) const { return Value == other.Value; }
877
878 /// Return the default value of FPOptions that's used when trailing
879 /// storage isn't required.
881
884 FPOptions Opts;
885 Opts.Value = Value;
886 return Opts;
887 }
888
889 /// Return difference with the given option set.
891
893
894 // We can define most of the accessors automatically:
895#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
896 TYPE get##NAME() const { \
897 return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift); \
898 } \
899 void set##NAME(TYPE value) { \
900 Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift); \
901 }
902#include "clang/Basic/FPOptions.def"
903 LLVM_DUMP_METHOD void dump();
904};
905
906/// Represents difference between two FPOptions values.
907///
908/// The effect of language constructs changing the set of floating point options
909/// is usually a change of some FP properties while leaving others intact. This
910/// class describes such changes by keeping information about what FP options
911/// are overridden.
912///
913/// The integral set of FP options, described by the class FPOptions, may be
914/// represented as a default FP option set, defined by language standard and
915/// command line options, with the overrides introduced by pragmas.
916///
917/// The is implemented as a value of the new FPOptions plus a mask showing which
918/// fields are actually set in it.
921 FPOptions::storage_type OverrideMask = 0;
922
923public:
924 using RoundingMode = llvm::RoundingMode;
925
926 /// The type suitable for storing values of FPOptionsOverride. Must be twice
927 /// as wide as bit size of FPOption.
928 using storage_type = uint64_t;
929 static_assert(sizeof(storage_type) >= 2 * sizeof(FPOptions::storage_type),
930 "Too short type for FPOptionsOverride");
931
932 /// Bit mask selecting bits of OverrideMask in serialized representation of
933 /// FPOptionsOverride.
935 (static_cast<storage_type>(1) << FPOptions::StorageBitSize) - 1;
936
939 : Options(LO), OverrideMask(OverrideMaskBits) {}
941 : Options(FPO), OverrideMask(OverrideMaskBits) {}
943 : Options(FPO), OverrideMask(Mask) {}
944
945 bool requiresTrailingStorage() const { return OverrideMask != 0; }
946
948 setFPContractModeOverride(LangOptions::FPM_On);
949 }
950
952 setFPContractModeOverride(LangOptions::FPM_Fast);
953 }
954
956 setFPContractModeOverride(LangOptions::FPM_Off);
957 }
958
960 setAllowFPReassociateOverride(!Value);
961 setNoHonorNaNsOverride(!Value);
962 setNoHonorInfsOverride(!Value);
963 setNoSignedZeroOverride(!Value);
964 setAllowReciprocalOverride(!Value);
965 setAllowApproxFuncOverride(!Value);
966 setMathErrnoOverride(Value);
967 if (Value)
968 /* Precise mode implies fp_contract=on and disables ffast-math */
970 else
971 /* Precise mode disabled sets fp_contract=fast and enables ffast-math */
973 }
974
976
978 return (static_cast<storage_type>(Options.getAsOpaqueInt())
980 OverrideMask;
981 }
984 Opts.OverrideMask = I & OverrideMaskBits;
986 return Opts;
987 }
988
991 FPOptions::getFromOpaqueInt((Base.getAsOpaqueInt() & ~OverrideMask) |
992 (Options.getAsOpaqueInt() & OverrideMask));
993 return Result;
994 }
995
997 return applyOverrides(FPOptions(LO));
998 }
999
1000 bool operator==(FPOptionsOverride other) const {
1001 return Options == other.Options && OverrideMask == other.OverrideMask;
1002 }
1003 bool operator!=(FPOptionsOverride other) const { return !(*this == other); }
1004
1005#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
1006 bool has##NAME##Override() const { \
1007 return OverrideMask & FPOptions::NAME##Mask; \
1008 } \
1009 TYPE get##NAME##Override() const { \
1010 assert(has##NAME##Override()); \
1011 return Options.get##NAME(); \
1012 } \
1013 void clear##NAME##Override() { \
1014 /* Clear the actual value so that we don't have spurious differences when \
1015 * testing equality. */ \
1016 Options.set##NAME(TYPE(0)); \
1017 OverrideMask &= ~FPOptions::NAME##Mask; \
1018 } \
1019 void set##NAME##Override(TYPE value) { \
1020 Options.set##NAME(value); \
1021 OverrideMask |= FPOptions::NAME##Mask; \
1022 }
1023#include "clang/Basic/FPOptions.def"
1024 LLVM_DUMP_METHOD void dump();
1025};
1028 if (Value == Base.Value)
1029 return FPOptionsOverride();
1030 return getChangesSlow(Base);
1031}
1034 *this = FPO.applyOverrides(*this);
1035}
1036
1037/// Describes the kind of translation unit being processed.
1039 /// The translation unit is a complete translation unit.
1041
1042 /// The translation unit is a prefix to a translation unit, and is
1043 /// not complete.
1044 TU_Prefix,
1045
1046 /// The translation unit is a clang module.
1048
1049 /// The translation unit is a is a complete translation unit that we might
1050 /// incrementally extend later.
1052};
1053
1054} // namespace clang
1055
1056#endif // LLVM_CLANG_BASIC_LANGOPTIONS_H
IndirectLocalPath & Path
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:919
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:951
static FPOptionsOverride getFromOpaqueInt(storage_type I)
Definition: LangOptions.h:982
bool operator!=(FPOptionsOverride other) const
Definition: LangOptions.h:1003
FPOptionsOverride(FPOptions FPO)
Definition: LangOptions.h:940
LLVM_DUMP_METHOD void dump()
void setFPPreciseEnabled(bool Value)
Definition: LangOptions.h:959
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:947
FPOptionsOverride(FPOptions FPO, FPOptions::storage_type Mask)
Definition: LangOptions.h:942
FPOptions applyOverrides(FPOptions Base)
Definition: LangOptions.h:989
bool operator==(FPOptionsOverride other) const
Definition: LangOptions.h:1000
llvm::RoundingMode RoundingMode
Definition: LangOptions.h:924
static constexpr storage_type OverrideMaskBits
Bit mask selecting bits of OverrideMask in serialized representation of FPOptionsOverride.
Definition: LangOptions.h:934
storage_type getAsOpaqueInt() const
Definition: LangOptions.h:977
FPOptions applyOverrides(const LangOptions &LO)
Definition: LangOptions.h:996
uint64_t storage_type
The type suitable for storing values of FPOptionsOverride.
Definition: LangOptions.h:928
FPOptionsOverride(const LangOptions &LO)
Definition: LangOptions.h:938
bool requiresTrailingStorage() const
Definition: LangOptions.h:945
void applyChanges(FPOptionsOverride FPO)
Definition: LangOptions.h:1032
bool isFPConstrained() const
Definition: LangOptions.h:847
static constexpr storage_type FirstShift
Definition: LangOptions.h:778
FPOptionsOverride getChangesFrom(const FPOptions &Base) const
Return difference with the given option set.
Definition: LangOptions.h:1026
storage_type getAsOpaqueInt() const
Definition: LangOptions.h:882
static constexpr storage_type TotalWidth
Definition: LangOptions.h:787
LangOptions::FPExceptionModeKind getExceptionMode() const
Definition: LangOptions.h:865
FPOptions(const LangOptions &LO)
Definition: LangOptions.h:804
static constexpr storage_type FirstWidth
Definition: LangOptions.h:778
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:836
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:883
bool allowFPContractAcrossStatement() const
Definition: LangOptions.h:840
uint32_t storage_type
Definition: LangOptions.h:770
bool operator==(FPOptions other) const
Definition: LangOptions.h:876
bool allowFPContractWithinStatement() const
Definition: LangOptions.h:833
LLVM_DUMP_METHOD void dump()
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:843
static constexpr unsigned StorageBitSize
Definition: LangOptions.h:774
llvm::RoundingMode RoundingMode
Definition: LangOptions.h:772
RoundingMode getRoundingMode() const
Definition: LangOptions.h:853
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:687
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:708
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:629
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:757
bool requiresStrictPrototypes() const
Returns true if functions without prototypes or functions with an identifier list (aka K&R C function...
Definition: LangOptions.h:662
bool isImplicitIntAllowed() const
Returns true if implicit int is supported at all.
Definition: LangOptions.h:679
bool isCompilingModuleImplementation() const
Are we compiling a module implementation?
Definition: LangOptions.h:611
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:696
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:714
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:719
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:673
bool trackLocalOwningModule() const
Do we need to track the owning module for a local declaration?
Definition: LangOptions.h:616
bool isAllDefaultVisibilityExportMapping() const
Definition: LangOptions.h:724
bool isSubscriptPointerArithmetic() const
Definition: LangOptions.h:624
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:620
bool hasDefaultGlobalAllocationFunctionVisibility() const
Definition: LangOptions.h:734
bool hasGlobalAllocationFunctionVisibility() const
Definition: LangOptions.h:729
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:668
bool hasSignReturnAddress() const
Check if return address signing is enabled.
Definition: LangOptions.h:682
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:704
bool assumeFunctionsAreConvergent() const
Definition: LangOptions.h:646
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:642
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:744
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:739
LangStandard::Kind LangStd
The used language standard.
Definition: LangOptions.h:464
RoundingMode getDefaultRoundingMode() const
Definition: LangOptions.h:752
bool isCompilingModule() const
Are we compiling a module?
Definition: LangOptions.h:606
bool isImplicitIntRequired() const
Returns true if implicit int is part of the language requirements.
Definition: LangOptions.h:676
bool hasSEHExceptions() const
Definition: LangOptions.h:700
std::string OpenACCMacroOverride
Definition: LangOptions.h:576
bool isSignReturnAddressScopeAll() const
Check if leaf functions are also signed.
Definition: LangOptions.h:692
bool isSYCL() const
Definition: LangOptions.h:712
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:66
@ CPlusPlus
Definition: LangStandard.h:56
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:1037
@ TU_Incremental
The translation unit is a is a complete translation unit that we might incrementally extend later.
Definition: LangOptions.h:1050
@ TU_Complete
The translation unit is a complete translation unit.
Definition: LangOptions.h:1039
@ TU_ClangModule
The translation unit is a clang module.
Definition: LangOptions.h:1046
@ TU_Prefix
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:1043
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.