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 enum class LaxVectorConversionKind {
194 /// Permit no implicit vector bitcasts.
196 /// Permit vector bitcasts between integer vectors with different numbers
197 /// of elements but the same total bit-width.
199 /// Permit vector bitcasts between all vectors with the same total
205 /// Set of enabled sanitizers.
206 SanitizerSet Sanitize;
208 /// Paths to blacklist files specifying which objects
209 /// (files, functions, variables) should not be instrumented.
210 std::vector<std::string> SanitizerBlacklistFiles;
212 /// Paths to the XRay "always instrument" files specifying which
213 /// objects (files, functions, variables) should be imbued with the XRay
214 /// "always instrument" attribute.
215 /// WARNING: This is a deprecated field and will go away in the future.
216 std::vector<std::string> XRayAlwaysInstrumentFiles;
218 /// Paths to the XRay "never instrument" files specifying which
219 /// objects (files, functions, variables) should be imbued with the XRay
220 /// "never instrument" attribute.
221 /// WARNING: This is a deprecated field and will go away in the future.
222 std::vector<std::string> XRayNeverInstrumentFiles;
224 /// Paths to the XRay attribute list files, specifying which objects
225 /// (files, functions, variables) should be imbued with the appropriate XRay
227 std::vector<std::string> XRayAttrListFiles;
229 clang::ObjCRuntime ObjCRuntime;
231 CoreFoundationABI CFRuntime = CoreFoundationABI::Unspecified;
233 std::string ObjCConstantStringClass;
235 /// The name of the handler function to be called when -ftrapv is
238 /// If none is specified, abort (GCC-compatible behaviour).
239 std::string OverflowHandler;
241 /// The module currently being compiled as specified by -fmodule-name.
242 std::string ModuleName;
244 /// The name of the current module, of which the main source file
245 /// is a part. If CompilingModule is set, we are compiling the interface
246 /// of this module, otherwise we are compiling an implementation file of
247 /// it. This starts as ModuleName in case -fmodule-name is provided and
248 /// changes during compilation to reflect the current module.
249 std::string CurrentModule;
251 /// The names of any features to enable in module 'requires' decls
252 /// in addition to the hard-coded list in Module.cpp and the target features.
254 /// This list is sorted.
255 std::vector<std::string> ModuleFeatures;
257 /// Options for parsing comments.
258 CommentOptions CommentOpts;
260 /// A list of all -fno-builtin-* function names (e.g., memset).
261 std::vector<std::string> NoBuiltinFuncs;
263 /// Triples of the OpenMP targets that the host code codegen should
264 /// take into account in order to generate accurate offloading descriptors.
265 std::vector<llvm::Triple> OMPTargetTriples;
267 /// Name of the IR file that contains the result of the OpenMP target
268 /// host code generation.
269 std::string OMPHostIRFile;
271 /// Indicates whether the front-end is explicitly told that the
272 /// input is a header file (i.e. -x c-header).
273 bool IsHeaderFile = false;
277 // Define accessors/mutators for language options of enumeration type.
278 #define LANGOPT(Name, Bits, Default, Description)
279 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
280 Type get##Name() const { return static_cast<Type>(Name); } \
281 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
282 #include "clang/Basic/LangOptions.def"
284 /// Are we compiling a module interface (.cppm or module map)?
285 bool isCompilingModule() const {
286 return getCompilingModule() != CMK_None;
289 /// Do we need to track the owning module for a local declaration?
290 bool trackLocalOwningModule() const {
291 return isCompilingModule() || ModulesLocalVisibility;
294 bool isSignedOverflowDefined() const {
295 return getSignedOverflowBehavior() == SOB_Defined;
298 bool isSubscriptPointerArithmetic() const {
299 return ObjCRuntime.isSubscriptPointerArithmetic() &&
300 !ObjCSubscriptingLegacyRuntime;
303 bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
304 return MSCompatibilityVersion >= MajorVersion * 100000U;
307 /// Reset all of the options that are not considered when building a
309 void resetNonModularOptions();
311 /// Is this a libc/libm function that is no longer recognized as a
312 /// builtin because a -fno-builtin-* option has been specified?
313 bool isNoBuiltinFunc(StringRef Name) const;
315 /// True if any ObjC types may have non-trivial lifetime qualifiers.
316 bool allowsNonTrivialObjCLifetimeQualifiers() const {
317 return ObjCAutoRefCount || ObjCWeak;
320 bool assumeFunctionsAreConvergent() const {
321 return ConvergentFunctions;
324 /// Return the OpenCL C or C++ version as a VersionTuple.
325 VersionTuple getOpenCLVersionTuple() const;
328 /// Floating point control options
331 FPOptions() : fp_contract(LangOptions::FPC_Off),
332 fenv_access(LangOptions::FEA_Off) {}
334 // Used for serializing.
335 explicit FPOptions(unsigned I)
336 : fp_contract(static_cast<LangOptions::FPContractModeKind>(I & 3)),
337 fenv_access(static_cast<LangOptions::FEnvAccessModeKind>((I >> 2) & 1))
340 explicit FPOptions(const LangOptions &LangOpts)
341 : fp_contract(LangOpts.getDefaultFPContractMode()),
342 fenv_access(LangOptions::FEA_Off) {}
343 // FIXME: Use getDefaultFEnvAccessMode() when available.
345 bool allowFPContractWithinStatement() const {
346 return fp_contract == LangOptions::FPC_On;
349 bool allowFPContractAcrossStatement() const {
350 return fp_contract == LangOptions::FPC_Fast;
353 void setAllowFPContractWithinStatement() {
354 fp_contract = LangOptions::FPC_On;
357 void setAllowFPContractAcrossStatement() {
358 fp_contract = LangOptions::FPC_Fast;
361 void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
363 bool allowFEnvAccess() const {
364 return fenv_access == LangOptions::FEA_On;
367 void setAllowFEnvAccess() {
368 fenv_access = LangOptions::FEA_On;
371 void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; }
373 /// Used to serialize this.
374 unsigned getInt() const { return fp_contract | (fenv_access << 2); }
377 /// Adjust BinaryOperator::FPFeatures to match the total bit-field size
379 unsigned fp_contract : 2;
380 unsigned fenv_access : 1;
383 /// Describes the kind of translation unit being processed.
384 enum TranslationUnitKind {
385 /// The translation unit is a complete translation unit.
388 /// The translation unit is a prefix to a translation unit, and is
392 /// The translation unit is a module.
398 #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H