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 /// \brief 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"
28 /// Bitfields of LangOptions, split out from LangOptions in order to ensure that
29 /// this large collection of bitfields is a trivial class type.
30 class LangOptionsBase {
32 // Define simple language options (with no accessors).
33 #define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
34 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
35 #include "clang/Basic/LangOptions.def"
38 // Define language options of enumeration type. These are private, and will
39 // have accessors (below).
40 #define LANGOPT(Name, Bits, Default, Description)
41 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
43 #include "clang/Basic/LangOptions.def"
46 /// \brief Keeps track of the various options that can be
47 /// enabled, which controls the dialect of C or C++ that is accepted.
48 class LangOptions : public LangOptionsBase {
50 typedef clang::Visibility Visibility;
52 enum GCMode { NonGC, GCOnly, HybridGC };
53 enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
55 enum SignedOverflowBehaviorTy {
56 SOB_Undefined, // Default C standard behavior.
57 SOB_Defined, // -fwrapv
58 SOB_Trapping // -ftrapv
61 // FIXME: Unify with TUKind.
62 enum CompilingModuleKind {
63 CMK_None, ///< Not compiling a module interface at all.
64 CMK_ModuleMap, ///< Compiling a module from a module map.
65 CMK_ModuleInterface ///< Compiling a C++ modules TS module interface unit.
68 enum PragmaMSPointersToMembersKind {
70 PPTMK_FullGeneralitySingleInheritance,
71 PPTMK_FullGeneralityMultipleInheritance,
72 PPTMK_FullGeneralityVirtualInheritance
75 enum DefaultCallingConvention {
83 enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
85 enum MSVCMajorVersion {
92 enum FPContractModeKind {
93 FPC_Off, // Form fused FP ops only where result will not be affected.
94 FPC_On, // Form fused FP ops according to FP_CONTRACT rules.
95 FPC_Fast // Aggressively fuse FP ops (E.g. FMA).
99 /// \brief Set of enabled sanitizers.
100 SanitizerSet Sanitize;
102 /// \brief Paths to blacklist files specifying which objects
103 /// (files, functions, variables) should not be instrumented.
104 std::vector<std::string> SanitizerBlacklistFiles;
106 /// \brief Paths to the XRay "always instrument" files specifying which
107 /// objects (files, functions, variables) should be imbued with the XRay
108 /// "always instrument" attribute.
109 std::vector<std::string> XRayAlwaysInstrumentFiles;
111 /// \brief Paths to the XRay "never instrument" files specifying which
112 /// objects (files, functions, variables) should be imbued with the XRay
113 /// "never instrument" attribute.
114 std::vector<std::string> XRayNeverInstrumentFiles;
116 clang::ObjCRuntime ObjCRuntime;
118 std::string ObjCConstantStringClass;
120 /// \brief The name of the handler function to be called when -ftrapv is
123 /// If none is specified, abort (GCC-compatible behaviour).
124 std::string OverflowHandler;
126 /// \brief The name of the current module, of which the main source file
127 /// is a part. If CompilingModule is set, we are compiling the interface
128 /// of this module, otherwise we are compiling an implementation file of
130 std::string CurrentModule;
132 /// \brief The names of any features to enable in module 'requires' decls
133 /// in addition to the hard-coded list in Module.cpp and the target features.
135 /// This list is sorted.
136 std::vector<std::string> ModuleFeatures;
138 /// \brief Options for parsing comments.
139 CommentOptions CommentOpts;
141 /// \brief A list of all -fno-builtin-* function names (e.g., memset).
142 std::vector<std::string> NoBuiltinFuncs;
144 /// \brief Triples of the OpenMP targets that the host code codegen should
145 /// take into account in order to generate accurate offloading descriptors.
146 std::vector<llvm::Triple> OMPTargetTriples;
148 /// \brief Name of the IR file that contains the result of the OpenMP target
149 /// host code generation.
150 std::string OMPHostIRFile;
152 /// \brief Indicates whether the front-end is explicitly told that the
153 /// input is a header file (i.e. -x c-header).
158 // Define accessors/mutators for language options of enumeration type.
159 #define LANGOPT(Name, Bits, Default, Description)
160 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
161 Type get##Name() const { return static_cast<Type>(Name); } \
162 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
163 #include "clang/Basic/LangOptions.def"
165 /// Are we compiling a module interface (.cppm or module map)?
166 bool isCompilingModule() const {
167 return getCompilingModule() != CMK_None;
170 /// Do we need to track the owning module for a local declaration?
171 bool trackLocalOwningModule() const {
172 return isCompilingModule() || ModulesLocalVisibility || ModulesTS;
175 bool isSignedOverflowDefined() const {
176 return getSignedOverflowBehavior() == SOB_Defined;
179 bool isSubscriptPointerArithmetic() const {
180 return ObjCRuntime.isSubscriptPointerArithmetic() &&
181 !ObjCSubscriptingLegacyRuntime;
184 bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
185 return MSCompatibilityVersion >= MajorVersion * 10000000U;
188 /// \brief Reset all of the options that are not considered when building a
190 void resetNonModularOptions();
192 /// \brief Is this a libc/libm function that is no longer recognized as a
193 /// builtin because a -fno-builtin-* option has been specified?
194 bool isNoBuiltinFunc(StringRef Name) const;
196 /// \brief True if any ObjC types may have non-trivial lifetime qualifiers.
197 bool allowsNonTrivialObjCLifetimeQualifiers() const {
198 return ObjCAutoRefCount || ObjCWeak;
202 /// \brief Floating point control options
205 FPOptions() : fp_contract(LangOptions::FPC_Off) {}
207 // Used for serializing.
208 explicit FPOptions(unsigned I)
209 : fp_contract(static_cast<LangOptions::FPContractModeKind>(I)) {}
211 explicit FPOptions(const LangOptions &LangOpts)
212 : fp_contract(LangOpts.getDefaultFPContractMode()) {}
214 bool allowFPContractWithinStatement() const {
215 return fp_contract == LangOptions::FPC_On;
217 bool allowFPContractAcrossStatement() const {
218 return fp_contract == LangOptions::FPC_Fast;
220 void setAllowFPContractWithinStatement() {
221 fp_contract = LangOptions::FPC_On;
223 void setAllowFPContractAcrossStatement() {
224 fp_contract = LangOptions::FPC_Fast;
226 void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
228 /// Used to serialize this.
229 unsigned getInt() const { return fp_contract; }
232 /// Adjust BinaryOperator::FPFeatures to match the bit-field size of this.
233 unsigned fp_contract : 2;
236 /// \brief Describes the kind of translation unit being processed.
237 enum TranslationUnitKind {
238 /// \brief The translation unit is a complete translation unit.
240 /// \brief The translation unit is a prefix to a translation unit, and is
243 /// \brief The translation unit is a module.
247 } // end namespace clang