1 //===- LangOptions.h - C Language Family Language Options -------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 /// \file 11 /// Defines the clang::LangOptions interface. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_CLANG_BASIC_LANGOPTIONS_H 16 #define LLVM_CLANG_BASIC_LANGOPTIONS_H 17 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" 25 #include <string> 26 #include <vector> 27 28 namespace clang { 29 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 { 33 public: 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" 38 39 protected: 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) \ 44 unsigned Name : Bits; 45 #include "clang/Basic/LangOptions.def" 46 }; 47 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 { 51 public: 52 using Visibility = clang::Visibility; 53 54 enum GCMode { NonGC, GCOnly, HybridGC }; 55 enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq }; 56 57 // Automatic variables live on the stack, and when trivial they're usually 58 // uninitialized because it's undefined behavior to use them without 59 // initializing them. 60 enum class TrivialAutoVarInitKind { Uninitialized, Zero, Pattern }; 61 62 enum SignedOverflowBehaviorTy { 63 // Default C standard behavior. 64 SOB_Undefined, 65 66 // -fwrapv 67 SOB_Defined, 68 69 // -ftrapv 70 SOB_Trapping 71 }; 72 73 // FIXME: Unify with TUKind. 74 enum CompilingModuleKind { 75 /// Not compiling a module interface at all. 76 CMK_None, 77 78 /// Compiling a module from a module map. 79 CMK_ModuleMap, 80 81 /// Compiling a module from a list of header files. 82 CMK_HeaderModule, 83 84 /// Compiling a C++ modules TS module interface unit. 85 CMK_ModuleInterface, 86 }; 87 88 enum PragmaMSPointersToMembersKind { 89 PPTMK_BestCase, 90 PPTMK_FullGeneralitySingleInheritance, 91 PPTMK_FullGeneralityMultipleInheritance, 92 PPTMK_FullGeneralityVirtualInheritance 93 }; 94 95 enum DefaultCallingConvention { 96 DCC_None, 97 DCC_CDecl, 98 DCC_FastCall, 99 DCC_StdCall, 100 DCC_VectorCall, 101 DCC_RegCall 102 }; 103 104 enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off }; 105 106 // Corresponds to _MSC_VER 107 enum MSVCMajorVersion { 108 MSVC2010 = 1600, 109 MSVC2012 = 1700, 110 MSVC2013 = 1800, 111 MSVC2015 = 1900, 112 MSVC2017 = 1910, 113 MSVC2017_5 = 1912 114 }; 115 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. 121 Ver3_8, 122 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. 126 Ver4, 127 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. 133 Ver6, 134 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. 139 Ver7, 140 141 /// Conform to the underlying platform's C and C++ ABIs as closely 142 /// as we can. 143 Latest 144 }; 145 146 enum class CoreFoundationABI { 147 /// No interoperability ABI has been specified 148 Unspecified, 149 /// CoreFoundation does not have any language interoperability 150 Standalone, 151 /// Interoperability with the ObjectiveC runtime 152 ObjectiveC, 153 /// Interoperability with the latest known version of the Swift runtime 154 Swift, 155 /// Interoperability with the Swift 5.0 runtime 156 Swift5_0, 157 /// Interoperability with the Swift 4.2 runtime 158 Swift4_2, 159 /// Interoperability with the Swift 4.1 runtime 160 Swift4_1, 161 }; 162 163 enum FPContractModeKind { 164 // Form fused FP ops only where result will not be affected. 165 FPC_Off, 166 167 // Form fused FP ops according to FP_CONTRACT rules. 168 FPC_On, 169 170 // Aggressively fuse FP ops (E.g. FMA). 171 FPC_Fast 172 }; 173 174 // TODO: merge FEnvAccessModeKind and FPContractModeKind 175 enum FEnvAccessModeKind { 176 FEA_Off, 177 178 FEA_On 179 }; 180 181 182 public: 183 /// Set of enabled sanitizers. 184 SanitizerSet Sanitize; 185 186 /// Paths to blacklist files specifying which objects 187 /// (files, functions, variables) should not be instrumented. 188 std::vector<std::string> SanitizerBlacklistFiles; 189 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; 195 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; 201 202 /// Paths to the XRay attribute list files, specifying which objects 203 /// (files, functions, variables) should be imbued with the appropriate XRay 204 /// attribute(s). 205 std::vector<std::string> XRayAttrListFiles; 206 207 clang::ObjCRuntime ObjCRuntime; 208 209 CoreFoundationABI CFRuntime = CoreFoundationABI::Unspecified; 210 211 std::string ObjCConstantStringClass; 212 213 /// The name of the handler function to be called when -ftrapv is 214 /// specified. 215 /// 216 /// If none is specified, abort (GCC-compatible behaviour). 217 std::string OverflowHandler; 218 219 /// The module currently being compiled as speficied by -fmodule-name. 220 std::string ModuleName; 221 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; 228 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. 231 /// 232 /// This list is sorted. 233 std::vector<std::string> ModuleFeatures; 234 235 /// Options for parsing comments. 236 CommentOptions CommentOpts; 237 238 /// A list of all -fno-builtin-* function names (e.g., memset). 239 std::vector<std::string> NoBuiltinFuncs; 240 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; 244 245 /// Name of the IR file that contains the result of the OpenMP target 246 /// host code generation. 247 std::string OMPHostIRFile; 248 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; 252 253 LangOptions(); 254 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" 261 262 /// Are we compiling a module interface (.cppm or module map)? isCompilingModule()263 bool isCompilingModule() const { 264 return getCompilingModule() != CMK_None; 265 } 266 267 /// Do we need to track the owning module for a local declaration? trackLocalOwningModule()268 bool trackLocalOwningModule() const { 269 return isCompilingModule() || ModulesLocalVisibility || ModulesTS; 270 } 271 isSignedOverflowDefined()272 bool isSignedOverflowDefined() const { 273 return getSignedOverflowBehavior() == SOB_Defined; 274 } 275 isSubscriptPointerArithmetic()276 bool isSubscriptPointerArithmetic() const { 277 return ObjCRuntime.isSubscriptPointerArithmetic() && 278 !ObjCSubscriptingLegacyRuntime; 279 } 280 isCompatibleWithMSVC(MSVCMajorVersion MajorVersion)281 bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const { 282 return MSCompatibilityVersion >= MajorVersion * 100000U; 283 } 284 285 /// Reset all of the options that are not considered when building a 286 /// module. 287 void resetNonModularOptions(); 288 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; 292 293 /// True if any ObjC types may have non-trivial lifetime qualifiers. allowsNonTrivialObjCLifetimeQualifiers()294 bool allowsNonTrivialObjCLifetimeQualifiers() const { 295 return ObjCAutoRefCount || ObjCWeak; 296 } 297 assumeFunctionsAreConvergent()298 bool assumeFunctionsAreConvergent() const { 299 return (CUDA && CUDAIsDevice) || OpenCL; 300 } 301 302 /// Return the OpenCL C or C++ version as a VersionTuple. 303 VersionTuple getOpenCLVersionTuple() const; 304 }; 305 306 /// Floating point control options 307 class FPOptions { 308 public: FPOptions()309 FPOptions() : fp_contract(LangOptions::FPC_Off), 310 fenv_access(LangOptions::FEA_Off) {} 311 312 // Used for serializing. FPOptions(unsigned I)313 explicit FPOptions(unsigned I) 314 : fp_contract(static_cast<LangOptions::FPContractModeKind>(I & 3)), 315 fenv_access(static_cast<LangOptions::FEnvAccessModeKind>((I >> 2) & 1)) 316 {} 317 FPOptions(const LangOptions & LangOpts)318 explicit FPOptions(const LangOptions &LangOpts) 319 : fp_contract(LangOpts.getDefaultFPContractMode()), 320 fenv_access(LangOptions::FEA_Off) {} 321 // FIXME: Use getDefaultFEnvAccessMode() when available. 322 allowFPContractWithinStatement()323 bool allowFPContractWithinStatement() const { 324 return fp_contract == LangOptions::FPC_On; 325 } 326 allowFPContractAcrossStatement()327 bool allowFPContractAcrossStatement() const { 328 return fp_contract == LangOptions::FPC_Fast; 329 } 330 setAllowFPContractWithinStatement()331 void setAllowFPContractWithinStatement() { 332 fp_contract = LangOptions::FPC_On; 333 } 334 setAllowFPContractAcrossStatement()335 void setAllowFPContractAcrossStatement() { 336 fp_contract = LangOptions::FPC_Fast; 337 } 338 setDisallowFPContract()339 void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; } 340 allowFEnvAccess()341 bool allowFEnvAccess() const { 342 return fenv_access == LangOptions::FEA_On; 343 } 344 setAllowFEnvAccess()345 void setAllowFEnvAccess() { 346 fenv_access = LangOptions::FEA_On; 347 } 348 setDisallowFEnvAccess()349 void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; } 350 351 /// Used to serialize this. getInt()352 unsigned getInt() const { return fp_contract | (fenv_access << 2); } 353 354 private: 355 /// Adjust BinaryOperator::FPFeatures to match the total bit-field size 356 /// of these two. 357 unsigned fp_contract : 2; 358 unsigned fenv_access : 1; 359 }; 360 361 /// Describes the kind of translation unit being processed. 362 enum TranslationUnitKind { 363 /// The translation unit is a complete translation unit. 364 TU_Complete, 365 366 /// The translation unit is a prefix to a translation unit, and is 367 /// not complete. 368 TU_Prefix, 369 370 /// The translation unit is a module. 371 TU_Module 372 }; 373 374 } // namespace clang 375 376 #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H 377