clang  8.0.0svn
LangOptions.h
Go to the documentation of this file.
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 
19 #include "clang/Basic/LLVM.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.
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:
53 
54  enum GCMode { NonGC, GCOnly, HybridGC };
55  enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
56 
58  // Default C standard behavior.
60 
61  // -fwrapv
63 
64  // -ftrapv
65  SOB_Trapping
66  };
67 
68  // FIXME: Unify with TUKind.
70  /// Not compiling a module interface at all.
72 
73  /// Compiling a module from a module map.
75 
76  /// Compiling a C++ modules TS module interface unit.
77  CMK_ModuleInterface
78  };
79 
84  PPTMK_FullGeneralityVirtualInheritance
85  };
86 
93  DCC_RegCall
94  };
95 
96  enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
97 
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 
130  // Form fused FP ops only where result will not be affected.
132 
133  // Form fused FP ops according to FP_CONTRACT rules.
135 
136  // Aggressively fuse FP ops (E.g. FMA).
137  FPC_Fast
138  };
139 
140  // TODO: merge FEnvAccessModeKind and FPContractModeKind
143 
144  FEA_On
145  };
146 
147 
148 public:
149  /// Set of enabled sanitizers.
151 
152  /// Paths to blacklist files specifying which objects
153  /// (files, functions, variables) should not be instrumented.
154  std::vector<std::string> SanitizerBlacklistFiles;
155 
156  /// Paths to the XRay "always instrument" files specifying which
157  /// objects (files, functions, variables) should be imbued with the XRay
158  /// "always instrument" attribute.
159  /// WARNING: This is a deprecated field and will go away in the future.
160  std::vector<std::string> XRayAlwaysInstrumentFiles;
161 
162  /// Paths to the XRay "never instrument" files specifying which
163  /// objects (files, functions, variables) should be imbued with the XRay
164  /// "never instrument" attribute.
165  /// WARNING: This is a deprecated field and will go away in the future.
166  std::vector<std::string> XRayNeverInstrumentFiles;
167 
168  /// Paths to the XRay attribute list files, specifying which objects
169  /// (files, functions, variables) should be imbued with the appropriate XRay
170  /// attribute(s).
171  std::vector<std::string> XRayAttrListFiles;
172 
174 
176 
177  /// The name of the handler function to be called when -ftrapv is
178  /// specified.
179  ///
180  /// If none is specified, abort (GCC-compatible behaviour).
181  std::string OverflowHandler;
182 
183  /// The module currently being compiled as speficied by -fmodule-name.
184  std::string ModuleName;
185 
186  /// The name of the current module, of which the main source file
187  /// is a part. If CompilingModule is set, we are compiling the interface
188  /// of this module, otherwise we are compiling an implementation file of
189  /// it. This starts as ModuleName in case -fmodule-name is provided and
190  /// changes during compilation to reflect the current module.
191  std::string CurrentModule;
192 
193  /// The names of any features to enable in module 'requires' decls
194  /// in addition to the hard-coded list in Module.cpp and the target features.
195  ///
196  /// This list is sorted.
197  std::vector<std::string> ModuleFeatures;
198 
199  /// Options for parsing comments.
201 
202  /// A list of all -fno-builtin-* function names (e.g., memset).
203  std::vector<std::string> NoBuiltinFuncs;
204 
205  /// Triples of the OpenMP targets that the host code codegen should
206  /// take into account in order to generate accurate offloading descriptors.
207  std::vector<llvm::Triple> OMPTargetTriples;
208 
209  /// Name of the IR file that contains the result of the OpenMP target
210  /// host code generation.
211  std::string OMPHostIRFile;
212 
213  /// Indicates whether the front-end is explicitly told that the
214  /// input is a header file (i.e. -x c-header).
215  bool IsHeaderFile = false;
216 
217  LangOptions();
218 
219  // Define accessors/mutators for language options of enumeration type.
220 #define LANGOPT(Name, Bits, Default, Description)
221 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
222  Type get##Name() const { return static_cast<Type>(Name); } \
223  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
224 #include "clang/Basic/LangOptions.def"
225 
226  /// Are we compiling a module interface (.cppm or module map)?
227  bool isCompilingModule() const {
228  return getCompilingModule() != CMK_None;
229  }
230 
231  /// Do we need to track the owning module for a local declaration?
232  bool trackLocalOwningModule() const {
233  return isCompilingModule() || ModulesLocalVisibility || ModulesTS;
234  }
235 
236  bool isSignedOverflowDefined() const {
237  return getSignedOverflowBehavior() == SOB_Defined;
238  }
239 
241  return ObjCRuntime.isSubscriptPointerArithmetic() &&
242  !ObjCSubscriptingLegacyRuntime;
243  }
244 
245  bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
246  return MSCompatibilityVersion >= MajorVersion * 10000000U;
247  }
248 
249  /// Reset all of the options that are not considered when building a
250  /// module.
251  void resetNonModularOptions();
252 
253  /// Is this a libc/libm function that is no longer recognized as a
254  /// builtin because a -fno-builtin-* option has been specified?
255  bool isNoBuiltinFunc(StringRef Name) const;
256 
257  /// True if any ObjC types may have non-trivial lifetime qualifiers.
259  return ObjCAutoRefCount || ObjCWeak;
260  }
261 
263  return (CUDA && CUDAIsDevice) || OpenCL;
264  }
265 
266  /// Return the OpenCL C or C++ version as a VersionTuple.
267  VersionTuple getOpenCLVersionTuple() const;
268 };
269 
270 /// Floating point control options
271 class FPOptions {
272 public:
273  FPOptions() : fp_contract(LangOptions::FPC_Off),
274  fenv_access(LangOptions::FEA_Off) {}
275 
276  // Used for serializing.
277  explicit FPOptions(unsigned I)
278  : fp_contract(static_cast<LangOptions::FPContractModeKind>(I & 3)),
279  fenv_access(static_cast<LangOptions::FEnvAccessModeKind>((I >> 2) & 1))
280  {}
281 
282  explicit FPOptions(const LangOptions &LangOpts)
283  : fp_contract(LangOpts.getDefaultFPContractMode()),
284  fenv_access(LangOptions::FEA_Off) {}
285  // FIXME: Use getDefaultFEnvAccessMode() when available.
286 
288  return fp_contract == LangOptions::FPC_On;
289  }
290 
292  return fp_contract == LangOptions::FPC_Fast;
293  }
294 
296  fp_contract = LangOptions::FPC_On;
297  }
298 
300  fp_contract = LangOptions::FPC_Fast;
301  }
302 
303  void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
304 
305  bool allowFEnvAccess() const {
306  return fenv_access == LangOptions::FEA_On;
307  }
308 
310  fenv_access = LangOptions::FEA_On;
311  }
312 
313  void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; }
314 
315  /// Used to serialize this.
316  unsigned getInt() const { return fp_contract | (fenv_access << 2); }
317 
318 private:
319  /// Adjust BinaryOperator::FPFeatures to match the total bit-field size
320  /// of these two.
321  unsigned fp_contract : 2;
322  unsigned fenv_access : 1;
323 };
324 
325 /// Describes the kind of translation unit being processed.
327  /// The translation unit is a complete translation unit.
329 
330  /// The translation unit is a prefix to a translation unit, and is
331  /// not complete.
333 
334  /// The translation unit is a module.
336 };
337 
338 } // namespace clang
339 
340 #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H
bool isSignedOverflowDefined() const
Definition: LangOptions.h:236
FPOptions(const LangOptions &LangOpts)
Definition: LangOptions.h:282
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:245
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:150
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:332
Defines types useful for describing an Objective-C runtime.
bool isCompilingModule() const
Are we compiling a module interface (.cppm or module map)?
Definition: LangOptions.h:227
Floating point control options.
Definition: LangOptions.h:271
Options for controlling comment parsing.
Defines the clang::SanitizerKind enum.
std::vector< std::string > XRayAlwaysInstrumentFiles
Paths to the XRay "always instrument" files specifying which objects (files, functions, variables) should be imbued with the XRay "always instrument" attribute.
Definition: LangOptions.h:160
bool allowsNonTrivialObjCLifetimeQualifiers() const
True if any ObjC types may have non-trivial lifetime qualifiers.
Definition: LangOptions.h:258
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
Compiling a module from a module map.
Definition: LangOptions.h:74
std::vector< std::string > XRayAttrListFiles
Paths to the XRay attribute list files, specifying which objects (files, functions, variables) should be imbued with the appropriate XRay attribute(s).
Definition: LangOptions.h:171
bool assumeFunctionsAreConvergent() const
Definition: LangOptions.h:262
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:34
unsigned getInt() const
Used to serialize this.
Definition: LangOptions.h:316
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:295
Defines the clang::Visibility enumeration and various utility functions.
std::vector< std::string > ModuleFeatures
The names of any features to enable in module &#39;requires&#39; decls in addition to the hard-coded list in ...
Definition: LangOptions.h:197
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:191
ClangABI
Clang versions with different platform ABI conformance.
Definition: LangOptions.h:106
bool allowFEnvAccess() const
Definition: LangOptions.h:305
static bool IsHeaderFile(const std::string &Filename)
bool isSubscriptPointerArithmetic() const
Definition: LangOptions.h:240
bool isSubscriptPointerArithmetic() const
Is subscripting pointer arithmetic?
Definition: ObjCRuntime.h:250
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:200
void setDisallowFPContract()
Definition: LangOptions.h:303
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
Definition: LangOptions.h:211
Defines the clang::CommentOptions interface.
Not compiling a module interface at all.
Definition: LangOptions.h:71
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:173
bool allowFPContractAcrossStatement() const
Definition: LangOptions.h:291
std::string ModuleName
The module currently being compiled as speficied by -fmodule-name.
Definition: LangOptions.h:184
Dataflow Directional Tag Classes.
std::string OverflowHandler
The name of the handler function to be called when -ftrapv is specified.
Definition: LangOptions.h:181
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:28
std::vector< llvm::Triple > OMPTargetTriples
Triples of the OpenMP targets that the host code codegen should take into account in order to generat...
Definition: LangOptions.h:207
void setDisallowFEnvAccess()
Definition: LangOptions.h:313
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:299
FPOptions(unsigned I)
Definition: LangOptions.h:277
bool allowFPContractWithinStatement() const
Definition: LangOptions.h:287
std::vector< std::string > XRayNeverInstrumentFiles
Paths to the XRay "never instrument" files specifying which objects (files, functions, variables) should be imbued with the XRay "never instrument" attribute.
Definition: LangOptions.h:166
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
Definition: LangOptions.h:203
Not within a conflict marker.
Definition: Lexer.h:45
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:326
void setAllowFEnvAccess()
Definition: LangOptions.h:309
The translation unit is a complete translation unit.
Definition: LangOptions.h:328
std::vector< std::string > SanitizerBlacklistFiles
Paths to blacklist files specifying which objects (files, functions, variables) should not be instrum...
Definition: LangOptions.h:154
Bitfields of LangOptions, split out from LangOptions in order to ensure that this large collection of...
Definition: LangOptions.h:32
bool trackLocalOwningModule() const
Do we need to track the owning module for a local declaration?
Definition: LangOptions.h:232
std::string ObjCConstantStringClass
Definition: LangOptions.h:175
The translation unit is a module.
Definition: LangOptions.h:335