clang  9.0.0svn
LangOptions.h
Go to the documentation of this file.
1 //===- LangOptions.h - C Language Family Language Options -------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// \file
10 /// Defines the clang::LangOptions interface.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_BASIC_LANGOPTIONS_H
15 #define LLVM_CLANG_BASIC_LANGOPTIONS_H
16 
18 #include "clang/Basic/LLVM.h"
20 #include "clang/Basic/Sanitizers.h"
21 #include "clang/Basic/Visibility.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/ADT/Triple.h"
24 #include <string>
25 #include <vector>
26 
27 namespace clang {
28 
29 /// Bitfields of LangOptions, split out from LangOptions in order to ensure that
30 /// this large collection of bitfields is a trivial class type.
32 public:
33  // Define simple language options (with no accessors).
34 #define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
35 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
36 #include "clang/Basic/LangOptions.def"
37 
38 protected:
39  // Define language options of enumeration type. These are private, and will
40  // have accessors (below).
41 #define LANGOPT(Name, Bits, Default, Description)
42 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
43  unsigned Name : Bits;
44 #include "clang/Basic/LangOptions.def"
45 };
46 
47 /// Keeps track of the various options that can be
48 /// enabled, which controls the dialect of C or C++ that is accepted.
49 class LangOptions : public LangOptionsBase {
50 public:
52 
53  enum GCMode { NonGC, GCOnly, HybridGC };
54  enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
55 
56  // Automatic variables live on the stack, and when trivial they're usually
57  // uninitialized because it's undefined behavior to use them without
58  // initializing them.
59  enum class TrivialAutoVarInitKind { Uninitialized, Zero, Pattern };
60 
62  // Default C standard behavior.
64 
65  // -fwrapv
67 
68  // -ftrapv
69  SOB_Trapping
70  };
71 
72  // FIXME: Unify with TUKind.
74  /// Not compiling a module interface at all.
76 
77  /// Compiling a module from a module map.
79 
80  /// Compiling a module from a list of header files.
82 
83  /// Compiling a C++ modules TS module interface unit.
85  };
86 
91  PPTMK_FullGeneralityVirtualInheritance
92  };
93 
100  DCC_RegCall
101  };
102 
103  enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
104 
105  // Corresponds to _MSC_VER
107  MSVC2010 = 1600,
108  MSVC2012 = 1700,
109  MSVC2013 = 1800,
110  MSVC2015 = 1900,
111  MSVC2017 = 1910,
112  MSVC2017_5 = 1912,
113  MSVC2017_7 = 1914,
114  };
115 
116  /// Clang versions with different platform ABI conformance.
117  enum class ClangABI {
118  /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
119  /// (SVN r257626). This causes <1 x long long> to be passed in an
120  /// integer register instead of an SSE register on x64_64.
121  Ver3_8,
122 
123  /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
124  /// (SVN r291814). This causes move operations to be ignored when
125  /// determining whether a class type can be passed or returned directly.
126  Ver4,
127 
128  /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
129  /// (SVN r321711). This causes determination of whether a type is
130  /// standard-layout to ignore collisions between empty base classes
131  /// and between base classes and member subobjects, which affects
132  /// whether we reuse base class tail padding in some ABIs.
133  Ver6,
134 
135  /// Attempt to be ABI-compatible with code generated by Clang 7.0.x
136  /// (SVN r338536). This causes alignof (C++) and _Alignof (C11) to be
137  /// compatible with __alignof (i.e., return the preferred alignment)
138  /// rather than returning the required alignment.
139  Ver7,
140 
141  /// Conform to the underlying platform's C and C++ ABIs as closely
142  /// as we can.
143  Latest
144  };
145 
146  enum class CoreFoundationABI {
147  /// No interoperability ABI has been specified
148  Unspecified,
149  /// CoreFoundation does not have any language interoperability
150  Standalone,
151  /// Interoperability with the ObjectiveC runtime
152  ObjectiveC,
153  /// Interoperability with the latest known version of the Swift runtime
154  Swift,
155  /// Interoperability with the Swift 5.0 runtime
156  Swift5_0,
157  /// Interoperability with the Swift 4.2 runtime
158  Swift4_2,
159  /// Interoperability with the Swift 4.1 runtime
160  Swift4_1,
161  };
162 
164  // Form fused FP ops only where result will not be affected.
166 
167  // Form fused FP ops according to FP_CONTRACT rules.
169 
170  // Aggressively fuse FP ops (E.g. FMA).
171  FPC_Fast
172  };
173 
174  // TODO: merge FEnvAccessModeKind and FPContractModeKind
177 
178  FEA_On
179  };
180 
181 
182 public:
183  /// Set of enabled sanitizers.
185 
186  /// Paths to blacklist files specifying which objects
187  /// (files, functions, variables) should not be instrumented.
188  std::vector<std::string> SanitizerBlacklistFiles;
189 
190  /// Paths to the XRay "always instrument" files specifying which
191  /// objects (files, functions, variables) should be imbued with the XRay
192  /// "always instrument" attribute.
193  /// WARNING: This is a deprecated field and will go away in the future.
194  std::vector<std::string> XRayAlwaysInstrumentFiles;
195 
196  /// Paths to the XRay "never instrument" files specifying which
197  /// objects (files, functions, variables) should be imbued with the XRay
198  /// "never instrument" attribute.
199  /// WARNING: This is a deprecated field and will go away in the future.
200  std::vector<std::string> XRayNeverInstrumentFiles;
201 
202  /// Paths to the XRay attribute list files, specifying which objects
203  /// (files, functions, variables) should be imbued with the appropriate XRay
204  /// attribute(s).
205  std::vector<std::string> XRayAttrListFiles;
206 
208 
210 
212 
213  /// The name of the handler function to be called when -ftrapv is
214  /// specified.
215  ///
216  /// If none is specified, abort (GCC-compatible behaviour).
217  std::string OverflowHandler;
218 
219  /// The module currently being compiled as specified by -fmodule-name.
220  std::string ModuleName;
221 
222  /// The name of the current module, of which the main source file
223  /// is a part. If CompilingModule is set, we are compiling the interface
224  /// of this module, otherwise we are compiling an implementation file of
225  /// it. This starts as ModuleName in case -fmodule-name is provided and
226  /// changes during compilation to reflect the current module.
227  std::string CurrentModule;
228 
229  /// The names of any features to enable in module 'requires' decls
230  /// in addition to the hard-coded list in Module.cpp and the target features.
231  ///
232  /// This list is sorted.
233  std::vector<std::string> ModuleFeatures;
234 
235  /// Options for parsing comments.
237 
238  /// A list of all -fno-builtin-* function names (e.g., memset).
239  std::vector<std::string> NoBuiltinFuncs;
240 
241  /// Triples of the OpenMP targets that the host code codegen should
242  /// take into account in order to generate accurate offloading descriptors.
243  std::vector<llvm::Triple> OMPTargetTriples;
244 
245  /// Name of the IR file that contains the result of the OpenMP target
246  /// host code generation.
247  std::string OMPHostIRFile;
248 
249  /// Indicates whether the front-end is explicitly told that the
250  /// input is a header file (i.e. -x c-header).
251  bool IsHeaderFile = false;
252 
253  LangOptions();
254 
255  // Define accessors/mutators for language options of enumeration type.
256 #define LANGOPT(Name, Bits, Default, Description)
257 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
258  Type get##Name() const { return static_cast<Type>(Name); } \
259  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
260 #include "clang/Basic/LangOptions.def"
261 
262  /// Are we compiling a module interface (.cppm or module map)?
263  bool isCompilingModule() const {
264  return getCompilingModule() != CMK_None;
265  }
266 
267  /// Do we need to track the owning module for a local declaration?
268  bool trackLocalOwningModule() const {
269  return isCompilingModule() || ModulesLocalVisibility;
270  }
271 
272  bool isSignedOverflowDefined() const {
273  return getSignedOverflowBehavior() == SOB_Defined;
274  }
275 
277  return ObjCRuntime.isSubscriptPointerArithmetic() &&
278  !ObjCSubscriptingLegacyRuntime;
279  }
280 
281  bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
282  return MSCompatibilityVersion >= MajorVersion * 100000U;
283  }
284 
285  /// Reset all of the options that are not considered when building a
286  /// module.
287  void resetNonModularOptions();
288 
289  /// Is this a libc/libm function that is no longer recognized as a
290  /// builtin because a -fno-builtin-* option has been specified?
291  bool isNoBuiltinFunc(StringRef Name) const;
292 
293  /// True if any ObjC types may have non-trivial lifetime qualifiers.
295  return ObjCAutoRefCount || ObjCWeak;
296  }
297 
299  return (CUDA && CUDAIsDevice) || OpenCL;
300  }
301 
302  /// Return the OpenCL C or C++ version as a VersionTuple.
303  VersionTuple getOpenCLVersionTuple() const;
304 };
305 
306 /// Floating point control options
307 class FPOptions {
308 public:
309  FPOptions() : fp_contract(LangOptions::FPC_Off),
310  fenv_access(LangOptions::FEA_Off) {}
311 
312  // Used for serializing.
313  explicit FPOptions(unsigned I)
314  : fp_contract(static_cast<LangOptions::FPContractModeKind>(I & 3)),
315  fenv_access(static_cast<LangOptions::FEnvAccessModeKind>((I >> 2) & 1))
316  {}
317 
318  explicit FPOptions(const LangOptions &LangOpts)
319  : fp_contract(LangOpts.getDefaultFPContractMode()),
320  fenv_access(LangOptions::FEA_Off) {}
321  // FIXME: Use getDefaultFEnvAccessMode() when available.
322 
324  return fp_contract == LangOptions::FPC_On;
325  }
326 
328  return fp_contract == LangOptions::FPC_Fast;
329  }
330 
332  fp_contract = LangOptions::FPC_On;
333  }
334 
336  fp_contract = LangOptions::FPC_Fast;
337  }
338 
339  void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
340 
341  bool allowFEnvAccess() const {
342  return fenv_access == LangOptions::FEA_On;
343  }
344 
346  fenv_access = LangOptions::FEA_On;
347  }
348 
349  void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; }
350 
351  /// Used to serialize this.
352  unsigned getInt() const { return fp_contract | (fenv_access << 2); }
353 
354 private:
355  /// Adjust BinaryOperator::FPFeatures to match the total bit-field size
356  /// of these two.
357  unsigned fp_contract : 2;
358  unsigned fenv_access : 1;
359 };
360 
361 /// Describes the kind of translation unit being processed.
363  /// The translation unit is a complete translation unit.
365 
366  /// The translation unit is a prefix to a translation unit, and is
367  /// not complete.
369 
370  /// The translation unit is a module.
372 };
373 
374 } // namespace clang
375 
376 #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H
bool isSignedOverflowDefined() const
Definition: LangOptions.h:272
FPOptions(const LangOptions &LangOpts)
Definition: LangOptions.h:318
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:281
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:184
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:368
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:263
Floating point control options.
Definition: LangOptions.h:307
Options for controlling comment parsing.
Compiling a C++ modules TS module interface unit.
Definition: LangOptions.h:84
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:194
bool allowsNonTrivialObjCLifetimeQualifiers() const
True if any ObjC types may have non-trivial lifetime qualifiers.
Definition: LangOptions.h:294
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:49
Compiling a module from a module map.
Definition: LangOptions.h:78
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:205
bool assumeFunctionsAreConvergent() const
Definition: LangOptions.h:298
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:33
unsigned getInt() const
Used to serialize this.
Definition: LangOptions.h:352
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:331
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:233
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:227
ClangABI
Clang versions with different platform ABI conformance.
Definition: LangOptions.h:117
bool allowFEnvAccess() const
Definition: LangOptions.h:341
static bool IsHeaderFile(const std::string &Filename)
bool isSubscriptPointerArithmetic() const
Definition: LangOptions.h:276
bool isSubscriptPointerArithmetic() const
Is subscripting pointer arithmetic?
Definition: ObjCRuntime.h:339
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:236
void setDisallowFPContract()
Definition: LangOptions.h:339
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
Definition: LangOptions.h:247
Defines the clang::CommentOptions interface.
Compiling a module from a list of header files.
Definition: LangOptions.h:81
Not compiling a module interface at all.
Definition: LangOptions.h:75
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:207
bool allowFPContractAcrossStatement() const
Definition: LangOptions.h:327
std::string ModuleName
The module currently being compiled as specified by -fmodule-name.
Definition: LangOptions.h:220
Dataflow Directional Tag Classes.
std::string OverflowHandler
The name of the handler function to be called when -ftrapv is specified.
Definition: LangOptions.h:217
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:27
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:243
void setDisallowFEnvAccess()
Definition: LangOptions.h:349
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:335
FPOptions(unsigned I)
Definition: LangOptions.h:313
bool allowFPContractWithinStatement() const
Definition: LangOptions.h:323
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:200
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
Definition: LangOptions.h:239
Not within a conflict marker.
Definition: Lexer.h:44
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:362
void setAllowFEnvAccess()
Definition: LangOptions.h:345
The translation unit is a complete translation unit.
Definition: LangOptions.h:364
std::vector< std::string > SanitizerBlacklistFiles
Paths to blacklist files specifying which objects (files, functions, variables) should not be instrum...
Definition: LangOptions.h:188
Bitfields of LangOptions, split out from LangOptions in order to ensure that this large collection of...
Definition: LangOptions.h:31
bool trackLocalOwningModule() const
Do we need to track the owning module for a local declaration?
Definition: LangOptions.h:268
std::string ObjCConstantStringClass
Definition: LangOptions.h:211
The translation unit is a module.
Definition: LangOptions.h:371