Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Basic/LangOptions.h
Line
Count
Source (jump to first uncovered line)
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
17
#include "clang/Basic/CommentOptions.h"
18
#include "clang/Basic/LLVM.h"
19
#include "clang/Basic/ObjCRuntime.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.
31
class LangOptionsBase {
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:
51
  using Visibility = clang::Visibility;
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
61
  enum SignedOverflowBehaviorTy {
62
    // Default C standard behavior.
63
    SOB_Undefined,
64
65
    // -fwrapv
66
    SOB_Defined,
67
68
    // -ftrapv
69
    SOB_Trapping
70
  };
71
72
  // FIXME: Unify with TUKind.
73
  enum CompilingModuleKind {
74
    /// Not compiling a module interface at all.
75
    CMK_None,
76
77
    /// Compiling a module from a module map.
78
    CMK_ModuleMap,
79
80
    /// Compiling a module from a list of header files.
81
    CMK_HeaderModule,
82
83
    /// Compiling a C++ modules TS module interface unit.
84
    CMK_ModuleInterface,
85
  };
86
87
  enum PragmaMSPointersToMembersKind {
88
    PPTMK_BestCase,
89
    PPTMK_FullGeneralitySingleInheritance,
90
    PPTMK_FullGeneralityMultipleInheritance,
91
    PPTMK_FullGeneralityVirtualInheritance
92
  };
93
94
  enum DefaultCallingConvention {
95
    DCC_None,
96
    DCC_CDecl,
97
    DCC_FastCall,
98
    DCC_StdCall,
99
    DCC_VectorCall,
100
    DCC_RegCall
101
  };
102
103
  enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
104
105
  // Corresponds to _MSC_VER
106
  enum MSVCMajorVersion {
107
    MSVC2010 = 1600,
108
    MSVC2012 = 1700,
109
    MSVC2013 = 1800,
110
    MSVC2015 = 1900,
111
    MSVC2017 = 1910,
112
    MSVC2017_5 = 1912,
113
    MSVC2017_7 = 1914,
114
  };
115
116
  /// Clang versions with different platform ABI conformance.
117
  enum class ClangABI {
118
    /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
119
    /// (SVN r257626). This causes <1 x long long> to be passed in an
120
    /// integer register instead of an SSE register on x64_64.
121
    Ver3_8,
122
123
    /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
124
    /// (SVN r291814). This causes move operations to be ignored when
125
    /// determining whether a class type can be passed or returned directly.
126
    Ver4,
127
128
    /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
129
    /// (SVN r321711). This causes determination of whether a type is
130
    /// standard-layout to ignore collisions between empty base classes
131
    /// and between base classes and member subobjects, which affects
132
    /// whether we reuse base class tail padding in some ABIs.
133
    Ver6,
134
135
    /// Attempt to be ABI-compatible with code generated by Clang 7.0.x
136
    /// (SVN r338536). This causes alignof (C++) and _Alignof (C11) to be
137
    /// compatible with __alignof (i.e., return the preferred alignment)
138
    /// rather than returning the required alignment.
139
    Ver7,
140
141
    /// Conform to the underlying platform's C and C++ ABIs as closely
142
    /// as we can.
143
    Latest
144
  };
145
146
  enum class CoreFoundationABI {
147
    /// No interoperability ABI has been specified
148
    Unspecified,
149
    /// CoreFoundation does not have any language interoperability
150
    Standalone,
151
    /// Interoperability with the ObjectiveC runtime
152
    ObjectiveC,
153
    /// Interoperability with the latest known version of the Swift runtime
154
    Swift,
155
    /// Interoperability with the Swift 5.0 runtime
156
    Swift5_0,
157
    /// Interoperability with the Swift 4.2 runtime
158
    Swift4_2,
159
    /// Interoperability with the Swift 4.1 runtime
160
    Swift4_1,
161
  };
162
163
  enum FPContractModeKind {
164
    // Form fused FP ops only where result will not be affected.
165
    FPC_Off,
166
167
    // Form fused FP ops according to FP_CONTRACT rules.
168
    FPC_On,
169
170
    // Aggressively fuse FP ops (E.g. FMA).
171
    FPC_Fast
172
  };
173
174
  // TODO: merge FEnvAccessModeKind and FPContractModeKind
175
  enum FEnvAccessModeKind {
176
    FEA_Off,
177
178
    FEA_On
179
  };
180
181
182
public:
183
  /// Set of enabled sanitizers.
184
  SanitizerSet Sanitize;
185
186
  /// Paths to blacklist files specifying which objects
187
  /// (files, functions, variables) should not be instrumented.
188
  std::vector<std::string> SanitizerBlacklistFiles;
189
190
  /// Paths to the XRay "always instrument" files specifying which
191
  /// objects (files, functions, variables) should be imbued with the XRay
192
  /// "always instrument" attribute.
193
  /// WARNING: This is a deprecated field and will go away in the future.
194
  std::vector<std::string> XRayAlwaysInstrumentFiles;
195
196
  /// Paths to the XRay "never instrument" files specifying which
197
  /// objects (files, functions, variables) should be imbued with the XRay
198
  /// "never instrument" attribute.
199
  /// WARNING: This is a deprecated field and will go away in the future.
200
  std::vector<std::string> XRayNeverInstrumentFiles;
201
202
  /// Paths to the XRay attribute list files, specifying which objects
203
  /// (files, functions, variables) should be imbued with the appropriate XRay
204
  /// attribute(s).
205
  std::vector<std::string> XRayAttrListFiles;
206
207
  clang::ObjCRuntime ObjCRuntime;
208
209
  CoreFoundationABI CFRuntime = CoreFoundationABI::Unspecified;
210
211
  std::string ObjCConstantStringClass;
212
213
  /// The name of the handler function to be called when -ftrapv is
214
  /// specified.
215
  ///
216
  /// If none is specified, abort (GCC-compatible behaviour).
217
  std::string OverflowHandler;
218
219
  /// The module currently being compiled as specified by -fmodule-name.
220
  std::string ModuleName;
221
222
  /// The name of the current module, of which the main source file
223
  /// is a part. If CompilingModule is set, we are compiling the interface
224
  /// of this module, otherwise we are compiling an implementation file of
225
  /// it. This starts as ModuleName in case -fmodule-name is provided and
226
  /// changes during compilation to reflect the current module.
227
  std::string CurrentModule;
228
229
  /// The names of any features to enable in module 'requires' decls
230
  /// in addition to the hard-coded list in Module.cpp and the target features.
231
  ///
232
  /// This list is sorted.
233
  std::vector<std::string> ModuleFeatures;
234
235
  /// Options for parsing comments.
236
  CommentOptions CommentOpts;
237
238
  /// A list of all -fno-builtin-* function names (e.g., memset).
239
  std::vector<std::string> NoBuiltinFuncs;
240
241
  /// Triples of the OpenMP targets that the host code codegen should
242
  /// take into account in order to generate accurate offloading descriptors.
243
  std::vector<llvm::Triple> OMPTargetTriples;
244
245
  /// Name of the IR file that contains the result of the OpenMP target
246
  /// host code generation.
247
  std::string OMPHostIRFile;
248
249
  /// Indicates whether the front-end is explicitly told that the
250
  /// input is a header file (i.e. -x c-header).
251
  bool IsHeaderFile = false;
252
253
  LangOptions();
254
255
  // Define accessors/mutators for language options of enumeration type.
256
#define LANGOPT(Name, Bits, Default, Description)
257
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
258
73.6M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getCompilingModule() const
Line
Count
Source
258
45.8M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getMSPointerToMemberRepresentationMethod() const
Line
Count
Source
258
55.4k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getDefaultCallingConv() const
Line
Count
Source
258
5.03M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getDefaultFPContractMode() const
Line
Count
Source
258
76.9k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getAddressSpaceMapMangling() const
Line
Count
Source
258
55.5k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getGC() const
Line
Count
Source
258
13.1M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getValueVisibilityMode() const
Line
Count
Source
258
1.20M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getTypeVisibilityMode() const
Line
Count
Source
258
913k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getStackProtector() const
Line
Count
Source
258
1.00M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getTrivialAutoVarInit() const
Line
Count
Source
258
442k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getSignedOverflowBehavior() const
Line
Count
Source
258
580k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::LangOptions::getClangABICompat() const
Line
Count
Source
258
5.23M
  Type get##Name() const { return static_cast<Type>(Name); } \
259
12.1M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setCompilingModule(clang::LangOptions::CompilingModuleKind)
Line
Count
Source
259
1.05M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setMSPointerToMemberRepresentationMethod(clang::LangOptions::PragmaMSPointersToMembersKind)
Line
Count
Source
259
1.00M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setDefaultCallingConv(clang::LangOptions::DefaultCallingConvention)
Line
Count
Source
259
1.00M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setDefaultFPContractMode(clang::LangOptions::FPContractModeKind)
Line
Count
Source
259
1.00M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setAddressSpaceMapMangling(clang::LangOptions::AddrSpaceMapMangling)
Line
Count
Source
259
1.00M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setGC(clang::LangOptions::GCMode)
Line
Count
Source
259
1.00M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setValueVisibilityMode(clang::Visibility)
Line
Count
Source
259
1.04M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setTypeVisibilityMode(clang::Visibility)
Line
Count
Source
259
1.04M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setStackProtector(clang::LangOptions::StackProtectorMode)
Line
Count
Source
259
1.04M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setTrivialAutoVarInit(clang::LangOptions::TrivialAutoVarInitKind)
Line
Count
Source
259
1.00M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setSignedOverflowBehavior(clang::LangOptions::SignedOverflowBehaviorTy)
Line
Count
Source
259
1.00M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::LangOptions::setClangABICompat(clang::LangOptions::ClangABI)
Line
Count
Source
259
1.00M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
260
#include "clang/Basic/LangOptions.def"
261
262
  /// Are we compiling a module interface (.cppm or module map)?
263
45.8M
  bool isCompilingModule() const {
264
45.8M
    return getCompilingModule() != CMK_None;
265
45.8M
  }
266
267
  /// Do we need to track the owning module for a local declaration?
268
45.1M
  bool trackLocalOwningModule() const {
269
45.1M
    return isCompilingModule() || 
ModulesLocalVisibility44.8M
;
270
45.1M
  }
271
272
260k
  bool isSignedOverflowDefined() const {
273
260k
    return getSignedOverflowBehavior() == SOB_Defined;
274
260k
  }
275
276
267
  bool isSubscriptPointerArithmetic() const {
277
267
    return ObjCRuntime.isSubscriptPointerArithmetic() &&
278
267
           
!ObjCSubscriptingLegacyRuntime11
;
279
267
  }
280
281
50.0k
  bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
282
50.0k
    return MSCompatibilityVersion >= MajorVersion * 100000U;
283
50.0k
  }
284
285
  /// Reset all of the options that are not considered when building a
286
  /// module.
287
  void resetNonModularOptions();
288
289
  /// Is this a libc/libm function that is no longer recognized as a
290
  /// builtin because a -fno-builtin-* option has been specified?
291
  bool isNoBuiltinFunc(StringRef Name) const;
292
293
  /// True if any ObjC types may have non-trivial lifetime qualifiers.
294
5.89M
  bool allowsNonTrivialObjCLifetimeQualifiers() const {
295
5.89M
    return ObjCAutoRefCount || 
ObjCWeak5.88M
;
296
5.89M
  }
297
298
1.37M
  bool assumeFunctionsAreConvergent() const {
299
1.37M
    return (CUDA && 
CUDAIsDevice993
) ||
OpenCL1.37M
;
300
1.37M
  }
301
302
  /// Return the OpenCL C or C++ version as a VersionTuple.
303
  VersionTuple getOpenCLVersionTuple() const;
304
};
305
306
/// Floating point control options
307
class FPOptions {
308
public:
309
  FPOptions() : fp_contract(LangOptions::FPC_Off),
310
950k
                fenv_access(LangOptions::FEA_Off) {}
311
312
  // Used for serializing.
313
  explicit FPOptions(unsigned I)
314
      : fp_contract(static_cast<LangOptions::FPContractModeKind>(I & 3)),
315
        fenv_access(static_cast<LangOptions::FEnvAccessModeKind>((I >> 2) & 1))
316
2.28M
        {}
317
318
  explicit FPOptions(const LangOptions &LangOpts)
319
      : fp_contract(LangOpts.getDefaultFPContractMode()),
320
41.5k
        fenv_access(LangOptions::FEA_Off) {}
321
  // FIXME: Use getDefaultFEnvAccessMode() when available.
322
323
35.4k
  bool allowFPContractWithinStatement() const {
324
35.4k
    return fp_contract == LangOptions::FPC_On;
325
35.4k
  }
326
327
46.5k
  bool allowFPContractAcrossStatement() const {
328
46.5k
    return fp_contract == LangOptions::FPC_Fast;
329
46.5k
  }
330
331
17
  void setAllowFPContractWithinStatement() {
332
17
    fp_contract = LangOptions::FPC_On;
333
17
  }
334
335
6
  void setAllowFPContractAcrossStatement() {
336
6
    fp_contract = LangOptions::FPC_Fast;
337
6
  }
338
339
74
  void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
340
341
0
  bool allowFEnvAccess() const {
342
0
    return fenv_access == LangOptions::FEA_On;
343
0
  }
344
345
1
  void setAllowFEnvAccess() {
346
1
    fenv_access = LangOptions::FEA_On;
347
1
  }
348
349
2
  void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; }
350
351
  /// Used to serialize this.
352
8.32M
  unsigned getInt() const { return fp_contract | (fenv_access << 2); }
353
354
private:
355
  /// Adjust BinaryOperator::FPFeatures to match the total bit-field size
356
  /// of these two.
357
  unsigned fp_contract : 2;
358
  unsigned fenv_access : 1;
359
};
360
361
/// Describes the kind of translation unit being processed.
362
enum TranslationUnitKind {
363
  /// The translation unit is a complete translation unit.
364
  TU_Complete,
365
366
  /// The translation unit is a prefix to a translation unit, and is
367
  /// not complete.
368
  TU_Prefix,
369
370
  /// The translation unit is a module.
371
  TU_Module
372
};
373
374
} // namespace clang
375
376
#endif // LLVM_CLANG_BASIC_LANGOPTIONS_H