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
400
401 // Define simple language options (with no accessors).
402#define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
403#define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
404#include "clang/Basic/LangOptions.def"
405
406protected:
407 // Define language options of enumeration type. These are private, and will
408 // have accessors (below).
409#define LANGOPT(Name, Bits, Default, Description)
410#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
411 LLVM_PREFERRED_TYPE(Type) \
412 unsigned Name : Bits;
413#include "clang/Basic/LangOptions.def"
414};
415
416/// Keeps track of the various options that can be
417/// enabled, which controls the dialect of C or C++ that is accepted.
419public:
420 /// The used language standard.
422
423 /// Set of enabled sanitizers.
425 /// Is at least one coverage instrumentation type enabled.
426 bool SanitizeCoverage = false;
427
428 /// Paths to files specifying which objects
429 /// (files, functions, variables) should not be instrumented.
430 std::vector<std::string> NoSanitizeFiles;
431
432 /// Paths to the XRay "always instrument" files specifying which
433 /// objects (files, functions, variables) should be imbued with the XRay
434 /// "always instrument" attribute.
435 /// WARNING: This is a deprecated field and will go away in the future.
436 std::vector<std::string> XRayAlwaysInstrumentFiles;
437
438 /// Paths to the XRay "never instrument" files specifying which
439 /// objects (files, functions, variables) should be imbued with the XRay
440 /// "never instrument" attribute.
441 /// WARNING: This is a deprecated field and will go away in the future.
442 std::vector<std::string> XRayNeverInstrumentFiles;
443
444 /// Paths to the XRay attribute list files, specifying which objects
445 /// (files, functions, variables) should be imbued with the appropriate XRay
446 /// attribute(s).
447 std::vector<std::string> XRayAttrListFiles;
448
449 /// Paths to special case list files specifying which entities
450 /// (files, functions) should or should not be instrumented.
451 std::vector<std::string> ProfileListFiles;
452
454
456
458
459 /// The name of the handler function to be called when -ftrapv is
460 /// specified.
461 ///
462 /// If none is specified, abort (GCC-compatible behaviour).
463 std::string OverflowHandler;
464
465 /// The module currently being compiled as specified by -fmodule-name.
466 std::string ModuleName;
467
468 /// The name of the current module, of which the main source file
469 /// is a part. If CompilingModule is set, we are compiling the interface
470 /// of this module, otherwise we are compiling an implementation file of
471 /// it. This starts as ModuleName in case -fmodule-name is provided and
472 /// changes during compilation to reflect the current module.
473 std::string CurrentModule;
474
475 /// The names of any features to enable in module 'requires' decls
476 /// in addition to the hard-coded list in Module.cpp and the target features.
477 ///
478 /// This list is sorted.
479 std::vector<std::string> ModuleFeatures;
480
481 /// Options for parsing comments.
483
484 /// A list of all -fno-builtin-* function names (e.g., memset).
485 std::vector<std::string> NoBuiltinFuncs;
486
487 /// A prefix map for __FILE__, __BASE_FILE__ and __builtin_FILE().
488 std::map<std::string, std::string, std::greater<std::string>> MacroPrefixMap;
489
490 /// Triples of the OpenMP targets that the host code codegen should
491 /// take into account in order to generate accurate offloading descriptors.
492 std::vector<llvm::Triple> OMPTargetTriples;
493
494 /// Name of the IR file that contains the result of the OpenMP target
495 /// host code generation.
496 std::string OMPHostIRFile;
497
498 /// The user provided compilation unit ID, if non-empty. This is used to
499 /// externalize static variables which is needed to support accessing static
500 /// device variables in host code for single source offloading languages
501 /// like CUDA/HIP.
502 std::string CUID;
503
504 /// C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
505 /// This overrides the default ABI used by the target.
506 std::optional<TargetCXXABI::Kind> CXXABI;
507
508 /// Indicates whether the front-end is explicitly told that the
509 /// input is a header file (i.e. -x c-header).
510 bool IsHeaderFile = false;
511
512 /// The default stream kind used for HIP kernel launching.
514
515 /// The seed used by the randomize structure layout feature.
516 std::string RandstructSeed;
517
518 /// Indicates whether to use target's platform-specific file separator when
519 /// __FILE__ macro is used and when concatenating filename with directory or
520 /// to use build environment environment's platform-specific file separator.
521 ///
522 /// The plaform-specific path separator is the backslash(\‍) for Windows and
523 /// forward slash (/) elsewhere.
525
526 // Indicates whether we should keep all nullptr checks for pointers
527 // received as a result of a standard operator new (-fcheck-new)
528 bool CheckNew = false;
529
530 // In OpenACC mode, contains a user provided override for the _OPENACC macro.
531 // This exists so that we can override the macro value and test our incomplete
532 // implementation on real-world examples.
534
535 LangOptions();
536
537 /// Set language defaults for the given input language and
538 /// language standard in the given LangOptions object.
539 ///
540 /// \param Opts - The LangOptions object to set up.
541 /// \param Lang - The input language.
542 /// \param T - The target triple.
543 /// \param Includes - If the language requires extra headers to be implicitly
544 /// included, they will be appended to this list.
545 /// \param LangStd - The input language standard.
546 static void
547 setLangDefaults(LangOptions &Opts, Language Lang, const llvm::Triple &T,
548 std::vector<std::string> &Includes,
550
551 // Define accessors/mutators for language options of enumeration type.
552#define LANGOPT(Name, Bits, Default, Description)
553#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
554 Type get##Name() const { return static_cast<Type>(Name); } \
555 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
556#include "clang/Basic/LangOptions.def"
557
558 /// Are we compiling a module?
559 bool isCompilingModule() const {
560 return getCompilingModule() != CMK_None;
561 }
562
563 /// Are we compiling a module implementation?
565 return !isCompilingModule() && !ModuleName.empty();
566 }
567
568 /// Do we need to track the owning module for a local declaration?
570 return isCompilingModule() || ModulesLocalVisibility;
571 }
572
574 return getSignedOverflowBehavior() == SOB_Defined;
575 }
576
579 !ObjCSubscriptingLegacyRuntime;
580 }
581
582 bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
583 return MSCompatibilityVersion >= MajorVersion * 100000U;
584 }
585
586 /// Reset all of the options that are not considered when building a
587 /// module.
589
590 /// Is this a libc/libm function that is no longer recognized as a
591 /// builtin because a -fno-builtin-* option has been specified?
592 bool isNoBuiltinFunc(StringRef Name) const;
593
594 /// True if any ObjC types may have non-trivial lifetime qualifiers.
596 return ObjCAutoRefCount || ObjCWeak;
597 }
598
600 return ConvergentFunctions;
601 }
602
603 /// Return the OpenCL C or C++ version as a VersionTuple.
604 VersionTuple getOpenCLVersionTuple() const;
605
606 /// Return the OpenCL version that kernel language is compatible with
607 unsigned getOpenCLCompatibleVersion() const;
608
609 /// Return the OpenCL C or C++ for OpenCL language name and version
610 /// as a string.
611 std::string getOpenCLVersionString() const;
612
613 /// Returns true if functions without prototypes or functions with an
614 /// identifier list (aka K&R C functions) are not allowed.
616 return CPlusPlus || C23 || DisableKNRFunctions;
617 }
618
619 /// Returns true if implicit function declarations are allowed in the current
620 /// language mode.
622 return !requiresStrictPrototypes() && !OpenCL;
623 }
624
625 /// Returns true if the language supports calling the 'atexit' function.
626 bool hasAtExit() const { return !(OpenMP && OpenMPIsTargetDevice); }
627
628 /// Returns true if implicit int is part of the language requirements.
629 bool isImplicitIntRequired() const { return !CPlusPlus && !C99; }
630
631 /// Returns true if implicit int is supported at all.
632 bool isImplicitIntAllowed() const { return !CPlusPlus && !C23; }
633
634 /// Check if return address signing is enabled.
635 bool hasSignReturnAddress() const {
636 return getSignReturnAddressScope() != SignReturnAddressScopeKind::None;
637 }
638
639 /// Check if return address signing uses AKey.
641 return getSignReturnAddressKey() == SignReturnAddressKeyKind::AKey;
642 }
643
644 /// Check if leaf functions are also signed.
646 return getSignReturnAddressScope() == SignReturnAddressScopeKind::All;
647 }
648
649 bool hasSjLjExceptions() const {
650 return getExceptionHandling() == ExceptionHandlingKind::SjLj;
651 }
652
653 bool hasSEHExceptions() const {
654 return getExceptionHandling() == ExceptionHandlingKind::WinEH;
655 }
656
657 bool hasDWARFExceptions() const {
658 return getExceptionHandling() == ExceptionHandlingKind::DwarfCFI;
659 }
660
661 bool hasWasmExceptions() const {
662 return getExceptionHandling() == ExceptionHandlingKind::Wasm;
663 }
664
665 bool isSYCL() const { return SYCLIsDevice || SYCLIsHost; }
666
668 return getDefaultVisibilityExportMapping() !=
670 }
671
673 return getDefaultVisibilityExportMapping() ==
675 }
676
678 return getDefaultVisibilityExportMapping() ==
680 }
681
683 return getGlobalAllocationFunctionVisibility() !=
685 }
686
688 return getGlobalAllocationFunctionVisibility() ==
690 }
691
693 return getGlobalAllocationFunctionVisibility() ==
695 }
696
698 return getGlobalAllocationFunctionVisibility() ==
700 }
701
702 /// Remap path prefix according to -fmacro-prefix-path option.
703 void remapPathPrefix(SmallVectorImpl<char> &Path) const;
704
706 return RoundingMath ? RoundingMode::Dynamic
707 : RoundingMode::NearestTiesToEven;
708 }
709
711 FPExceptionModeKind EM = getFPExceptionMode();
714 return EM;
715 }
716};
717
718/// Floating point control options
719class FPOptionsOverride;
721public:
722 // We start by defining the layout.
723 using storage_type = uint32_t;
724
725 using RoundingMode = llvm::RoundingMode;
726
727 static constexpr unsigned StorageBitSize = 8 * sizeof(storage_type);
728
729 // Define a fake option named "First" so that we have a PREVIOUS even for the
730 // real first option.
731 static constexpr storage_type FirstShift = 0, FirstWidth = 0;
732#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
733 static constexpr storage_type NAME##Shift = \
734 PREVIOUS##Shift + PREVIOUS##Width; \
735 static constexpr storage_type NAME##Width = WIDTH; \
736 static constexpr storage_type NAME##Mask = ((1 << NAME##Width) - 1) \
737 << NAME##Shift;
738#include "clang/Basic/FPOptions.def"
739
740 static constexpr storage_type TotalWidth = 0
741#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) +WIDTH
742#include "clang/Basic/FPOptions.def"
743 ;
744 static_assert(TotalWidth <= StorageBitSize, "Too short type for FPOptions");
745
746private:
748
749 FPOptionsOverride getChangesSlow(const FPOptions &Base) const;
750
751public:
753 setFPContractMode(LangOptions::FPM_Off);
754 setConstRoundingMode(RoundingMode::Dynamic);
755 setSpecifiedExceptionMode(LangOptions::FPE_Default);
756 }
757 explicit FPOptions(const LangOptions &LO) {
758 Value = 0;
759 // The language fp contract option FPM_FastHonorPragmas has the same effect
760 // as FPM_Fast in frontend. For simplicity, use FPM_Fast uniformly in
761 // frontend.
762 auto LangOptContractMode = LO.getDefaultFPContractMode();
763 if (LangOptContractMode == LangOptions::FPM_FastHonorPragmas)
764 LangOptContractMode = LangOptions::FPM_Fast;
765 setFPContractMode(LangOptContractMode);
766 setRoundingMath(LO.RoundingMath);
767 setConstRoundingMode(LangOptions::RoundingMode::Dynamic);
768 setSpecifiedExceptionMode(LO.getFPExceptionMode());
769 setAllowFPReassociate(LO.AllowFPReassoc);
770 setNoHonorNaNs(LO.NoHonorNaNs);
771 setNoHonorInfs(LO.NoHonorInfs);
772 setNoSignedZero(LO.NoSignedZero);
773 setAllowReciprocal(LO.AllowRecip);
774 setAllowApproxFunc(LO.ApproxFunc);
775 if (getFPContractMode() == LangOptions::FPM_On &&
776 getRoundingMode() == llvm::RoundingMode::Dynamic &&
778 // If the FP settings are set to the "strict" model, then
779 // FENV access is set to true. (ffp-model=strict)
780 setAllowFEnvAccess(true);
781 else
782 setAllowFEnvAccess(LangOptions::FPM_Off);
783 setComplexRange(LO.getComplexRange());
784 }
785
787 return getFPContractMode() == LangOptions::FPM_On;
788 }
790 setFPContractMode(LangOptions::FPM_On);
791 }
792
794 return getFPContractMode() == LangOptions::FPM_Fast;
795 }
797 setFPContractMode(LangOptions::FPM_Fast);
798 }
799
800 bool isFPConstrained() const {
801 return getRoundingMode() != llvm::RoundingMode::NearestTiesToEven ||
803 getAllowFEnvAccess();
804 }
805
807 RoundingMode RM = getConstRoundingMode();
808 if (RM == RoundingMode::Dynamic) {
809 // C23: 7.6.2p3 If the FE_DYNAMIC mode is specified and FENV_ACCESS is
810 // "off", the translator may assume that the default rounding mode is in
811 // effect.
812 if (!getAllowFEnvAccess() && !getRoundingMath())
813 RM = RoundingMode::NearestTiesToEven;
814 }
815 return RM;
816 }
817
819 LangOptions::FPExceptionModeKind EM = getSpecifiedExceptionMode();
821 if (getAllowFEnvAccess())
823 else
825 }
826 return EM;
827 }
828
829 bool operator==(FPOptions other) const { return Value == other.Value; }
830
831 /// Return the default value of FPOptions that's used when trailing
832 /// storage isn't required.
834
837 FPOptions Opts;
838 Opts.Value = Value;
839 return Opts;
840 }
841
842 /// Return difference with the given option set.
844
845 // We can define most of the accessors automatically:
846#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
847 TYPE get##NAME() const { \
848 return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift); \
849 } \
850 void set##NAME(TYPE value) { \
851 Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift); \
852 }
853#include "clang/Basic/FPOptions.def"
854 LLVM_DUMP_METHOD void dump();
855};
856
857/// Represents difference between two FPOptions values.
858///
859/// The effect of language constructs changing the set of floating point options
860/// is usually a change of some FP properties while leaving others intact. This
861/// class describes such changes by keeping information about what FP options
862/// are overridden.
863///
864/// The integral set of FP options, described by the class FPOptions, may be
865/// represented as a default FP option set, defined by language standard and
866/// command line options, with the overrides introduced by pragmas.
867///
868/// The is implemented as a value of the new FPOptions plus a mask showing which
869/// fields are actually set in it.
872 FPOptions::storage_type OverrideMask = 0;
873
874public:
875 using RoundingMode = llvm::RoundingMode;
876
877 /// The type suitable for storing values of FPOptionsOverride. Must be twice
878 /// as wide as bit size of FPOption.
879 using storage_type = uint64_t;
880 static_assert(sizeof(storage_type) >= 2 * sizeof(FPOptions::storage_type),
881 "Too short type for FPOptionsOverride");
882
883 /// Bit mask selecting bits of OverrideMask in serialized representation of
884 /// FPOptionsOverride.
886 (static_cast<storage_type>(1) << FPOptions::StorageBitSize) - 1;
887
890 : Options(LO), OverrideMask(OverrideMaskBits) {}
892 : Options(FPO), OverrideMask(OverrideMaskBits) {}
894 : Options(FPO), OverrideMask(Mask) {}
895
896 bool requiresTrailingStorage() const { return OverrideMask != 0; }
897
899 setFPContractModeOverride(LangOptions::FPM_On);
900 }
901
903 setFPContractModeOverride(LangOptions::FPM_Fast);
904 }
905
907 setFPContractModeOverride(LangOptions::FPM_Off);
908 }
909
911 setAllowFPReassociateOverride(!Value);
912 setNoHonorNaNsOverride(!Value);
913 setNoHonorInfsOverride(!Value);
914 setNoSignedZeroOverride(!Value);
915 setAllowReciprocalOverride(!Value);
916 setAllowApproxFuncOverride(!Value);
917 setMathErrnoOverride(Value);
918 if (Value)
919 /* Precise mode implies fp_contract=on and disables ffast-math */
921 else
922 /* Precise mode disabled sets fp_contract=fast and enables ffast-math */
924 }
925
927 return (static_cast<storage_type>(Options.getAsOpaqueInt())
929 OverrideMask;
930 }
933 Opts.OverrideMask = I & OverrideMaskBits;
935 return Opts;
936 }
937
940 FPOptions::getFromOpaqueInt((Base.getAsOpaqueInt() & ~OverrideMask) |
941 (Options.getAsOpaqueInt() & OverrideMask));
942 return Result;
943 }
944
946 return applyOverrides(FPOptions(LO));
947 }
948
949 bool operator==(FPOptionsOverride other) const {
950 return Options == other.Options && OverrideMask == other.OverrideMask;
951 }
952 bool operator!=(FPOptionsOverride other) const { return !(*this == other); }
953
954#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
955 bool has##NAME##Override() const { \
956 return OverrideMask & FPOptions::NAME##Mask; \
957 } \
958 TYPE get##NAME##Override() const { \
959 assert(has##NAME##Override()); \
960 return Options.get##NAME(); \
961 } \
962 void clear##NAME##Override() { \
963 /* Clear the actual value so that we don't have spurious differences when \
964 * testing equality. */ \
965 Options.set##NAME(TYPE(0)); \
966 OverrideMask &= ~FPOptions::NAME##Mask; \
967 } \
968 void set##NAME##Override(TYPE value) { \
969 Options.set##NAME(value); \
970 OverrideMask |= FPOptions::NAME##Mask; \
971 }
972#include "clang/Basic/FPOptions.def"
973 LLVM_DUMP_METHOD void dump();
974};
977 if (Value == Base.Value)
978 return FPOptionsOverride();
979 return getChangesSlow(Base);
980}
981
982/// Describes the kind of translation unit being processed.
984 /// The translation unit is a complete translation unit.
986
987 /// The translation unit is a prefix to a translation unit, and is
988 /// not complete.
989 TU_Prefix,
990
991 /// The translation unit is a clang module.
993
994 /// The translation unit is a is a complete translation unit that we might
995 /// incrementally extend later.
997};
998
999} // namespace clang
1000
1001#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:870
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:902
static FPOptionsOverride getFromOpaqueInt(storage_type I)
Definition: LangOptions.h:931
bool operator!=(FPOptionsOverride other) const
Definition: LangOptions.h:952
FPOptionsOverride(FPOptions FPO)
Definition: LangOptions.h:891
LLVM_DUMP_METHOD void dump()
void setFPPreciseEnabled(bool Value)
Definition: LangOptions.h:910
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:898
FPOptionsOverride(FPOptions FPO, FPOptions::storage_type Mask)
Definition: LangOptions.h:893
FPOptions applyOverrides(FPOptions Base)
Definition: LangOptions.h:938
bool operator==(FPOptionsOverride other) const
Definition: LangOptions.h:949
llvm::RoundingMode RoundingMode
Definition: LangOptions.h:875
static constexpr storage_type OverrideMaskBits
Bit mask selecting bits of OverrideMask in serialized representation of FPOptionsOverride.
Definition: LangOptions.h:885
storage_type getAsOpaqueInt() const
Definition: LangOptions.h:926
FPOptions applyOverrides(const LangOptions &LO)
Definition: LangOptions.h:945
uint64_t storage_type
The type suitable for storing values of FPOptionsOverride.
Definition: LangOptions.h:879
FPOptionsOverride(const LangOptions &LO)
Definition: LangOptions.h:889
bool requiresTrailingStorage() const
Definition: LangOptions.h:896
bool isFPConstrained() const
Definition: LangOptions.h:800
static constexpr storage_type FirstShift
Definition: LangOptions.h:731
FPOptionsOverride getChangesFrom(const FPOptions &Base) const
Return difference with the given option set.
Definition: LangOptions.h:975
storage_type getAsOpaqueInt() const
Definition: LangOptions.h:835
static constexpr storage_type TotalWidth
Definition: LangOptions.h:740
LangOptions::FPExceptionModeKind getExceptionMode() const
Definition: LangOptions.h:818
FPOptions(const LangOptions &LO)
Definition: LangOptions.h:757
static constexpr storage_type FirstWidth
Definition: LangOptions.h:731
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:789
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:836
bool allowFPContractAcrossStatement() const
Definition: LangOptions.h:793
uint32_t storage_type
Definition: LangOptions.h:723
bool operator==(FPOptions other) const
Definition: LangOptions.h:829
bool allowFPContractWithinStatement() const
Definition: LangOptions.h:786
LLVM_DUMP_METHOD void dump()
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:796
static constexpr unsigned StorageBitSize
Definition: LangOptions.h:727
llvm::RoundingMode RoundingMode
Definition: LangOptions.h:725
RoundingMode getRoundingMode() const
Definition: LangOptions.h:806
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
@ 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:418
bool isSignReturnAddressWithAKey() const
Check if return address signing uses AKey.
Definition: LangOptions.h:640
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:661
std::optional< TargetCXXABI::Kind > CXXABI
C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
Definition: LangOptions.h:506
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:582
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
Definition: LangOptions.h:485
std::string ModuleName
The module currently being compiled as specified by -fmodule-name.
Definition: LangOptions.h:466
std::vector< std::string > XRayNeverInstrumentFiles
Paths to the XRay "never instrument" files specifying which objects (files, functions,...
Definition: LangOptions.h:442
FPExceptionModeKind getDefaultExceptionMode() const
Definition: LangOptions.h:710
bool requiresStrictPrototypes() const
Returns true if functions without prototypes or functions with an identifier list (aka K&R C function...
Definition: LangOptions.h:615
bool isImplicitIntAllowed() const
Returns true if implicit int is supported at all.
Definition: LangOptions.h:632
bool isCompilingModuleImplementation() const
Are we compiling a module implementation?
Definition: LangOptions.h:564
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:453
CoreFoundationABI CFRuntime
Definition: LangOptions.h:455
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:649
bool IsHeaderFile
Indicates whether the front-end is explicitly told that the input is a header file (i....
Definition: LangOptions.h:510
bool hasDefaultVisibilityExportMapping() const
Definition: LangOptions.h:667
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:424
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:482
bool isExplicitDefaultVisibilityExportMapping() const
Definition: LangOptions.h:672
std::vector< std::string > XRayAlwaysInstrumentFiles
Paths to the XRay "always instrument" files specifying which objects (files, functions,...
Definition: LangOptions.h:436
bool hasAtExit() const
Returns true if the language supports calling the 'atexit' function.
Definition: LangOptions.h:626
bool trackLocalOwningModule() const
Do we need to track the owning module for a local declaration?
Definition: LangOptions.h:569
bool isAllDefaultVisibilityExportMapping() const
Definition: LangOptions.h:677
bool isSubscriptPointerArithmetic() const
Definition: LangOptions.h:577
bool UseTargetPathSeparator
Indicates whether to use target's platform-specific file separator when FILE macro is used and when c...
Definition: LangOptions.h:524
bool isSignedOverflowDefined() const
Definition: LangOptions.h:573
bool hasDefaultGlobalAllocationFunctionVisibility() const
Definition: LangOptions.h:687
bool hasGlobalAllocationFunctionVisibility() const
Definition: LangOptions.h:682
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:621
bool hasSignReturnAddress() const
Check if return address signing is enabled.
Definition: LangOptions.h:635
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:657
bool assumeFunctionsAreConvergent() const
Definition: LangOptions.h:599
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
Definition: LangOptions.h:496
bool allowsNonTrivialObjCLifetimeQualifiers() const
True if any ObjC types may have non-trivial lifetime qualifiers.
Definition: LangOptions.h:595
std::string OverflowHandler
The name of the handler function to be called when -ftrapv is specified.
Definition: LangOptions.h:463
bool hasHiddenGlobalAllocationFunctionVisibility() const
Definition: LangOptions.h:697
std::string RandstructSeed
The seed used by the randomize structure layout feature.
Definition: LangOptions.h:516
std::map< std::string, std::string, std::greater< std::string > > MacroPrefixMap
A prefix map for FILE, BASE_FILE and __builtin_FILE().
Definition: LangOptions.h:488
std::vector< std::string > ProfileListFiles
Paths to special case list files specifying which entities (files, functions) should or should not be...
Definition: LangOptions.h:451
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:692
LangStandard::Kind LangStd
The used language standard.
Definition: LangOptions.h:421
RoundingMode getDefaultRoundingMode() const
Definition: LangOptions.h:705
bool isCompilingModule() const
Are we compiling a module?
Definition: LangOptions.h:559
bool isImplicitIntRequired() const
Returns true if implicit int is part of the language requirements.
Definition: LangOptions.h:629
bool hasSEHExceptions() const
Definition: LangOptions.h:653
std::string OpenACCMacroOverride
Definition: LangOptions.h:533
bool isSignReturnAddressScopeAll() const
Check if leaf functions are also signed.
Definition: LangOptions.h:645
bool isSYCL() const
Definition: LangOptions.h:665
std::string ObjCConstantStringClass
Definition: LangOptions.h:457
std::string CUID
The user provided compilation unit ID, if non-empty.
Definition: LangOptions.h:502
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:513
std::vector< std::string > XRayAttrListFiles
Paths to the XRay attribute list files, specifying which objects (files, functions,...
Definition: LangOptions.h:447
bool SanitizeCoverage
Is at least one coverage instrumentation type enabled.
Definition: LangOptions.h:426
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:492
std::vector< std::string > NoSanitizeFiles
Paths to files specifying which objects (files, functions, variables) should not be instrumented.
Definition: LangOptions.h:430
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:473
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:479
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:64
@ CPlusPlus
Definition: LangStandard.h:54
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:982
@ TU_Incremental
The translation unit is a is a complete translation unit that we might incrementally extend later.
Definition: LangOptions.h:995
@ TU_Complete
The translation unit is a complete translation unit.
Definition: LangOptions.h:984
@ TU_ClangModule
The translation unit is a clang module.
Definition: LangOptions.h:991
@ TU_Prefix
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:988
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:34
Options for controlling comment parsing.