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