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 module from a list of header files.
78 
79  /// Compiling a C++ modules TS module interface unit.
81  };
82 
87  PPTMK_FullGeneralityVirtualInheritance
88  };
89 
96  DCC_RegCall
97  };
98 
99  enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
100 
102  MSVC2010 = 16,
103  MSVC2012 = 17,
104  MSVC2013 = 18,
105  MSVC2015 = 19
106  };
107 
108  /// Clang versions with different platform ABI conformance.
109  enum class ClangABI {
110  /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
111  /// (SVN r257626). This causes <1 x long long> to be passed in an
112  /// integer register instead of an SSE register on x64_64.
113  Ver3_8,
114 
115  /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
116  /// (SVN r291814). This causes move operations to be ignored when
117  /// determining whether a class type can be passed or returned directly.
118  Ver4,
119 
120  /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
121  /// (SVN r321711). This causes determination of whether a type is
122  /// standard-layout to ignore collisions between empty base classes
123  /// and between base classes and member subobjects, which affects
124  /// whether we reuse base class tail padding in some ABIs.
125  Ver6,
126 
127  /// Attempt to be ABI-compatible with code generated by Clang 7.0.x
128  /// (SVN r338536). This causes alignof (C++) and _Alignof (C11) to be
129  /// compatible with __alignof (i.e., return the preferred alignment)
130  /// rather than returning the required alignment.
131  Ver7,
132 
133  /// Conform to the underlying platform's C and C++ ABIs as closely
134  /// as we can.
135  Latest
136  };
137 
138  enum class CoreFoundationABI {
139  /// No interoperability ABI has been specified
140  Unspecified,
141  /// CoreFoundation does not have any language interoperability
142  Standalone,
143  /// Interoperability with the ObjectiveC runtime
144  ObjectiveC,
145  /// Interoperability with the latest known version of the Swift runtime
146  Swift,
147  /// Interoperability with the Swift 5.0 runtime
148  Swift5_0,
149  /// Interoperability with the Swift 4.2 runtime
150  Swift4_2,
151  /// Interoperability with the Swift 4.1 runtime
152  Swift4_1,
153  };
154 
156  // Form fused FP ops only where result will not be affected.
158 
159  // Form fused FP ops according to FP_CONTRACT rules.
161 
162  // Aggressively fuse FP ops (E.g. FMA).
163  FPC_Fast
164  };
165 
166  // TODO: merge FEnvAccessModeKind and FPContractModeKind
169 
170  FEA_On
171  };
172 
173 
174 public:
175  /// Set of enabled sanitizers.
177 
178  /// Paths to blacklist files specifying which objects
179  /// (files, functions, variables) should not be instrumented.
180  std::vector<std::string> SanitizerBlacklistFiles;
181 
182  /// Paths to the XRay "always instrument" files specifying which
183  /// objects (files, functions, variables) should be imbued with the XRay
184  /// "always instrument" attribute.
185  /// WARNING: This is a deprecated field and will go away in the future.
186  std::vector<std::string> XRayAlwaysInstrumentFiles;
187 
188  /// Paths to the XRay "never instrument" files specifying which
189  /// objects (files, functions, variables) should be imbued with the XRay
190  /// "never instrument" attribute.
191  /// WARNING: This is a deprecated field and will go away in the future.
192  std::vector<std::string> XRayNeverInstrumentFiles;
193 
194  /// Paths to the XRay attribute list files, specifying which objects
195  /// (files, functions, variables) should be imbued with the appropriate XRay
196  /// attribute(s).
197  std::vector<std::string> XRayAttrListFiles;
198 
200 
202 
204 
205  /// The name of the handler function to be called when -ftrapv is
206  /// specified.
207  ///
208  /// If none is specified, abort (GCC-compatible behaviour).
209  std::string OverflowHandler;
210 
211  /// The module currently being compiled as speficied by -fmodule-name.
212  std::string ModuleName;
213 
214  /// The name of the current module, of which the main source file
215  /// is a part. If CompilingModule is set, we are compiling the interface
216  /// of this module, otherwise we are compiling an implementation file of
217  /// it. This starts as ModuleName in case -fmodule-name is provided and
218  /// changes during compilation to reflect the current module.
219  std::string CurrentModule;
220 
221  /// The names of any features to enable in module 'requires' decls
222  /// in addition to the hard-coded list in Module.cpp and the target features.
223  ///
224  /// This list is sorted.
225  std::vector<std::string> ModuleFeatures;
226 
227  /// Options for parsing comments.
229 
230  /// A list of all -fno-builtin-* function names (e.g., memset).
231  std::vector<std::string> NoBuiltinFuncs;
232 
233  /// Triples of the OpenMP targets that the host code codegen should
234  /// take into account in order to generate accurate offloading descriptors.
235  std::vector<llvm::Triple> OMPTargetTriples;
236 
237  /// Name of the IR file that contains the result of the OpenMP target
238  /// host code generation.
239  std::string OMPHostIRFile;
240 
241  /// Indicates whether the front-end is explicitly told that the
242  /// input is a header file (i.e. -x c-header).
243  bool IsHeaderFile = false;
244 
245  LangOptions();
246 
247  // Define accessors/mutators for language options of enumeration type.
248 #define LANGOPT(Name, Bits, Default, Description)
249 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
250  Type get##Name() const { return static_cast<Type>(Name); } \
251  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
252 #include "clang/Basic/LangOptions.def"
253 
254  /// Are we compiling a module interface (.cppm or module map)?
255  bool isCompilingModule() const {
256  return getCompilingModule() != CMK_None;
257  }
258 
259  /// Do we need to track the owning module for a local declaration?
260  bool trackLocalOwningModule() const {
261  return isCompilingModule() || ModulesLocalVisibility || ModulesTS;
262  }
263 
264  bool isSignedOverflowDefined() const {
265  return getSignedOverflowBehavior() == SOB_Defined;
266  }
267 
269  return ObjCRuntime.isSubscriptPointerArithmetic() &&
270  !ObjCSubscriptingLegacyRuntime;
271  }
272 
273  bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
274  return MSCompatibilityVersion >= MajorVersion * 10000000U;
275  }
276 
277  /// Reset all of the options that are not considered when building a
278  /// module.
279  void resetNonModularOptions();
280 
281  /// Is this a libc/libm function that is no longer recognized as a
282  /// builtin because a -fno-builtin-* option has been specified?
283  bool isNoBuiltinFunc(StringRef Name) const;
284 
285  /// True if any ObjC types may have non-trivial lifetime qualifiers.
287  return ObjCAutoRefCount || ObjCWeak;
288  }
289 
291  return (CUDA && CUDAIsDevice) || OpenCL;
292  }
293 
294  /// Return the OpenCL C or C++ version as a VersionTuple.
295  VersionTuple getOpenCLVersionTuple() const;
296 };
297 
298 /// Floating point control options
299 class FPOptions {
300 public:
301  FPOptions() : fp_contract(LangOptions::FPC_Off),
302  fenv_access(LangOptions::FEA_Off) {}
303 
304  // Used for serializing.
305  explicit FPOptions(unsigned I)
306  : fp_contract(static_cast<LangOptions::FPContractModeKind>(I & 3)),
307  fenv_access(static_cast<LangOptions::FEnvAccessModeKind>((I >> 2) & 1))
308  {}
309 
310  explicit FPOptions(const LangOptions &LangOpts)
311  : fp_contract(LangOpts.getDefaultFPContractMode()),
312  fenv_access(LangOptions::FEA_Off) {}
313  // FIXME: Use getDefaultFEnvAccessMode() when available.
314 
316  return fp_contract == LangOptions::FPC_On;
317  }
318 
320  return fp_contract == LangOptions::FPC_Fast;
321  }
322 
324  fp_contract = LangOptions::FPC_On;
325  }
326 
328  fp_contract = LangOptions::FPC_Fast;
329  }
330 
331  void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
332 
333  bool allowFEnvAccess() const {
334  return fenv_access == LangOptions::FEA_On;
335  }
336 
338  fenv_access = LangOptions::FEA_On;
339  }
340 
341  void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; }
342 
343  /// Used to serialize this.
344  unsigned getInt() const { return fp_contract | (fenv_access << 2); }
345 
346 private:
347  /// Adjust BinaryOperator::FPFeatures to match the total bit-field size
348  /// of these two.
349  unsigned fp_contract : 2;
350  unsigned fenv_access : 1;
351 };
352 
353 /// Describes the kind of translation unit being processed.
355  /// The translation unit is a complete translation unit.
357 
358  /// The translation unit is a prefix to a translation unit, and is
359  /// not complete.
361 
362  /// The translation unit is a module.
364 };
365 
366 } // namespace clang
367 
368 #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H
bool isSignedOverflowDefined() const
Definition: LangOptions.h:264
FPOptions(const LangOptions &LangOpts)
Definition: LangOptions.h:310
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:273
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:176
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:360
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:255
Floating point control options.
Definition: LangOptions.h:299
Options for controlling comment parsing.
Compiling a C++ modules TS module interface unit.
Definition: LangOptions.h:80
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:186
bool allowsNonTrivialObjCLifetimeQualifiers() const
True if any ObjC types may have non-trivial lifetime qualifiers.
Definition: LangOptions.h:286
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:197
bool assumeFunctionsAreConvergent() const
Definition: LangOptions.h:290
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Whether values of this type can be null is (explicitly) unspecified.
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:344
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:323
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:225
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:219
ClangABI
Clang versions with different platform ABI conformance.
Definition: LangOptions.h:109
bool allowFEnvAccess() const
Definition: LangOptions.h:333
static bool IsHeaderFile(const std::string &Filename)
bool isSubscriptPointerArithmetic() const
Definition: LangOptions.h:268
bool isSubscriptPointerArithmetic() const
Is subscripting pointer arithmetic?
Definition: ObjCRuntime.h:250
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:228
void setDisallowFPContract()
Definition: LangOptions.h:331
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
Definition: LangOptions.h:239
Defines the clang::CommentOptions interface.
Compiling a module from a list of header files.
Definition: LangOptions.h:77
Not compiling a module interface at all.
Definition: LangOptions.h:71
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:199
bool allowFPContractAcrossStatement() const
Definition: LangOptions.h:319
std::string ModuleName
The module currently being compiled as speficied by -fmodule-name.
Definition: LangOptions.h:212
Dataflow Directional Tag Classes.
std::string OverflowHandler
The name of the handler function to be called when -ftrapv is specified.
Definition: LangOptions.h:209
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:235
void setDisallowFEnvAccess()
Definition: LangOptions.h:341
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:327
FPOptions(unsigned I)
Definition: LangOptions.h:305
bool allowFPContractWithinStatement() const
Definition: LangOptions.h:315
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:192
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
Definition: LangOptions.h:231
Not within a conflict marker.
Definition: Lexer.h:45
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:354
void setAllowFEnvAccess()
Definition: LangOptions.h:337
The translation unit is a complete translation unit.
Definition: LangOptions.h:356
std::vector< std::string > SanitizerBlacklistFiles
Paths to blacklist files specifying which objects (files, functions, variables) should not be instrum...
Definition: LangOptions.h:180
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:260
std::string ObjCConstantStringClass
Definition: LangOptions.h:203
The translation unit is a module.
Definition: LangOptions.h:363