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 /// \brief 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 /// \brief 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 
106  // Form fused FP ops only where result will not be affected.
108 
109  // Form fused FP ops according to FP_CONTRACT rules.
111 
112  // Aggressively fuse FP ops (E.g. FMA).
113  FPC_Fast
114  };
115 
116 public:
117  /// \brief Set of enabled sanitizers.
119 
120  /// \brief Paths to blacklist files specifying which objects
121  /// (files, functions, variables) should not be instrumented.
122  std::vector<std::string> SanitizerBlacklistFiles;
123 
124  /// \brief Paths to the XRay "always instrument" files specifying which
125  /// objects (files, functions, variables) should be imbued with the XRay
126  /// "always instrument" attribute.
127  std::vector<std::string> XRayAlwaysInstrumentFiles;
128 
129  /// \brief Paths to the XRay "never instrument" files specifying which
130  /// objects (files, functions, variables) should be imbued with the XRay
131  /// "never instrument" attribute.
132  std::vector<std::string> XRayNeverInstrumentFiles;
133 
135 
137 
138  /// \brief The name of the handler function to be called when -ftrapv is
139  /// specified.
140  ///
141  /// If none is specified, abort (GCC-compatible behaviour).
142  std::string OverflowHandler;
143 
144  /// \brief The name of the current module, of which the main source file
145  /// is a part. If CompilingModule is set, we are compiling the interface
146  /// of this module, otherwise we are compiling an implementation file of
147  /// it.
148  std::string CurrentModule;
149 
150  /// \brief The names of any features to enable in module 'requires' decls
151  /// in addition to the hard-coded list in Module.cpp and the target features.
152  ///
153  /// This list is sorted.
154  std::vector<std::string> ModuleFeatures;
155 
156  /// \brief Options for parsing comments.
158 
159  /// \brief A list of all -fno-builtin-* function names (e.g., memset).
160  std::vector<std::string> NoBuiltinFuncs;
161 
162  /// \brief Triples of the OpenMP targets that the host code codegen should
163  /// take into account in order to generate accurate offloading descriptors.
164  std::vector<llvm::Triple> OMPTargetTriples;
165 
166  /// \brief Name of the IR file that contains the result of the OpenMP target
167  /// host code generation.
168  std::string OMPHostIRFile;
169 
170  /// \brief Indicates whether the front-end is explicitly told that the
171  /// input is a header file (i.e. -x c-header).
172  bool IsHeaderFile = false;
173 
174  LangOptions();
175 
176  // Define accessors/mutators for language options of enumeration type.
177 #define LANGOPT(Name, Bits, Default, Description)
178 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
179  Type get##Name() const { return static_cast<Type>(Name); } \
180  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
181 #include "clang/Basic/LangOptions.def"
182 
183  /// Are we compiling a module interface (.cppm or module map)?
184  bool isCompilingModule() const {
185  return getCompilingModule() != CMK_None;
186  }
187 
188  /// Do we need to track the owning module for a local declaration?
189  bool trackLocalOwningModule() const {
190  return isCompilingModule() || ModulesLocalVisibility || ModulesTS;
191  }
192 
193  bool isSignedOverflowDefined() const {
194  return getSignedOverflowBehavior() == SOB_Defined;
195  }
196 
198  return ObjCRuntime.isSubscriptPointerArithmetic() &&
199  !ObjCSubscriptingLegacyRuntime;
200  }
201 
202  bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
203  return MSCompatibilityVersion >= MajorVersion * 10000000U;
204  }
205 
206  /// \brief Reset all of the options that are not considered when building a
207  /// module.
208  void resetNonModularOptions();
209 
210  /// \brief Is this a libc/libm function that is no longer recognized as a
211  /// builtin because a -fno-builtin-* option has been specified?
212  bool isNoBuiltinFunc(StringRef Name) const;
213 
214  /// \brief True if any ObjC types may have non-trivial lifetime qualifiers.
216  return ObjCAutoRefCount || ObjCWeak;
217  }
218 
220  return (CUDA && CUDAIsDevice) || OpenCL;
221  }
222 };
223 
224 /// \brief Floating point control options
225 class FPOptions {
226 public:
227  FPOptions() : fp_contract(LangOptions::FPC_Off) {}
228 
229  // Used for serializing.
230  explicit FPOptions(unsigned I)
231  : fp_contract(static_cast<LangOptions::FPContractModeKind>(I)) {}
232 
233  explicit FPOptions(const LangOptions &LangOpts)
234  : fp_contract(LangOpts.getDefaultFPContractMode()) {}
235 
237  return fp_contract == LangOptions::FPC_On;
238  }
239 
241  return fp_contract == LangOptions::FPC_Fast;
242  }
243 
245  fp_contract = LangOptions::FPC_On;
246  }
247 
249  fp_contract = LangOptions::FPC_Fast;
250  }
251 
252  void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
253 
254  /// Used to serialize this.
255  unsigned getInt() const { return fp_contract; }
256 
257 private:
258  /// Adjust BinaryOperator::FPFeatures to match the bit-field size of this.
259  unsigned fp_contract : 2;
260 };
261 
262 /// \brief Describes the kind of translation unit being processed.
264  /// \brief The translation unit is a complete translation unit.
266 
267  /// \brief The translation unit is a prefix to a translation unit, and is
268  /// not complete.
270 
271  /// \brief The translation unit is a module.
273 };
274 
275 } // namespace clang
276 
277 #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H
bool isSignedOverflowDefined() const
Definition: LangOptions.h:193
FPOptions(const LangOptions &LangOpts)
Definition: LangOptions.h:233
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:202
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:118
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:269
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:184
Floating point control options.
Definition: LangOptions.h:225
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:127
bool allowsNonTrivialObjCLifetimeQualifiers() const
True if any ObjC types may have non-trivial lifetime qualifiers.
Definition: LangOptions.h:215
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
bool assumeFunctionsAreConvergent() const
Definition: LangOptions.h:219
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:32
unsigned getInt() const
Used to serialize this.
Definition: LangOptions.h:255
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:244
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:154
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:148
static bool IsHeaderFile(const std::string &Filename)
bool isSubscriptPointerArithmetic() const
Definition: LangOptions.h:197
bool isSubscriptPointerArithmetic() const
Is subscripting pointer arithmetic?
Definition: ObjCRuntime.h:249
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:157
void setDisallowFPContract()
Definition: LangOptions.h:252
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
Definition: LangOptions.h:168
Defines the clang::CommentOptions interface.
Not compiling a module interface at all.
Definition: LangOptions.h:71
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:134
bool allowFPContractAcrossStatement() const
Definition: LangOptions.h:240
Dataflow Directional Tag Classes.
std::string OverflowHandler
The name of the handler function to be called when -ftrapv is specified.
Definition: LangOptions.h:142
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:25
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:164
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:248
FPOptions(unsigned I)
Definition: LangOptions.h:230
bool allowFPContractWithinStatement() const
Definition: LangOptions.h:236
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:132
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
Definition: LangOptions.h:160
Not within a conflict marker.
Definition: Lexer.h:45
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:263
The translation unit is a complete translation unit.
Definition: LangOptions.h:265
std::vector< std::string > SanitizerBlacklistFiles
Paths to blacklist files specifying which objects (files, functions, variables) should not be instrum...
Definition: LangOptions.h:122
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:189
std::string ObjCConstantStringClass
Definition: LangOptions.h:136
The translation unit is a module.
Definition: LangOptions.h:272