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