clang  10.0.0git
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 /// In the Microsoft ABI, this controls the placement of virtual displacement
48 /// members used to implement virtual inheritance.
50 
51 /// Keeps track of the various options that can be
52 /// enabled, which controls the dialect of C or C++ that is accepted.
53 class LangOptions : public LangOptionsBase {
54 public:
56 
57  enum GCMode { NonGC, GCOnly, HybridGC };
58  enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
59 
60  // Automatic variables live on the stack, and when trivial they're usually
61  // uninitialized because it's undefined behavior to use them without
62  // initializing them.
63  enum class TrivialAutoVarInitKind { Uninitialized, Zero, Pattern };
64 
66  // Default C standard behavior.
68 
69  // -fwrapv
71 
72  // -ftrapv
73  SOB_Trapping
74  };
75 
76  // FIXME: Unify with TUKind.
78  /// Not compiling a module interface at all.
80 
81  /// Compiling a module from a module map.
83 
84  /// Compiling a module from a list of header files.
86 
87  /// Compiling a C++ modules TS module interface unit.
89  };
90 
95  PPTMK_FullGeneralityVirtualInheritance
96  };
97 
99 
106  DCC_RegCall
107  };
108 
109  enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
110 
111  // Corresponds to _MSC_VER
113  MSVC2010 = 1600,
114  MSVC2012 = 1700,
115  MSVC2013 = 1800,
116  MSVC2015 = 1900,
117  MSVC2017 = 1910,
118  MSVC2017_5 = 1912,
119  MSVC2017_7 = 1914,
120  };
121 
122  /// Clang versions with different platform ABI conformance.
123  enum class ClangABI {
124  /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
125  /// (SVN r257626). This causes <1 x long long> to be passed in an
126  /// integer register instead of an SSE register on x64_64.
127  Ver3_8,
128 
129  /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
130  /// (SVN r291814). This causes move operations to be ignored when
131  /// determining whether a class type can be passed or returned directly.
132  Ver4,
133 
134  /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
135  /// (SVN r321711). This causes determination of whether a type is
136  /// standard-layout to ignore collisions between empty base classes
137  /// and between base classes and member subobjects, which affects
138  /// whether we reuse base class tail padding in some ABIs.
139  Ver6,
140 
141  /// Attempt to be ABI-compatible with code generated by Clang 7.0.x
142  /// (SVN r338536). This causes alignof (C++) and _Alignof (C11) to be
143  /// compatible with __alignof (i.e., return the preferred alignment)
144  /// rather than returning the required alignment.
145  Ver7,
146 
147  /// Attempt to be ABI-compatible with code generated by Clang 9.0.x
148  /// (SVN r351319). This causes vectors of __int128 to be passed in memory
149  /// instead of passing in multiple scalar registers on x86_64 on Linux and
150  /// NetBSD.
151  Ver9,
152 
153  /// Conform to the underlying platform's C and C++ ABIs as closely
154  /// as we can.
155  Latest
156  };
157 
158  enum class CoreFoundationABI {
159  /// No interoperability ABI has been specified
160  Unspecified,
161  /// CoreFoundation does not have any language interoperability
162  Standalone,
163  /// Interoperability with the ObjectiveC runtime
164  ObjectiveC,
165  /// Interoperability with the latest known version of the Swift runtime
166  Swift,
167  /// Interoperability with the Swift 5.0 runtime
168  Swift5_0,
169  /// Interoperability with the Swift 4.2 runtime
170  Swift4_2,
171  /// Interoperability with the Swift 4.1 runtime
172  Swift4_1,
173  };
174 
176  // Form fused FP ops only where result will not be affected.
178 
179  // Form fused FP ops according to FP_CONTRACT rules.
181 
182  // Aggressively fuse FP ops (E.g. FMA).
183  FPC_Fast
184  };
185 
186  // TODO: merge FEnvAccessModeKind and FPContractModeKind
189 
190  FEA_On
191  };
192 
193  // Values of the following enumerations correspond to metadata arguments
194  // specified for constrained floating-point intrinsics:
195  // http://llvm.org/docs/LangRef.html#constrained-floating-point-intrinsics.
196 
197  /// Possible rounding modes.
199  /// Rounding to nearest, corresponds to "round.tonearest".
201  /// Rounding toward -Inf, corresponds to "round.downward".
203  /// Rounding toward +Inf, corresponds to "round.upward".
205  /// Rounding toward zero, corresponds to "round.towardzero".
207  /// Is determined by runtime environment, corresponds to "round.dynamic".
208  FPR_Dynamic
209  };
210 
211  /// Possible floating point exception behavior.
213  /// Assume that floating-point exceptions are masked.
215  /// Transformations do not cause new exceptions but may hide some.
217  /// Strictly preserve the floating-point exception semantics.
218  FPE_Strict
219  };
220 
222  /// Permit no implicit vector bitcasts.
223  None,
224  /// Permit vector bitcasts between integer vectors with different numbers
225  /// of elements but the same total bit-width.
226  Integer,
227  /// Permit vector bitcasts between all vectors with the same total
228  /// bit-width.
229  All,
230  };
231 
232 public:
233  /// Set of enabled sanitizers.
235 
236  /// Paths to blacklist files specifying which objects
237  /// (files, functions, variables) should not be instrumented.
238  std::vector<std::string> SanitizerBlacklistFiles;
239 
240  /// Paths to the XRay "always instrument" files specifying which
241  /// objects (files, functions, variables) should be imbued with the XRay
242  /// "always instrument" attribute.
243  /// WARNING: This is a deprecated field and will go away in the future.
244  std::vector<std::string> XRayAlwaysInstrumentFiles;
245 
246  /// Paths to the XRay "never instrument" files specifying which
247  /// objects (files, functions, variables) should be imbued with the XRay
248  /// "never instrument" attribute.
249  /// WARNING: This is a deprecated field and will go away in the future.
250  std::vector<std::string> XRayNeverInstrumentFiles;
251 
252  /// Paths to the XRay attribute list files, specifying which objects
253  /// (files, functions, variables) should be imbued with the appropriate XRay
254  /// attribute(s).
255  std::vector<std::string> XRayAttrListFiles;
256 
258 
260 
262 
263  /// The name of the handler function to be called when -ftrapv is
264  /// specified.
265  ///
266  /// If none is specified, abort (GCC-compatible behaviour).
267  std::string OverflowHandler;
268 
269  /// The module currently being compiled as specified by -fmodule-name.
270  std::string ModuleName;
271 
272  /// The name of the current module, of which the main source file
273  /// is a part. If CompilingModule is set, we are compiling the interface
274  /// of this module, otherwise we are compiling an implementation file of
275  /// it. This starts as ModuleName in case -fmodule-name is provided and
276  /// changes during compilation to reflect the current module.
277  std::string CurrentModule;
278 
279  /// The names of any features to enable in module 'requires' decls
280  /// in addition to the hard-coded list in Module.cpp and the target features.
281  ///
282  /// This list is sorted.
283  std::vector<std::string> ModuleFeatures;
284 
285  /// Options for parsing comments.
287 
288  /// A list of all -fno-builtin-* function names (e.g., memset).
289  std::vector<std::string> NoBuiltinFuncs;
290 
291  /// Triples of the OpenMP targets that the host code codegen should
292  /// take into account in order to generate accurate offloading descriptors.
293  std::vector<llvm::Triple> OMPTargetTriples;
294 
295  /// Name of the IR file that contains the result of the OpenMP target
296  /// host code generation.
297  std::string OMPHostIRFile;
298 
299  /// Indicates whether the front-end is explicitly told that the
300  /// input is a header file (i.e. -x c-header).
301  bool IsHeaderFile = false;
302 
303  LangOptions();
304 
305  // Define accessors/mutators for language options of enumeration type.
306 #define LANGOPT(Name, Bits, Default, Description)
307 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
308  Type get##Name() const { return static_cast<Type>(Name); } \
309  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
310 #include "clang/Basic/LangOptions.def"
311 
312  /// Are we compiling a module interface (.cppm or module map)?
313  bool isCompilingModule() const {
314  return getCompilingModule() != CMK_None;
315  }
316 
317  /// Do we need to track the owning module for a local declaration?
318  bool trackLocalOwningModule() const {
319  return isCompilingModule() || ModulesLocalVisibility;
320  }
321 
322  bool isSignedOverflowDefined() const {
323  return getSignedOverflowBehavior() == SOB_Defined;
324  }
325 
327  return ObjCRuntime.isSubscriptPointerArithmetic() &&
328  !ObjCSubscriptingLegacyRuntime;
329  }
330 
331  bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
332  return MSCompatibilityVersion >= MajorVersion * 100000U;
333  }
334 
335  /// Reset all of the options that are not considered when building a
336  /// module.
337  void resetNonModularOptions();
338 
339  /// Is this a libc/libm function that is no longer recognized as a
340  /// builtin because a -fno-builtin-* option has been specified?
341  bool isNoBuiltinFunc(StringRef Name) const;
342 
343  /// True if any ObjC types may have non-trivial lifetime qualifiers.
345  return ObjCAutoRefCount || ObjCWeak;
346  }
347 
349  return ConvergentFunctions;
350  }
351 
352  /// Return the OpenCL C or C++ version as a VersionTuple.
353  VersionTuple getOpenCLVersionTuple() const;
354 };
355 
356 /// Floating point control options
357 class FPOptions {
358 public:
359  FPOptions() : fp_contract(LangOptions::FPC_Off),
360  fenv_access(LangOptions::FEA_Off) {}
361 
362  // Used for serializing.
363  explicit FPOptions(unsigned I)
364  : fp_contract(static_cast<LangOptions::FPContractModeKind>(I & 3)),
365  fenv_access(static_cast<LangOptions::FEnvAccessModeKind>((I >> 2) & 1))
366  {}
367 
368  explicit FPOptions(const LangOptions &LangOpts)
369  : fp_contract(LangOpts.getDefaultFPContractMode()),
370  fenv_access(LangOptions::FEA_Off) {}
371  // FIXME: Use getDefaultFEnvAccessMode() when available.
372 
374  return fp_contract == LangOptions::FPC_On;
375  }
376 
378  return fp_contract == LangOptions::FPC_Fast;
379  }
380 
382  fp_contract = LangOptions::FPC_On;
383  }
384 
386  fp_contract = LangOptions::FPC_Fast;
387  }
388 
389  void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
390 
391  bool allowFEnvAccess() const {
392  return fenv_access == LangOptions::FEA_On;
393  }
394 
396  fenv_access = LangOptions::FEA_On;
397  }
398 
399  void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; }
400 
401  /// Used to serialize this.
402  unsigned getInt() const { return fp_contract | (fenv_access << 2); }
403 
404 private:
405  /// Adjust BinaryOperator::FPFeatures to match the total bit-field size
406  /// of these two.
407  unsigned fp_contract : 2;
408  unsigned fenv_access : 1;
409 };
410 
411 /// Describes the kind of translation unit being processed.
413  /// The translation unit is a complete translation unit.
415 
416  /// The translation unit is a prefix to a translation unit, and is
417  /// not complete.
419 
420  /// The translation unit is a module.
422 };
423 
424 } // namespace clang
425 
426 #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H
MSVtorDispMode
In the Microsoft ABI, this controls the placement of virtual displacement members used to implement v...
Definition: LangOptions.h:49
bool isSignedOverflowDefined() const
Definition: LangOptions.h:322
FPOptions(const LangOptions &LangOpts)
Definition: LangOptions.h:368
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:331
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:234
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:418
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:313
Floating point control options.
Definition: LangOptions.h:357
Options for controlling comment parsing.
FPRoundingModeKind
Possible rounding modes.
Definition: LangOptions.h:198
Compiling a C++ modules TS module interface unit.
Definition: LangOptions.h:88
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:244
bool allowsNonTrivialObjCLifetimeQualifiers() const
True if any ObjC types may have non-trivial lifetime qualifiers.
Definition: LangOptions.h:344
bool Zero(InterpState &S, CodePtr OpPC)
Definition: Interp.h:812
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:53
Compiling a module from a module map.
Definition: LangOptions.h:82
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:255
bool assumeFunctionsAreConvergent() const
Definition: LangOptions.h:348
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:402
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:381
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:283
Rounding toward +Inf, corresponds to "round.upward".
Definition: LangOptions.h:204
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:277
ClangABI
Clang versions with different platform ABI conformance.
Definition: LangOptions.h:123
bool allowFEnvAccess() const
Definition: LangOptions.h:391
static bool IsHeaderFile(const std::string &Filename)
bool isSubscriptPointerArithmetic() const
Definition: LangOptions.h:326
bool isSubscriptPointerArithmetic() const
Is subscripting pointer arithmetic?
Definition: ObjCRuntime.h:339
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:286
void setDisallowFPContract()
Definition: LangOptions.h:389
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
Definition: LangOptions.h:297
Defines the clang::CommentOptions interface.
Compiling a module from a list of header files.
Definition: LangOptions.h:85
FPExceptionModeKind
Possible floating point exception behavior.
Definition: LangOptions.h:212
Not compiling a module interface at all.
Definition: LangOptions.h:79
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:257
bool allowFPContractAcrossStatement() const
Definition: LangOptions.h:377
Rounding to nearest, corresponds to "round.tonearest".
Definition: LangOptions.h:200
Rounding toward -Inf, corresponds to "round.downward".
Definition: LangOptions.h:202
std::string ModuleName
The module currently being compiled as specified by -fmodule-name.
Definition: LangOptions.h:270
Dataflow Directional Tag Classes.
std::string OverflowHandler
The name of the handler function to be called when -ftrapv is specified.
Definition: LangOptions.h:267
Assume that floating-point exceptions are masked.
Definition: LangOptions.h:214
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:293
void setDisallowFEnvAccess()
Definition: LangOptions.h:399
Rounding toward zero, corresponds to "round.towardzero".
Definition: LangOptions.h:206
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:385
FPOptions(unsigned I)
Definition: LangOptions.h:363
bool allowFPContractWithinStatement() const
Definition: LangOptions.h:373
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:250
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
Definition: LangOptions.h:289
Not within a conflict marker.
Definition: Lexer.h:44
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:412
void setAllowFEnvAccess()
Definition: LangOptions.h:395
The translation unit is a complete translation unit.
Definition: LangOptions.h:414
std::vector< std::string > SanitizerBlacklistFiles
Paths to blacklist files specifying which objects (files, functions, variables) should not be instrum...
Definition: LangOptions.h:238
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:318
std::string ObjCConstantStringClass
Definition: LangOptions.h:261
Transformations do not cause new exceptions but may hide some.
Definition: LangOptions.h:216
The translation unit is a module.
Definition: LangOptions.h:421