]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Basic/LangOptions.h
MFV r336800: libarchive: Cherry-pick upstream 2c8c83b9
[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 /// \brief 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 <string>
24 #include <vector>
25
26 namespace clang {
27
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 {
31 public:
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"
36
37 protected:
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) \
42   unsigned Name : Bits;
43 #include "clang/Basic/LangOptions.def"
44 };
45
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 {
49 public:
50   typedef clang::Visibility Visibility;
51   
52   enum GCMode { NonGC, GCOnly, HybridGC };
53   enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
54   
55   enum SignedOverflowBehaviorTy {
56     SOB_Undefined,  // Default C standard behavior.
57     SOB_Defined,    // -fwrapv
58     SOB_Trapping    // -ftrapv
59   };
60
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.
66   };
67
68   enum PragmaMSPointersToMembersKind {
69     PPTMK_BestCase,
70     PPTMK_FullGeneralitySingleInheritance,
71     PPTMK_FullGeneralityMultipleInheritance,
72     PPTMK_FullGeneralityVirtualInheritance
73   };
74
75   enum DefaultCallingConvention {
76     DCC_None,
77     DCC_CDecl,
78     DCC_FastCall,
79     DCC_StdCall,
80     DCC_VectorCall,
81     DCC_RegCall
82   };
83
84   enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
85
86   enum MSVCMajorVersion {
87     MSVC2010 = 16,
88     MSVC2012 = 17,
89     MSVC2013 = 18,
90     MSVC2015 = 19
91   };
92
93   enum FPContractModeKind {
94     FPC_Off,        // Form fused FP ops only where result will not be affected.
95     FPC_On,         // Form fused FP ops according to FP_CONTRACT rules.
96     FPC_Fast        // Aggressively fuse FP ops (E.g. FMA).
97   };
98
99 public:
100   /// \brief Set of enabled sanitizers.
101   SanitizerSet Sanitize;
102
103   /// \brief Paths to blacklist files specifying which objects
104   /// (files, functions, variables) should not be instrumented.
105   std::vector<std::string> SanitizerBlacklistFiles;
106
107   /// \brief Paths to the XRay "always instrument" files specifying which
108   /// objects (files, functions, variables) should be imbued with the XRay
109   /// "always instrument" attribute.
110   std::vector<std::string> XRayAlwaysInstrumentFiles;
111
112   /// \brief Paths to the XRay "never instrument" files specifying which
113   /// objects (files, functions, variables) should be imbued with the XRay
114   /// "never instrument" attribute.
115   std::vector<std::string> XRayNeverInstrumentFiles;
116
117   clang::ObjCRuntime ObjCRuntime;
118
119   std::string ObjCConstantStringClass;
120   
121   /// \brief The name of the handler function to be called when -ftrapv is
122   /// specified.
123   ///
124   /// If none is specified, abort (GCC-compatible behaviour).
125   std::string OverflowHandler;
126
127   /// \brief The name of the current module, of which the main source file
128   /// is a part. If CompilingModule is set, we are compiling the interface
129   /// of this module, otherwise we are compiling an implementation file of
130   /// it.
131   std::string CurrentModule;
132
133   /// \brief The names of any features to enable in module 'requires' decls
134   /// in addition to the hard-coded list in Module.cpp and the target features.
135   ///
136   /// This list is sorted.
137   std::vector<std::string> ModuleFeatures;
138
139   /// \brief Options for parsing comments.
140   CommentOptions CommentOpts;
141
142   /// \brief A list of all -fno-builtin-* function names (e.g., memset).
143   std::vector<std::string> NoBuiltinFuncs;
144
145   /// \brief Triples of the OpenMP targets that the host code codegen should
146   /// take into account in order to generate accurate offloading descriptors.
147   std::vector<llvm::Triple> OMPTargetTriples;
148
149   /// \brief Name of the IR file that contains the result of the OpenMP target
150   /// host code generation.
151   std::string OMPHostIRFile;
152
153   /// \brief Indicates whether the front-end is explicitly told that the
154   /// input is a header file (i.e. -x c-header).
155   bool IsHeaderFile;
156
157   LangOptions();
158
159   // Define accessors/mutators for language options of enumeration type.
160 #define LANGOPT(Name, Bits, Default, Description) 
161 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
162   Type get##Name() const { return static_cast<Type>(Name); } \
163   void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }  
164 #include "clang/Basic/LangOptions.def"
165
166   /// Are we compiling a module interface (.cppm or module map)?
167   bool isCompilingModule() const {
168     return getCompilingModule() != CMK_None;
169   }
170
171   /// Do we need to track the owning module for a local declaration?
172   bool trackLocalOwningModule() const {
173     return isCompilingModule() || ModulesLocalVisibility || ModulesTS;
174   }
175
176   bool isSignedOverflowDefined() const {
177     return getSignedOverflowBehavior() == SOB_Defined;
178   }
179   
180   bool isSubscriptPointerArithmetic() const {
181     return ObjCRuntime.isSubscriptPointerArithmetic() &&
182            !ObjCSubscriptingLegacyRuntime;
183   }
184
185   bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
186     return MSCompatibilityVersion >= MajorVersion * 10000000U;
187   }
188
189   /// \brief Reset all of the options that are not considered when building a
190   /// module.
191   void resetNonModularOptions();
192
193   /// \brief Is this a libc/libm function that is no longer recognized as a
194   /// builtin because a -fno-builtin-* option has been specified?
195   bool isNoBuiltinFunc(StringRef Name) const;
196
197   /// \brief True if any ObjC types may have non-trivial lifetime qualifiers.
198   bool allowsNonTrivialObjCLifetimeQualifiers() const {
199     return ObjCAutoRefCount || ObjCWeak;
200   }
201
202   bool assumeFunctionsAreConvergent() const {
203     return (CUDA && CUDAIsDevice) || OpenCL;
204   }
205 };
206
207 /// \brief Floating point control options
208 class FPOptions {
209 public:
210   FPOptions() : fp_contract(LangOptions::FPC_Off) {}
211
212   // Used for serializing.
213   explicit FPOptions(unsigned I)
214       : fp_contract(static_cast<LangOptions::FPContractModeKind>(I)) {}
215
216   explicit FPOptions(const LangOptions &LangOpts)
217       : fp_contract(LangOpts.getDefaultFPContractMode()) {}
218
219   bool allowFPContractWithinStatement() const {
220     return fp_contract == LangOptions::FPC_On;
221   }
222   bool allowFPContractAcrossStatement() const {
223     return fp_contract == LangOptions::FPC_Fast;
224   }
225   void setAllowFPContractWithinStatement() {
226     fp_contract = LangOptions::FPC_On;
227   }
228   void setAllowFPContractAcrossStatement() {
229     fp_contract = LangOptions::FPC_Fast;
230   }
231   void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
232
233   /// Used to serialize this.
234   unsigned getInt() const { return fp_contract; }
235
236 private:
237   /// Adjust BinaryOperator::FPFeatures to match the bit-field size of this.
238   unsigned fp_contract : 2;
239 };
240
241 /// \brief Describes the kind of translation unit being processed.
242 enum TranslationUnitKind {
243   /// \brief The translation unit is a complete translation unit.
244   TU_Complete,
245   /// \brief The translation unit is a prefix to a translation unit, and is
246   /// not complete.
247   TU_Prefix,
248   /// \brief The translation unit is a module.
249   TU_Module
250 };
251   
252 }  // end namespace clang
253
254 #endif