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 enum SignedOverflowBehaviorTy {
58 // Default C standard behavior.
68 // FIXME: Unify with TUKind.
69 enum CompilingModuleKind {
70 /// Not compiling a module interface at all.
73 /// Compiling a module from a module map.
76 /// Compiling a C++ modules TS module interface unit.
80 enum PragmaMSPointersToMembersKind {
82 PPTMK_FullGeneralitySingleInheritance,
83 PPTMK_FullGeneralityMultipleInheritance,
84 PPTMK_FullGeneralityVirtualInheritance
87 enum DefaultCallingConvention {
96 enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
98 enum MSVCMajorVersion {
105 /// Clang versions with different platform ABI conformance.
106 enum class ClangABI {
107 /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
108 /// (SVN r257626). This causes <1 x long long> to be passed in an
109 /// integer register instead of an SSE register on x64_64.
112 /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
113 /// (SVN r291814). This causes move operations to be ignored when
114 /// determining whether a class type can be passed or returned directly.
117 /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
118 /// (SVN r321711). This causes determination of whether a type is
119 /// standard-layout to ignore collisions between empty base classes
120 /// and between base classes and member subobjects, which affects
121 /// whether we reuse base class tail padding in some ABIs.
124 /// Conform to the underlying platform's C and C++ ABIs as closely
129 enum FPContractModeKind {
130 // Form fused FP ops only where result will not be affected.
133 // Form fused FP ops according to FP_CONTRACT rules.
136 // Aggressively fuse FP ops (E.g. FMA).
141 /// Set of enabled sanitizers.
142 SanitizerSet Sanitize;
144 /// Paths to blacklist files specifying which objects
145 /// (files, functions, variables) should not be instrumented.
146 std::vector<std::string> SanitizerBlacklistFiles;
148 /// Paths to the XRay "always instrument" files specifying which
149 /// objects (files, functions, variables) should be imbued with the XRay
150 /// "always instrument" attribute.
151 /// WARNING: This is a deprecated field and will go away in the future.
152 std::vector<std::string> XRayAlwaysInstrumentFiles;
154 /// Paths to the XRay "never instrument" files specifying which
155 /// objects (files, functions, variables) should be imbued with the XRay
156 /// "never instrument" attribute.
157 /// WARNING: This is a deprecated field and will go away in the future.
158 std::vector<std::string> XRayNeverInstrumentFiles;
160 /// Paths to the XRay attribute list files, specifying which objects
161 /// (files, functions, variables) should be imbued with the appropriate XRay
163 std::vector<std::string> XRayAttrListFiles;
165 clang::ObjCRuntime ObjCRuntime;
167 std::string ObjCConstantStringClass;
169 /// The name of the handler function to be called when -ftrapv is
172 /// If none is specified, abort (GCC-compatible behaviour).
173 std::string OverflowHandler;
175 /// The module currently being compiled as speficied by -fmodule-name.
176 std::string ModuleName;
178 /// The name of the current module, of which the main source file
179 /// is a part. If CompilingModule is set, we are compiling the interface
180 /// of this module, otherwise we are compiling an implementation file of
181 /// it. This starts as ModuleName in case -fmodule-name is provided and
182 /// changes during compilation to reflect the current module.
183 std::string CurrentModule;
185 /// The names of any features to enable in module 'requires' decls
186 /// in addition to the hard-coded list in Module.cpp and the target features.
188 /// This list is sorted.
189 std::vector<std::string> ModuleFeatures;
191 /// Options for parsing comments.
192 CommentOptions CommentOpts;
194 /// A list of all -fno-builtin-* function names (e.g., memset).
195 std::vector<std::string> NoBuiltinFuncs;
197 /// Triples of the OpenMP targets that the host code codegen should
198 /// take into account in order to generate accurate offloading descriptors.
199 std::vector<llvm::Triple> OMPTargetTriples;
201 /// Name of the IR file that contains the result of the OpenMP target
202 /// host code generation.
203 std::string OMPHostIRFile;
205 /// Indicates whether the front-end is explicitly told that the
206 /// input is a header file (i.e. -x c-header).
207 bool IsHeaderFile = false;
211 // Define accessors/mutators for language options of enumeration type.
212 #define LANGOPT(Name, Bits, Default, Description)
213 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
214 Type get##Name() const { return static_cast<Type>(Name); } \
215 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
216 #include "clang/Basic/LangOptions.def"
218 /// Are we compiling a module interface (.cppm or module map)?
219 bool isCompilingModule() const {
220 return getCompilingModule() != CMK_None;
223 /// Do we need to track the owning module for a local declaration?
224 bool trackLocalOwningModule() const {
225 return isCompilingModule() || ModulesLocalVisibility || ModulesTS;
228 bool isSignedOverflowDefined() const {
229 return getSignedOverflowBehavior() == SOB_Defined;
232 bool isSubscriptPointerArithmetic() const {
233 return ObjCRuntime.isSubscriptPointerArithmetic() &&
234 !ObjCSubscriptingLegacyRuntime;
237 bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
238 return MSCompatibilityVersion >= MajorVersion * 10000000U;
241 /// Reset all of the options that are not considered when building a
243 void resetNonModularOptions();
245 /// Is this a libc/libm function that is no longer recognized as a
246 /// builtin because a -fno-builtin-* option has been specified?
247 bool isNoBuiltinFunc(StringRef Name) const;
249 /// True if any ObjC types may have non-trivial lifetime qualifiers.
250 bool allowsNonTrivialObjCLifetimeQualifiers() const {
251 return ObjCAutoRefCount || ObjCWeak;
254 bool assumeFunctionsAreConvergent() const {
255 return (CUDA && CUDAIsDevice) || OpenCL;
258 /// Return the OpenCL C or C++ version as a VersionTuple.
259 VersionTuple getOpenCLVersionTuple() const;
262 /// Floating point control options
265 FPOptions() : fp_contract(LangOptions::FPC_Off) {}
267 // Used for serializing.
268 explicit FPOptions(unsigned I)
269 : fp_contract(static_cast<LangOptions::FPContractModeKind>(I)) {}
271 explicit FPOptions(const LangOptions &LangOpts)
272 : fp_contract(LangOpts.getDefaultFPContractMode()) {}
274 bool allowFPContractWithinStatement() const {
275 return fp_contract == LangOptions::FPC_On;
278 bool allowFPContractAcrossStatement() const {
279 return fp_contract == LangOptions::FPC_Fast;
282 void setAllowFPContractWithinStatement() {
283 fp_contract = LangOptions::FPC_On;
286 void setAllowFPContractAcrossStatement() {
287 fp_contract = LangOptions::FPC_Fast;
290 void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
292 /// Used to serialize this.
293 unsigned getInt() const { return fp_contract; }
296 /// Adjust BinaryOperator::FPFeatures to match the bit-field size of this.
297 unsigned fp_contract : 2;
300 /// Describes the kind of translation unit being processed.
301 enum TranslationUnitKind {
302 /// The translation unit is a complete translation unit.
305 /// The translation unit is a prefix to a translation unit, and is
309 /// The translation unit is a module.
315 #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H