clang  10.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  /// Attempt to be ABI-compatible with code generated by Clang 9.0.x
142  /// (SVN r351319). This causes vectors of __int128 to be passed in memory
143  /// instead of passing in multiple scalar registers on x86_64 on Linux and
144  /// NetBSD.
145  Ver9,
146 
147  /// Conform to the underlying platform's C and C++ ABIs as closely
148  /// as we can.
149  Latest
150  };
151 
152  enum class CoreFoundationABI {
153  /// No interoperability ABI has been specified
154  Unspecified,
155  /// CoreFoundation does not have any language interoperability
156  Standalone,
157  /// Interoperability with the ObjectiveC runtime
158  ObjectiveC,
159  /// Interoperability with the latest known version of the Swift runtime
160  Swift,
161  /// Interoperability with the Swift 5.0 runtime
162  Swift5_0,
163  /// Interoperability with the Swift 4.2 runtime
164  Swift4_2,
165  /// Interoperability with the Swift 4.1 runtime
166  Swift4_1,
167  };
168 
170  // Form fused FP ops only where result will not be affected.
172 
173  // Form fused FP ops according to FP_CONTRACT rules.
175 
176  // Aggressively fuse FP ops (E.g. FMA).
177  FPC_Fast
178  };
179 
180  // TODO: merge FEnvAccessModeKind and FPContractModeKind
183 
184  FEA_On
185  };
186 
188  /// Permit no implicit vector bitcasts.
189  None,
190  /// Permit vector bitcasts between integer vectors with different numbers
191  /// of elements but the same total bit-width.
192  Integer,
193  /// Permit vector bitcasts between all vectors with the same total
194  /// bit-width.
195  All,
196  };
197 
198 public:
199  /// Set of enabled sanitizers.
201 
202  /// Paths to blacklist files specifying which objects
203  /// (files, functions, variables) should not be instrumented.
204  std::vector<std::string> SanitizerBlacklistFiles;
205 
206  /// Paths to the XRay "always instrument" files specifying which
207  /// objects (files, functions, variables) should be imbued with the XRay
208  /// "always instrument" attribute.
209  /// WARNING: This is a deprecated field and will go away in the future.
210  std::vector<std::string> XRayAlwaysInstrumentFiles;
211 
212  /// Paths to the XRay "never instrument" files specifying which
213  /// objects (files, functions, variables) should be imbued with the XRay
214  /// "never instrument" attribute.
215  /// WARNING: This is a deprecated field and will go away in the future.
216  std::vector<std::string> XRayNeverInstrumentFiles;
217 
218  /// Paths to the XRay attribute list files, specifying which objects
219  /// (files, functions, variables) should be imbued with the appropriate XRay
220  /// attribute(s).
221  std::vector<std::string> XRayAttrListFiles;
222 
224 
226 
228 
229  /// The name of the handler function to be called when -ftrapv is
230  /// specified.
231  ///
232  /// If none is specified, abort (GCC-compatible behaviour).
233  std::string OverflowHandler;
234 
235  /// The module currently being compiled as specified by -fmodule-name.
236  std::string ModuleName;
237 
238  /// The name of the current module, of which the main source file
239  /// is a part. If CompilingModule is set, we are compiling the interface
240  /// of this module, otherwise we are compiling an implementation file of
241  /// it. This starts as ModuleName in case -fmodule-name is provided and
242  /// changes during compilation to reflect the current module.
243  std::string CurrentModule;
244 
245  /// The names of any features to enable in module 'requires' decls
246  /// in addition to the hard-coded list in Module.cpp and the target features.
247  ///
248  /// This list is sorted.
249  std::vector<std::string> ModuleFeatures;
250 
251  /// Options for parsing comments.
253 
254  /// A list of all -fno-builtin-* function names (e.g., memset).
255  std::vector<std::string> NoBuiltinFuncs;
256 
257  /// Triples of the OpenMP targets that the host code codegen should
258  /// take into account in order to generate accurate offloading descriptors.
259  std::vector<llvm::Triple> OMPTargetTriples;
260 
261  /// Name of the IR file that contains the result of the OpenMP target
262  /// host code generation.
263  std::string OMPHostIRFile;
264 
265  /// Indicates whether the front-end is explicitly told that the
266  /// input is a header file (i.e. -x c-header).
267  bool IsHeaderFile = false;
268 
269  LangOptions();
270 
271  // Define accessors/mutators for language options of enumeration type.
272 #define LANGOPT(Name, Bits, Default, Description)
273 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
274  Type get##Name() const { return static_cast<Type>(Name); } \
275  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
276 #include "clang/Basic/LangOptions.def"
277 
278  /// Are we compiling a module interface (.cppm or module map)?
279  bool isCompilingModule() const {
280  return getCompilingModule() != CMK_None;
281  }
282 
283  /// Do we need to track the owning module for a local declaration?
284  bool trackLocalOwningModule() const {
285  return isCompilingModule() || ModulesLocalVisibility;
286  }
287 
288  bool isSignedOverflowDefined() const {
289  return getSignedOverflowBehavior() == SOB_Defined;
290  }
291 
293  return ObjCRuntime.isSubscriptPointerArithmetic() &&
294  !ObjCSubscriptingLegacyRuntime;
295  }
296 
297  bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
298  return MSCompatibilityVersion >= MajorVersion * 100000U;
299  }
300 
301  /// Reset all of the options that are not considered when building a
302  /// module.
303  void resetNonModularOptions();
304 
305  /// Is this a libc/libm function that is no longer recognized as a
306  /// builtin because a -fno-builtin-* option has been specified?
307  bool isNoBuiltinFunc(StringRef Name) const;
308 
309  /// True if any ObjC types may have non-trivial lifetime qualifiers.
311  return ObjCAutoRefCount || ObjCWeak;
312  }
313 
315  return (CUDA && CUDAIsDevice) || OpenCL;
316  }
317 
318  /// Return the OpenCL C or C++ version as a VersionTuple.
319  VersionTuple getOpenCLVersionTuple() const;
320 };
321 
322 /// Floating point control options
323 class FPOptions {
324 public:
325  FPOptions() : fp_contract(LangOptions::FPC_Off),
326  fenv_access(LangOptions::FEA_Off) {}
327 
328  // Used for serializing.
329  explicit FPOptions(unsigned I)
330  : fp_contract(static_cast<LangOptions::FPContractModeKind>(I & 3)),
331  fenv_access(static_cast<LangOptions::FEnvAccessModeKind>((I >> 2) & 1))
332  {}
333 
334  explicit FPOptions(const LangOptions &LangOpts)
335  : fp_contract(LangOpts.getDefaultFPContractMode()),
336  fenv_access(LangOptions::FEA_Off) {}
337  // FIXME: Use getDefaultFEnvAccessMode() when available.
338 
340  return fp_contract == LangOptions::FPC_On;
341  }
342 
344  return fp_contract == LangOptions::FPC_Fast;
345  }
346 
348  fp_contract = LangOptions::FPC_On;
349  }
350 
352  fp_contract = LangOptions::FPC_Fast;
353  }
354 
355  void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
356 
357  bool allowFEnvAccess() const {
358  return fenv_access == LangOptions::FEA_On;
359  }
360 
362  fenv_access = LangOptions::FEA_On;
363  }
364 
365  void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; }
366 
367  /// Used to serialize this.
368  unsigned getInt() const { return fp_contract | (fenv_access << 2); }
369 
370 private:
371  /// Adjust BinaryOperator::FPFeatures to match the total bit-field size
372  /// of these two.
373  unsigned fp_contract : 2;
374  unsigned fenv_access : 1;
375 };
376 
377 /// Describes the kind of translation unit being processed.
379  /// The translation unit is a complete translation unit.
381 
382  /// The translation unit is a prefix to a translation unit, and is
383  /// not complete.
385 
386  /// The translation unit is a module.
388 };
389 
390 } // namespace clang
391 
392 #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H
bool isSignedOverflowDefined() const
Definition: LangOptions.h:288
FPOptions(const LangOptions &LangOpts)
Definition: LangOptions.h:334
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:297
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:200
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:384
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:279
Floating point control options.
Definition: LangOptions.h:323
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:210
bool allowsNonTrivialObjCLifetimeQualifiers() const
True if any ObjC types may have non-trivial lifetime qualifiers.
Definition: LangOptions.h:310
bool Zero(InterpState &S, CodePtr OpPC)
Definition: Interp.h:815
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:221
bool assumeFunctionsAreConvergent() const
Definition: LangOptions.h:314
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:368
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:347
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:249
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:243
ClangABI
Clang versions with different platform ABI conformance.
Definition: LangOptions.h:117
bool allowFEnvAccess() const
Definition: LangOptions.h:357
static bool IsHeaderFile(const std::string &Filename)
bool isSubscriptPointerArithmetic() const
Definition: LangOptions.h:292
bool isSubscriptPointerArithmetic() const
Is subscripting pointer arithmetic?
Definition: ObjCRuntime.h:339
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:252
void setDisallowFPContract()
Definition: LangOptions.h:355
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
Definition: LangOptions.h:263
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:223
bool allowFPContractAcrossStatement() const
Definition: LangOptions.h:343
std::string ModuleName
The module currently being compiled as specified by -fmodule-name.
Definition: LangOptions.h:236
Dataflow Directional Tag Classes.
std::string OverflowHandler
The name of the handler function to be called when -ftrapv is specified.
Definition: LangOptions.h:233
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:259
void setDisallowFEnvAccess()
Definition: LangOptions.h:365
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:351
FPOptions(unsigned I)
Definition: LangOptions.h:329
bool allowFPContractWithinStatement() const
Definition: LangOptions.h:339
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:216
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
Definition: LangOptions.h:255
Not within a conflict marker.
Definition: Lexer.h:44
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:378
void setAllowFEnvAccess()
Definition: LangOptions.h:361
The translation unit is a complete translation unit.
Definition: LangOptions.h:380
std::vector< std::string > SanitizerBlacklistFiles
Paths to blacklist files specifying which objects (files, functions, variables) should not be instrum...
Definition: LangOptions.h:204
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:284
std::string ObjCConstantStringClass
Definition: LangOptions.h:227
The translation unit is a module.
Definition: LangOptions.h:387