1 //===- LangOptions.h - C Language Family Language Options -------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// Defines the clang::LangOptions interface.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_BASIC_LANGOPTIONS_H
15 #define LLVM_CLANG_BASIC_LANGOPTIONS_H
17 #include "clang/Basic/CommentOptions.h"
18 #include "clang/Basic/LLVM.h"
19 #include "clang/Basic/ObjCRuntime.h"
20 #include "clang/Basic/Sanitizers.h"
21 #include "clang/Basic/Visibility.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/ADT/Triple.h"
29 /// Bitfields of LangOptions, split out from LangOptions in order to ensure that
30 /// this large collection of bitfields is a trivial class type.
31 class LangOptionsBase {
33 // Define simple language options (with no accessors).
34 #define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
35 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
36 #include "clang/Basic/LangOptions.def"
39 // Define language options of enumeration type. These are private, and will
40 // have accessors (below).
41 #define LANGOPT(Name, Bits, Default, Description)
42 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
44 #include "clang/Basic/LangOptions.def"
47 /// In the Microsoft ABI, this controls the placement of virtual displacement
48 /// members used to implement virtual inheritance.
49 enum class MSVtorDispMode { Never, ForVBaseOverride, ForVFTable };
51 /// Keeps track of the various options that can be
52 /// enabled, which controls the dialect of C or C++ that is accepted.
53 class LangOptions : public LangOptionsBase {
55 using Visibility = clang::Visibility;
57 enum GCMode { NonGC, GCOnly, HybridGC };
58 enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
60 // Automatic variables live on the stack, and when trivial they're usually
61 // uninitialized because it's undefined behavior to use them without
63 enum class TrivialAutoVarInitKind { Uninitialized, Zero, Pattern };
65 enum SignedOverflowBehaviorTy {
66 // Default C standard behavior.
76 // FIXME: Unify with TUKind.
77 enum CompilingModuleKind {
78 /// Not compiling a module interface at all.
81 /// Compiling a module from a module map.
84 /// Compiling a module from a list of header files.
87 /// Compiling a C++ modules TS module interface unit.
91 enum PragmaMSPointersToMembersKind {
93 PPTMK_FullGeneralitySingleInheritance,
94 PPTMK_FullGeneralityMultipleInheritance,
95 PPTMK_FullGeneralityVirtualInheritance
98 using MSVtorDispMode = clang::MSVtorDispMode;
100 enum DefaultCallingConvention {
109 enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
111 // Corresponds to _MSC_VER
112 enum MSVCMajorVersion {
122 /// Clang versions with different platform ABI conformance.
123 enum class ClangABI {
124 /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
125 /// (SVN r257626). This causes <1 x long long> to be passed in an
126 /// integer register instead of an SSE register on x64_64.
129 /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
130 /// (SVN r291814). This causes move operations to be ignored when
131 /// determining whether a class type can be passed or returned directly.
134 /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
135 /// (SVN r321711). This causes determination of whether a type is
136 /// standard-layout to ignore collisions between empty base classes
137 /// and between base classes and member subobjects, which affects
138 /// whether we reuse base class tail padding in some ABIs.
141 /// Attempt to be ABI-compatible with code generated by Clang 7.0.x
142 /// (SVN r338536). This causes alignof (C++) and _Alignof (C11) to be
143 /// compatible with __alignof (i.e., return the preferred alignment)
144 /// rather than returning the required alignment.
147 /// Attempt to be ABI-compatible with code generated by Clang 9.0.x
148 /// (SVN r351319). This causes vectors of __int128 to be passed in memory
149 /// instead of passing in multiple scalar registers on x86_64 on Linux and
153 /// Conform to the underlying platform's C and C++ ABIs as closely
158 enum class CoreFoundationABI {
159 /// No interoperability ABI has been specified
161 /// CoreFoundation does not have any language interoperability
163 /// Interoperability with the ObjectiveC runtime
165 /// Interoperability with the latest known version of the Swift runtime
167 /// Interoperability with the Swift 5.0 runtime
169 /// Interoperability with the Swift 4.2 runtime
171 /// Interoperability with the Swift 4.1 runtime
175 enum FPContractModeKind {
176 // Form fused FP ops only where result will not be affected.
179 // Form fused FP ops according to FP_CONTRACT rules.
182 // Aggressively fuse FP ops (E.g. FMA).
186 // TODO: merge FEnvAccessModeKind and FPContractModeKind
187 enum FEnvAccessModeKind {
193 // Values of the following enumerations correspond to metadata arguments
194 // specified for constrained floating-point intrinsics:
195 // http://llvm.org/docs/LangRef.html#constrained-floating-point-intrinsics.
197 /// Possible rounding modes.
198 enum FPRoundingModeKind {
199 /// Rounding to nearest, corresponds to "round.tonearest".
201 /// Rounding toward -Inf, corresponds to "round.downward".
203 /// Rounding toward +Inf, corresponds to "round.upward".
205 /// Rounding toward zero, corresponds to "round.towardzero".
207 /// Is determined by runtime environment, corresponds to "round.dynamic".
211 /// Possible floating point exception behavior.
212 enum FPExceptionModeKind {
213 /// Assume that floating-point exceptions are masked.
215 /// Transformations do not cause new exceptions but may hide some.
217 /// Strictly preserve the floating-point exception semantics.
221 enum class LaxVectorConversionKind {
222 /// Permit no implicit vector bitcasts.
224 /// Permit vector bitcasts between integer vectors with different numbers
225 /// of elements but the same total bit-width.
227 /// Permit vector bitcasts between all vectors with the same total
233 /// Set of enabled sanitizers.
234 SanitizerSet Sanitize;
236 /// Paths to blacklist files specifying which objects
237 /// (files, functions, variables) should not be instrumented.
238 std::vector<std::string> SanitizerBlacklistFiles;
240 /// Paths to the XRay "always instrument" files specifying which
241 /// objects (files, functions, variables) should be imbued with the XRay
242 /// "always instrument" attribute.
243 /// WARNING: This is a deprecated field and will go away in the future.
244 std::vector<std::string> XRayAlwaysInstrumentFiles;
246 /// Paths to the XRay "never instrument" files specifying which
247 /// objects (files, functions, variables) should be imbued with the XRay
248 /// "never instrument" attribute.
249 /// WARNING: This is a deprecated field and will go away in the future.
250 std::vector<std::string> XRayNeverInstrumentFiles;
252 /// Paths to the XRay attribute list files, specifying which objects
253 /// (files, functions, variables) should be imbued with the appropriate XRay
255 std::vector<std::string> XRayAttrListFiles;
257 clang::ObjCRuntime ObjCRuntime;
259 CoreFoundationABI CFRuntime = CoreFoundationABI::Unspecified;
261 std::string ObjCConstantStringClass;
263 /// The name of the handler function to be called when -ftrapv is
266 /// If none is specified, abort (GCC-compatible behaviour).
267 std::string OverflowHandler;
269 /// The module currently being compiled as specified by -fmodule-name.
270 std::string ModuleName;
272 /// The name of the current module, of which the main source file
273 /// is a part. If CompilingModule is set, we are compiling the interface
274 /// of this module, otherwise we are compiling an implementation file of
275 /// it. This starts as ModuleName in case -fmodule-name is provided and
276 /// changes during compilation to reflect the current module.
277 std::string CurrentModule;
279 /// The names of any features to enable in module 'requires' decls
280 /// in addition to the hard-coded list in Module.cpp and the target features.
282 /// This list is sorted.
283 std::vector<std::string> ModuleFeatures;
285 /// Options for parsing comments.
286 CommentOptions CommentOpts;
288 /// A list of all -fno-builtin-* function names (e.g., memset).
289 std::vector<std::string> NoBuiltinFuncs;
291 /// Triples of the OpenMP targets that the host code codegen should
292 /// take into account in order to generate accurate offloading descriptors.
293 std::vector<llvm::Triple> OMPTargetTriples;
295 /// Name of the IR file that contains the result of the OpenMP target
296 /// host code generation.
297 std::string OMPHostIRFile;
299 /// Indicates whether the front-end is explicitly told that the
300 /// input is a header file (i.e. -x c-header).
301 bool IsHeaderFile = false;
305 // Define accessors/mutators for language options of enumeration type.
306 #define LANGOPT(Name, Bits, Default, Description)
307 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
308 Type get##Name() const { return static_cast<Type>(Name); } \
309 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
310 #include "clang/Basic/LangOptions.def"
312 /// Are we compiling a module interface (.cppm or module map)?
313 bool isCompilingModule() const {
314 return getCompilingModule() != CMK_None;
317 /// Do we need to track the owning module for a local declaration?
318 bool trackLocalOwningModule() const {
319 return isCompilingModule() || ModulesLocalVisibility;
322 bool isSignedOverflowDefined() const {
323 return getSignedOverflowBehavior() == SOB_Defined;
326 bool isSubscriptPointerArithmetic() const {
327 return ObjCRuntime.isSubscriptPointerArithmetic() &&
328 !ObjCSubscriptingLegacyRuntime;
331 bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
332 return MSCompatibilityVersion >= MajorVersion * 100000U;
335 /// Reset all of the options that are not considered when building a
337 void resetNonModularOptions();
339 /// Is this a libc/libm function that is no longer recognized as a
340 /// builtin because a -fno-builtin-* option has been specified?
341 bool isNoBuiltinFunc(StringRef Name) const;
343 /// True if any ObjC types may have non-trivial lifetime qualifiers.
344 bool allowsNonTrivialObjCLifetimeQualifiers() const {
345 return ObjCAutoRefCount || ObjCWeak;
348 bool assumeFunctionsAreConvergent() const {
349 return ConvergentFunctions;
352 /// Return the OpenCL C or C++ version as a VersionTuple.
353 VersionTuple getOpenCLVersionTuple() const;
356 /// Floating point control options
359 FPOptions() : fp_contract(LangOptions::FPC_Off),
360 fenv_access(LangOptions::FEA_Off) {}
362 // Used for serializing.
363 explicit FPOptions(unsigned I)
364 : fp_contract(static_cast<LangOptions::FPContractModeKind>(I & 3)),
365 fenv_access(static_cast<LangOptions::FEnvAccessModeKind>((I >> 2) & 1))
368 explicit FPOptions(const LangOptions &LangOpts)
369 : fp_contract(LangOpts.getDefaultFPContractMode()),
370 fenv_access(LangOptions::FEA_Off) {}
371 // FIXME: Use getDefaultFEnvAccessMode() when available.
373 bool allowFPContractWithinStatement() const {
374 return fp_contract == LangOptions::FPC_On;
377 bool allowFPContractAcrossStatement() const {
378 return fp_contract == LangOptions::FPC_Fast;
381 void setAllowFPContractWithinStatement() {
382 fp_contract = LangOptions::FPC_On;
385 void setAllowFPContractAcrossStatement() {
386 fp_contract = LangOptions::FPC_Fast;
389 void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
391 bool allowFEnvAccess() const {
392 return fenv_access == LangOptions::FEA_On;
395 void setAllowFEnvAccess() {
396 fenv_access = LangOptions::FEA_On;
399 void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; }
401 /// Used to serialize this.
402 unsigned getInt() const { return fp_contract | (fenv_access << 2); }
405 /// Adjust BinaryOperator::FPFeatures to match the total bit-field size
407 unsigned fp_contract : 2;
408 unsigned fenv_access : 1;
411 /// Describes the kind of translation unit being processed.
412 enum TranslationUnitKind {
413 /// The translation unit is a complete translation unit.
416 /// The translation unit is a prefix to a translation unit, and is
420 /// The translation unit is a module.
426 #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H