Coverage Report

Created: 2019-02-21 13:17

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