]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Basic/LangOptions.h
MFV r342532: 5882 Temporary pool names
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Basic / LangOptions.h
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   enum SignedOverflowBehaviorTy {
58     // Default C standard behavior.
59     SOB_Undefined,
60
61     // -fwrapv
62     SOB_Defined,
63
64     // -ftrapv
65     SOB_Trapping
66   };
67
68   // FIXME: Unify with TUKind.
69   enum CompilingModuleKind {
70     /// Not compiling a module interface at all.
71     CMK_None,
72
73     /// Compiling a module from a module map.
74     CMK_ModuleMap,
75
76     /// Compiling a C++ modules TS module interface unit.
77     CMK_ModuleInterface
78   };
79
80   enum PragmaMSPointersToMembersKind {
81     PPTMK_BestCase,
82     PPTMK_FullGeneralitySingleInheritance,
83     PPTMK_FullGeneralityMultipleInheritance,
84     PPTMK_FullGeneralityVirtualInheritance
85   };
86
87   enum DefaultCallingConvention {
88     DCC_None,
89     DCC_CDecl,
90     DCC_FastCall,
91     DCC_StdCall,
92     DCC_VectorCall,
93     DCC_RegCall
94   };
95
96   enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
97
98   enum MSVCMajorVersion {
99     MSVC2010 = 16,
100     MSVC2012 = 17,
101     MSVC2013 = 18,
102     MSVC2015 = 19
103   };
104
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.
110     Ver3_8,
111
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.
115     Ver4,
116
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.
122     Ver6,
123
124     /// Conform to the underlying platform's C and C++ ABIs as closely
125     /// as we can.
126     Latest
127   };
128
129   enum FPContractModeKind {
130     // Form fused FP ops only where result will not be affected.
131     FPC_Off,
132
133     // Form fused FP ops according to FP_CONTRACT rules.
134     FPC_On,
135
136     // Aggressively fuse FP ops (E.g. FMA).
137     FPC_Fast
138   };
139
140 public:
141   /// Set of enabled sanitizers.
142   SanitizerSet Sanitize;
143
144   /// Paths to blacklist files specifying which objects
145   /// (files, functions, variables) should not be instrumented.
146   std::vector<std::string> SanitizerBlacklistFiles;
147
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;
153
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;
159
160   /// Paths to the XRay attribute list files, specifying which objects
161   /// (files, functions, variables) should be imbued with the appropriate XRay
162   /// attribute(s).
163   std::vector<std::string> XRayAttrListFiles;
164
165   clang::ObjCRuntime ObjCRuntime;
166
167   std::string ObjCConstantStringClass;
168
169   /// The name of the handler function to be called when -ftrapv is
170   /// specified.
171   ///
172   /// If none is specified, abort (GCC-compatible behaviour).
173   std::string OverflowHandler;
174
175   /// The module currently being compiled as speficied by -fmodule-name.
176   std::string ModuleName;
177
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;
184
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.
187   ///
188   /// This list is sorted.
189   std::vector<std::string> ModuleFeatures;
190
191   /// Options for parsing comments.
192   CommentOptions CommentOpts;
193
194   /// A list of all -fno-builtin-* function names (e.g., memset).
195   std::vector<std::string> NoBuiltinFuncs;
196
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;
200
201   /// Name of the IR file that contains the result of the OpenMP target
202   /// host code generation.
203   std::string OMPHostIRFile;
204
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;
208
209   LangOptions();
210
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"
217
218   /// Are we compiling a module interface (.cppm or module map)?
219   bool isCompilingModule() const {
220     return getCompilingModule() != CMK_None;
221   }
222
223   /// Do we need to track the owning module for a local declaration?
224   bool trackLocalOwningModule() const {
225     return isCompilingModule() || ModulesLocalVisibility || ModulesTS;
226   }
227
228   bool isSignedOverflowDefined() const {
229     return getSignedOverflowBehavior() == SOB_Defined;
230   }
231
232   bool isSubscriptPointerArithmetic() const {
233     return ObjCRuntime.isSubscriptPointerArithmetic() &&
234            !ObjCSubscriptingLegacyRuntime;
235   }
236
237   bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
238     return MSCompatibilityVersion >= MajorVersion * 10000000U;
239   }
240
241   /// Reset all of the options that are not considered when building a
242   /// module.
243   void resetNonModularOptions();
244
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;
248
249   /// True if any ObjC types may have non-trivial lifetime qualifiers.
250   bool allowsNonTrivialObjCLifetimeQualifiers() const {
251     return ObjCAutoRefCount || ObjCWeak;
252   }
253
254   bool assumeFunctionsAreConvergent() const {
255     return (CUDA && CUDAIsDevice) || OpenCL;
256   }
257
258   /// Return the OpenCL C or C++ version as a VersionTuple.
259   VersionTuple getOpenCLVersionTuple() const;
260 };
261
262 /// Floating point control options
263 class FPOptions {
264 public:
265   FPOptions() : fp_contract(LangOptions::FPC_Off) {}
266
267   // Used for serializing.
268   explicit FPOptions(unsigned I)
269       : fp_contract(static_cast<LangOptions::FPContractModeKind>(I)) {}
270
271   explicit FPOptions(const LangOptions &LangOpts)
272       : fp_contract(LangOpts.getDefaultFPContractMode()) {}
273
274   bool allowFPContractWithinStatement() const {
275     return fp_contract == LangOptions::FPC_On;
276   }
277
278   bool allowFPContractAcrossStatement() const {
279     return fp_contract == LangOptions::FPC_Fast;
280   }
281
282   void setAllowFPContractWithinStatement() {
283     fp_contract = LangOptions::FPC_On;
284   }
285
286   void setAllowFPContractAcrossStatement() {
287     fp_contract = LangOptions::FPC_Fast;
288   }
289
290   void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
291
292   /// Used to serialize this.
293   unsigned getInt() const { return fp_contract; }
294
295 private:
296   /// Adjust BinaryOperator::FPFeatures to match the bit-field size of this.
297   unsigned fp_contract : 2;
298 };
299
300 /// Describes the kind of translation unit being processed.
301 enum TranslationUnitKind {
302   /// The translation unit is a complete translation unit.
303   TU_Complete,
304
305   /// The translation unit is a prefix to a translation unit, and is
306   /// not complete.
307   TU_Prefix,
308
309   /// The translation unit is a module.
310   TU_Module
311 };
312
313 } // namespace clang
314
315 #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H