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  /// Conform to the underlying platform's C and C++ ABIs as closely
128  /// as we can.
129  Latest
130  };
131 
133  // Form fused FP ops only where result will not be affected.
135 
136  // Form fused FP ops according to FP_CONTRACT rules.
138 
139  // Aggressively fuse FP ops (E.g. FMA).
140  FPC_Fast
141  };
142 
143  // TODO: merge FEnvAccessModeKind and FPContractModeKind
146 
147  FEA_On
148  };
149 
150 
151 public:
152  /// Set of enabled sanitizers.
154 
155  /// Paths to blacklist files specifying which objects
156  /// (files, functions, variables) should not be instrumented.
157  std::vector<std::string> SanitizerBlacklistFiles;
158 
159  /// Paths to the XRay "always instrument" files specifying which
160  /// objects (files, functions, variables) should be imbued with the XRay
161  /// "always instrument" attribute.
162  /// WARNING: This is a deprecated field and will go away in the future.
163  std::vector<std::string> XRayAlwaysInstrumentFiles;
164 
165  /// Paths to the XRay "never instrument" files specifying which
166  /// objects (files, functions, variables) should be imbued with the XRay
167  /// "never instrument" attribute.
168  /// WARNING: This is a deprecated field and will go away in the future.
169  std::vector<std::string> XRayNeverInstrumentFiles;
170 
171  /// Paths to the XRay attribute list files, specifying which objects
172  /// (files, functions, variables) should be imbued with the appropriate XRay
173  /// attribute(s).
174  std::vector<std::string> XRayAttrListFiles;
175 
177 
179 
180  /// The name of the handler function to be called when -ftrapv is
181  /// specified.
182  ///
183  /// If none is specified, abort (GCC-compatible behaviour).
184  std::string OverflowHandler;
185 
186  /// The module currently being compiled as speficied by -fmodule-name.
187  std::string ModuleName;
188 
189  /// The name of the current module, of which the main source file
190  /// is a part. If CompilingModule is set, we are compiling the interface
191  /// of this module, otherwise we are compiling an implementation file of
192  /// it. This starts as ModuleName in case -fmodule-name is provided and
193  /// changes during compilation to reflect the current module.
194  std::string CurrentModule;
195 
196  /// The names of any features to enable in module 'requires' decls
197  /// in addition to the hard-coded list in Module.cpp and the target features.
198  ///
199  /// This list is sorted.
200  std::vector<std::string> ModuleFeatures;
201 
202  /// Options for parsing comments.
204 
205  /// A list of all -fno-builtin-* function names (e.g., memset).
206  std::vector<std::string> NoBuiltinFuncs;
207 
208  /// Triples of the OpenMP targets that the host code codegen should
209  /// take into account in order to generate accurate offloading descriptors.
210  std::vector<llvm::Triple> OMPTargetTriples;
211 
212  /// Name of the IR file that contains the result of the OpenMP target
213  /// host code generation.
214  std::string OMPHostIRFile;
215 
216  /// Indicates whether the front-end is explicitly told that the
217  /// input is a header file (i.e. -x c-header).
218  bool IsHeaderFile = false;
219 
220  LangOptions();
221 
222  // Define accessors/mutators for language options of enumeration type.
223 #define LANGOPT(Name, Bits, Default, Description)
224 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
225  Type get##Name() const { return static_cast<Type>(Name); } \
226  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
227 #include "clang/Basic/LangOptions.def"
228 
229  /// Are we compiling a module interface (.cppm or module map)?
230  bool isCompilingModule() const {
231  return getCompilingModule() != CMK_None;
232  }
233 
234  /// Do we need to track the owning module for a local declaration?
235  bool trackLocalOwningModule() const {
236  return isCompilingModule() || ModulesLocalVisibility || ModulesTS;
237  }
238 
239  bool isSignedOverflowDefined() const {
240  return getSignedOverflowBehavior() == SOB_Defined;
241  }
242 
244  return ObjCRuntime.isSubscriptPointerArithmetic() &&
245  !ObjCSubscriptingLegacyRuntime;
246  }
247 
248  bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
249  return MSCompatibilityVersion >= MajorVersion * 10000000U;
250  }
251 
252  /// Reset all of the options that are not considered when building a
253  /// module.
254  void resetNonModularOptions();
255 
256  /// Is this a libc/libm function that is no longer recognized as a
257  /// builtin because a -fno-builtin-* option has been specified?
258  bool isNoBuiltinFunc(StringRef Name) const;
259 
260  /// True if any ObjC types may have non-trivial lifetime qualifiers.
262  return ObjCAutoRefCount || ObjCWeak;
263  }
264 
266  return (CUDA && CUDAIsDevice) || OpenCL;
267  }
268 
269  /// Return the OpenCL C or C++ version as a VersionTuple.
270  VersionTuple getOpenCLVersionTuple() const;
271 };
272 
273 /// Floating point control options
274 class FPOptions {
275 public:
276  FPOptions() : fp_contract(LangOptions::FPC_Off),
277  fenv_access(LangOptions::FEA_Off) {}
278 
279  // Used for serializing.
280  explicit FPOptions(unsigned I)
281  : fp_contract(static_cast<LangOptions::FPContractModeKind>(I & 3)),
282  fenv_access(static_cast<LangOptions::FEnvAccessModeKind>((I >> 2) & 1))
283  {}
284 
285  explicit FPOptions(const LangOptions &LangOpts)
286  : fp_contract(LangOpts.getDefaultFPContractMode()),
287  fenv_access(LangOptions::FEA_Off) {}
288  // FIXME: Use getDefaultFEnvAccessMode() when available.
289 
291  return fp_contract == LangOptions::FPC_On;
292  }
293 
295  return fp_contract == LangOptions::FPC_Fast;
296  }
297 
299  fp_contract = LangOptions::FPC_On;
300  }
301 
303  fp_contract = LangOptions::FPC_Fast;
304  }
305 
306  void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
307 
308  bool allowFEnvAccess() const {
309  return fenv_access == LangOptions::FEA_On;
310  }
311 
313  fenv_access = LangOptions::FEA_On;
314  }
315 
316  void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; }
317 
318  /// Used to serialize this.
319  unsigned getInt() const { return fp_contract | (fenv_access << 2); }
320 
321 private:
322  /// Adjust BinaryOperator::FPFeatures to match the total bit-field size
323  /// of these two.
324  unsigned fp_contract : 2;
325  unsigned fenv_access : 1;
326 };
327 
328 /// Describes the kind of translation unit being processed.
330  /// The translation unit is a complete translation unit.
332 
333  /// The translation unit is a prefix to a translation unit, and is
334  /// not complete.
336 
337  /// The translation unit is a module.
339 };
340 
341 } // namespace clang
342 
343 #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H
bool isSignedOverflowDefined() const
Definition: LangOptions.h:239
FPOptions(const LangOptions &LangOpts)
Definition: LangOptions.h:285
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:248
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:153
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:335
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:230
Floating point control options.
Definition: LangOptions.h:274
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:163
bool allowsNonTrivialObjCLifetimeQualifiers() const
True if any ObjC types may have non-trivial lifetime qualifiers.
Definition: LangOptions.h:261
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:174
bool assumeFunctionsAreConvergent() const
Definition: LangOptions.h:265
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
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:319
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:298
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:200
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:194
ClangABI
Clang versions with different platform ABI conformance.
Definition: LangOptions.h:109
bool allowFEnvAccess() const
Definition: LangOptions.h:308
static bool IsHeaderFile(const std::string &Filename)
bool isSubscriptPointerArithmetic() const
Definition: LangOptions.h:243
bool isSubscriptPointerArithmetic() const
Is subscripting pointer arithmetic?
Definition: ObjCRuntime.h:250
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:203
void setDisallowFPContract()
Definition: LangOptions.h:306
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
Definition: LangOptions.h:214
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:176
bool allowFPContractAcrossStatement() const
Definition: LangOptions.h:294
std::string ModuleName
The module currently being compiled as speficied by -fmodule-name.
Definition: LangOptions.h:187
Dataflow Directional Tag Classes.
std::string OverflowHandler
The name of the handler function to be called when -ftrapv is specified.
Definition: LangOptions.h:184
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:210
void setDisallowFEnvAccess()
Definition: LangOptions.h:316
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:302
FPOptions(unsigned I)
Definition: LangOptions.h:280
bool allowFPContractWithinStatement() const
Definition: LangOptions.h:290
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:169
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
Definition: LangOptions.h:206
Not within a conflict marker.
Definition: Lexer.h:45
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:329
void setAllowFEnvAccess()
Definition: LangOptions.h:312
The translation unit is a complete translation unit.
Definition: LangOptions.h:331
std::vector< std::string > SanitizerBlacklistFiles
Paths to blacklist files specifying which objects (files, functions, variables) should not be instrum...
Definition: LangOptions.h:157
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:235
std::string ObjCConstantStringClass
Definition: LangOptions.h:178
The translation unit is a module.
Definition: LangOptions.h:338