1 //===- LangOptions.h - C Language Family Language Options -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// Defines the clang::LangOptions interface.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_BASIC_LANGOPTIONS_H
16 #define LLVM_CLANG_BASIC_LANGOPTIONS_H
18 #include "clang/Basic/CommentOptions.h"
19 #include "clang/Basic/LLVM.h"
20 #include "clang/Basic/ObjCRuntime.h"
21 #include "clang/Basic/Sanitizers.h"
22 #include "clang/Basic/Visibility.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/ADT/Triple.h"
30 /// Bitfields of LangOptions, split out from LangOptions in order to ensure that
31 /// this large collection of bitfields is a trivial class type.
32 class LangOptionsBase {
34 // Define simple language options (with no accessors).
35 #define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
36 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
37 #include "clang/Basic/LangOptions.def"
40 // Define language options of enumeration type. These are private, and will
41 // have accessors (below).
42 #define LANGOPT(Name, Bits, Default, Description)
43 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
45 #include "clang/Basic/LangOptions.def"
48 /// Keeps track of the various options that can be
49 /// enabled, which controls the dialect of C or C++ that is accepted.
50 class LangOptions : public LangOptionsBase {
52 using Visibility = clang::Visibility;
54 enum GCMode { NonGC, GCOnly, HybridGC };
55 enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
57 // Automatic variables live on the stack, and when trivial they're usually
58 // uninitialized because it's undefined behavior to use them without
60 enum class TrivialAutoVarInitKind { Uninitialized, Zero, Pattern };
62 enum SignedOverflowBehaviorTy {
63 // Default C standard behavior.
73 // FIXME: Unify with TUKind.
74 enum CompilingModuleKind {
75 /// Not compiling a module interface at all.
78 /// Compiling a module from a module map.
81 /// Compiling a module from a list of header files.
84 /// Compiling a C++ modules TS module interface unit.
88 enum PragmaMSPointersToMembersKind {
90 PPTMK_FullGeneralitySingleInheritance,
91 PPTMK_FullGeneralityMultipleInheritance,
92 PPTMK_FullGeneralityVirtualInheritance
95 enum DefaultCallingConvention {
104 enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
106 // Corresponds to _MSC_VER
107 enum MSVCMajorVersion {
116 /// Clang versions with different platform ABI conformance.
117 enum class ClangABI {
118 /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
119 /// (SVN r257626). This causes <1 x long long> to be passed in an
120 /// integer register instead of an SSE register on x64_64.
123 /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
124 /// (SVN r291814). This causes move operations to be ignored when
125 /// determining whether a class type can be passed or returned directly.
128 /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
129 /// (SVN r321711). This causes determination of whether a type is
130 /// standard-layout to ignore collisions between empty base classes
131 /// and between base classes and member subobjects, which affects
132 /// whether we reuse base class tail padding in some ABIs.
135 /// Attempt to be ABI-compatible with code generated by Clang 7.0.x
136 /// (SVN r338536). This causes alignof (C++) and _Alignof (C11) to be
137 /// compatible with __alignof (i.e., return the preferred alignment)
138 /// rather than returning the required alignment.
141 /// Conform to the underlying platform's C and C++ ABIs as closely
146 enum class CoreFoundationABI {
147 /// No interoperability ABI has been specified
149 /// CoreFoundation does not have any language interoperability
151 /// Interoperability with the ObjectiveC runtime
153 /// Interoperability with the latest known version of the Swift runtime
155 /// Interoperability with the Swift 5.0 runtime
157 /// Interoperability with the Swift 4.2 runtime
159 /// Interoperability with the Swift 4.1 runtime
163 enum FPContractModeKind {
164 // Form fused FP ops only where result will not be affected.
167 // Form fused FP ops according to FP_CONTRACT rules.
170 // Aggressively fuse FP ops (E.g. FMA).
174 // TODO: merge FEnvAccessModeKind and FPContractModeKind
175 enum FEnvAccessModeKind {
183 /// Set of enabled sanitizers.
184 SanitizerSet Sanitize;
186 /// Paths to blacklist files specifying which objects
187 /// (files, functions, variables) should not be instrumented.
188 std::vector<std::string> SanitizerBlacklistFiles;
190 /// Paths to the XRay "always instrument" files specifying which
191 /// objects (files, functions, variables) should be imbued with the XRay
192 /// "always instrument" attribute.
193 /// WARNING: This is a deprecated field and will go away in the future.
194 std::vector<std::string> XRayAlwaysInstrumentFiles;
196 /// Paths to the XRay "never instrument" files specifying which
197 /// objects (files, functions, variables) should be imbued with the XRay
198 /// "never instrument" attribute.
199 /// WARNING: This is a deprecated field and will go away in the future.
200 std::vector<std::string> XRayNeverInstrumentFiles;
202 /// Paths to the XRay attribute list files, specifying which objects
203 /// (files, functions, variables) should be imbued with the appropriate XRay
205 std::vector<std::string> XRayAttrListFiles;
207 clang::ObjCRuntime ObjCRuntime;
209 CoreFoundationABI CFRuntime = CoreFoundationABI::Unspecified;
211 std::string ObjCConstantStringClass;
213 /// The name of the handler function to be called when -ftrapv is
216 /// If none is specified, abort (GCC-compatible behaviour).
217 std::string OverflowHandler;
219 /// The module currently being compiled as speficied by -fmodule-name.
220 std::string ModuleName;
222 /// The name of the current module, of which the main source file
223 /// is a part. If CompilingModule is set, we are compiling the interface
224 /// of this module, otherwise we are compiling an implementation file of
225 /// it. This starts as ModuleName in case -fmodule-name is provided and
226 /// changes during compilation to reflect the current module.
227 std::string CurrentModule;
229 /// The names of any features to enable in module 'requires' decls
230 /// in addition to the hard-coded list in Module.cpp and the target features.
232 /// This list is sorted.
233 std::vector<std::string> ModuleFeatures;
235 /// Options for parsing comments.
236 CommentOptions CommentOpts;
238 /// A list of all -fno-builtin-* function names (e.g., memset).
239 std::vector<std::string> NoBuiltinFuncs;
241 /// Triples of the OpenMP targets that the host code codegen should
242 /// take into account in order to generate accurate offloading descriptors.
243 std::vector<llvm::Triple> OMPTargetTriples;
245 /// Name of the IR file that contains the result of the OpenMP target
246 /// host code generation.
247 std::string OMPHostIRFile;
249 /// Indicates whether the front-end is explicitly told that the
250 /// input is a header file (i.e. -x c-header).
251 bool IsHeaderFile = false;
255 // Define accessors/mutators for language options of enumeration type.
256 #define LANGOPT(Name, Bits, Default, Description)
257 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
258 Type get##Name() const { return static_cast<Type>(Name); } \
259 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
260 #include "clang/Basic/LangOptions.def"
262 /// Are we compiling a module interface (.cppm or module map)?
263 bool isCompilingModule() const {
264 return getCompilingModule() != CMK_None;
267 /// Do we need to track the owning module for a local declaration?
268 bool trackLocalOwningModule() const {
269 return isCompilingModule() || ModulesLocalVisibility || ModulesTS;
272 bool isSignedOverflowDefined() const {
273 return getSignedOverflowBehavior() == SOB_Defined;
276 bool isSubscriptPointerArithmetic() const {
277 return ObjCRuntime.isSubscriptPointerArithmetic() &&
278 !ObjCSubscriptingLegacyRuntime;
281 bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
282 return MSCompatibilityVersion >= MajorVersion * 100000U;
285 /// Reset all of the options that are not considered when building a
287 void resetNonModularOptions();
289 /// Is this a libc/libm function that is no longer recognized as a
290 /// builtin because a -fno-builtin-* option has been specified?
291 bool isNoBuiltinFunc(StringRef Name) const;
293 /// True if any ObjC types may have non-trivial lifetime qualifiers.
294 bool allowsNonTrivialObjCLifetimeQualifiers() const {
295 return ObjCAutoRefCount || ObjCWeak;
298 bool assumeFunctionsAreConvergent() const {
299 return (CUDA && CUDAIsDevice) || OpenCL;
302 /// Return the OpenCL C or C++ version as a VersionTuple.
303 VersionTuple getOpenCLVersionTuple() const;
306 /// Floating point control options
309 FPOptions() : fp_contract(LangOptions::FPC_Off),
310 fenv_access(LangOptions::FEA_Off) {}
312 // Used for serializing.
313 explicit FPOptions(unsigned I)
314 : fp_contract(static_cast<LangOptions::FPContractModeKind>(I & 3)),
315 fenv_access(static_cast<LangOptions::FEnvAccessModeKind>((I >> 2) & 1))
318 explicit FPOptions(const LangOptions &LangOpts)
319 : fp_contract(LangOpts.getDefaultFPContractMode()),
320 fenv_access(LangOptions::FEA_Off) {}
321 // FIXME: Use getDefaultFEnvAccessMode() when available.
323 bool allowFPContractWithinStatement() const {
324 return fp_contract == LangOptions::FPC_On;
327 bool allowFPContractAcrossStatement() const {
328 return fp_contract == LangOptions::FPC_Fast;
331 void setAllowFPContractWithinStatement() {
332 fp_contract = LangOptions::FPC_On;
335 void setAllowFPContractAcrossStatement() {
336 fp_contract = LangOptions::FPC_Fast;
339 void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
341 bool allowFEnvAccess() const {
342 return fenv_access == LangOptions::FEA_On;
345 void setAllowFEnvAccess() {
346 fenv_access = LangOptions::FEA_On;
349 void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; }
351 /// Used to serialize this.
352 unsigned getInt() const { return fp_contract | (fenv_access << 2); }
355 /// Adjust BinaryOperator::FPFeatures to match the total bit-field size
357 unsigned fp_contract : 2;
358 unsigned fenv_access : 1;
361 /// Describes the kind of translation unit being processed.
362 enum TranslationUnitKind {
363 /// The translation unit is a complete translation unit.
366 /// The translation unit is a prefix to a translation unit, and is
370 /// The translation unit is a module.
376 #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H