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
60/// Bitfields of LangOptions, split out from LangOptions in order to ensure that
61/// this large collection of bitfields is a trivial class type.
63 friend class CompilerInvocation;
65
66public:
68 using RoundingMode = llvm::RoundingMode;
69
72
73 // Automatic variables live on the stack, and when trivial they're usually
74 // uninitialized because it's undefined behavior to use them without
75 // initializing them.
77
79 // Default C standard behavior.
81
82 // -fwrapv
84
85 // -ftrapv
87 };
88
89 // FIXME: Unify with TUKind.
91 /// Not compiling a module interface at all.
93
94 /// Compiling a module from a module map.
96
97 /// Compiling a module header unit.
99
100 /// Compiling a C++ modules interface unit.
102 };
103
109 };
110
112
121 };
122
124
125 // Corresponds to _MSC_VER
127 MSVC2010 = 1600,
128 MSVC2012 = 1700,
129 MSVC2013 = 1800,
130 MSVC2015 = 1900,
131 MSVC2017 = 1910,
134 MSVC2019 = 1920,
138 };
139
144 // The "default" SYCL version to be used when none is specified on the
145 // frontend command line.
147 };
148
151 HLSL_2015 = 2015,
152 HLSL_2016 = 2016,
153 HLSL_2017 = 2017,
154 HLSL_2018 = 2018,
155 HLSL_2021 = 2021,
156 HLSL_202x = 2029,
157 };
158
159 /// Clang versions with different platform ABI conformance.
160 enum class ClangABI {
161 /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
162 /// (SVN r257626). This causes <1 x long long> to be passed in an
163 /// integer register instead of an SSE register on x64_64.
164 Ver3_8,
165
166 /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
167 /// (SVN r291814). This causes move operations to be ignored when
168 /// determining whether a class type can be passed or returned directly.
169 Ver4,
170
171 /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
172 /// (SVN r321711). This causes determination of whether a type is
173 /// standard-layout to ignore collisions between empty base classes
174 /// and between base classes and member subobjects, which affects
175 /// whether we reuse base class tail padding in some ABIs.
176 Ver6,
177
178 /// Attempt to be ABI-compatible with code generated by Clang 7.0.x
179 /// (SVN r338536). This causes alignof (C++) and _Alignof (C11) to be
180 /// compatible with __alignof (i.e., return the preferred alignment)
181 /// rather than returning the required alignment.
182 Ver7,
183
184 /// Attempt to be ABI-compatible with code generated by Clang 9.0.x
185 /// (SVN r351319). This causes vectors of __int128 to be passed in memory
186 /// instead of passing in multiple scalar registers on x86_64 on Linux and
187 /// NetBSD.
188 Ver9,
189
190 /// Attempt to be ABI-compatible with code generated by Clang 11.0.x
191 /// (git 2e10b7a39b93). This causes clang to pass unions with a 256-bit
192 /// vector member on the stack instead of using registers, to not properly
193 /// mangle substitutions for template names in some cases, and to mangle
194 /// declaration template arguments without a cast to the parameter type
195 /// even when that can lead to mangling collisions.
196 Ver11,
197
198 /// Attempt to be ABI-compatible with code generated by Clang 12.0.x
199 /// (git 8e464dd76bef). This causes clang to mangle lambdas within
200 /// global-scope inline variables incorrectly.
201 Ver12,
202
203 /// Attempt to be ABI-compatible with code generated by Clang 14.0.x.
204 /// This causes clang to:
205 /// - mangle dependent nested names incorrectly.
206 /// - make trivial only those defaulted copy constructors with a
207 /// parameter-type-list equivalent to the parameter-type-list of an
208 /// implicit declaration.
209 Ver14,
210
211 /// Attempt to be ABI-compatible with code generated by Clang 15.0.x.
212 /// This causes clang to:
213 /// - Reverse the implementation for DR692, DR1395 and DR1432.
214 /// - pack non-POD members of packed structs.
215 /// - consider classes with defaulted special member functions non-pod.
216 Ver15,
217
218 /// Attempt to be ABI-compatible with code generated by Clang 17.0.x.
219 /// This causes clang to revert some fixes to its implementation of the
220 /// Itanium name mangling scheme, with the consequence that overloaded
221 /// function templates are mangled the same if they differ only by:
222 /// - constraints
223 /// - whether a non-type template parameter has a deduced type
224 /// - the parameter list of a template template parameter
225 Ver17,
226
227 /// Conform to the underlying platform's C and C++ ABIs as closely
228 /// as we can.
229 Latest
230 };
231
232 enum class CoreFoundationABI {
233 /// No interoperability ABI has been specified
235 /// CoreFoundation does not have any language interoperability
237 /// Interoperability with the ObjectiveC runtime
239 /// Interoperability with the latest known version of the Swift runtime
240 Swift,
241 /// Interoperability with the Swift 5.0 runtime
242 Swift5_0,
243 /// Interoperability with the Swift 4.2 runtime
244 Swift4_2,
245 /// Interoperability with the Swift 4.1 runtime
246 Swift4_1,
247 };
248
250 // Disable the floating point pragma
252
253 // Enable the floating point pragma
255
256 // Aggressively fuse FP ops (E.g. FMA) disregarding pragmas.
258
259 // Aggressively fuse FP ops and honor pragmas.
261 };
262
263 /// Possible floating point exception behavior.
265 /// Assume that floating-point exceptions are masked.
267 /// Transformations do not cause new exceptions but may hide some.
269 /// Strictly preserve the floating-point exception semantics.
271 /// Used internally to represent initial unspecified value.
273 };
274
275 /// Possible float expression evaluation method choices.
277 /// The evaluation method cannot be determined or is inconsistent for this
278 /// target.
280 /// Use the declared type for fp arithmetic.
282 /// Use the type double for fp arithmetic.
284 /// Use extended type for fp arithmetic.
286 /// Used only for FE option processing; this is only used to indicate that
287 /// the user did not specify an explicit evaluation method on the command
288 /// line and so the target should be queried for its default evaluation
289 /// method instead.
291 };
292
294
295 /// Possible exception handling behavior.
297
299 /// Permit no implicit vector bitcasts.
300 None,
301 /// Permit vector bitcasts between integer vectors with different numbers
302 /// of elements but the same total bit-width.
303 Integer,
304 /// Permit vector bitcasts between all vectors with the same total
305 /// bit-width.
306 All,
307 };
308
310 // All vector compares produce scalars except vector pixel and vector bool.
311 // The types vector pixel and vector bool return vector results.
312 Mixed,
313 // All vector compares produce vector results as in GCC.
314 GCC,
315 // All vector compares produce scalars as in XL.
316 XL,
317 // Default clang behaviour.
318 Default = Mixed,
319 };
320
322 /// No signing for any function.
323 None,
324 /// Sign the return address of functions that spill LR.
325 NonLeaf,
326 /// Sign the return address of all functions,
327 All
328 };
329
331 /// Return address signing uses APIA key.
332 AKey,
333 /// Return address signing uses APIB key.
334 BKey
335 };
336
337 enum class ThreadModelKind {
338 /// POSIX Threads.
339 POSIX,
340 /// Single Threaded Environment.
341 Single
342 };
343
344 enum class ExtendArgsKind {
345 /// Integer arguments are sign or zero extended to 32/64 bits
346 /// during default argument promotions.
349 };
350
352 /// Legacy default stream
353 Legacy,
354 /// Per-thread default stream
355 PerThread,
356 };
357
359 None,
360 /// map only explicit default visibilities to exported
361 Explicit,
362 /// map all default visibilities to exported
363 All,
364 };
365
367 /// Force hidden visibility
369 /// Force protected visibility
371 /// Force default visibility
373 /// Don't alter the visibility
374 Source,
375 };
376
378 /// Keep the IR-gen assigned visibility.
379 Keep,
380 /// Override the IR-gen assigned visibility with default visibility.
381 Default,
382 /// Override the IR-gen assigned visibility with hidden visibility.
383 Hidden,
384 /// Override the IR-gen assigned visibility with protected visibility.
385 Protected,
386 };
387
389 /// Any trailing array member is a FAM.
390 Default = 0,
391 /// Any trailing array member of undefined, 0, or 1 size is a FAM.
393 /// Any trailing array member of undefined or 0 size is a FAM.
395 /// Any trailing array member of undefined size is a FAM.
396 IncompleteOnly = 3,
397 };
398
399 /// Controls the various implementations for complex multiplication and
400 // division.
402 /// Implementation of complex division and multiplication using a call to
403 /// runtime library functions(generally the case, but the BE might
404 /// sometimes replace the library call if it knows enough about the
405 /// potential range of the inputs). Overflow and non-finite values are
406 /// handled by the library implementation. This is the default value.
408
409 /// Implementation of complex division offering an improved handling
410 /// for overflow in intermediate calculations with no special handling for
411 /// NaN and infinite values.
413
414 /// Implementation of complex division using algebraic formulas at
415 /// higher precision. Overflow is handled. Non-finite values are handled in
416 /// some cases. If the target hardware does not have native support for a
417 /// higher precision data type, an implementation for the complex operation
418 /// will be used to provide improved guards against intermediate overflow,
419 /// but overflow and underflow may still occur in some cases. NaN and
420 /// infinite values are not handled.
422
423 /// Implementation of complex division and multiplication using
424 /// algebraic formulas at source precision. No special handling to avoid
425 /// overflow. NaN and infinite values are not handled.
427
428 /// No range rule is enabled.
429 CX_None
430 };
431
432 // Define simple language options (with no accessors).
433#define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
434#define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
435#include "clang/Basic/LangOptions.def"
436
437protected:
438 // Define language options of enumeration type. These are private, and will
439 // have accessors (below).
440#define LANGOPT(Name, Bits, Default, Description)
441#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
442 LLVM_PREFERRED_TYPE(Type) \
443 unsigned Name : Bits;
444#include "clang/Basic/LangOptions.def"
445};
446
447/// Keeps track of the various options that can be
448/// enabled, which controls the dialect of C or C++ that is accepted.
450public:
451 /// The used language standard.
453
454 /// Set of enabled sanitizers.
456 /// Is at least one coverage instrumentation type enabled.
457 bool SanitizeCoverage = false;
458
459 /// Paths to files specifying which objects
460 /// (files, functions, variables) should not be instrumented.
461 std::vector<std::string> NoSanitizeFiles;
462
463 /// Paths to the XRay "always instrument" files specifying which
464 /// objects (files, functions, variables) should be imbued with the XRay
465 /// "always instrument" attribute.
466 /// WARNING: This is a deprecated field and will go away in the future.
467 std::vector<std::string> XRayAlwaysInstrumentFiles;
468
469 /// Paths to the XRay "never instrument" files specifying which
470 /// objects (files, functions, variables) should be imbued with the XRay
471 /// "never instrument" attribute.
472 /// WARNING: This is a deprecated field and will go away in the future.
473 std::vector<std::string> XRayNeverInstrumentFiles;
474
475 /// Paths to the XRay attribute list files, specifying which objects
476 /// (files, functions, variables) should be imbued with the appropriate XRay
477 /// attribute(s).
478 std::vector<std::string> XRayAttrListFiles;
479
480 /// Paths to special case list files specifying which entities
481 /// (files, functions) should or should not be instrumented.
482 std::vector<std::string> ProfileListFiles;
483
485
487
489
490 /// The name of the handler function to be called when -ftrapv is
491 /// specified.
492 ///
493 /// If none is specified, abort (GCC-compatible behaviour).
494 std::string OverflowHandler;
495
496 /// The module currently being compiled as specified by -fmodule-name.
497 std::string ModuleName;
498
499 /// The name of the current module, of which the main source file
500 /// is a part. If CompilingModule is set, we are compiling the interface
501 /// of this module, otherwise we are compiling an implementation file of
502 /// it. This starts as ModuleName in case -fmodule-name is provided and
503 /// changes during compilation to reflect the current module.
504 std::string CurrentModule;
505
506 /// The names of any features to enable in module 'requires' decls
507 /// in addition to the hard-coded list in Module.cpp and the target features.
508 ///
509 /// This list is sorted.
510 std::vector<std::string> ModuleFeatures;
511
512 /// Options for parsing comments.
514
515 /// A list of all -fno-builtin-* function names (e.g., memset).
516 std::vector<std::string> NoBuiltinFuncs;
517
518 /// A prefix map for __FILE__, __BASE_FILE__ and __builtin_FILE().
519 std::map<std::string, std::string, std::greater<std::string>> MacroPrefixMap;
520
521 /// Triples of the OpenMP targets that the host code codegen should
522 /// take into account in order to generate accurate offloading descriptors.
523 std::vector<llvm::Triple> OMPTargetTriples;
524
525 /// Name of the IR file that contains the result of the OpenMP target
526 /// host code generation.
527 std::string OMPHostIRFile;
528
529 /// The user provided compilation unit ID, if non-empty. This is used to
530 /// externalize static variables which is needed to support accessing static
531 /// device variables in host code for single source offloading languages
532 /// like CUDA/HIP.
533 std::string CUID;
534
535 /// C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
536 /// This overrides the default ABI used by the target.
537 std::optional<TargetCXXABI::Kind> CXXABI;
538
539 /// Indicates whether the front-end is explicitly told that the
540 /// input is a header file (i.e. -x c-header).
541 bool IsHeaderFile = false;
542
543 /// The default stream kind used for HIP kernel launching.
545
546 /// The seed used by the randomize structure layout feature.
547 std::string RandstructSeed;
548
549 /// Indicates whether to use target's platform-specific file separator when
550 /// __FILE__ macro is used and when concatenating filename with directory or
551 /// to use build environment environment's platform-specific file separator.
552 ///
553 /// The plaform-specific path separator is the backslash(\‍) for Windows and
554 /// forward slash (/) elsewhere.
556
557 // Indicates whether we should keep all nullptr checks for pointers
558 // received as a result of a standard operator new (-fcheck-new)
559 bool CheckNew = false;
560
561 // In OpenACC mode, contains a user provided override for the _OPENACC macro.
562 // This exists so that we can override the macro value and test our incomplete
563 // implementation on real-world examples.
565
566 LangOptions();
567
568 /// Set language defaults for the given input language and
569 /// language standard in the given LangOptions object.
570 ///
571 /// \param Opts - The LangOptions object to set up.
572 /// \param Lang - The input language.
573 /// \param T - The target triple.
574 /// \param Includes - If the language requires extra headers to be implicitly
575 /// included, they will be appended to this list.
576 /// \param LangStd - The input language standard.
577 static void
578 setLangDefaults(LangOptions &Opts, Language Lang, const llvm::Triple &T,
579 std::vector<std::string> &Includes,
581
582 // Define accessors/mutators for language options of enumeration type.
583#define LANGOPT(Name, Bits, Default, Description)
584#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
585 Type get##Name() const { return static_cast<Type>(Name); } \
586 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
587#include "clang/Basic/LangOptions.def"
588
589 /// Are we compiling a module?
590 bool isCompilingModule() const {
591 return getCompilingModule() != CMK_None;
592 }
593
594 /// Are we compiling a module implementation?
596 return !isCompilingModule() && !ModuleName.empty();
597 }
598
599 /// Do we need to track the owning module for a local declaration?
601 return isCompilingModule() || ModulesLocalVisibility;
602 }
603
605 return getSignedOverflowBehavior() == SOB_Defined;
606 }
607
610 !ObjCSubscriptingLegacyRuntime;
611 }
612
613 bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
614 return MSCompatibilityVersion >= MajorVersion * 100000U;
615 }
616
617 /// Reset all of the options that are not considered when building a
618 /// module.
620
621 /// Is this a libc/libm function that is no longer recognized as a
622 /// builtin because a -fno-builtin-* option has been specified?
623 bool isNoBuiltinFunc(StringRef Name) const;
624
625 /// True if any ObjC types may have non-trivial lifetime qualifiers.
627 return ObjCAutoRefCount || ObjCWeak;
628 }
629
631 return ConvergentFunctions;
632 }
633
634 /// Return the OpenCL C or C++ version as a VersionTuple.
635 VersionTuple getOpenCLVersionTuple() const;
636
637 /// Return the OpenCL version that kernel language is compatible with
638 unsigned getOpenCLCompatibleVersion() const;
639
640 /// Return the OpenCL C or C++ for OpenCL language name and version
641 /// as a string.
642 std::string getOpenCLVersionString() const;
643
644 /// Returns true if functions without prototypes or functions with an
645 /// identifier list (aka K&R C functions) are not allowed.
647 return CPlusPlus || C23 || DisableKNRFunctions;
648 }
649
650 /// Returns true if implicit function declarations are allowed in the current
651 /// language mode.
653 return !requiresStrictPrototypes() && !OpenCL;
654 }
655
656 /// Returns true if the language supports calling the 'atexit' function.
657 bool hasAtExit() const { return !(OpenMP && OpenMPIsTargetDevice); }
658
659 /// Returns true if implicit int is part of the language requirements.
660 bool isImplicitIntRequired() const { return !CPlusPlus && !C99; }
661
662 /// Returns true if implicit int is supported at all.
663 bool isImplicitIntAllowed() const { return !CPlusPlus && !C23; }
664
665 /// Check if return address signing is enabled.
666 bool hasSignReturnAddress() const {
667 return getSignReturnAddressScope() != SignReturnAddressScopeKind::None;
668 }
669
670 /// Check if return address signing uses AKey.
672 return getSignReturnAddressKey() == SignReturnAddressKeyKind::AKey;
673 }
674
675 /// Check if leaf functions are also signed.
677 return getSignReturnAddressScope() == SignReturnAddressScopeKind::All;
678 }
679
680 bool hasSjLjExceptions() const {
681 return getExceptionHandling() == ExceptionHandlingKind::SjLj;
682 }
683
684 bool hasSEHExceptions() const {
685 return getExceptionHandling() == ExceptionHandlingKind::WinEH;
686 }
687
688 bool hasDWARFExceptions() const {
689 return getExceptionHandling() == ExceptionHandlingKind::DwarfCFI;
690 }
691
692 bool hasWasmExceptions() const {
693 return getExceptionHandling() == ExceptionHandlingKind::Wasm;
694 }
695
696 bool isSYCL() const { return SYCLIsDevice || SYCLIsHost; }
697
699 return getDefaultVisibilityExportMapping() !=
701 }
702
704 return getDefaultVisibilityExportMapping() ==
706 }
707
709 return getDefaultVisibilityExportMapping() ==
711 }
712
714 return getGlobalAllocationFunctionVisibility() !=
716 }
717
719 return getGlobalAllocationFunctionVisibility() ==
721 }
722
724 return getGlobalAllocationFunctionVisibility() ==
726 }
727
729 return getGlobalAllocationFunctionVisibility() ==
731 }
732
733 /// Remap path prefix according to -fmacro-prefix-path option.
734 void remapPathPrefix(SmallVectorImpl<char> &Path) const;
735
737 return RoundingMath ? RoundingMode::Dynamic
738 : RoundingMode::NearestTiesToEven;
739 }
740
742 FPExceptionModeKind EM = getFPExceptionMode();
745 return EM;
746 }
747};
748
749/// Floating point control options
750class FPOptionsOverride;
752public:
753 // We start by defining the layout.
754 using storage_type = uint32_t;
755
756 using RoundingMode = llvm::RoundingMode;
757
758 static constexpr unsigned StorageBitSize = 8 * sizeof(storage_type);
759
760 // Define a fake option named "First" so that we have a PREVIOUS even for the
761 // real first option.
762 static constexpr storage_type FirstShift = 0, FirstWidth = 0;
763#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
764 static constexpr storage_type NAME##Shift = \
765 PREVIOUS##Shift + PREVIOUS##Width; \
766 static constexpr storage_type NAME##Width = WIDTH; \
767 static constexpr storage_type NAME##Mask = ((1 << NAME##Width) - 1) \
768 << NAME##Shift;
769#include "clang/Basic/FPOptions.def"
770
771 static constexpr storage_type TotalWidth = 0
772#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) +WIDTH
773#include "clang/Basic/FPOptions.def"
774 ;
775 static_assert(TotalWidth <= StorageBitSize, "Too short type for FPOptions");
776
777private:
779
780 FPOptionsOverride getChangesSlow(const FPOptions &Base) const;
781
782public:
784 setFPContractMode(LangOptions::FPM_Off);
785 setConstRoundingMode(RoundingMode::Dynamic);
786 setSpecifiedExceptionMode(LangOptions::FPE_Default);
787 }
788 explicit FPOptions(const LangOptions &LO) {
789 Value = 0;
790 // The language fp contract option FPM_FastHonorPragmas has the same effect
791 // as FPM_Fast in frontend. For simplicity, use FPM_Fast uniformly in
792 // frontend.
793 auto LangOptContractMode = LO.getDefaultFPContractMode();
794 if (LangOptContractMode == LangOptions::FPM_FastHonorPragmas)
795 LangOptContractMode = LangOptions::FPM_Fast;
796 setFPContractMode(LangOptContractMode);
797 setRoundingMath(LO.RoundingMath);
798 setConstRoundingMode(LangOptions::RoundingMode::Dynamic);
799 setSpecifiedExceptionMode(LO.getFPExceptionMode());
800 setAllowFPReassociate(LO.AllowFPReassoc);
801 setNoHonorNaNs(LO.NoHonorNaNs);
802 setNoHonorInfs(LO.NoHonorInfs);
803 setNoSignedZero(LO.NoSignedZero);
804 setAllowReciprocal(LO.AllowRecip);
805 setAllowApproxFunc(LO.ApproxFunc);
806 if (getFPContractMode() == LangOptions::FPM_On &&
807 getRoundingMode() == llvm::RoundingMode::Dynamic &&
809 // If the FP settings are set to the "strict" model, then
810 // FENV access is set to true. (ffp-model=strict)
811 setAllowFEnvAccess(true);
812 else
813 setAllowFEnvAccess(LangOptions::FPM_Off);
814 setComplexRange(LO.getComplexRange());
815 }
816
818 return getFPContractMode() == LangOptions::FPM_On;
819 }
821 setFPContractMode(LangOptions::FPM_On);
822 }
823
825 return getFPContractMode() == LangOptions::FPM_Fast;
826 }
828 setFPContractMode(LangOptions::FPM_Fast);
829 }
830
831 bool isFPConstrained() const {
832 return getRoundingMode() != llvm::RoundingMode::NearestTiesToEven ||
834 getAllowFEnvAccess();
835 }
836
838 RoundingMode RM = getConstRoundingMode();
839 if (RM == RoundingMode::Dynamic) {
840 // C23: 7.6.2p3 If the FE_DYNAMIC mode is specified and FENV_ACCESS is
841 // "off", the translator may assume that the default rounding mode is in
842 // effect.
843 if (!getAllowFEnvAccess() && !getRoundingMath())
844 RM = RoundingMode::NearestTiesToEven;
845 }
846 return RM;
847 }
848
850 LangOptions::FPExceptionModeKind EM = getSpecifiedExceptionMode();
852 if (getAllowFEnvAccess())
854 else
856 }
857 return EM;
858 }
859
860 bool operator==(FPOptions other) const { return Value == other.Value; }
861
862 /// Return the default value of FPOptions that's used when trailing
863 /// storage isn't required.
865
868 FPOptions Opts;
869 Opts.Value = Value;
870 return Opts;
871 }
872
873 /// Return difference with the given option set.
875
876 // We can define most of the accessors automatically:
877#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
878 TYPE get##NAME() const { \
879 return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift); \
880 } \
881 void set##NAME(TYPE value) { \
882 Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift); \
883 }
884#include "clang/Basic/FPOptions.def"
885 LLVM_DUMP_METHOD void dump();
886};
887
888/// Represents difference between two FPOptions values.
889///
890/// The effect of language constructs changing the set of floating point options
891/// is usually a change of some FP properties while leaving others intact. This
892/// class describes such changes by keeping information about what FP options
893/// are overridden.
894///
895/// The integral set of FP options, described by the class FPOptions, may be
896/// represented as a default FP option set, defined by language standard and
897/// command line options, with the overrides introduced by pragmas.
898///
899/// The is implemented as a value of the new FPOptions plus a mask showing which
900/// fields are actually set in it.
903 FPOptions::storage_type OverrideMask = 0;
904
905public:
906 using RoundingMode = llvm::RoundingMode;
907
908 /// The type suitable for storing values of FPOptionsOverride. Must be twice
909 /// as wide as bit size of FPOption.
910 using storage_type = uint64_t;
911 static_assert(sizeof(storage_type) >= 2 * sizeof(FPOptions::storage_type),
912 "Too short type for FPOptionsOverride");
913
914 /// Bit mask selecting bits of OverrideMask in serialized representation of
915 /// FPOptionsOverride.
917 (static_cast<storage_type>(1) << FPOptions::StorageBitSize) - 1;
918
921 : Options(LO), OverrideMask(OverrideMaskBits) {}
923 : Options(FPO), OverrideMask(OverrideMaskBits) {}
925 : Options(FPO), OverrideMask(Mask) {}
926
927 bool requiresTrailingStorage() const { return OverrideMask != 0; }
928
930 setFPContractModeOverride(LangOptions::FPM_On);
931 }
932
934 setFPContractModeOverride(LangOptions::FPM_Fast);
935 }
936
938 setFPContractModeOverride(LangOptions::FPM_Off);
939 }
940
942 setAllowFPReassociateOverride(!Value);
943 setNoHonorNaNsOverride(!Value);
944 setNoHonorInfsOverride(!Value);
945 setNoSignedZeroOverride(!Value);
946 setAllowReciprocalOverride(!Value);
947 setAllowApproxFuncOverride(!Value);
948 setMathErrnoOverride(Value);
949 if (Value)
950 /* Precise mode implies fp_contract=on and disables ffast-math */
952 else
953 /* Precise mode disabled sets fp_contract=fast and enables ffast-math */
955 }
956
958 return (static_cast<storage_type>(Options.getAsOpaqueInt())
960 OverrideMask;
961 }
964 Opts.OverrideMask = I & OverrideMaskBits;
966 return Opts;
967 }
968
971 FPOptions::getFromOpaqueInt((Base.getAsOpaqueInt() & ~OverrideMask) |
972 (Options.getAsOpaqueInt() & OverrideMask));
973 return Result;
974 }
975
977 return applyOverrides(FPOptions(LO));
978 }
979
980 bool operator==(FPOptionsOverride other) const {
981 return Options == other.Options && OverrideMask == other.OverrideMask;
982 }
983 bool operator!=(FPOptionsOverride other) const { return !(*this == other); }
984
985#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
986 bool has##NAME##Override() const { \
987 return OverrideMask & FPOptions::NAME##Mask; \
988 } \
989 TYPE get##NAME##Override() const { \
990 assert(has##NAME##Override()); \
991 return Options.get##NAME(); \
992 } \
993 void clear##NAME##Override() { \
994 /* Clear the actual value so that we don't have spurious differences when \
995 * testing equality. */ \
996 Options.set##NAME(TYPE(0)); \
997 OverrideMask &= ~FPOptions::NAME##Mask; \
998 } \
999 void set##NAME##Override(TYPE value) { \
1000 Options.set##NAME(value); \
1001 OverrideMask |= FPOptions::NAME##Mask; \
1002 }
1003#include "clang/Basic/FPOptions.def"
1004 LLVM_DUMP_METHOD void dump();
1005};
1008 if (Value == Base.Value)
1009 return FPOptionsOverride();
1010 return getChangesSlow(Base);
1011}
1012
1013/// Describes the kind of translation unit being processed.
1015 /// The translation unit is a complete translation unit.
1017
1018 /// The translation unit is a prefix to a translation unit, and is
1019 /// not complete.
1020 TU_Prefix,
1021
1022 /// The translation unit is a clang module.
1024
1025 /// The translation unit is a is a complete translation unit that we might
1026 /// incrementally extend later.
1028};
1029
1030} // namespace clang
1031
1032#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:901
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:933
static FPOptionsOverride getFromOpaqueInt(storage_type I)
Definition: LangOptions.h:962
bool operator!=(FPOptionsOverride other) const
Definition: LangOptions.h:983
FPOptionsOverride(FPOptions FPO)
Definition: LangOptions.h:922
LLVM_DUMP_METHOD void dump()
void setFPPreciseEnabled(bool Value)
Definition: LangOptions.h:941
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:929
FPOptionsOverride(FPOptions FPO, FPOptions::storage_type Mask)
Definition: LangOptions.h:924
FPOptions applyOverrides(FPOptions Base)
Definition: LangOptions.h:969
bool operator==(FPOptionsOverride other) const
Definition: LangOptions.h:980
llvm::RoundingMode RoundingMode
Definition: LangOptions.h:906
static constexpr storage_type OverrideMaskBits
Bit mask selecting bits of OverrideMask in serialized representation of FPOptionsOverride.
Definition: LangOptions.h:916
storage_type getAsOpaqueInt() const
Definition: LangOptions.h:957
FPOptions applyOverrides(const LangOptions &LO)
Definition: LangOptions.h:976
uint64_t storage_type
The type suitable for storing values of FPOptionsOverride.
Definition: LangOptions.h:910
FPOptionsOverride(const LangOptions &LO)
Definition: LangOptions.h:920
bool requiresTrailingStorage() const
Definition: LangOptions.h:927
bool isFPConstrained() const
Definition: LangOptions.h:831
static constexpr storage_type FirstShift
Definition: LangOptions.h:762
FPOptionsOverride getChangesFrom(const FPOptions &Base) const
Return difference with the given option set.
Definition: LangOptions.h:1006
storage_type getAsOpaqueInt() const
Definition: LangOptions.h:866
static constexpr storage_type TotalWidth
Definition: LangOptions.h:771
LangOptions::FPExceptionModeKind getExceptionMode() const
Definition: LangOptions.h:849
FPOptions(const LangOptions &LO)
Definition: LangOptions.h:788
static constexpr storage_type FirstWidth
Definition: LangOptions.h:762
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:820
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:867
bool allowFPContractAcrossStatement() const
Definition: LangOptions.h:824
uint32_t storage_type
Definition: LangOptions.h:754
bool operator==(FPOptions other) const
Definition: LangOptions.h:860
bool allowFPContractWithinStatement() const
Definition: LangOptions.h:817
LLVM_DUMP_METHOD void dump()
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:827
static constexpr unsigned StorageBitSize
Definition: LangOptions.h:758
llvm::RoundingMode RoundingMode
Definition: LangOptions.h:756
RoundingMode getRoundingMode() const
Definition: LangOptions.h:837
Bitfields of LangOptions, split out from LangOptions in order to ensure that this large collection of...
Definition: LangOptions.h:62
@ 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:92
@ CMK_HeaderUnit
Compiling a module header unit.
Definition: LangOptions.h:98
@ CMK_ModuleMap
Compiling a module from a module map.
Definition: LangOptions.h:95
@ CMK_ModuleInterface
Compiling a C++ modules interface unit.
Definition: LangOptions.h:101
ComplexRangeKind
Controls the various implementations for complex multiplication and.
Definition: LangOptions.h:401
@ CX_Full
Implementation of complex division and multiplication using a call to runtime library functions(gener...
Definition: LangOptions.h:407
@ CX_Basic
Implementation of complex division and multiplication using algebraic formulas at source precision.
Definition: LangOptions.h:426
@ CX_Promoted
Implementation of complex division using algebraic formulas at higher precision.
Definition: LangOptions.h:421
@ CX_None
No range rule is enabled.
Definition: LangOptions.h:429
@ CX_Improved
Implementation of complex division offering an improved handling for overflow in intermediate calcula...
Definition: LangOptions.h:412
@ 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:68
@ 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:276
@ FEM_Extended
Use extended type for fp arithmetic.
Definition: LangOptions.h:285
@ FEM_Double
Use the type double for fp arithmetic.
Definition: LangOptions.h:283
@ FEM_Indeterminable
The evaluation method cannot be determined or is inconsistent for this target.
Definition: LangOptions.h:279
@ 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:290
@ FEM_Source
Use the declared type for fp arithmetic.
Definition: LangOptions.h:281
@ 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:296
@ Explicit
map only explicit default visibilities to exported
@ All
map all default visibilities to exported
FPExceptionModeKind
Possible floating point exception behavior.
Definition: LangOptions.h:264
@ FPE_Default
Used internally to represent initial unspecified value.
Definition: LangOptions.h:272
@ FPE_Strict
Strictly preserve the floating-point exception semantics.
Definition: LangOptions.h:270
@ FPE_MayTrap
Transformations do not cause new exceptions but may hide some.
Definition: LangOptions.h:268
@ FPE_Ignore
Assume that floating-point exceptions are masked.
Definition: LangOptions.h:266
@ 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:160
@ Ver6
Attempt to be ABI-compatible with code generated by Clang 6.0.x (SVN r321711).
@ 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:449
bool isSignReturnAddressWithAKey() const
Check if return address signing uses AKey.
Definition: LangOptions.h:671
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:692
std::optional< TargetCXXABI::Kind > CXXABI
C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
Definition: LangOptions.h:537
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:613
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
Definition: LangOptions.h:516
std::string ModuleName
The module currently being compiled as specified by -fmodule-name.
Definition: LangOptions.h:497
std::vector< std::string > XRayNeverInstrumentFiles
Paths to the XRay "never instrument" files specifying which objects (files, functions,...
Definition: LangOptions.h:473
FPExceptionModeKind getDefaultExceptionMode() const
Definition: LangOptions.h:741
bool requiresStrictPrototypes() const
Returns true if functions without prototypes or functions with an identifier list (aka K&R C function...
Definition: LangOptions.h:646
bool isImplicitIntAllowed() const
Returns true if implicit int is supported at all.
Definition: LangOptions.h:663
bool isCompilingModuleImplementation() const
Are we compiling a module implementation?
Definition: LangOptions.h:595
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:484
CoreFoundationABI CFRuntime
Definition: LangOptions.h:486
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:680
bool IsHeaderFile
Indicates whether the front-end is explicitly told that the input is a header file (i....
Definition: LangOptions.h:541
bool hasDefaultVisibilityExportMapping() const
Definition: LangOptions.h:698
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:455
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:513
bool isExplicitDefaultVisibilityExportMapping() const
Definition: LangOptions.h:703
std::vector< std::string > XRayAlwaysInstrumentFiles
Paths to the XRay "always instrument" files specifying which objects (files, functions,...
Definition: LangOptions.h:467
bool hasAtExit() const
Returns true if the language supports calling the 'atexit' function.
Definition: LangOptions.h:657
bool trackLocalOwningModule() const
Do we need to track the owning module for a local declaration?
Definition: LangOptions.h:600
bool isAllDefaultVisibilityExportMapping() const
Definition: LangOptions.h:708
bool isSubscriptPointerArithmetic() const
Definition: LangOptions.h:608
bool UseTargetPathSeparator
Indicates whether to use target's platform-specific file separator when FILE macro is used and when c...
Definition: LangOptions.h:555
bool isSignedOverflowDefined() const
Definition: LangOptions.h:604
bool hasDefaultGlobalAllocationFunctionVisibility() const
Definition: LangOptions.h:718
bool hasGlobalAllocationFunctionVisibility() const
Definition: LangOptions.h:713
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:652
bool hasSignReturnAddress() const
Check if return address signing is enabled.
Definition: LangOptions.h:666
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:688
bool assumeFunctionsAreConvergent() const
Definition: LangOptions.h:630
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
Definition: LangOptions.h:527
bool allowsNonTrivialObjCLifetimeQualifiers() const
True if any ObjC types may have non-trivial lifetime qualifiers.
Definition: LangOptions.h:626
std::string OverflowHandler
The name of the handler function to be called when -ftrapv is specified.
Definition: LangOptions.h:494
bool hasHiddenGlobalAllocationFunctionVisibility() const
Definition: LangOptions.h:728
std::string RandstructSeed
The seed used by the randomize structure layout feature.
Definition: LangOptions.h:547
std::map< std::string, std::string, std::greater< std::string > > MacroPrefixMap
A prefix map for FILE, BASE_FILE and __builtin_FILE().
Definition: LangOptions.h:519
std::vector< std::string > ProfileListFiles
Paths to special case list files specifying which entities (files, functions) should or should not be...
Definition: LangOptions.h:482
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:723
LangStandard::Kind LangStd
The used language standard.
Definition: LangOptions.h:452
RoundingMode getDefaultRoundingMode() const
Definition: LangOptions.h:736
bool isCompilingModule() const
Are we compiling a module?
Definition: LangOptions.h:590
bool isImplicitIntRequired() const
Returns true if implicit int is part of the language requirements.
Definition: LangOptions.h:660
bool hasSEHExceptions() const
Definition: LangOptions.h:684
std::string OpenACCMacroOverride
Definition: LangOptions.h:564
bool isSignReturnAddressScopeAll() const
Check if leaf functions are also signed.
Definition: LangOptions.h:676
bool isSYCL() const
Definition: LangOptions.h:696
std::string ObjCConstantStringClass
Definition: LangOptions.h:488
std::string CUID
The user provided compilation unit ID, if non-empty.
Definition: LangOptions.h:533
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:544
std::vector< std::string > XRayAttrListFiles
Paths to the XRay attribute list files, specifying which objects (files, functions,...
Definition: LangOptions.h:478
bool SanitizeCoverage
Is at least one coverage instrumentation type enabled.
Definition: LangOptions.h:457
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:523
std::vector< std::string > NoSanitizeFiles
Paths to files specifying which objects (files, functions, variables) should not be instrumented.
Definition: LangOptions.h:461
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:504
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:510
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:1013
@ TU_Incremental
The translation unit is a is a complete translation unit that we might incrementally extend later.
Definition: LangOptions.h:1026
@ TU_Complete
The translation unit is a complete translation unit.
Definition: LangOptions.h:1015
@ TU_ClangModule
The translation unit is a clang module.
Definition: LangOptions.h:1022
@ TU_Prefix
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:1019
const FunctionProtoType * T
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:34
Options for controlling comment parsing.