clang  7.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 C++ modules TS module interface unit.
77  CMK_ModuleInterface
78  };
79 
84  PPTMK_FullGeneralityVirtualInheritance
85  };
86 
93  DCC_RegCall
94  };
95 
96  enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
97 
99  MSVC2010 = 16,
100  MSVC2012 = 17,
101  MSVC2013 = 18,
102  MSVC2015 = 19
103  };
104 
105  /// Clang versions with different platform ABI conformance.
106  enum class ClangABI {
107  /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
108  /// (SVN r257626). This causes <1 x long long> to be passed in an
109  /// integer register instead of an SSE register on x64_64.
110  Ver3_8,
111 
112  /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
113  /// (SVN r291814). This causes move operations to be ignored when
114  /// determining whether a class type can be passed or returned directly.
115  Ver4,
116 
117  /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
118  /// (SVN r321711). This causes determination of whether a type is
119  /// standard-layout to ignore collisions between empty base classes
120  /// and between base classes and member subobjects, which affects
121  /// whether we reuse base class tail padding in some ABIs.
122  Ver6,
123 
124  /// Conform to the underlying platform's C and C++ ABIs as closely
125  /// as we can.
126  Latest
127  };
128 
130  // Form fused FP ops only where result will not be affected.
132 
133  // Form fused FP ops according to FP_CONTRACT rules.
135 
136  // Aggressively fuse FP ops (E.g. FMA).
137  FPC_Fast
138  };
139 
140 public:
141  /// Set of enabled sanitizers.
143 
144  /// Paths to blacklist files specifying which objects
145  /// (files, functions, variables) should not be instrumented.
146  std::vector<std::string> SanitizerBlacklistFiles;
147 
148  /// Paths to the XRay "always instrument" files specifying which
149  /// objects (files, functions, variables) should be imbued with the XRay
150  /// "always instrument" attribute.
151  /// WARNING: This is a deprecated field and will go away in the future.
152  std::vector<std::string> XRayAlwaysInstrumentFiles;
153 
154  /// Paths to the XRay "never instrument" files specifying which
155  /// objects (files, functions, variables) should be imbued with the XRay
156  /// "never instrument" attribute.
157  /// WARNING: This is a deprecated field and will go away in the future.
158  std::vector<std::string> XRayNeverInstrumentFiles;
159 
160  /// Paths to the XRay attribute list files, specifying which objects
161  /// (files, functions, variables) should be imbued with the appropriate XRay
162  /// attribute(s).
163  std::vector<std::string> XRayAttrListFiles;
164 
166 
168 
169  /// The name of the handler function to be called when -ftrapv is
170  /// specified.
171  ///
172  /// If none is specified, abort (GCC-compatible behaviour).
173  std::string OverflowHandler;
174 
175  /// The module currently being compiled as speficied by -fmodule-name.
176  std::string ModuleName;
177 
178  /// The name of the current module, of which the main source file
179  /// is a part. If CompilingModule is set, we are compiling the interface
180  /// of this module, otherwise we are compiling an implementation file of
181  /// it. This starts as ModuleName in case -fmodule-name is provided and
182  /// changes during compilation to reflect the current module.
183  std::string CurrentModule;
184 
185  /// The names of any features to enable in module 'requires' decls
186  /// in addition to the hard-coded list in Module.cpp and the target features.
187  ///
188  /// This list is sorted.
189  std::vector<std::string> ModuleFeatures;
190 
191  /// Options for parsing comments.
193 
194  /// A list of all -fno-builtin-* function names (e.g., memset).
195  std::vector<std::string> NoBuiltinFuncs;
196 
197  /// Triples of the OpenMP targets that the host code codegen should
198  /// take into account in order to generate accurate offloading descriptors.
199  std::vector<llvm::Triple> OMPTargetTriples;
200 
201  /// Name of the IR file that contains the result of the OpenMP target
202  /// host code generation.
203  std::string OMPHostIRFile;
204 
205  /// Indicates whether the front-end is explicitly told that the
206  /// input is a header file (i.e. -x c-header).
207  bool IsHeaderFile = false;
208 
209  LangOptions();
210 
211  // Define accessors/mutators for language options of enumeration type.
212 #define LANGOPT(Name, Bits, Default, Description)
213 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
214  Type get##Name() const { return static_cast<Type>(Name); } \
215  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
216 #include "clang/Basic/LangOptions.def"
217 
218  /// Are we compiling a module interface (.cppm or module map)?
219  bool isCompilingModule() const {
220  return getCompilingModule() != CMK_None;
221  }
222 
223  /// Do we need to track the owning module for a local declaration?
224  bool trackLocalOwningModule() const {
225  return isCompilingModule() || ModulesLocalVisibility || ModulesTS;
226  }
227 
228  bool isSignedOverflowDefined() const {
229  return getSignedOverflowBehavior() == SOB_Defined;
230  }
231 
233  return ObjCRuntime.isSubscriptPointerArithmetic() &&
234  !ObjCSubscriptingLegacyRuntime;
235  }
236 
237  bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
238  return MSCompatibilityVersion >= MajorVersion * 10000000U;
239  }
240 
241  /// Reset all of the options that are not considered when building a
242  /// module.
243  void resetNonModularOptions();
244 
245  /// Is this a libc/libm function that is no longer recognized as a
246  /// builtin because a -fno-builtin-* option has been specified?
247  bool isNoBuiltinFunc(StringRef Name) const;
248 
249  /// True if any ObjC types may have non-trivial lifetime qualifiers.
251  return ObjCAutoRefCount || ObjCWeak;
252  }
253 
255  return (CUDA && CUDAIsDevice) || OpenCL;
256  }
257 
258  /// Return the OpenCL C or C++ version as a VersionTuple.
259  VersionTuple getOpenCLVersionTuple() const;
260 };
261 
262 /// Floating point control options
263 class FPOptions {
264 public:
265  FPOptions() : fp_contract(LangOptions::FPC_Off) {}
266 
267  // Used for serializing.
268  explicit FPOptions(unsigned I)
269  : fp_contract(static_cast<LangOptions::FPContractModeKind>(I)) {}
270 
271  explicit FPOptions(const LangOptions &LangOpts)
272  : fp_contract(LangOpts.getDefaultFPContractMode()) {}
273 
275  return fp_contract == LangOptions::FPC_On;
276  }
277 
279  return fp_contract == LangOptions::FPC_Fast;
280  }
281 
283  fp_contract = LangOptions::FPC_On;
284  }
285 
287  fp_contract = LangOptions::FPC_Fast;
288  }
289 
290  void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
291 
292  /// Used to serialize this.
293  unsigned getInt() const { return fp_contract; }
294 
295 private:
296  /// Adjust BinaryOperator::FPFeatures to match the bit-field size of this.
297  unsigned fp_contract : 2;
298 };
299 
300 /// Describes the kind of translation unit being processed.
302  /// The translation unit is a complete translation unit.
304 
305  /// The translation unit is a prefix to a translation unit, and is
306  /// not complete.
308 
309  /// The translation unit is a module.
311 };
312 
313 } // namespace clang
314 
315 #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H
bool isSignedOverflowDefined() const
Definition: LangOptions.h:228
FPOptions(const LangOptions &LangOpts)
Definition: LangOptions.h:271
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:26
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:237
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:142
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:307
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:219
Floating point control options.
Definition: LangOptions.h:263
Options for controlling comment parsing.
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:152
bool allowsNonTrivialObjCLifetimeQualifiers() const
True if any ObjC types may have non-trivial lifetime qualifiers.
Definition: LangOptions.h:250
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:163
bool assumeFunctionsAreConvergent() const
Definition: LangOptions.h:254
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:293
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:282
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:189
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:183
ClangABI
Clang versions with different platform ABI conformance.
Definition: LangOptions.h:106
static bool IsHeaderFile(const std::string &Filename)
bool isSubscriptPointerArithmetic() const
Definition: LangOptions.h:232
bool isSubscriptPointerArithmetic() const
Is subscripting pointer arithmetic?
Definition: ObjCRuntime.h:250
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:192
void setDisallowFPContract()
Definition: LangOptions.h:290
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
Definition: LangOptions.h:203
Defines the clang::CommentOptions interface.
Not compiling a module interface at all.
Definition: LangOptions.h:71
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:165
bool allowFPContractAcrossStatement() const
Definition: LangOptions.h:278
std::string ModuleName
The module currently being compiled as speficied by -fmodule-name.
Definition: LangOptions.h:176
Dataflow Directional Tag Classes.
std::string OverflowHandler
The name of the handler function to be called when -ftrapv is specified.
Definition: LangOptions.h:173
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:199
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:286
FPOptions(unsigned I)
Definition: LangOptions.h:268
bool allowFPContractWithinStatement() const
Definition: LangOptions.h:274
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:158
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
Definition: LangOptions.h:195
Not within a conflict marker.
Definition: Lexer.h:45
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:301
The translation unit is a complete translation unit.
Definition: LangOptions.h:303
std::vector< std::string > SanitizerBlacklistFiles
Paths to blacklist files specifying which objects (files, functions, variables) should not be instrum...
Definition: LangOptions.h:146
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:224
std::string ObjCConstantStringClass
Definition: LangOptions.h:167
The translation unit is a module.
Definition: LangOptions.h:310