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