clang  5.0.0
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 <string>
24 #include <vector>
25 
26 namespace clang {
27 
28 /// Bitfields of LangOptions, split out from LangOptions in order to ensure that
29 /// this large collection of bitfields is a trivial class type.
31 public:
32  // Define simple language options (with no accessors).
33 #define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
34 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
35 #include "clang/Basic/LangOptions.def"
36 
37 protected:
38  // Define language options of enumeration type. These are private, and will
39  // have accessors (below).
40 #define LANGOPT(Name, Bits, Default, Description)
41 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
42  unsigned Name : Bits;
43 #include "clang/Basic/LangOptions.def"
44 };
45 
46 /// \brief Keeps track of the various options that can be
47 /// enabled, which controls the dialect of C or C++ that is accepted.
48 class LangOptions : public LangOptionsBase {
49 public:
51 
54 
56  SOB_Undefined, // Default C standard behavior.
57  SOB_Defined, // -fwrapv
58  SOB_Trapping // -ftrapv
59  };
60 
61  // FIXME: Unify with TUKind.
63  CMK_None, ///< Not compiling a module interface at all.
64  CMK_ModuleMap, ///< Compiling a module from a module map.
65  CMK_ModuleInterface ///< Compiling a C++ modules TS module interface unit.
66  };
67 
73  };
74 
81  };
82 
84 
86  MSVC2010 = 16,
87  MSVC2012 = 17,
88  MSVC2013 = 18,
89  MSVC2015 = 19
90  };
91 
93  FPC_Off, // Form fused FP ops only where result will not be affected.
94  FPC_On, // Form fused FP ops according to FP_CONTRACT rules.
95  FPC_Fast // Aggressively fuse FP ops (E.g. FMA).
96  };
97 
98 public:
99  /// \brief Set of enabled sanitizers.
101 
102  /// \brief Paths to blacklist files specifying which objects
103  /// (files, functions, variables) should not be instrumented.
104  std::vector<std::string> SanitizerBlacklistFiles;
105 
106  /// \brief Paths to the XRay "always instrument" files specifying which
107  /// objects (files, functions, variables) should be imbued with the XRay
108  /// "always instrument" attribute.
109  std::vector<std::string> XRayAlwaysInstrumentFiles;
110 
111  /// \brief Paths to the XRay "never instrument" files specifying which
112  /// objects (files, functions, variables) should be imbued with the XRay
113  /// "never instrument" attribute.
114  std::vector<std::string> XRayNeverInstrumentFiles;
115 
117 
119 
120  /// \brief The name of the handler function to be called when -ftrapv is
121  /// specified.
122  ///
123  /// If none is specified, abort (GCC-compatible behaviour).
124  std::string OverflowHandler;
125 
126  /// \brief The name of the current module, of which the main source file
127  /// is a part. If CompilingModule is set, we are compiling the interface
128  /// of this module, otherwise we are compiling an implementation file of
129  /// it.
130  std::string CurrentModule;
131 
132  /// \brief The names of any features to enable in module 'requires' decls
133  /// in addition to the hard-coded list in Module.cpp and the target features.
134  ///
135  /// This list is sorted.
136  std::vector<std::string> ModuleFeatures;
137 
138  /// \brief Options for parsing comments.
140 
141  /// \brief A list of all -fno-builtin-* function names (e.g., memset).
142  std::vector<std::string> NoBuiltinFuncs;
143 
144  /// \brief Triples of the OpenMP targets that the host code codegen should
145  /// take into account in order to generate accurate offloading descriptors.
146  std::vector<llvm::Triple> OMPTargetTriples;
147 
148  /// \brief Name of the IR file that contains the result of the OpenMP target
149  /// host code generation.
150  std::string OMPHostIRFile;
151 
152  /// \brief Indicates whether the front-end is explicitly told that the
153  /// input is a header file (i.e. -x c-header).
155 
156  LangOptions();
157 
158  // Define accessors/mutators for language options of enumeration type.
159 #define LANGOPT(Name, Bits, Default, Description)
160 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
161  Type get##Name() const { return static_cast<Type>(Name); } \
162  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
163 #include "clang/Basic/LangOptions.def"
164 
165  /// Are we compiling a module interface (.cppm or module map)?
166  bool isCompilingModule() const {
167  return getCompilingModule() != CMK_None;
168  }
169 
170  /// Do we need to track the owning module for a local declaration?
171  bool trackLocalOwningModule() const {
172  return isCompilingModule() || ModulesLocalVisibility || ModulesTS;
173  }
174 
175  bool isSignedOverflowDefined() const {
176  return getSignedOverflowBehavior() == SOB_Defined;
177  }
178 
181  !ObjCSubscriptingLegacyRuntime;
182  }
183 
184  bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
185  return MSCompatibilityVersion >= MajorVersion * 10000000U;
186  }
187 
188  /// \brief Reset all of the options that are not considered when building a
189  /// module.
190  void resetNonModularOptions();
191 
192  /// \brief Is this a libc/libm function that is no longer recognized as a
193  /// builtin because a -fno-builtin-* option has been specified?
194  bool isNoBuiltinFunc(StringRef Name) const;
195 
196  /// \brief True if any ObjC types may have non-trivial lifetime qualifiers.
198  return ObjCAutoRefCount || ObjCWeak;
199  }
200 };
201 
202 /// \brief Floating point control options
203 class FPOptions {
204 public:
205  FPOptions() : fp_contract(LangOptions::FPC_Off) {}
206 
207  // Used for serializing.
208  explicit FPOptions(unsigned I)
209  : fp_contract(static_cast<LangOptions::FPContractModeKind>(I)) {}
210 
211  explicit FPOptions(const LangOptions &LangOpts)
212  : fp_contract(LangOpts.getDefaultFPContractMode()) {}
213 
215  return fp_contract == LangOptions::FPC_On;
216  }
218  return fp_contract == LangOptions::FPC_Fast;
219  }
221  fp_contract = LangOptions::FPC_On;
222  }
224  fp_contract = LangOptions::FPC_Fast;
225  }
226  void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
227 
228  /// Used to serialize this.
229  unsigned getInt() const { return fp_contract; }
230 
231 private:
232  /// Adjust BinaryOperator::FPFeatures to match the bit-field size of this.
233  unsigned fp_contract : 2;
234 };
235 
236 /// \brief Describes the kind of translation unit being processed.
238  /// \brief The translation unit is a complete translation unit.
240  /// \brief The translation unit is a prefix to a translation unit, and is
241  /// not complete.
243  /// \brief The translation unit is a module.
245 };
246 
247 } // end namespace clang
248 
249 #endif
bool isNoBuiltinFunc(StringRef Name) const
Is this a libc/libm function that is no longer recognized as a builtin because a -fno-builtin-* optio...
Definition: LangOptions.cpp:41
bool allowFPContractWithinStatement() const
Definition: LangOptions.h:214
bool isSignedOverflowDefined() const
Definition: LangOptions.h:175
FPOptions(const LangOptions &LangOpts)
Definition: LangOptions.h:211
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:100
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:242
Defines types useful for describing an Objective-C runtime.
Floating point control options.
Definition: LangOptions.h:203
Options for controlling comment parsing.
unsigned getInt() const
Used to serialize this.
Definition: LangOptions.h:229
Compiling a C++ modules TS module interface unit.
Definition: LangOptions.h:65
bool allowsNonTrivialObjCLifetimeQualifiers() const
True if any ObjC types may have non-trivial lifetime qualifiers.
Definition: LangOptions.h:197
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:109
void resetNonModularOptions()
Reset all of the options that are not considered when building a module.
Definition: LangOptions.cpp:25
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
Compiling a module from a module map.
Definition: LangOptions.h:64
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
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:220
detail::InMemoryDirectory::const_iterator I
Defines the clang::Visibility enumeration and various utility functions.
std::vector< std::string > ModuleFeatures
The names of any features to enable in module 'requires' decls in addition to the hard-coded list in ...
Definition: LangOptions.h:136
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:130
bool trackLocalOwningModule() const
Do we need to track the owning module for a local declaration?
Definition: LangOptions.h:171
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:139
void setDisallowFPContract()
Definition: LangOptions.h:226
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
Definition: LangOptions.h:150
Defines the clang::CommentOptions interface.
Not compiling a module interface at all.
Definition: LangOptions.h:63
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:116
bool allowFPContractAcrossStatement() const
Definition: LangOptions.h:217
std::string OverflowHandler
The name of the handler function to be called when -ftrapv is specified.
Definition: LangOptions.h:124
StringRef Name
Definition: USRFinder.cpp:123
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:146
bool IsHeaderFile
Indicates whether the front-end is explicitly told that the input is a header file (i...
Definition: LangOptions.h:154
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:223
bool isSubscriptPointerArithmetic() const
Is subscripting pointer arithmetic?
Definition: ObjCRuntime.h:249
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:184
FPOptions(unsigned I)
Definition: LangOptions.h:208
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:114
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
Definition: LangOptions.h:142
bool isSubscriptPointerArithmetic() const
Definition: LangOptions.h:179
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:237
The translation unit is a complete translation unit.
Definition: LangOptions.h:239
bool isCompilingModule() const
Are we compiling a module interface (.cppm or module map)?
Definition: LangOptions.h:166
std::vector< std::string > SanitizerBlacklistFiles
Paths to blacklist files specifying which objects (files, functions, variables) should not be instrum...
Definition: LangOptions.h:104
Bitfields of LangOptions, split out from LangOptions in order to ensure that this large collection of...
Definition: LangOptions.h:30
std::string ObjCConstantStringClass
Definition: LangOptions.h:118
clang::Visibility Visibility
Definition: LangOptions.h:50
The translation unit is a module.
Definition: LangOptions.h:244