Coverage Report

Created: 2020-02-15 09:57

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/ASTContext.h
Line
Count
Source (jump to first uncovered line)
1
//===- ASTContext.h - Context to hold long-lived AST nodes ------*- 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::ASTContext interface.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_ASTCONTEXT_H
15
#define LLVM_CLANG_AST_ASTCONTEXT_H
16
17
#include "clang/AST/ASTContextAllocate.h"
18
#include "clang/AST/ASTFwd.h"
19
#include "clang/AST/CanonicalType.h"
20
#include "clang/AST/CommentCommandTraits.h"
21
#include "clang/AST/ComparisonCategories.h"
22
#include "clang/AST/Decl.h"
23
#include "clang/AST/DeclBase.h"
24
#include "clang/AST/DeclarationName.h"
25
#include "clang/AST/ExternalASTSource.h"
26
#include "clang/AST/NestedNameSpecifier.h"
27
#include "clang/AST/PrettyPrinter.h"
28
#include "clang/AST/RawCommentList.h"
29
#include "clang/AST/TemplateName.h"
30
#include "clang/AST/Type.h"
31
#include "clang/Basic/AddressSpaces.h"
32
#include "clang/Basic/AttrKinds.h"
33
#include "clang/Basic/IdentifierTable.h"
34
#include "clang/Basic/LLVM.h"
35
#include "clang/Basic/LangOptions.h"
36
#include "clang/Basic/Linkage.h"
37
#include "clang/Basic/OperatorKinds.h"
38
#include "clang/Basic/PartialDiagnostic.h"
39
#include "clang/Basic/SanitizerBlacklist.h"
40
#include "clang/Basic/SourceLocation.h"
41
#include "clang/Basic/Specifiers.h"
42
#include "clang/Basic/TargetInfo.h"
43
#include "clang/Basic/XRayLists.h"
44
#include "llvm/ADT/APSInt.h"
45
#include "llvm/ADT/ArrayRef.h"
46
#include "llvm/ADT/DenseMap.h"
47
#include "llvm/ADT/FoldingSet.h"
48
#include "llvm/ADT/IntrusiveRefCntPtr.h"
49
#include "llvm/ADT/MapVector.h"
50
#include "llvm/ADT/None.h"
51
#include "llvm/ADT/Optional.h"
52
#include "llvm/ADT/PointerIntPair.h"
53
#include "llvm/ADT/PointerUnion.h"
54
#include "llvm/ADT/SmallVector.h"
55
#include "llvm/ADT/StringMap.h"
56
#include "llvm/ADT/StringRef.h"
57
#include "llvm/ADT/TinyPtrVector.h"
58
#include "llvm/ADT/Triple.h"
59
#include "llvm/ADT/iterator_range.h"
60
#include "llvm/Support/AlignOf.h"
61
#include "llvm/Support/Allocator.h"
62
#include "llvm/Support/Casting.h"
63
#include "llvm/Support/Compiler.h"
64
#include <cassert>
65
#include <cstddef>
66
#include <cstdint>
67
#include <iterator>
68
#include <memory>
69
#include <string>
70
#include <type_traits>
71
#include <utility>
72
#include <vector>
73
74
namespace llvm {
75
76
struct fltSemantics;
77
78
} // namespace llvm
79
80
namespace clang {
81
82
class APFixedPoint;
83
class APValue;
84
class ASTMutationListener;
85
class ASTRecordLayout;
86
class AtomicExpr;
87
class BlockExpr;
88
class BuiltinTemplateDecl;
89
class CharUnits;
90
class ConceptDecl;
91
class CXXABI;
92
class CXXConstructorDecl;
93
class CXXMethodDecl;
94
class CXXRecordDecl;
95
class DiagnosticsEngine;
96
class ParentMapContext;
97
class DynTypedNode;
98
class DynTypedNodeList;
99
class Expr;
100
class FixedPointSemantics;
101
class GlobalDecl;
102
class MangleContext;
103
class MangleNumberingContext;
104
class MaterializeTemporaryExpr;
105
class MemberSpecializationInfo;
106
class Module;
107
class ObjCCategoryDecl;
108
class ObjCCategoryImplDecl;
109
class ObjCContainerDecl;
110
class ObjCImplDecl;
111
class ObjCImplementationDecl;
112
class ObjCInterfaceDecl;
113
class ObjCIvarDecl;
114
class ObjCMethodDecl;
115
class ObjCPropertyDecl;
116
class ObjCPropertyImplDecl;
117
class ObjCProtocolDecl;
118
class ObjCTypeParamDecl;
119
struct ParsedTargetAttr;
120
class Preprocessor;
121
class Stmt;
122
class StoredDeclsMap;
123
class TargetAttr;
124
class TemplateDecl;
125
class TemplateParameterList;
126
class TemplateTemplateParmDecl;
127
class TemplateTypeParmDecl;
128
class UnresolvedSetIterator;
129
class UsingShadowDecl;
130
class VarTemplateDecl;
131
class VTableContextBase;
132
struct BlockVarCopyInit;
133
134
135
namespace Builtin {
136
137
class Context;
138
139
} // namespace Builtin
140
141
enum BuiltinTemplateKind : int;
142
143
namespace comments {
144
145
class FullComment;
146
147
} // namespace comments
148
149
namespace interp {
150
151
class Context;
152
153
} // namespace interp
154
155
namespace serialization {
156
template <class> class AbstractTypeReader;
157
} // namespace serialization
158
159
struct TypeInfo {
160
  uint64_t Width = 0;
161
  unsigned Align = 0;
162
  bool AlignIsRequired : 1;
163
164
1.61M
  TypeInfo() : AlignIsRequired(false) {}
165
  TypeInfo(uint64_t Width, unsigned Align, bool AlignIsRequired)
166
1.34M
      : Width(Width), Align(Align), AlignIsRequired(AlignIsRequired) {}
167
};
168
169
/// Holds long-lived AST nodes (such as types and decls) that can be
170
/// referred to throughout the semantic analysis of a file.
171
class ASTContext : public RefCountedBase<ASTContext> {
172
  friend class NestedNameSpecifier;
173
174
  mutable SmallVector<Type *, 0> Types;
175
  mutable llvm::FoldingSet<ExtQuals> ExtQualNodes;
176
  mutable llvm::FoldingSet<ComplexType> ComplexTypes;
177
  mutable llvm::FoldingSet<PointerType> PointerTypes;
178
  mutable llvm::FoldingSet<AdjustedType> AdjustedTypes;
179
  mutable llvm::FoldingSet<BlockPointerType> BlockPointerTypes;
180
  mutable llvm::FoldingSet<LValueReferenceType> LValueReferenceTypes;
181
  mutable llvm::FoldingSet<RValueReferenceType> RValueReferenceTypes;
182
  mutable llvm::FoldingSet<MemberPointerType> MemberPointerTypes;
183
  mutable llvm::ContextualFoldingSet<ConstantArrayType, ASTContext &>
184
      ConstantArrayTypes;
185
  mutable llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes;
186
  mutable std::vector<VariableArrayType*> VariableArrayTypes;
187
  mutable llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes;
188
  mutable llvm::FoldingSet<DependentSizedExtVectorType>
189
    DependentSizedExtVectorTypes;
190
  mutable llvm::FoldingSet<DependentAddressSpaceType>
191
      DependentAddressSpaceTypes;
192
  mutable llvm::FoldingSet<VectorType> VectorTypes;
193
  mutable llvm::FoldingSet<DependentVectorType> DependentVectorTypes;
194
  mutable llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes;
195
  mutable llvm::ContextualFoldingSet<FunctionProtoType, ASTContext&>
196
    FunctionProtoTypes;
197
  mutable llvm::FoldingSet<DependentTypeOfExprType> DependentTypeOfExprTypes;
198
  mutable llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes;
199
  mutable llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes;
200
  mutable llvm::FoldingSet<ObjCTypeParamType> ObjCTypeParamTypes;
201
  mutable llvm::FoldingSet<SubstTemplateTypeParmType>
202
    SubstTemplateTypeParmTypes;
203
  mutable llvm::FoldingSet<SubstTemplateTypeParmPackType>
204
    SubstTemplateTypeParmPackTypes;
205
  mutable llvm::ContextualFoldingSet<TemplateSpecializationType, ASTContext&>
206
    TemplateSpecializationTypes;
207
  mutable llvm::FoldingSet<ParenType> ParenTypes;
208
  mutable llvm::FoldingSet<ElaboratedType> ElaboratedTypes;
209
  mutable llvm::FoldingSet<DependentNameType> DependentNameTypes;
210
  mutable llvm::ContextualFoldingSet<DependentTemplateSpecializationType,
211
                                     ASTContext&>
212
    DependentTemplateSpecializationTypes;
213
  llvm::FoldingSet<PackExpansionType> PackExpansionTypes;
214
  mutable llvm::FoldingSet<ObjCObjectTypeImpl> ObjCObjectTypes;
215
  mutable llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes;
216
  mutable llvm::FoldingSet<DependentUnaryTransformType>
217
    DependentUnaryTransformTypes;
218
  mutable llvm::ContextualFoldingSet<AutoType, ASTContext&> AutoTypes;
219
  mutable llvm::FoldingSet<DeducedTemplateSpecializationType>
220
    DeducedTemplateSpecializationTypes;
221
  mutable llvm::FoldingSet<AtomicType> AtomicTypes;
222
  llvm::FoldingSet<AttributedType> AttributedTypes;
223
  mutable llvm::FoldingSet<PipeType> PipeTypes;
224
225
  mutable llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames;
226
  mutable llvm::FoldingSet<DependentTemplateName> DependentTemplateNames;
227
  mutable llvm::FoldingSet<SubstTemplateTemplateParmStorage>
228
    SubstTemplateTemplateParms;
229
  mutable llvm::ContextualFoldingSet<SubstTemplateTemplateParmPackStorage,
230
                                     ASTContext&>
231
    SubstTemplateTemplateParmPacks;
232
233
  /// The set of nested name specifiers.
234
  ///
235
  /// This set is managed by the NestedNameSpecifier class.
236
  mutable llvm::FoldingSet<NestedNameSpecifier> NestedNameSpecifiers;
237
  mutable NestedNameSpecifier *GlobalNestedNameSpecifier = nullptr;
238
239
  /// A cache mapping from RecordDecls to ASTRecordLayouts.
240
  ///
241
  /// This is lazily created.  This is intentionally not serialized.
242
  mutable llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>
243
    ASTRecordLayouts;
244
  mutable llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*>
245
    ObjCLayouts;
246
247
  /// A cache from types to size and alignment information.
248
  using TypeInfoMap = llvm::DenseMap<const Type *, struct TypeInfo>;
249
  mutable TypeInfoMap MemoizedTypeInfo;
250
251
  /// A cache from types to unadjusted alignment information. Only ARM and
252
  /// AArch64 targets need this information, keeping it separate prevents
253
  /// imposing overhead on TypeInfo size.
254
  using UnadjustedAlignMap = llvm::DenseMap<const Type *, unsigned>;
255
  mutable UnadjustedAlignMap MemoizedUnadjustedAlign;
256
257
  /// A cache mapping from CXXRecordDecls to key functions.
258
  llvm::DenseMap<const CXXRecordDecl*, LazyDeclPtr> KeyFunctions;
259
260
  /// Mapping from ObjCContainers to their ObjCImplementations.
261
  llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls;
262
263
  /// Mapping from ObjCMethod to its duplicate declaration in the same
264
  /// interface.
265
  llvm::DenseMap<const ObjCMethodDecl*,const ObjCMethodDecl*> ObjCMethodRedecls;
266
267
  /// Mapping from __block VarDecls to BlockVarCopyInit.
268
  llvm::DenseMap<const VarDecl *, BlockVarCopyInit> BlockVarCopyInits;
269
270
  /// Used to cleanups APValues stored in the AST.
271
  mutable llvm::SmallVector<APValue *, 0> APValueCleanups;
272
273
  /// A cache mapping a string value to a StringLiteral object with the same
274
  /// value.
275
  ///
276
  /// This is lazily created.  This is intentionally not serialized.
277
  mutable llvm::StringMap<StringLiteral *> StringLiteralCache;
278
279
  /// Representation of a "canonical" template template parameter that
280
  /// is used in canonical template names.
281
  class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode {
282
    TemplateTemplateParmDecl *Parm;
283
284
  public:
285
    CanonicalTemplateTemplateParm(TemplateTemplateParmDecl *Parm)
286
3.30k
        : Parm(Parm) {}
287
288
8.69k
    TemplateTemplateParmDecl *getParam() const { return Parm; }
289
290
8.92k
    void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C) {
291
8.92k
      Profile(ID, C, Parm);
292
8.92k
    }
293
294
    static void Profile(llvm::FoldingSetNodeID &ID,
295
                        const ASTContext &C,
296
                        TemplateTemplateParmDecl *Parm);
297
  };
298
  mutable llvm::ContextualFoldingSet<CanonicalTemplateTemplateParm,
299
                                     const ASTContext&>
300
    CanonTemplateTemplateParms;
301
302
  TemplateTemplateParmDecl *
303
    getCanonicalTemplateTemplateParmDecl(TemplateTemplateParmDecl *TTP) const;
304
305
  /// The typedef for the __int128_t type.
306
  mutable TypedefDecl *Int128Decl = nullptr;
307
308
  /// The typedef for the __uint128_t type.
309
  mutable TypedefDecl *UInt128Decl = nullptr;
310
311
  /// The typedef for the target specific predefined
312
  /// __builtin_va_list type.
313
  mutable TypedefDecl *BuiltinVaListDecl = nullptr;
314
315
  /// The typedef for the predefined \c __builtin_ms_va_list type.
316
  mutable TypedefDecl *BuiltinMSVaListDecl = nullptr;
317
318
  /// The typedef for the predefined \c id type.
319
  mutable TypedefDecl *ObjCIdDecl = nullptr;
320
321
  /// The typedef for the predefined \c SEL type.
322
  mutable TypedefDecl *ObjCSelDecl = nullptr;
323
324
  /// The typedef for the predefined \c Class type.
325
  mutable TypedefDecl *ObjCClassDecl = nullptr;
326
327
  /// The typedef for the predefined \c Protocol class in Objective-C.
328
  mutable ObjCInterfaceDecl *ObjCProtocolClassDecl = nullptr;
329
330
  /// The typedef for the predefined 'BOOL' type.
331
  mutable TypedefDecl *BOOLDecl = nullptr;
332
333
  // Typedefs which may be provided defining the structure of Objective-C
334
  // pseudo-builtins
335
  QualType ObjCIdRedefinitionType;
336
  QualType ObjCClassRedefinitionType;
337
  QualType ObjCSelRedefinitionType;
338
339
  /// The identifier 'bool'.
340
  mutable IdentifierInfo *BoolName = nullptr;
341
342
  /// The identifier 'NSObject'.
343
  mutable IdentifierInfo *NSObjectName = nullptr;
344
345
  /// The identifier 'NSCopying'.
346
  IdentifierInfo *NSCopyingName = nullptr;
347
348
  /// The identifier '__make_integer_seq'.
349
  mutable IdentifierInfo *MakeIntegerSeqName = nullptr;
350
351
  /// The identifier '__type_pack_element'.
352
  mutable IdentifierInfo *TypePackElementName = nullptr;
353
354
  QualType ObjCConstantStringType;
355
  mutable RecordDecl *CFConstantStringTagDecl = nullptr;
356
  mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
357
358
  mutable QualType ObjCSuperType;
359
360
  QualType ObjCNSStringType;
361
362
  /// The typedef declaration for the Objective-C "instancetype" type.
363
  TypedefDecl *ObjCInstanceTypeDecl = nullptr;
364
365
  /// The type for the C FILE type.
366
  TypeDecl *FILEDecl = nullptr;
367
368
  /// The type for the C jmp_buf type.
369
  TypeDecl *jmp_bufDecl = nullptr;
370
371
  /// The type for the C sigjmp_buf type.
372
  TypeDecl *sigjmp_bufDecl = nullptr;
373
374
  /// The type for the C ucontext_t type.
375
  TypeDecl *ucontext_tDecl = nullptr;
376
377
  /// Type for the Block descriptor for Blocks CodeGen.
378
  ///
379
  /// Since this is only used for generation of debug info, it is not
380
  /// serialized.
381
  mutable RecordDecl *BlockDescriptorType = nullptr;
382
383
  /// Type for the Block descriptor for Blocks CodeGen.
384
  ///
385
  /// Since this is only used for generation of debug info, it is not
386
  /// serialized.
387
  mutable RecordDecl *BlockDescriptorExtendedType = nullptr;
388
389
  /// Declaration for the CUDA cudaConfigureCall function.
390
  FunctionDecl *cudaConfigureCallDecl = nullptr;
391
392
  /// Keeps track of all declaration attributes.
393
  ///
394
  /// Since so few decls have attrs, we keep them in a hash map instead of
395
  /// wasting space in the Decl class.
396
  llvm::DenseMap<const Decl*, AttrVec*> DeclAttrs;
397
398
  /// A mapping from non-redeclarable declarations in modules that were
399
  /// merged with other declarations to the canonical declaration that they were
400
  /// merged into.
401
  llvm::DenseMap<Decl*, Decl*> MergedDecls;
402
403
  /// A mapping from a defining declaration to a list of modules (other
404
  /// than the owning module of the declaration) that contain merged
405
  /// definitions of that entity.
406
  llvm::DenseMap<NamedDecl*, llvm::TinyPtrVector<Module*>> MergedDefModules;
407
408
  /// Initializers for a module, in order. Each Decl will be either
409
  /// something that has a semantic effect on startup (such as a variable with
410
  /// a non-constant initializer), or an ImportDecl (which recursively triggers
411
  /// initialization of another module).
412
  struct PerModuleInitializers {
413
    llvm::SmallVector<Decl*, 4> Initializers;
414
    llvm::SmallVector<uint32_t, 4> LazyInitializers;
415
416
    void resolve(ASTContext &Ctx);
417
  };
418
  llvm::DenseMap<Module*, PerModuleInitializers*> ModuleInitializers;
419
420
493k
  ASTContext &this_() { return *this; }
421
422
public:
423
  /// A type synonym for the TemplateOrInstantiation mapping.
424
  using TemplateOrSpecializationInfo =
425
      llvm::PointerUnion<VarTemplateDecl *, MemberSpecializationInfo *>;
426
427
private:
428
  friend class ASTDeclReader;
429
  friend class ASTReader;
430
  friend class ASTWriter;
431
  template <class> friend class serialization::AbstractTypeReader;
432
  friend class CXXRecordDecl;
433
434
  /// A mapping to contain the template or declaration that
435
  /// a variable declaration describes or was instantiated from,
436
  /// respectively.
437
  ///
438
  /// For non-templates, this value will be NULL. For variable
439
  /// declarations that describe a variable template, this will be a
440
  /// pointer to a VarTemplateDecl. For static data members
441
  /// of class template specializations, this will be the
442
  /// MemberSpecializationInfo referring to the member variable that was
443
  /// instantiated or specialized. Thus, the mapping will keep track of
444
  /// the static data member templates from which static data members of
445
  /// class template specializations were instantiated.
446
  ///
447
  /// Given the following example:
448
  ///
449
  /// \code
450
  /// template<typename T>
451
  /// struct X {
452
  ///   static T value;
453
  /// };
454
  ///
455
  /// template<typename T>
456
  ///   T X<T>::value = T(17);
457
  ///
458
  /// int *x = &X<int>::value;
459
  /// \endcode
460
  ///
461
  /// This mapping will contain an entry that maps from the VarDecl for
462
  /// X<int>::value to the corresponding VarDecl for X<T>::value (within the
463
  /// class template X) and will be marked TSK_ImplicitInstantiation.
464
  llvm::DenseMap<const VarDecl *, TemplateOrSpecializationInfo>
465
  TemplateOrInstantiation;
466
467
  /// Keeps track of the declaration from which a using declaration was
468
  /// created during instantiation.
469
  ///
470
  /// The source and target declarations are always a UsingDecl, an
471
  /// UnresolvedUsingValueDecl, or an UnresolvedUsingTypenameDecl.
472
  ///
473
  /// For example:
474
  /// \code
475
  /// template<typename T>
476
  /// struct A {
477
  ///   void f();
478
  /// };
479
  ///
480
  /// template<typename T>
481
  /// struct B : A<T> {
482
  ///   using A<T>::f;
483
  /// };
484
  ///
485
  /// template struct B<int>;
486
  /// \endcode
487
  ///
488
  /// This mapping will contain an entry that maps from the UsingDecl in
489
  /// B<int> to the UnresolvedUsingDecl in B<T>.
490
  llvm::DenseMap<NamedDecl *, NamedDecl *> InstantiatedFromUsingDecl;
491
492
  llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>
493
    InstantiatedFromUsingShadowDecl;
494
495
  llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl;
496
497
  /// Mapping that stores the methods overridden by a given C++
498
  /// member function.
499
  ///
500
  /// Since most C++ member functions aren't virtual and therefore
501
  /// don't override anything, we store the overridden functions in
502
  /// this map on the side rather than within the CXXMethodDecl structure.
503
  using CXXMethodVector = llvm::TinyPtrVector<const CXXMethodDecl *>;
504
  llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector> OverriddenMethods;
505
506
  /// Mapping from each declaration context to its corresponding
507
  /// mangling numbering context (used for constructs like lambdas which
508
  /// need to be consistently numbered for the mangler).
509
  llvm::DenseMap<const DeclContext *, std::unique_ptr<MangleNumberingContext>>
510
      MangleNumberingContexts;
511
  llvm::DenseMap<const Decl *, std::unique_ptr<MangleNumberingContext>>
512
      ExtraMangleNumberingContexts;
513
514
  /// Side-table of mangling numbers for declarations which rarely
515
  /// need them (like static local vars).
516
  llvm::MapVector<const NamedDecl *, unsigned> MangleNumbers;
517
  llvm::MapVector<const VarDecl *, unsigned> StaticLocalNumbers;
518
519
  /// Mapping that stores parameterIndex values for ParmVarDecls when
520
  /// that value exceeds the bitfield size of ParmVarDeclBits.ParameterIndex.
521
  using ParameterIndexTable = llvm::DenseMap<const VarDecl *, unsigned>;
522
  ParameterIndexTable ParamIndices;
523
524
  ImportDecl *FirstLocalImport = nullptr;
525
  ImportDecl *LastLocalImport = nullptr;
526
527
  TranslationUnitDecl *TUDecl;
528
  mutable ExternCContextDecl *ExternCContext = nullptr;
529
  mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
530
  mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
531
532
  /// The associated SourceManager object.
533
  SourceManager &SourceMgr;
534
535
  /// The language options used to create the AST associated with
536
  ///  this ASTContext object.
537
  LangOptions &LangOpts;
538
539
  /// Blacklist object that is used by sanitizers to decide which
540
  /// entities should not be instrumented.
541
  std::unique_ptr<SanitizerBlacklist> SanitizerBL;
542
543
  /// Function filtering mechanism to determine whether a given function
544
  /// should be imbued with the XRay "always" or "never" attributes.
545
  std::unique_ptr<XRayFunctionFilter> XRayFilter;
546
547
  /// The allocator used to create AST objects.
548
  ///
549
  /// AST objects are never destructed; rather, all memory associated with the
550
  /// AST objects will be released when the ASTContext itself is destroyed.
551
  mutable llvm::BumpPtrAllocator BumpAlloc;
552
553
  /// Allocator for partial diagnostics.
554
  PartialDiagnostic::StorageAllocator DiagAllocator;
555
556
  /// The current C++ ABI.
557
  std::unique_ptr<CXXABI> ABI;
558
  CXXABI *createCXXABI(const TargetInfo &T);
559
560
  /// The logical -> physical address space map.
561
  const LangASMap *AddrSpaceMap = nullptr;
562
563
  /// Address space map mangling must be used with language specific
564
  /// address spaces (e.g. OpenCL/CUDA)
565
  bool AddrSpaceMapMangling;
566
567
  const TargetInfo *Target = nullptr;
568
  const TargetInfo *AuxTarget = nullptr;
569
  clang::PrintingPolicy PrintingPolicy;
570
  std::unique_ptr<interp::Context> InterpContext;
571
  std::unique_ptr<ParentMapContext> ParentMapCtx;
572
573
public:
574
  IdentifierTable &Idents;
575
  SelectorTable &Selectors;
576
  Builtin::Context &BuiltinInfo;
577
  mutable DeclarationNameTable DeclarationNames;
578
  IntrusiveRefCntPtr<ExternalASTSource> ExternalSource;
579
  ASTMutationListener *Listener = nullptr;
580
581
  /// Returns the clang bytecode interpreter context.
582
  interp::Context &getInterpContext();
583
584
  /// Returns the dynamic AST node parent map context.
585
  ParentMapContext &getParentMapContext();
586
587
  // A traversal scope limits the parts of the AST visible to certain analyses.
588
  // RecursiveASTVisitor::TraverseAST will only visit reachable nodes, and
589
  // getParents() will only observe reachable parent edges.
590
  //
591
  // The scope is defined by a set of "top-level" declarations.
592
  // Initially, it is the entire TU: {getTranslationUnitDecl()}.
593
  // Changing the scope clears the parent cache, which is expensive to rebuild.
594
9.03k
  std::vector<Decl *> getTraversalScope() const { return TraversalScope; }
595
  void setTraversalScope(const std::vector<Decl *> &);
596
597
  /// Forwards to get node parents from the ParentMapContext. New callers should
598
  /// use ParentMapContext::getParents() directly.
599
  template <typename NodeT> DynTypedNodeList getParents(const NodeT &Node);
600
601
56.1M
  const clang::PrintingPolicy &getPrintingPolicy() const {
602
56.1M
    return PrintingPolicy;
603
56.1M
  }
604
605
2.07M
  void setPrintingPolicy(const clang::PrintingPolicy &Policy) {
606
2.07M
    PrintingPolicy = Policy;
607
2.07M
  }
608
609
37.7M
  SourceManager& getSourceManager() { return SourceMgr; }
610
21.8k
  const SourceManager& getSourceManager() const { return SourceMgr; }
611
612
4.99k
  llvm::BumpPtrAllocator &getAllocator() const {
613
4.99k
    return BumpAlloc;
614
4.99k
  }
615
616
305M
  void *Allocate(size_t Size, unsigned Align = 8) const {
617
305M
    return BumpAlloc.Allocate(Size, Align);
618
305M
  }
619
468k
  template <typename T> T *Allocate(size_t Num = 1) const {
620
468k
    return static_cast<T *>(Allocate(Num * sizeof(T), alignof(T)));
621
468k
  }
clang::BlockDecl::Capture* clang::ASTContext::Allocate<clang::BlockDecl::Capture>(unsigned long) const
Line
Count
Source
619
1.35k
  template <typename T> T *Allocate(size_t Num = 1) const {
620
1.35k
    return static_cast<T *>(Allocate(Num * sizeof(T), alignof(T)));
621
1.35k
  }
clang::OMPClause** clang::ASTContext::Allocate<clang::OMPClause*>(unsigned long) const
Line
Count
Source
619
268
  template <typename T> T *Allocate(size_t Num = 1) const {
620
268
    return static_cast<T *>(Allocate(Num * sizeof(T), alignof(T)));
621
268
  }
char* clang::ASTContext::Allocate<char>(unsigned long) const
Line
Count
Source
619
580
  template <typename T> T *Allocate(size_t Num = 1) const {
620
580
    return static_cast<T *>(Allocate(Num * sizeof(T), alignof(T)));
621
580
  }
clang::TemplateArgument* clang::ASTContext::Allocate<clang::TemplateArgument>(unsigned long) const
Line
Count
Source
619
466k
  template <typename T> T *Allocate(size_t Num = 1) const {
620
466k
    return static_cast<T *>(Allocate(Num * sizeof(T), alignof(T)));
621
466k
  }
Unexecuted instantiation: clang::QualType* clang::ASTContext::Allocate<clang::QualType>(unsigned long) const
622
718k
  void Deallocate(void *Ptr) const {}
623
624
  /// Return the total amount of physical memory allocated for representing
625
  /// AST nodes and type information.
626
1
  size_t getASTAllocatedMemory() const {
627
1
    return BumpAlloc.getTotalMemory();
628
1
  }
629
630
  /// Return the total memory used for various side tables.
631
  size_t getSideTableAllocatedMemory() const;
632
633
3.25M
  PartialDiagnostic::StorageAllocator &getDiagAllocator() {
634
3.25M
    return DiagAllocator;
635
3.25M
  }
636
637
130M
  const TargetInfo &getTargetInfo() const { return *Target; }
638
171
  const TargetInfo *getAuxTargetInfo() const { return AuxTarget; }
639
640
  /// getIntTypeForBitwidth -
641
  /// sets integer QualTy according to specified details:
642
  /// bitwidth, signed/unsigned.
643
  /// Returns empty type if there is no appropriate target types.
644
  QualType getIntTypeForBitwidth(unsigned DestWidth,
645
                                 unsigned Signed) const;
646
647
  /// getRealTypeForBitwidth -
648
  /// sets floating point QualTy according to specified bitwidth.
649
  /// Returns empty type if there is no appropriate target types.
650
  QualType getRealTypeForBitwidth(unsigned DestWidth) const;
651
652
  bool AtomicUsesUnsupportedLibcall(const AtomicExpr *E) const;
653
654
490M
  const LangOptions& getLangOpts() const { return LangOpts; }
655
656
8.00k
  const SanitizerBlacklist &getSanitizerBlacklist() const {
657
8.00k
    return *SanitizerBL;
658
8.00k
  }
659
660
20
  const XRayFunctionFilter &getXRayFilter() const {
661
20
    return *XRayFilter;
662
20
  }
663
664
  DiagnosticsEngine &getDiagnostics() const;
665
666
456
  FullSourceLoc getFullLoc(SourceLocation Loc) const {
667
456
    return FullSourceLoc(Loc,SourceMgr);
668
456
  }
669
670
  /// All comments in this translation unit.
671
  RawCommentList Comments;
672
673
  /// True if comments are already loaded from ExternalASTSource.
674
  mutable bool CommentsLoaded = false;
675
676
  /// Mapping from declaration to directly attached comment.
677
  ///
678
  /// Raw comments are owned by Comments list.  This mapping is populated
679
  /// lazily.
680
  mutable llvm::DenseMap<const Decl *, const RawComment *> DeclRawComments;
681
682
  /// Mapping from canonical declaration to the first redeclaration in chain
683
  /// that has a comment attached.
684
  ///
685
  /// Raw comments are owned by Comments list.  This mapping is populated
686
  /// lazily.
687
  mutable llvm::DenseMap<const Decl *, const Decl *> RedeclChainComments;
688
689
  /// Keeps track of redeclaration chains that don't have any comment attached.
690
  /// Mapping from canonical declaration to redeclaration chain that has no
691
  /// comments attached to any redeclaration. Specifically it's mapping to
692
  /// the last redeclaration we've checked.
693
  ///
694
  /// Shall not contain declarations that have comments attached to any
695
  /// redeclaration in their chain.
696
  mutable llvm::DenseMap<const Decl *, const Decl *> CommentlessRedeclChains;
697
698
  /// Mapping from declarations to parsed comments attached to any
699
  /// redeclaration.
700
  mutable llvm::DenseMap<const Decl *, comments::FullComment *> ParsedComments;
701
702
  /// Attaches \p Comment to \p OriginalD and to its redeclaration chain
703
  /// and removes the redeclaration chain from the set of commentless chains.
704
  ///
705
  /// Don't do anything if a comment has already been attached to \p OriginalD
706
  /// or its redeclaration chain.
707
  void cacheRawCommentForDecl(const Decl &OriginalD,
708
                              const RawComment &Comment) const;
709
710
  /// \returns searches \p CommentsInFile for doc comment for \p D.
711
  ///
712
  /// \p RepresentativeLocForDecl is used as a location for searching doc
713
  /// comments. \p CommentsInFile is a mapping offset -> comment of files in the
714
  /// same file where \p RepresentativeLocForDecl is.
715
  RawComment *getRawCommentForDeclNoCacheImpl(
716
      const Decl *D, const SourceLocation RepresentativeLocForDecl,
717
      const std::map<unsigned, RawComment *> &CommentsInFile) const;
718
719
  /// Return the documentation comment attached to a given declaration,
720
  /// without looking into cache.
721
  RawComment *getRawCommentForDeclNoCache(const Decl *D) const;
722
723
public:
724
0
  RawCommentList &getRawCommentList() {
725
0
    return Comments;
726
0
  }
727
728
23.9M
  void addComment(const RawComment &RC) {
729
23.9M
    assert(LangOpts.RetainCommentsFromSystemHeaders ||
730
23.9M
           !SourceMgr.isInSystemHeader(RC.getSourceRange().getBegin()));
731
23.9M
    Comments.addComment(RC, LangOpts.CommentOpts, BumpAlloc);
732
23.9M
  }
733
734
  /// Return the documentation comment attached to a given declaration.
735
  /// Returns nullptr if no comment is attached.
736
  ///
737
  /// \param OriginalDecl if not nullptr, is set to declaration AST node that
738
  /// had the comment, if the comment we found comes from a redeclaration.
739
  const RawComment *
740
  getRawCommentForAnyRedecl(const Decl *D,
741
                            const Decl **OriginalDecl = nullptr) const;
742
743
  /// Searches existing comments for doc comments that should be attached to \p
744
  /// Decls. If any doc comment is found, it is parsed.
745
  ///
746
  /// Requirement: All \p Decls are in the same file.
747
  ///
748
  /// If the last comment in the file is already attached we assume
749
  /// there are not comments left to be attached to \p Decls.
750
  void attachCommentsToJustParsedDecls(ArrayRef<Decl *> Decls,
751
                                       const Preprocessor *PP);
752
753
  /// Return parsed documentation comment attached to a given declaration.
754
  /// Returns nullptr if no comment is attached.
755
  ///
756
  /// \param PP the Preprocessor used with this TU.  Could be nullptr if
757
  /// preprocessor is not available.
758
  comments::FullComment *getCommentForDecl(const Decl *D,
759
                                           const Preprocessor *PP) const;
760
761
  /// Return parsed documentation comment attached to a given declaration.
762
  /// Returns nullptr if no comment is attached. Does not look at any
763
  /// redeclarations of the declaration.
764
  comments::FullComment *getLocalCommentForDeclUncached(const Decl *D) const;
765
766
  comments::FullComment *cloneFullComment(comments::FullComment *FC,
767
                                         const Decl *D) const;
768
769
private:
770
  mutable comments::CommandTraits CommentCommandTraits;
771
772
  /// Iterator that visits import declarations.
773
  class import_iterator {
774
    ImportDecl *Import = nullptr;
775
776
  public:
777
    using value_type = ImportDecl *;
778
    using reference = ImportDecl *;
779
    using pointer = ImportDecl *;
780
    using difference_type = int;
781
    using iterator_category = std::forward_iterator_tag;
782
783
2.50k
    import_iterator() = default;
784
2.50k
    explicit import_iterator(ImportDecl *Import) : Import(Import) {}
785
786
65
    reference operator*() const { return Import; }
787
0
    pointer operator->() const { return Import; }
788
789
65
    import_iterator &operator++() {
790
65
      Import = ASTContext::getNextLocalImport(Import);
791
65
      return *this;
792
65
    }
793
794
0
    import_iterator operator++(int) {
795
0
      import_iterator Other(*this);
796
0
      ++(*this);
797
0
      return Other;
798
0
    }
799
800
0
    friend bool operator==(import_iterator X, import_iterator Y) {
801
0
      return X.Import == Y.Import;
802
0
    }
803
804
2.56k
    friend bool operator!=(import_iterator X, import_iterator Y) {
805
2.56k
      return X.Import != Y.Import;
806
2.56k
    }
807
  };
808
809
public:
810
10.2k
  comments::CommandTraits &getCommentCommandTraits() const {
811
10.2k
    return CommentCommandTraits;
812
10.2k
  }
813
814
  /// Retrieve the attributes for the given declaration.
815
  AttrVec& getDeclAttrs(const Decl *D);
816
817
  /// Erase the attributes corresponding to the given declaration.
818
  void eraseDeclAttrs(const Decl *D);
819
820
  /// If this variable is an instantiated static data member of a
821
  /// class template specialization, returns the templated static data member
822
  /// from which it was instantiated.
823
  // FIXME: Remove ?
824
  MemberSpecializationInfo *getInstantiatedFromStaticDataMember(
825
                                                           const VarDecl *Var);
826
827
  TemplateOrSpecializationInfo
828
  getTemplateOrSpecializationInfo(const VarDecl *Var);
829
830
  /// Note that the static data member \p Inst is an instantiation of
831
  /// the static data member template \p Tmpl of a class template.
832
  void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl,
833
                                           TemplateSpecializationKind TSK,
834
                        SourceLocation PointOfInstantiation = SourceLocation());
835
836
  void setTemplateOrSpecializationInfo(VarDecl *Inst,
837
                                       TemplateOrSpecializationInfo TSI);
838
839
  /// If the given using decl \p Inst is an instantiation of a
840
  /// (possibly unresolved) using decl from a template instantiation,
841
  /// return it.
842
  NamedDecl *getInstantiatedFromUsingDecl(NamedDecl *Inst);
843
844
  /// Remember that the using decl \p Inst is an instantiation
845
  /// of the using decl \p Pattern of a class template.
846
  void setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern);
847
848
  void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst,
849
                                          UsingShadowDecl *Pattern);
850
  UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst);
851
852
  FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field);
853
854
  void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl);
855
856
  // Access to the set of methods overridden by the given C++ method.
857
  using overridden_cxx_method_iterator = CXXMethodVector::const_iterator;
858
  overridden_cxx_method_iterator
859
  overridden_methods_begin(const CXXMethodDecl *Method) const;
860
861
  overridden_cxx_method_iterator
862
  overridden_methods_end(const CXXMethodDecl *Method) const;
863
864
  unsigned overridden_methods_size(const CXXMethodDecl *Method) const;
865
866
  using overridden_method_range =
867
      llvm::iterator_range<overridden_cxx_method_iterator>;
868
869
  overridden_method_range overridden_methods(const CXXMethodDecl *Method) const;
870
871
  /// Note that the given C++ \p Method overrides the given \p
872
  /// Overridden method.
873
  void addOverriddenMethod(const CXXMethodDecl *Method,
874
                           const CXXMethodDecl *Overridden);
875
876
  /// Return C++ or ObjC overridden methods for the given \p Method.
877
  ///
878
  /// An ObjC method is considered to override any method in the class's
879
  /// base classes, its protocols, or its categories' protocols, that has
880
  /// the same selector and is of the same kind (class or instance).
881
  /// A method in an implementation is not considered as overriding the same
882
  /// method in the interface or its categories.
883
  void getOverriddenMethods(
884
                        const NamedDecl *Method,
885
                        SmallVectorImpl<const NamedDecl *> &Overridden) const;
886
887
  /// Notify the AST context that a new import declaration has been
888
  /// parsed or implicitly created within this translation unit.
889
  void addedLocalImportDecl(ImportDecl *Import);
890
891
65
  static ImportDecl *getNextLocalImport(ImportDecl *Import) {
892
65
    return Import->NextLocalImport;
893
65
  }
894
895
  using import_range = llvm::iterator_range<import_iterator>;
896
897
2.50k
  import_range local_imports() const {
898
2.50k
    return import_range(import_iterator(FirstLocalImport), import_iterator());
899
2.50k
  }
900
901
92.2k
  Decl *getPrimaryMergedDecl(Decl *D) {
902
92.2k
    Decl *Result = MergedDecls.lookup(D);
903
92.2k
    return Result ? 
Result866
:
D91.3k
;
904
92.2k
  }
905
496
  void setPrimaryMergedDecl(Decl *D, Decl *Primary) {
906
496
    MergedDecls[D] = Primary;
907
496
  }
908
909
  /// Note that the definition \p ND has been merged into module \p M,
910
  /// and should be visible whenever \p M is visible.
911
  void mergeDefinitionIntoModule(NamedDecl *ND, Module *M,
912
                                 bool NotifyListeners = true);
913
914
  /// Clean up the merged definition list. Call this if you might have
915
  /// added duplicates into the list.
916
  void deduplicateMergedDefinitonsFor(NamedDecl *ND);
917
918
  /// Get the additional modules in which the definition \p Def has
919
  /// been merged.
920
28.9k
  ArrayRef<Module*> getModulesWithMergedDefinition(const NamedDecl *Def) {
921
28.9k
    auto MergedIt =
922
28.9k
        MergedDefModules.find(cast<NamedDecl>(Def->getCanonicalDecl()));
923
28.9k
    if (MergedIt == MergedDefModules.end())
924
27.8k
      return None;
925
1.09k
    return MergedIt->second;
926
1.09k
  }
927
928
  /// Add a declaration to the list of declarations that are initialized
929
  /// for a module. This will typically be a global variable (with internal
930
  /// linkage) that runs module initializers, such as the iostream initializer,
931
  /// or an ImportDecl nominating another module that has initializers.
932
  void addModuleInitializer(Module *M, Decl *Init);
933
934
  void addLazyModuleInitializers(Module *M, ArrayRef<uint32_t> IDs);
935
936
  /// Get the initializations to perform when importing a module, if any.
937
  ArrayRef<Decl*> getModuleInitializers(Module *M);
938
939
26.2M
  TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
940
941
  ExternCContextDecl *getExternCContextDecl() const;
942
  BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
943
  BuiltinTemplateDecl *getTypePackElementDecl() const;
944
945
  // Builtin Types.
946
  CanQualType VoidTy;
947
  CanQualType BoolTy;
948
  CanQualType CharTy;
949
  CanQualType WCharTy;  // [C++ 3.9.1p5].
950
  CanQualType WideCharTy; // Same as WCharTy in C++, integer type in C99.
951
  CanQualType WIntTy;   // [C99 7.24.1], integer type unchanged by default promotions.
952
  CanQualType Char8Ty;  // [C++20 proposal]
953
  CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99.
954
  CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99.
955
  CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
956
  CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
957
  CanQualType UnsignedLongLongTy, UnsignedInt128Ty;
958
  CanQualType FloatTy, DoubleTy, LongDoubleTy, Float128Ty;
959
  CanQualType ShortAccumTy, AccumTy,
960
      LongAccumTy;  // ISO/IEC JTC1 SC22 WG14 N1169 Extension
961
  CanQualType UnsignedShortAccumTy, UnsignedAccumTy, UnsignedLongAccumTy;
962
  CanQualType ShortFractTy, FractTy, LongFractTy;
963
  CanQualType UnsignedShortFractTy, UnsignedFractTy, UnsignedLongFractTy;
964
  CanQualType SatShortAccumTy, SatAccumTy, SatLongAccumTy;
965
  CanQualType SatUnsignedShortAccumTy, SatUnsignedAccumTy,
966
      SatUnsignedLongAccumTy;
967
  CanQualType SatShortFractTy, SatFractTy, SatLongFractTy;
968
  CanQualType SatUnsignedShortFractTy, SatUnsignedFractTy,
969
      SatUnsignedLongFractTy;
970
  CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
971
  CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3
972
  CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
973
  CanQualType Float128ComplexTy;
974
  CanQualType VoidPtrTy, NullPtrTy;
975
  CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy;
976
  CanQualType BuiltinFnTy;
977
  CanQualType PseudoObjectTy, ARCUnbridgedCastTy;
978
  CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
979
  CanQualType ObjCBuiltinBoolTy;
980
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
981
  CanQualType SingletonId;
982
#include "clang/Basic/OpenCLImageTypes.def"
983
  CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy;
984
  CanQualType OCLQueueTy, OCLReserveIDTy;
985
  CanQualType OMPArraySectionTy;
986
#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
987
  CanQualType Id##Ty;
988
#include "clang/Basic/OpenCLExtensionTypes.def"
989
#define SVE_TYPE(Name, Id, SingletonId) \
990
  CanQualType SingletonId;
991
#include "clang/Basic/AArch64SVEACLETypes.def"
992
993
  // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand.
994
  mutable QualType AutoDeductTy;     // Deduction against 'auto'.
995
  mutable QualType AutoRRefDeductTy; // Deduction against 'auto &&'.
996
997
  // Decl used to help define __builtin_va_list for some targets.
998
  // The decl is built when constructing 'BuiltinVaListDecl'.
999
  mutable Decl *VaListTagDecl;
1000
1001
  ASTContext(LangOptions &LOpts, SourceManager &SM, IdentifierTable &idents,
1002
             SelectorTable &sels, Builtin::Context &builtins);
1003
  ASTContext(const ASTContext &) = delete;
1004
  ASTContext &operator=(const ASTContext &) = delete;
1005
  ~ASTContext();
1006
1007
  /// Attach an external AST source to the AST context.
1008
  ///
1009
  /// The external AST source provides the ability to load parts of
1010
  /// the abstract syntax tree as needed from some external storage,
1011
  /// e.g., a precompiled header.
1012
  void setExternalSource(IntrusiveRefCntPtr<ExternalASTSource> Source);
1013
1014
  /// Retrieve a pointer to the external AST source associated
1015
  /// with this AST context, if any.
1016
207M
  ExternalASTSource *getExternalSource() const {
1017
207M
    return ExternalSource.get();
1018
207M
  }
1019
1020
  /// Attach an AST mutation listener to the AST context.
1021
  ///
1022
  /// The AST mutation listener provides the ability to track modifications to
1023
  /// the abstract syntax tree entities committed after they were initially
1024
  /// created.
1025
43.2k
  void setASTMutationListener(ASTMutationListener *Listener) {
1026
43.2k
    this->Listener = Listener;
1027
43.2k
  }
1028
1029
  /// Retrieve a pointer to the AST mutation listener associated
1030
  /// with this AST context, if any.
1031
31.3M
  ASTMutationListener *getASTMutationListener() const { return Listener; }
1032
1033
  void PrintStats() const;
1034
3.13k
  const SmallVectorImpl<Type *>& getTypes() const { return Types; }
1035
1036
  BuiltinTemplateDecl *buildBuiltinTemplateDecl(BuiltinTemplateKind BTK,
1037
                                                const IdentifierInfo *II) const;
1038
1039
  /// Create a new implicit TU-level CXXRecordDecl or RecordDecl
1040
  /// declaration.
1041
  RecordDecl *buildImplicitRecord(StringRef Name,
1042
                                  RecordDecl::TagKind TK = TTK_Struct) const;
1043
1044
  /// Create a new implicit TU-level typedef declaration.
1045
  TypedefDecl *buildImplicitTypedef(QualType T, StringRef Name) const;
1046
1047
  /// Retrieve the declaration for the 128-bit signed integer type.
1048
  TypedefDecl *getInt128Decl() const;
1049
1050
  /// Retrieve the declaration for the 128-bit unsigned integer type.
1051
  TypedefDecl *getUInt128Decl() const;
1052
1053
  //===--------------------------------------------------------------------===//
1054
  //                           Type Constructors
1055
  //===--------------------------------------------------------------------===//
1056
1057
private:
1058
  /// Return a type with extended qualifiers.
1059
  QualType getExtQualType(const Type *Base, Qualifiers Quals) const;
1060
1061
  QualType getTypeDeclTypeSlow(const TypeDecl *Decl) const;
1062
1063
  QualType getPipeType(QualType T, bool ReadOnly) const;
1064
1065
public:
1066
  /// Return the uniqued reference to the type for an address space
1067
  /// qualified type with the specified type and address space.
1068
  ///
1069
  /// The resulting type has a union of the qualifiers from T and the address
1070
  /// space. If T already has an address space specifier, it is silently
1071
  /// replaced.
1072
  QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const;
1073
1074
  /// Remove any existing address space on the type and returns the type
1075
  /// with qualifiers intact (or that's the idea anyway)
1076
  ///
1077
  /// The return type should be T with all prior qualifiers minus the address
1078
  /// space.
1079
  QualType removeAddrSpaceQualType(QualType T) const;
1080
1081
  /// Apply Objective-C protocol qualifiers to the given type.
1082
  /// \param allowOnPointerType specifies if we can apply protocol
1083
  /// qualifiers on ObjCObjectPointerType. It can be set to true when
1084
  /// constructing the canonical type of a Objective-C type parameter.
1085
  QualType applyObjCProtocolQualifiers(QualType type,
1086
      ArrayRef<ObjCProtocolDecl *> protocols, bool &hasError,
1087
      bool allowOnPointerType = false) const;
1088
1089
  /// Return the uniqued reference to the type for an Objective-C
1090
  /// gc-qualified type.
1091
  ///
1092
  /// The resulting type has a union of the qualifiers from T and the gc
1093
  /// attribute.
1094
  QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const;
1095
1096
  /// Remove the existing address space on the type if it is a pointer size
1097
  /// address space and return the type with qualifiers intact.
1098
  QualType removePtrSizeAddrSpace(QualType T) const;
1099
1100
  /// Return the uniqued reference to the type for a \c restrict
1101
  /// qualified type.
1102
  ///
1103
  /// The resulting type has a union of the qualifiers from \p T and
1104
  /// \c restrict.
1105
312
  QualType getRestrictType(QualType T) const {
1106
312
    return T.withFastQualifiers(Qualifiers::Restrict);
1107
312
  }
1108
1109
  /// Return the uniqued reference to the type for a \c volatile
1110
  /// qualified type.
1111
  ///
1112
  /// The resulting type has a union of the qualifiers from \p T and
1113
  /// \c volatile.
1114
1.53M
  QualType getVolatileType(QualType T) const {
1115
1.53M
    return T.withFastQualifiers(Qualifiers::Volatile);
1116
1.53M
  }
1117
1118
  /// Return the uniqued reference to the type for a \c const
1119
  /// qualified type.
1120
  ///
1121
  /// The resulting type has a union of the qualifiers from \p T and \c const.
1122
  ///
1123
  /// It can be reasonably expected that this will always be equivalent to
1124
  /// calling T.withConst().
1125
2.75k
  QualType getConstType(QualType T) const { return T.withConst(); }
1126
1127
  /// Change the ExtInfo on a function type.
1128
  const FunctionType *adjustFunctionType(const FunctionType *Fn,
1129
                                         FunctionType::ExtInfo EInfo);
1130
1131
  /// Adjust the given function result type.
1132
  CanQualType getCanonicalFunctionResultType(QualType ResultType) const;
1133
1134
  /// Change the result type of a function type once it is deduced.
1135
  void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType);
1136
1137
  /// Get a function type and produce the equivalent function type with the
1138
  /// specified exception specification. Type sugar that can be present on a
1139
  /// declaration of a function with an exception specification is permitted
1140
  /// and preserved. Other type sugar (for instance, typedefs) is not.
1141
  QualType getFunctionTypeWithExceptionSpec(
1142
      QualType Orig, const FunctionProtoType::ExceptionSpecInfo &ESI);
1143
1144
  /// Determine whether two function types are the same, ignoring
1145
  /// exception specifications in cases where they're part of the type.
1146
  bool hasSameFunctionTypeIgnoringExceptionSpec(QualType T, QualType U);
1147
1148
  /// Change the exception specification on a function once it is
1149
  /// delay-parsed, instantiated, or computed.
1150
  void adjustExceptionSpec(FunctionDecl *FD,
1151
                           const FunctionProtoType::ExceptionSpecInfo &ESI,
1152
                           bool AsWritten = false);
1153
1154
  /// Get a function type and produce the equivalent function type where
1155
  /// pointer size address spaces in the return type and parameter tyeps are
1156
  /// replaced with the default address space.
1157
  QualType getFunctionTypeWithoutPtrSizes(QualType T);
1158
1159
  /// Determine whether two function types are the same, ignoring pointer sizes
1160
  /// in the return type and parameter types.
1161
  bool hasSameFunctionTypeIgnoringPtrSizes(QualType T, QualType U);
1162
1163
  /// Return the uniqued reference to the type for a complex
1164
  /// number with the specified element type.
1165
  QualType getComplexType(QualType T) const;
1166
246k
  CanQualType getComplexType(CanQualType T) const {
1167
246k
    return CanQualType::CreateUnsafe(getComplexType((QualType) T));
1168
246k
  }
1169
1170
  /// Return the uniqued reference to the type for a pointer to
1171
  /// the specified type.
1172
  QualType getPointerType(QualType T) const;
1173
2.24M
  CanQualType getPointerType(CanQualType T) const {
1174
2.24M
    return CanQualType::CreateUnsafe(getPointerType((QualType) T));
1175
2.24M
  }
1176
1177
  /// Return the uniqued reference to a type adjusted from the original
1178
  /// type to a new type.
1179
  QualType getAdjustedType(QualType Orig, QualType New) const;
1180
0
  CanQualType getAdjustedType(CanQualType Orig, CanQualType New) const {
1181
0
    return CanQualType::CreateUnsafe(
1182
0
        getAdjustedType((QualType)Orig, (QualType)New));
1183
0
  }
1184
1185
  /// Return the uniqued reference to the decayed version of the given
1186
  /// type.  Can only be called on array and function types which decay to
1187
  /// pointer types.
1188
  QualType getDecayedType(QualType T) const;
1189
0
  CanQualType getDecayedType(CanQualType T) const {
1190
0
    return CanQualType::CreateUnsafe(getDecayedType((QualType) T));
1191
0
  }
1192
1193
  /// Return the uniqued reference to the atomic type for the specified
1194
  /// type.
1195
  QualType getAtomicType(QualType T) const;
1196
1197
  /// Return the uniqued reference to the type for a block of the
1198
  /// specified type.
1199
  QualType getBlockPointerType(QualType T) const;
1200
1201
  /// Gets the struct used to keep track of the descriptor for pointer to
1202
  /// blocks.
1203
  QualType getBlockDescriptorType() const;
1204
1205
  /// Return a read_only pipe type for the specified type.
1206
  QualType getReadPipeType(QualType T) const;
1207
1208
  /// Return a write_only pipe type for the specified type.
1209
  QualType getWritePipeType(QualType T) const;
1210
1211
  /// Gets the struct used to keep track of the extended descriptor for
1212
  /// pointer to blocks.
1213
  QualType getBlockDescriptorExtendedType() const;
1214
1215
  /// Map an AST Type to an OpenCLTypeKind enum value.
1216
  TargetInfo::OpenCLTypeKind getOpenCLTypeKind(const Type *T) const;
1217
1218
  /// Get address space for OpenCL type.
1219
  LangAS getOpenCLTypeAddrSpace(const Type *T) const;
1220
1221
175
  void setcudaConfigureCallDecl(FunctionDecl *FD) {
1222
175
    cudaConfigureCallDecl = FD;
1223
175
  }
1224
1225
4.40k
  FunctionDecl *getcudaConfigureCallDecl() {
1226
4.40k
    return cudaConfigureCallDecl;
1227
4.40k
  }
1228
1229
  /// Returns true iff we need copy/dispose helpers for the given type.
1230
  bool BlockRequiresCopying(QualType Ty, const VarDecl *D);
1231
1232
  /// Returns true, if given type has a known lifetime. HasByrefExtendedLayout
1233
  /// is set to false in this case. If HasByrefExtendedLayout returns true,
1234
  /// byref variable has extended lifetime.
1235
  bool getByrefLifetime(QualType Ty,
1236
                        Qualifiers::ObjCLifetime &Lifetime,
1237
                        bool &HasByrefExtendedLayout) const;
1238
1239
  /// Return the uniqued reference to the type for an lvalue reference
1240
  /// to the specified type.
1241
  QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true)
1242
    const;
1243
1244
  /// Return the uniqued reference to the type for an rvalue reference
1245
  /// to the specified type.
1246
  QualType getRValueReferenceType(QualType T) const;
1247
1248
  /// Return the uniqued reference to the type for a member pointer to
1249
  /// the specified type in the specified class.
1250
  ///
1251
  /// The class \p Cls is a \c Type because it could be a dependent name.
1252
  QualType getMemberPointerType(QualType T, const Type *Cls) const;
1253
1254
  /// Return a non-unique reference to the type for a variable array of
1255
  /// the specified element type.
1256
  QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
1257
                                ArrayType::ArraySizeModifier ASM,
1258
                                unsigned IndexTypeQuals,
1259
                                SourceRange Brackets) const;
1260
1261
  /// Return a non-unique reference to the type for a dependently-sized
1262
  /// array of the specified element type.
1263
  ///
1264
  /// FIXME: We will need these to be uniqued, or at least comparable, at some
1265
  /// point.
1266
  QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
1267
                                      ArrayType::ArraySizeModifier ASM,
1268
                                      unsigned IndexTypeQuals,
1269
                                      SourceRange Brackets) const;
1270
1271
  /// Return a unique reference to the type for an incomplete array of
1272
  /// the specified element type.
1273
  QualType getIncompleteArrayType(QualType EltTy,
1274
                                  ArrayType::ArraySizeModifier ASM,
1275
                                  unsigned IndexTypeQuals) const;
1276
1277
  /// Return the unique reference to the type for a constant array of
1278
  /// the specified element type.
1279
  QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
1280
                                const Expr *SizeExpr,
1281
                                ArrayType::ArraySizeModifier ASM,
1282
                                unsigned IndexTypeQuals) const;
1283
1284
  /// Return a type for a constant array for a string literal of the
1285
  /// specified element type and length.
1286
  QualType getStringLiteralArrayType(QualType EltTy, unsigned Length) const;
1287
1288
  /// Returns a vla type where known sizes are replaced with [*].
1289
  QualType getVariableArrayDecayedType(QualType Ty) const;
1290
1291
  /// Return the unique reference to a vector type of the specified
1292
  /// element type and size.
1293
  ///
1294
  /// \pre \p VectorType must be a built-in type.
1295
  QualType getVectorType(QualType VectorType, unsigned NumElts,
1296
                         VectorType::VectorKind VecKind) const;
1297
  /// Return the unique reference to the type for a dependently sized vector of
1298
  /// the specified element type.
1299
  QualType getDependentVectorType(QualType VectorType, Expr *SizeExpr,
1300
                                  SourceLocation AttrLoc,
1301
                                  VectorType::VectorKind VecKind) const;
1302
1303
  /// Return the unique reference to an extended vector type
1304
  /// of the specified element type and size.
1305
  ///
1306
  /// \pre \p VectorType must be a built-in type.
1307
  QualType getExtVectorType(QualType VectorType, unsigned NumElts) const;
1308
1309
  /// \pre Return a non-unique reference to the type for a dependently-sized
1310
  /// vector of the specified element type.
1311
  ///
1312
  /// FIXME: We will need these to be uniqued, or at least comparable, at some
1313
  /// point.
1314
  QualType getDependentSizedExtVectorType(QualType VectorType,
1315
                                          Expr *SizeExpr,
1316
                                          SourceLocation AttrLoc) const;
1317
1318
  QualType getDependentAddressSpaceType(QualType PointeeType,
1319
                                        Expr *AddrSpaceExpr,
1320
                                        SourceLocation AttrLoc) const;
1321
1322
  /// Return a K&R style C function type like 'int()'.
1323
  QualType getFunctionNoProtoType(QualType ResultTy,
1324
                                  const FunctionType::ExtInfo &Info) const;
1325
1326
532
  QualType getFunctionNoProtoType(QualType ResultTy) const {
1327
532
    return getFunctionNoProtoType(ResultTy, FunctionType::ExtInfo());
1328
532
  }
1329
1330
  /// Return a normal function type with a typed argument list.
1331
  QualType getFunctionType(QualType ResultTy, ArrayRef<QualType> Args,
1332
11.3M
                           const FunctionProtoType::ExtProtoInfo &EPI) const {
1333
11.3M
    return getFunctionTypeInternal(ResultTy, Args, EPI, false);
1334
11.3M
  }
1335
1336
  QualType adjustStringLiteralBaseType(QualType StrLTy) const;
1337
1338
private:
1339
  /// Return a normal function type with a typed argument list.
1340
  QualType getFunctionTypeInternal(QualType ResultTy, ArrayRef<QualType> Args,
1341
                                   const FunctionProtoType::ExtProtoInfo &EPI,
1342
                                   bool OnlyWantCanonical) const;
1343
1344
public:
1345
  /// Return the unique reference to the type for the specified type
1346
  /// declaration.
1347
  QualType getTypeDeclType(const TypeDecl *Decl,
1348
75.4M
                           const TypeDecl *PrevDecl = nullptr) const {
1349
75.4M
    assert(Decl && "Passed null for Decl param");
1350
75.4M
    if (Decl->TypeForDecl) 
return QualType(Decl->TypeForDecl, 0)69.5M
;
1351
5.86M
1352
5.86M
    if (PrevDecl) {
1353
1.40M
      assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl");
1354
1.40M
      Decl->TypeForDecl = PrevDecl->TypeForDecl;
1355
1.40M
      return QualType(PrevDecl->TypeForDecl, 0);
1356
1.40M
    }
1357
4.45M
1358
4.45M
    return getTypeDeclTypeSlow(Decl);
1359
4.45M
  }
1360
1361
  /// Return the unique reference to the type for the specified
1362
  /// typedef-name decl.
1363
  QualType getTypedefType(const TypedefNameDecl *Decl,
1364
                          QualType Canon = QualType()) const;
1365
1366
  QualType getRecordType(const RecordDecl *Decl) const;
1367
1368
  QualType getEnumType(const EnumDecl *Decl) const;
1369
1370
  QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const;
1371
1372
  QualType getAttributedType(attr::Kind attrKind,
1373
                             QualType modifiedType,
1374
                             QualType equivalentType);
1375
1376
  QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced,
1377
                                        QualType Replacement) const;
1378
  QualType getSubstTemplateTypeParmPackType(
1379
                                          const TemplateTypeParmType *Replaced,
1380
                                            const TemplateArgument &ArgPack);
1381
1382
  QualType
1383
  getTemplateTypeParmType(unsigned Depth, unsigned Index,
1384
                          bool ParameterPack,
1385
                          TemplateTypeParmDecl *ParmDecl = nullptr) const;
1386
1387
  QualType getTemplateSpecializationType(TemplateName T,
1388
                                         ArrayRef<TemplateArgument> Args,
1389
                                         QualType Canon = QualType()) const;
1390
1391
  QualType
1392
  getCanonicalTemplateSpecializationType(TemplateName T,
1393
                                         ArrayRef<TemplateArgument> Args) const;
1394
1395
  QualType getTemplateSpecializationType(TemplateName T,
1396
                                         const TemplateArgumentListInfo &Args,
1397
                                         QualType Canon = QualType()) const;
1398
1399
  TypeSourceInfo *
1400
  getTemplateSpecializationTypeInfo(TemplateName T, SourceLocation TLoc,
1401
                                    const TemplateArgumentListInfo &Args,
1402
                                    QualType Canon = QualType()) const;
1403
1404
  QualType getParenType(QualType NamedType) const;
1405
1406
  QualType getMacroQualifiedType(QualType UnderlyingTy,
1407
                                 const IdentifierInfo *MacroII) const;
1408
1409
  QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
1410
                             NestedNameSpecifier *NNS, QualType NamedType,
1411
                             TagDecl *OwnedTagDecl = nullptr) const;
1412
  QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
1413
                                NestedNameSpecifier *NNS,
1414
                                const IdentifierInfo *Name,
1415
                                QualType Canon = QualType()) const;
1416
1417
  QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
1418
                                                  NestedNameSpecifier *NNS,
1419
                                                  const IdentifierInfo *Name,
1420
                                    const TemplateArgumentListInfo &Args) const;
1421
  QualType getDependentTemplateSpecializationType(
1422
      ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
1423
      const IdentifierInfo *Name, ArrayRef<TemplateArgument> Args) const;
1424
1425
  TemplateArgument getInjectedTemplateArg(NamedDecl *ParamDecl);
1426
1427
  /// Get a template argument list with one argument per template parameter
1428
  /// in a template parameter list, such as for the injected class name of
1429
  /// a class template.
1430
  void getInjectedTemplateArgs(const TemplateParameterList *Params,
1431
                               SmallVectorImpl<TemplateArgument> &Args);
1432
1433
  QualType getPackExpansionType(QualType Pattern,
1434
                                Optional<unsigned> NumExpansions);
1435
1436
  QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl,
1437
                                ObjCInterfaceDecl *PrevDecl = nullptr) const;
1438
1439
  /// Legacy interface: cannot provide type arguments or __kindof.
1440
  QualType getObjCObjectType(QualType Base,
1441
                             ObjCProtocolDecl * const *Protocols,
1442
                             unsigned NumProtocols) const;
1443
1444
  QualType getObjCObjectType(QualType Base,
1445
                             ArrayRef<QualType> typeArgs,
1446
                             ArrayRef<ObjCProtocolDecl *> protocols,
1447
                             bool isKindOf) const;
1448
1449
  QualType getObjCTypeParamType(const ObjCTypeParamDecl *Decl,
1450
                                ArrayRef<ObjCProtocolDecl *> protocols) const;
1451
1452
  bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl);
1453
1454
  /// QIdProtocolsAdoptObjCObjectProtocols - Checks that protocols in
1455
  /// QT's qualified-id protocol list adopt all protocols in IDecl's list
1456
  /// of protocols.
1457
  bool QIdProtocolsAdoptObjCObjectProtocols(QualType QT,
1458
                                            ObjCInterfaceDecl *IDecl);
1459
1460
  /// Return a ObjCObjectPointerType type for the given ObjCObjectType.
1461
  QualType getObjCObjectPointerType(QualType OIT) const;
1462
1463
  /// GCC extension.
1464
  QualType getTypeOfExprType(Expr *e) const;
1465
  QualType getTypeOfType(QualType t) const;
1466
1467
  /// C++11 decltype.
1468
  QualType getDecltypeType(Expr *e, QualType UnderlyingType) const;
1469
1470
  /// Unary type transforms
1471
  QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType,
1472
                                 UnaryTransformType::UTTKind UKind) const;
1473
1474
  /// C++11 deduced auto type.
1475
  QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword,
1476
                       bool IsDependent, bool IsPack = false,
1477
                       ConceptDecl *TypeConstraintConcept = nullptr,
1478
                       ArrayRef<TemplateArgument> TypeConstraintArgs ={}) const;
1479
1480
  /// C++11 deduction pattern for 'auto' type.
1481
  QualType getAutoDeductType() const;
1482
1483
  /// C++11 deduction pattern for 'auto &&' type.
1484
  QualType getAutoRRefDeductType() const;
1485
1486
  /// C++17 deduced class template specialization type.
1487
  QualType getDeducedTemplateSpecializationType(TemplateName Template,
1488
                                                QualType DeducedType,
1489
                                                bool IsDependent) const;
1490
1491
  /// Return the unique reference to the type for the specified TagDecl
1492
  /// (struct/union/class/enum) decl.
1493
  QualType getTagDeclType(const TagDecl *Decl) const;
1494
1495
  /// Return the unique type for "size_t" (C99 7.17), defined in
1496
  /// <stddef.h>.
1497
  ///
1498
  /// The sizeof operator requires this (C99 6.5.3.4p4).
1499
  CanQualType getSizeType() const;
1500
1501
  /// Return the unique signed counterpart of
1502
  /// the integer type corresponding to size_t.
1503
  CanQualType getSignedSizeType() const;
1504
1505
  /// Return the unique type for "intmax_t" (C99 7.18.1.5), defined in
1506
  /// <stdint.h>.
1507
  CanQualType getIntMaxType() const;
1508
1509
  /// Return the unique type for "uintmax_t" (C99 7.18.1.5), defined in
1510
  /// <stdint.h>.
1511
  CanQualType getUIntMaxType() const;
1512
1513
  /// Return the unique wchar_t type available in C++ (and available as
1514
  /// __wchar_t as a Microsoft extension).
1515
63
  QualType getWCharType() const { return WCharTy; }
1516
1517
  /// Return the type of wide characters. In C++, this returns the
1518
  /// unique wchar_t type. In C99, this returns a type compatible with the type
1519
  /// defined in <stddef.h> as defined by the target.
1520
32.0k
  QualType getWideCharType() const { return WideCharTy; }
1521
1522
  /// Return the type of "signed wchar_t".
1523
  ///
1524
  /// Used when in C++, as a GCC extension.
1525
  QualType getSignedWCharType() const;
1526
1527
  /// Return the type of "unsigned wchar_t".
1528
  ///
1529
  /// Used when in C++, as a GCC extension.
1530
  QualType getUnsignedWCharType() const;
1531
1532
  /// In C99, this returns a type compatible with the type
1533
  /// defined in <stddef.h> as defined by the target.
1534
22
  QualType getWIntType() const { return WIntTy; }
1535
1536
  /// Return a type compatible with "intptr_t" (C99 7.18.1.4),
1537
  /// as defined by the target.
1538
  QualType getIntPtrType() const;
1539
1540
  /// Return a type compatible with "uintptr_t" (C99 7.18.1.4),
1541
  /// as defined by the target.
1542
  QualType getUIntPtrType() const;
1543
1544
  /// Return the unique type for "ptrdiff_t" (C99 7.17) defined in
1545
  /// <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
1546
  QualType getPointerDiffType() const;
1547
1548
  /// Return the unique unsigned counterpart of "ptrdiff_t"
1549
  /// integer type. The standard (C11 7.21.6.1p7) refers to this type
1550
  /// in the definition of %tu format specifier.
1551
  QualType getUnsignedPointerDiffType() const;
1552
1553
  /// Return the unique type for "pid_t" defined in
1554
  /// <sys/types.h>. We need this to compute the correct type for vfork().
1555
  QualType getProcessIDType() const;
1556
1557
  /// Return the C structure type used to represent constant CFStrings.
1558
  QualType getCFConstantStringType() const;
1559
1560
  /// Returns the C struct type for objc_super
1561
  QualType getObjCSuperType() const;
1562
4
  void setObjCSuperType(QualType ST) { ObjCSuperType = ST; }
1563
1564
  /// Get the structure type used to representation CFStrings, or NULL
1565
  /// if it hasn't yet been built.
1566
4.35k
  QualType getRawCFConstantStringType() const {
1567
4.35k
    if (CFConstantStringTypeDecl)
1568
4.35k
      return getTypedefType(CFConstantStringTypeDecl);
1569
0
    return QualType();
1570
0
  }
1571
  void setCFConstantStringType(QualType T);
1572
  TypedefDecl *getCFConstantStringDecl() const;
1573
  RecordDecl *getCFConstantStringTagDecl() const;
1574
1575
  // This setter/getter represents the ObjC type for an NSConstantString.
1576
  void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl);
1577
6.88k
  QualType getObjCConstantStringInterface() const {
1578
6.88k
    return ObjCConstantStringType;
1579
6.88k
  }
1580
1581
209
  QualType getObjCNSStringType() const {
1582
209
    return ObjCNSStringType;
1583
209
  }
1584
1585
83
  void setObjCNSStringType(QualType T) {
1586
83
    ObjCNSStringType = T;
1587
83
  }
1588
1589
  /// Retrieve the type that \c id has been defined to, which may be
1590
  /// different from the built-in \c id if \c id has been typedef'd.
1591
19
  QualType getObjCIdRedefinitionType() const {
1592
19
    if (ObjCIdRedefinitionType.isNull())
1593
18
      return getObjCIdType();
1594
1
    return ObjCIdRedefinitionType;
1595
1
  }
1596
1597
  /// Set the user-written type that redefines \c id.
1598
332
  void setObjCIdRedefinitionType(QualType RedefType) {
1599
332
    ObjCIdRedefinitionType = RedefType;
1600
332
  }
1601
1602
  /// Retrieve the type that \c Class has been defined to, which may be
1603
  /// different from the built-in \c Class if \c Class has been typedef'd.
1604
10
  QualType getObjCClassRedefinitionType() const {
1605
10
    if (ObjCClassRedefinitionType.isNull())
1606
6
      return getObjCClassType();
1607
4
    return ObjCClassRedefinitionType;
1608
4
  }
1609
1610
  /// Set the user-written type that redefines 'SEL'.
1611
321
  void setObjCClassRedefinitionType(QualType RedefType) {
1612
321
    ObjCClassRedefinitionType = RedefType;
1613
321
  }
1614
1615
  /// Retrieve the type that 'SEL' has been defined to, which may be
1616
  /// different from the built-in 'SEL' if 'SEL' has been typedef'd.
1617
4
  QualType getObjCSelRedefinitionType() const {
1618
4
    if (ObjCSelRedefinitionType.isNull())
1619
0
      return getObjCSelType();
1620
4
    return ObjCSelRedefinitionType;
1621
4
  }
1622
1623
  /// Set the user-written type that redefines 'SEL'.
1624
317
  void setObjCSelRedefinitionType(QualType RedefType) {
1625
317
    ObjCSelRedefinitionType = RedefType;
1626
317
  }
1627
1628
  /// Retrieve the identifier 'NSObject'.
1629
378
  IdentifierInfo *getNSObjectName() const {
1630
378
    if (!NSObjectName) {
1631
125
      NSObjectName = &Idents.get("NSObject");
1632
125
    }
1633
378
1634
378
    return NSObjectName;
1635
378
  }
1636
1637
  /// Retrieve the identifier 'NSCopying'.
1638
20
  IdentifierInfo *getNSCopyingName() {
1639
20
    if (!NSCopyingName) {
1640
5
      NSCopyingName = &Idents.get("NSCopying");
1641
5
    }
1642
20
1643
20
    return NSCopyingName;
1644
20
  }
1645
1646
892
  CanQualType getNSUIntegerType() const {
1647
892
    assert(Target && "Expected target to be initialized");
1648
892
    const llvm::Triple &T = Target->getTriple();
1649
892
    // Windows is LLP64 rather than LP64
1650
892
    if (T.isOSWindows() && 
T.isArch64Bit()8
)
1651
4
      return UnsignedLongLongTy;
1652
888
    return UnsignedLongTy;
1653
888
  }
1654
1655
1.20k
  CanQualType getNSIntegerType() const {
1656
1.20k
    assert(Target && "Expected target to be initialized");
1657
1.20k
    const llvm::Triple &T = Target->getTriple();
1658
1.20k
    // Windows is LLP64 rather than LP64
1659
1.20k
    if (T.isOSWindows() && 
T.isArch64Bit()0
)
1660
0
      return LongLongTy;
1661
1.20k
    return LongTy;
1662
1.20k
  }
1663
1664
  /// Retrieve the identifier 'bool'.
1665
24.5M
  IdentifierInfo *getBoolName() const {
1666
24.5M
    if (!BoolName)
1667
11.0k
      BoolName = &Idents.get("bool");
1668
24.5M
    return BoolName;
1669
24.5M
  }
1670
1671
4.95M
  IdentifierInfo *getMakeIntegerSeqName() const {
1672
4.95M
    if (!MakeIntegerSeqName)
1673
36.0k
      MakeIntegerSeqName = &Idents.get("__make_integer_seq");
1674
4.95M
    return MakeIntegerSeqName;
1675
4.95M
  }
1676
1677
4.95M
  IdentifierInfo *getTypePackElementName() const {
1678
4.95M
    if (!TypePackElementName)
1679
36.0k
      TypePackElementName = &Idents.get("__type_pack_element");
1680
4.95M
    return TypePackElementName;
1681
4.95M
  }
1682
1683
  /// Retrieve the Objective-C "instancetype" type, if already known;
1684
  /// otherwise, returns a NULL type;
1685
972k
  QualType getObjCInstanceType() {
1686
972k
    return getTypeDeclType(getObjCInstanceTypeDecl());
1687
972k
  }
1688
1689
  /// Retrieve the typedef declaration corresponding to the Objective-C
1690
  /// "instancetype" type.
1691
  TypedefDecl *getObjCInstanceTypeDecl();
1692
1693
  /// Set the type for the C FILE type.
1694
3.75k
  void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; }
1695
1696
  /// Retrieve the C FILE type.
1697
5.01k
  QualType getFILEType() const {
1698
5.01k
    if (FILEDecl)
1699
1.00k
      return getTypeDeclType(FILEDecl);
1700
4.01k
    return QualType();
1701
4.01k
  }
1702
1703
  /// Set the type for the C jmp_buf type.
1704
2.33k
  void setjmp_bufDecl(TypeDecl *jmp_bufDecl) {
1705
2.33k
    this->jmp_bufDecl = jmp_bufDecl;
1706
2.33k
  }
1707
1708
  /// Retrieve the C jmp_buf type.
1709
4.45k
  QualType getjmp_bufType() const {
1710
4.45k
    if (jmp_bufDecl)
1711
315
      return getTypeDeclType(jmp_bufDecl);
1712
4.13k
    return QualType();
1713
4.13k
  }
1714
1715
  /// Set the type for the C sigjmp_buf type.
1716
2.31k
  void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) {
1717
2.31k
    this->sigjmp_bufDecl = sigjmp_bufDecl;
1718
2.31k
  }
1719
1720
  /// Retrieve the C sigjmp_buf type.
1721
4.38k
  QualType getsigjmp_bufType() const {
1722
4.38k
    if (sigjmp_bufDecl)
1723
246
      return getTypeDeclType(sigjmp_bufDecl);
1724
4.13k
    return QualType();
1725
4.13k
  }
1726
1727
  /// Set the type for the C ucontext_t type.
1728
2.84k
  void setucontext_tDecl(TypeDecl *ucontext_tDecl) {
1729
2.84k
    this->ucontext_tDecl = ucontext_tDecl;
1730
2.84k
  }
1731
1732
  /// Retrieve the C ucontext_t type.
1733
4.35k
  QualType getucontext_tType() const {
1734
4.35k
    if (ucontext_tDecl)
1735
221
      return getTypeDeclType(ucontext_tDecl);
1736
4.13k
    return QualType();
1737
4.13k
  }
1738
1739
  /// The result type of logical operations, '<', '>', '!=', etc.
1740
1.23M
  QualType getLogicalOperationType() const {
1741
1.23M
    return getLangOpts().CPlusPlus ? 
BoolTy1.15M
:
IntTy82.5k
;
1742
1.23M
  }
1743
1744
  /// Emit the Objective-CC type encoding for the given type \p T into
1745
  /// \p S.
1746
  ///
1747
  /// If \p Field is specified then record field names are also encoded.
1748
  void getObjCEncodingForType(QualType T, std::string &S,
1749
                              const FieldDecl *Field=nullptr,
1750
                              QualType *NotEncodedT=nullptr) const;
1751
1752
  /// Emit the Objective-C property type encoding for the given
1753
  /// type \p T into \p S.
1754
  void getObjCEncodingForPropertyType(QualType T, std::string &S) const;
1755
1756
  void getLegacyIntegralTypeEncoding(QualType &t) const;
1757
1758
  /// Put the string version of the type qualifiers \p QT into \p S.
1759
  void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT,
1760
                                       std::string &S) const;
1761
1762
  /// Emit the encoded type for the function \p Decl into \p S.
1763
  ///
1764
  /// This is in the same format as Objective-C method encodings.
1765
  ///
1766
  /// \returns true if an error occurred (e.g., because one of the parameter
1767
  /// types is incomplete), false otherwise.
1768
  std::string getObjCEncodingForFunctionDecl(const FunctionDecl *Decl) const;
1769
1770
  /// Emit the encoded type for the method declaration \p Decl into
1771
  /// \p S.
1772
  std::string getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl,
1773
                                           bool Extended = false) const;
1774
1775
  /// Return the encoded type for this block declaration.
1776
  std::string getObjCEncodingForBlock(const BlockExpr *blockExpr) const;
1777
1778
  /// getObjCEncodingForPropertyDecl - Return the encoded type for
1779
  /// this method declaration. If non-NULL, Container must be either
1780
  /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should
1781
  /// only be NULL when getting encodings for protocol properties.
1782
  std::string getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
1783
                                             const Decl *Container) const;
1784
1785
  bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto,
1786
                                      ObjCProtocolDecl *rProto) const;
1787
1788
  ObjCPropertyImplDecl *getObjCPropertyImplDeclForPropertyDecl(
1789
                                                  const ObjCPropertyDecl *PD,
1790
                                                  const Decl *Container) const;
1791
1792
  /// Return the size of type \p T for Objective-C encoding purpose,
1793
  /// in characters.
1794
  CharUnits getObjCEncodingTypeSize(QualType T) const;
1795
1796
  /// Retrieve the typedef corresponding to the predefined \c id type
1797
  /// in Objective-C.
1798
  TypedefDecl *getObjCIdDecl() const;
1799
1800
  /// Represents the Objective-CC \c id type.
1801
  ///
1802
  /// This is set up lazily, by Sema.  \c id is always a (typedef for a)
1803
  /// pointer type, a pointer to a struct.
1804
326k
  QualType getObjCIdType() const {
1805
326k
    return getTypeDeclType(getObjCIdDecl());
1806
326k
  }
1807
1808
  /// Retrieve the typedef corresponding to the predefined 'SEL' type
1809
  /// in Objective-C.
1810
  TypedefDecl *getObjCSelDecl() const;
1811
1812
  /// Retrieve the type that corresponds to the predefined Objective-C
1813
  /// 'SEL' type.
1814
1.62M
  QualType getObjCSelType() const {
1815
1.62M
    return getTypeDeclType(getObjCSelDecl());
1816
1.62M
  }
1817
1818
  /// Retrieve the typedef declaration corresponding to the predefined
1819
  /// Objective-C 'Class' type.
1820
  TypedefDecl *getObjCClassDecl() const;
1821
1822
  /// Represents the Objective-C \c Class type.
1823
  ///
1824
  /// This is set up lazily, by Sema.  \c Class is always a (typedef for a)
1825
  /// pointer type, a pointer to a struct.
1826
383k
  QualType getObjCClassType() const {
1827
383k
    return getTypeDeclType(getObjCClassDecl());
1828
383k
  }
1829
1830
  /// Retrieve the Objective-C class declaration corresponding to
1831
  /// the predefined \c Protocol class.
1832
  ObjCInterfaceDecl *getObjCProtocolDecl() const;
1833
1834
  /// Retrieve declaration of 'BOOL' typedef
1835
3.16k
  TypedefDecl *getBOOLDecl() const {
1836
3.16k
    return BOOLDecl;
1837
3.16k
  }
1838
1839
  /// Save declaration of 'BOOL' typedef
1840
338
  void setBOOLDecl(TypedefDecl *TD) {
1841
338
    BOOLDecl = TD;
1842
338
  }
1843
1844
  /// type of 'BOOL' type.
1845
1.03k
  QualType getBOOLType() const {
1846
1.03k
    return getTypeDeclType(getBOOLDecl());
1847
1.03k
  }
1848
1849
  /// Retrieve the type of the Objective-C \c Protocol class.
1850
125k
  QualType getObjCProtoType() const {
1851
125k
    return getObjCInterfaceType(getObjCProtocolDecl());
1852
125k
  }
1853
1854
  /// Retrieve the C type declaration corresponding to the predefined
1855
  /// \c __builtin_va_list type.
1856
  TypedefDecl *getBuiltinVaListDecl() const;
1857
1858
  /// Retrieve the type of the \c __builtin_va_list type.
1859
129k
  QualType getBuiltinVaListType() const {
1860
129k
    return getTypeDeclType(getBuiltinVaListDecl());
1861
129k
  }
1862
1863
  /// Retrieve the C type declaration corresponding to the predefined
1864
  /// \c __va_list_tag type used to help define the \c __builtin_va_list type
1865
  /// for some targets.
1866
  Decl *getVaListTagDecl() const;
1867
1868
  /// Retrieve the C type declaration corresponding to the predefined
1869
  /// \c __builtin_ms_va_list type.
1870
  TypedefDecl *getBuiltinMSVaListDecl() const;
1871
1872
  /// Retrieve the type of the \c __builtin_ms_va_list type.
1873
125k
  QualType getBuiltinMSVaListType() const {
1874
125k
    return getTypeDeclType(getBuiltinMSVaListDecl());
1875
125k
  }
1876
1877
  /// Return whether a declaration to a builtin is allowed to be
1878
  /// overloaded/redeclared.
1879
  bool canBuiltinBeRedeclared(const FunctionDecl *) const;
1880
1881
  /// Return a type with additional \c const, \c volatile, or
1882
  /// \c restrict qualifiers.
1883
3.72k
  QualType getCVRQualifiedType(QualType T, unsigned CVR) const {
1884
3.72k
    return getQualifiedType(T, Qualifiers::fromCVRMask(CVR));
1885
3.72k
  }
1886
1887
  /// Un-split a SplitQualType.
1888
2.95k
  QualType getQualifiedType(SplitQualType split) const {
1889
2.95k
    return getQualifiedType(split.Ty, split.Quals);
1890
2.95k
  }
1891
1892
  /// Return a type with additional qualifiers.
1893
31.1M
  QualType getQualifiedType(QualType T, Qualifiers Qs) const {
1894
31.1M
    if (!Qs.hasNonFastQualifiers())
1895
31.0M
      return T.withFastQualifiers(Qs.getFastQualifiers());
1896
48.8k
    QualifierCollector Qc(Qs);
1897
48.8k
    const Type *Ptr = Qc.strip(T);
1898
48.8k
    return getExtQualType(Ptr, Qc);
1899
48.8k
  }
1900
1901
  /// Return a type with additional qualifiers.
1902
10.8M
  QualType getQualifiedType(const Type *T, Qualifiers Qs) const {
1903
10.8M
    if (!Qs.hasNonFastQualifiers())
1904
10.8M
      return QualType(T, Qs.getFastQualifiers());
1905
4.39k
    return getExtQualType(T, Qs);
1906
4.39k
  }
1907
1908
  /// Return a type with the given lifetime qualifier.
1909
  ///
1910
  /// \pre Neither type.ObjCLifetime() nor \p lifetime may be \c OCL_None.
1911
  QualType getLifetimeQualifiedType(QualType type,
1912
16.1k
                                    Qualifiers::ObjCLifetime lifetime) {
1913
16.1k
    assert(type.getObjCLifetime() == Qualifiers::OCL_None);
1914
16.1k
    assert(lifetime != Qualifiers::OCL_None);
1915
16.1k
1916
16.1k
    Qualifiers qs;
1917
16.1k
    qs.addObjCLifetime(lifetime);
1918
16.1k
    return getQualifiedType(type, qs);
1919
16.1k
  }
1920
1921
  /// getUnqualifiedObjCPointerType - Returns version of
1922
  /// Objective-C pointer type with lifetime qualifier removed.
1923
2.71k
  QualType getUnqualifiedObjCPointerType(QualType type) const {
1924
2.71k
    if (!type.getTypePtr()->isObjCObjectPointerType() ||
1925
2.71k
        
!type.getQualifiers().hasObjCLifetime()220
)
1926
2.69k
      return type;
1927
16
    Qualifiers Qs = type.getQualifiers();
1928
16
    Qs.removeObjCLifetime();
1929
16
    return getQualifiedType(type.getUnqualifiedType(), Qs);
1930
16
  }
1931
1932
  unsigned char getFixedPointScale(QualType Ty) const;
1933
  unsigned char getFixedPointIBits(QualType Ty) const;
1934
  FixedPointSemantics getFixedPointSemantics(QualType Ty) const;
1935
  APFixedPoint getFixedPointMax(QualType Ty) const;
1936
  APFixedPoint getFixedPointMin(QualType Ty) const;
1937
1938
  DeclarationNameInfo getNameForTemplate(TemplateName Name,
1939
                                         SourceLocation NameLoc) const;
1940
1941
  TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin,
1942
                                         UnresolvedSetIterator End) const;
1943
  TemplateName getAssumedTemplateName(DeclarationName Name) const;
1944
1945
  TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS,
1946
                                        bool TemplateKeyword,
1947
                                        TemplateDecl *Template) const;
1948
1949
  TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
1950
                                        const IdentifierInfo *Name) const;
1951
  TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
1952
                                        OverloadedOperatorKind Operator) const;
1953
  TemplateName getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param,
1954
                                            TemplateName replacement) const;
1955
  TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param,
1956
                                        const TemplateArgument &ArgPack) const;
1957
1958
  enum GetBuiltinTypeError {
1959
    /// No error
1960
    GE_None,
1961
1962
    /// Missing a type
1963
    GE_Missing_type,
1964
1965
    /// Missing a type from <stdio.h>
1966
    GE_Missing_stdio,
1967
1968
    /// Missing a type from <setjmp.h>
1969
    GE_Missing_setjmp,
1970
1971
    /// Missing a type from <ucontext.h>
1972
    GE_Missing_ucontext
1973
  };
1974
1975
  /// Return the type for the specified builtin.
1976
  ///
1977
  /// If \p IntegerConstantArgs is non-null, it is filled in with a bitmask of
1978
  /// arguments to the builtin that are required to be integer constant
1979
  /// expressions.
1980
  QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error,
1981
                          unsigned *IntegerConstantArgs = nullptr) const;
1982
1983
  /// Types and expressions required to build C++2a three-way comparisons
1984
  /// using operator<=>, including the values return by builtin <=> operators.
1985
  ComparisonCategories CompCategories;
1986
1987
private:
1988
  CanQualType getFromTargetType(unsigned Type) const;
1989
  TypeInfo getTypeInfoImpl(const Type *T) const;
1990
1991
  //===--------------------------------------------------------------------===//
1992
  //                         Type Predicates.
1993
  //===--------------------------------------------------------------------===//
1994
1995
public:
1996
  /// Return one of the GCNone, Weak or Strong Objective-C garbage
1997
  /// collection attributes.
1998
  Qualifiers::GC getObjCGCAttrKind(QualType Ty) const;
1999
2000
  /// Return true if the given vector types are of the same unqualified
2001
  /// type or if they are equivalent to the same GCC vector type.
2002
  ///
2003
  /// \note This ignores whether they are target-specific (AltiVec or Neon)
2004
  /// types.
2005
  bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec);
2006
2007
  /// Return true if the type has been explicitly qualified with ObjC ownership.
2008
  /// A type may be implicitly qualified with ownership under ObjC ARC, and in
2009
  /// some cases the compiler treats these differently.
2010
  bool hasDirectOwnershipQualifier(QualType Ty) const;
2011
2012
  /// Return true if this is an \c NSObject object with its \c NSObject
2013
  /// attribute set.
2014
12.7k
  static bool isObjCNSObjectType(QualType Ty) {
2015
12.7k
    return Ty->isObjCNSObjectType();
2016
12.7k
  }
2017
2018
  //===--------------------------------------------------------------------===//
2019
  //                         Type Sizing and Analysis
2020
  //===--------------------------------------------------------------------===//
2021
2022
  /// Return the APFloat 'semantics' for the specified scalar floating
2023
  /// point type.
2024
  const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const;
2025
2026
  /// Get the size and alignment of the specified complete type in bits.
2027
  TypeInfo getTypeInfo(const Type *T) const;
2028
81.7M
  TypeInfo getTypeInfo(QualType T) const { return getTypeInfo(T.getTypePtr()); }
2029
2030
  /// Get default simd alignment of the specified complete type in bits.
2031
  unsigned getOpenMPDefaultSimdAlign(QualType T) const;
2032
2033
  /// Return the size of the specified (complete) type \p T, in bits.
2034
80.2M
  uint64_t getTypeSize(QualType T) const { return getTypeInfo(T).Width; }
2035
1.24M
  uint64_t getTypeSize(const Type *T) const { return getTypeInfo(T).Width; }
2036
2037
  /// Return the size of the character type, in bits.
2038
20.3M
  uint64_t getCharWidth() const {
2039
20.3M
    return getTypeSize(CharTy);
2040
20.3M
  }
2041
2042
  /// Convert a size in bits to a size in characters.
2043
  CharUnits toCharUnitsFromBits(int64_t BitSize) const;
2044
2045
  /// Convert a size in characters to a size in bits.
2046
  int64_t toBits(CharUnits CharSize) const;
2047
2048
  /// Return the size of the specified (complete) type \p T, in
2049
  /// characters.
2050
  CharUnits getTypeSizeInChars(QualType T) const;
2051
  CharUnits getTypeSizeInChars(const Type *T) const;
2052
2053
8
  Optional<CharUnits> getTypeSizeInCharsIfKnown(QualType Ty) const {
2054
8
    if (Ty->isIncompleteType() || Ty->isDependentType())
2055
0
      return None;
2056
8
    return getTypeSizeInChars(Ty);
2057
8
  }
2058
2059
8
  Optional<CharUnits> getTypeSizeInCharsIfKnown(const Type *Ty) const {
2060
8
    return getTypeSizeInCharsIfKnown(QualType(Ty, 0));
2061
8
  }
2062
2063
  /// Return the ABI-specified alignment of a (complete) type \p T, in
2064
  /// bits.
2065
1.04M
  unsigned getTypeAlign(QualType T) const { return getTypeInfo(T).Align; }
2066
2.89k
  unsigned getTypeAlign(const Type *T) const { return getTypeInfo(T).Align; }
2067
2068
  /// Return the ABI-specified natural alignment of a (complete) type \p T,
2069
  /// before alignment adjustments, in bits.
2070
  ///
2071
  /// This alignment is curently used only by ARM and AArch64 when passing
2072
  /// arguments of a composite type.
2073
400
  unsigned getTypeUnadjustedAlign(QualType T) const {
2074
400
    return getTypeUnadjustedAlign(T.getTypePtr());
2075
400
  }
2076
  unsigned getTypeUnadjustedAlign(const Type *T) const;
2077
2078
  /// Return the ABI-specified alignment of a type, in bits, or 0 if
2079
  /// the type is incomplete and we cannot determine the alignment (for
2080
  /// example, from alignment attributes).
2081
  unsigned getTypeAlignIfKnown(QualType T) const;
2082
2083
  /// Return the ABI-specified alignment of a (complete) type \p T, in
2084
  /// characters.
2085
  CharUnits getTypeAlignInChars(QualType T) const;
2086
  CharUnits getTypeAlignInChars(const Type *T) const;
2087
2088
  /// getTypeUnadjustedAlignInChars - Return the ABI-specified alignment of a type,
2089
  /// in characters, before alignment adjustments. This method does not work on
2090
  /// incomplete types.
2091
  CharUnits getTypeUnadjustedAlignInChars(QualType T) const;
2092
  CharUnits getTypeUnadjustedAlignInChars(const Type *T) const;
2093
2094
  // getTypeInfoDataSizeInChars - Return the size of a type, in chars. If the
2095
  // type is a record, its data size is returned.
2096
  std::pair<CharUnits, CharUnits> getTypeInfoDataSizeInChars(QualType T) const;
2097
2098
  std::pair<CharUnits, CharUnits> getTypeInfoInChars(const Type *T) const;
2099
  std::pair<CharUnits, CharUnits> getTypeInfoInChars(QualType T) const;
2100
2101
  /// Determine if the alignment the type has was required using an
2102
  /// alignment attribute.
2103
  bool isAlignmentRequired(const Type *T) const;
2104
  bool isAlignmentRequired(QualType T) const;
2105
2106
  /// Return the "preferred" alignment of the specified type \p T for
2107
  /// the current target, in bits.
2108
  ///
2109
  /// This can be different than the ABI alignment in cases where it is
2110
  /// beneficial for performance to overalign a data type.
2111
  unsigned getPreferredTypeAlign(const Type *T) const;
2112
2113
  /// Return the default alignment for __attribute__((aligned)) on
2114
  /// this target, to be used if no alignment value is specified.
2115
  unsigned getTargetDefaultAlignForAttributeAligned() const;
2116
2117
  /// Return the alignment in bits that should be given to a
2118
  /// global variable with type \p T.
2119
  unsigned getAlignOfGlobalVar(QualType T) const;
2120
2121
  /// Return the alignment in characters that should be given to a
2122
  /// global variable with type \p T.
2123
  CharUnits getAlignOfGlobalVarInChars(QualType T) const;
2124
2125
  /// Return a conservative estimate of the alignment of the specified
2126
  /// decl \p D.
2127
  ///
2128
  /// \pre \p D must not be a bitfield type, as bitfields do not have a valid
2129
  /// alignment.
2130
  ///
2131
  /// If \p ForAlignof, references are treated like their underlying type
2132
  /// and  large arrays don't get any special treatment. If not \p ForAlignof
2133
  /// it computes the value expected by CodeGen: references are treated like
2134
  /// pointers and large arrays get extra alignment.
2135
  CharUnits getDeclAlign(const Decl *D, bool ForAlignof = false) const;
2136
2137
  /// Return the alignment (in bytes) of the thrown exception object. This is
2138
  /// only meaningful for targets that allocate C++ exceptions in a system
2139
  /// runtime, such as those using the Itanium C++ ABI.
2140
4.86k
  CharUnits getExnObjectAlignment() const {
2141
4.86k
    return toCharUnitsFromBits(Target->getExnObjectAlignment());
2142
4.86k
  }
2143
2144
  /// Get or compute information about the layout of the specified
2145
  /// record (struct/union/class) \p D, which indicates its size and field
2146
  /// position information.
2147
  const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D) const;
2148
2149
  /// Get or compute information about the layout of the specified
2150
  /// Objective-C interface.
2151
  const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D)
2152
    const;
2153
2154
  void DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS,
2155
                        bool Simple = false) const;
2156
2157
  /// Get or compute information about the layout of the specified
2158
  /// Objective-C implementation.
2159
  ///
2160
  /// This may differ from the interface if synthesized ivars are present.
2161
  const ASTRecordLayout &
2162
  getASTObjCImplementationLayout(const ObjCImplementationDecl *D) const;
2163
2164
  /// Get our current best idea for the key function of the
2165
  /// given record decl, or nullptr if there isn't one.
2166
  ///
2167
  /// The key function is, according to the Itanium C++ ABI section 5.2.3:
2168
  ///   ...the first non-pure virtual function that is not inline at the
2169
  ///   point of class definition.
2170
  ///
2171
  /// Other ABIs use the same idea.  However, the ARM C++ ABI ignores
2172
  /// virtual functions that are defined 'inline', which means that
2173
  /// the result of this computation can change.
2174
  const CXXMethodDecl *getCurrentKeyFunction(const CXXRecordDecl *RD);
2175
2176
  /// Observe that the given method cannot be a key function.
2177
  /// Checks the key-function cache for the method's class and clears it
2178
  /// if matches the given declaration.
2179
  ///
2180
  /// This is used in ABIs where out-of-line definitions marked
2181
  /// inline are not considered to be key functions.
2182
  ///
2183
  /// \param method should be the declaration from the class definition
2184
  void setNonKeyFunction(const CXXMethodDecl *method);
2185
2186
  /// Loading virtual member pointers using the virtual inheritance model
2187
  /// always results in an adjustment using the vbtable even if the index is
2188
  /// zero.
2189
  ///
2190
  /// This is usually OK because the first slot in the vbtable points
2191
  /// backwards to the top of the MDC.  However, the MDC might be reusing a
2192
  /// vbptr from an nv-base.  In this case, the first slot in the vbtable
2193
  /// points to the start of the nv-base which introduced the vbptr and *not*
2194
  /// the MDC.  Modify the NonVirtualBaseAdjustment to account for this.
2195
  CharUnits getOffsetOfBaseWithVBPtr(const CXXRecordDecl *RD) const;
2196
2197
  /// Get the offset of a FieldDecl or IndirectFieldDecl, in bits.
2198
  uint64_t getFieldOffset(const ValueDecl *FD) const;
2199
2200
  /// Get the offset of an ObjCIvarDecl in bits.
2201
  uint64_t lookupFieldBitOffset(const ObjCInterfaceDecl *OID,
2202
                                const ObjCImplementationDecl *ID,
2203
                                const ObjCIvarDecl *Ivar) const;
2204
2205
  bool isNearlyEmpty(const CXXRecordDecl *RD) const;
2206
2207
  VTableContextBase *getVTableContext();
2208
2209
  /// If \p T is null pointer, assume the target in ASTContext.
2210
  MangleContext *createMangleContext(const TargetInfo *T = nullptr);
2211
2212
  void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass,
2213
                            SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const;
2214
2215
  unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const;
2216
  void CollectInheritedProtocols(const Decl *CDecl,
2217
                          llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols);
2218
2219
  /// Return true if the specified type has unique object representations
2220
  /// according to (C++17 [meta.unary.prop]p9)
2221
  bool hasUniqueObjectRepresentations(QualType Ty) const;
2222
2223
  //===--------------------------------------------------------------------===//
2224
  //                            Type Operators
2225
  //===--------------------------------------------------------------------===//
2226
2227
  /// Return the canonical (structural) type corresponding to the
2228
  /// specified potentially non-canonical type \p T.
2229
  ///
2230
  /// The non-canonical version of a type may have many "decorated" versions of
2231
  /// types.  Decorators can include typedefs, 'typeof' operators, etc. The
2232
  /// returned type is guaranteed to be free of any of these, allowing two
2233
  /// canonical types to be compared for exact equality with a simple pointer
2234
  /// comparison.
2235
538M
  CanQualType getCanonicalType(QualType T) const {
2236
538M
    return CanQualType::CreateUnsafe(T.getCanonicalType());
2237
538M
  }
2238
2239
1.19M
  const Type *getCanonicalType(const Type *T) const {
2240
1.19M
    return T->getCanonicalTypeInternal().getTypePtr();
2241
1.19M
  }
2242
2243
  /// Return the canonical parameter type corresponding to the specific
2244
  /// potentially non-canonical one.
2245
  ///
2246
  /// Qualifiers are stripped off, functions are turned into function
2247
  /// pointers, and arrays decay one level into pointers.
2248
  CanQualType getCanonicalParamType(QualType T) const;
2249
2250
  /// Determine whether the given types \p T1 and \p T2 are equivalent.
2251
39.0M
  bool hasSameType(QualType T1, QualType T2) const {
2252
39.0M
    return getCanonicalType(T1) == getCanonicalType(T2);
2253
39.0M
  }
2254
60
  bool hasSameType(const Type *T1, const Type *T2) const {
2255
60
    return getCanonicalType(T1) == getCanonicalType(T2);
2256
60
  }
2257
2258
  /// Return this type as a completely-unqualified array type,
2259
  /// capturing the qualifiers in \p Quals.
2260
  ///
2261
  /// This will remove the minimal amount of sugaring from the types, similar
2262
  /// to the behavior of QualType::getUnqualifiedType().
2263
  ///
2264
  /// \param T is the qualified type, which may be an ArrayType
2265
  ///
2266
  /// \param Quals will receive the full set of qualifiers that were
2267
  /// applied to the array.
2268
  ///
2269
  /// \returns if this is an array type, the completely unqualified array type
2270
  /// that corresponds to it. Otherwise, returns T.getUnqualifiedType().
2271
  QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals);
2272
2273
  /// Determine whether the given types are equivalent after
2274
  /// cvr-qualifiers have been removed.
2275
67.0M
  bool hasSameUnqualifiedType(QualType T1, QualType T2) const {
2276
67.0M
    return getCanonicalType(T1).getTypePtr() ==
2277
67.0M
           getCanonicalType(T2).getTypePtr();
2278
67.0M
  }
2279
2280
  bool hasSameNullabilityTypeQualifier(QualType SubT, QualType SuperT,
2281
90.9k
                                       bool IsParam) const {
2282
90.9k
    auto SubTnullability = SubT->getNullability(*this);
2283
90.9k
    auto SuperTnullability = SuperT->getNullability(*this);
2284
90.9k
    if (SubTnullability.hasValue() == SuperTnullability.hasValue()) {
2285
80.9k
      // Neither has nullability; return true
2286
80.9k
      if (!SubTnullability)
2287
18.2k
        return true;
2288
62.6k
      // Both have nullability qualifier.
2289
62.6k
      if (*SubTnullability == *SuperTnullability ||
2290
62.6k
          
*SubTnullability == NullabilityKind::Unspecified703
||
2291
62.6k
          
*SuperTnullability == NullabilityKind::Unspecified703
)
2292
61.9k
        return true;
2293
698
2294
698
      if (IsParam) {
2295
7
        // Ok for the superclass method parameter to be "nonnull" and the subclass
2296
7
        // method parameter to be "nullable"
2297
7
        return (*SuperTnullability == NullabilityKind::NonNull &&
2298
7
                
*SubTnullability == NullabilityKind::Nullable6
);
2299
7
      }
2300
691
      else {
2301
691
        // For the return type, it's okay for the superclass method to specify
2302
691
        // "nullable" and the subclass method specify "nonnull"
2303
691
        return (*SuperTnullability == NullabilityKind::Nullable &&
2304
691
                
*SubTnullability == NullabilityKind::NonNull690
);
2305
691
      }
2306
9.99k
    }
2307
9.99k
    return true;
2308
9.99k
  }
2309
2310
  bool ObjCMethodsAreEqual(const ObjCMethodDecl *MethodDecl,
2311
                           const ObjCMethodDecl *MethodImp);
2312
2313
  bool UnwrapSimilarTypes(QualType &T1, QualType &T2);
2314
  bool UnwrapSimilarArrayTypes(QualType &T1, QualType &T2);
2315
2316
  /// Determine if two types are similar, according to the C++ rules. That is,
2317
  /// determine if they are the same other than qualifiers on the initial
2318
  /// sequence of pointer / pointer-to-member / array (and in Clang, object
2319
  /// pointer) types and their element types.
2320
  ///
2321
  /// Clang offers a number of qualifiers in addition to the C++ qualifiers;
2322
  /// those qualifiers are also ignored in the 'similarity' check.
2323
  bool hasSimilarType(QualType T1, QualType T2);
2324
2325
  /// Determine if two types are similar, ignoring only CVR qualifiers.
2326
  bool hasCvrSimilarType(QualType T1, QualType T2);
2327
2328
  /// Retrieves the "canonical" nested name specifier for a
2329
  /// given nested name specifier.
2330
  ///
2331
  /// The canonical nested name specifier is a nested name specifier
2332
  /// that uniquely identifies a type or namespace within the type
2333
  /// system. For example, given:
2334
  ///
2335
  /// \code
2336
  /// namespace N {
2337
  ///   struct S {
2338
  ///     template<typename T> struct X { typename T* type; };
2339
  ///   };
2340
  /// }
2341
  ///
2342
  /// template<typename T> struct Y {
2343
  ///   typename N::S::X<T>::type member;
2344
  /// };
2345
  /// \endcode
2346
  ///
2347
  /// Here, the nested-name-specifier for N::S::X<T>:: will be
2348
  /// S::X<template-param-0-0>, since 'S' and 'X' are uniquely defined
2349
  /// by declarations in the type system and the canonical type for
2350
  /// the template type parameter 'T' is template-param-0-0.
2351
  NestedNameSpecifier *
2352
  getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const;
2353
2354
  /// Retrieves the default calling convention for the current target.
2355
  CallingConv getDefaultCallingConvention(bool IsVariadic,
2356
                                          bool IsCXXMethod,
2357
                                          bool IsBuiltin = false) const;
2358
2359
  /// Retrieves the "canonical" template name that refers to a
2360
  /// given template.
2361
  ///
2362
  /// The canonical template name is the simplest expression that can
2363
  /// be used to refer to a given template. For most templates, this
2364
  /// expression is just the template declaration itself. For example,
2365
  /// the template std::vector can be referred to via a variety of
2366
  /// names---std::vector, \::std::vector, vector (if vector is in
2367
  /// scope), etc.---but all of these names map down to the same
2368
  /// TemplateDecl, which is used to form the canonical template name.
2369
  ///
2370
  /// Dependent template names are more interesting. Here, the
2371
  /// template name could be something like T::template apply or
2372
  /// std::allocator<T>::template rebind, where the nested name
2373
  /// specifier itself is dependent. In this case, the canonical
2374
  /// template name uses the shortest form of the dependent
2375
  /// nested-name-specifier, which itself contains all canonical
2376
  /// types, values, and templates.
2377
  TemplateName getCanonicalTemplateName(TemplateName Name) const;
2378
2379
  /// Determine whether the given template names refer to the same
2380
  /// template.
2381
  bool hasSameTemplateName(TemplateName X, TemplateName Y);
2382
2383
  /// Retrieve the "canonical" template argument.
2384
  ///
2385
  /// The canonical template argument is the simplest template argument
2386
  /// (which may be a type, value, expression, or declaration) that
2387
  /// expresses the value of the argument.
2388
  TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg)
2389
    const;
2390
2391
  /// Type Query functions.  If the type is an instance of the specified class,
2392
  /// return the Type pointer for the underlying maximally pretty type.  This
2393
  /// is a member of ASTContext because this may need to do some amount of
2394
  /// canonicalization, e.g. to move type qualifiers into the element type.
2395
  const ArrayType *getAsArrayType(QualType T) const;
2396
4.56M
  const ConstantArrayType *getAsConstantArrayType(QualType T) const {
2397
4.56M
    return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T));
2398
4.56M
  }
2399
386k
  const VariableArrayType *getAsVariableArrayType(QualType T) const {
2400
386k
    return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T));
2401
386k
  }
2402
1.47M
  const IncompleteArrayType *getAsIncompleteArrayType(QualType T) const {
2403
1.47M
    return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T));
2404
1.47M
  }
2405
  const DependentSizedArrayType *getAsDependentSizedArrayType(QualType T)
2406
513
    const {
2407
513
    return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T));
2408
513
  }
2409
2410
  /// Return the innermost element type of an array type.
2411
  ///
2412
  /// For example, will return "int" for int[m][n]
2413
  QualType getBaseElementType(const ArrayType *VAT) const;
2414
2415
  /// Return the innermost element type of a type (which needn't
2416
  /// actually be an array type).
2417
  QualType getBaseElementType(QualType QT) const;
2418
2419
  /// Return number of constant array elements.
2420
  uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const;
2421
2422
  /// Perform adjustment on the parameter type of a function.
2423
  ///
2424
  /// This routine adjusts the given parameter type @p T to the actual
2425
  /// parameter type used by semantic analysis (C99 6.7.5.3p[7,8],
2426
  /// C++ [dcl.fct]p3). The adjusted parameter type is returned.
2427
  QualType getAdjustedParameterType(QualType T) const;
2428
2429
  /// Retrieve the parameter type as adjusted for use in the signature
2430
  /// of a function, decaying array and function types and removing top-level
2431
  /// cv-qualifiers.
2432
  QualType getSignatureParameterType(QualType T) const;
2433
2434
  QualType getExceptionObjectType(QualType T) const;
2435
2436
  /// Return the properly qualified result of decaying the specified
2437
  /// array type to a pointer.
2438
  ///
2439
  /// This operation is non-trivial when handling typedefs etc.  The canonical
2440
  /// type of \p T must be an array type, this returns a pointer to a properly
2441
  /// qualified element of the array.
2442
  ///
2443
  /// See C99 6.7.5.3p7 and C99 6.3.2.1p3.
2444
  QualType getArrayDecayedType(QualType T) const;
2445
2446
  /// Return the type that \p PromotableType will promote to: C99
2447
  /// 6.3.1.1p2, assuming that \p PromotableType is a promotable integer type.
2448
  QualType getPromotedIntegerType(QualType PromotableType) const;
2449
2450
  /// Recurses in pointer/array types until it finds an Objective-C
2451
  /// retainable type and returns its ownership.
2452
  Qualifiers::ObjCLifetime getInnerObjCOwnership(QualType T) const;
2453
2454
  /// Whether this is a promotable bitfield reference according
2455
  /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions).
2456
  ///
2457
  /// \returns the type this bit-field will promote to, or NULL if no
2458
  /// promotion occurs.
2459
  QualType isPromotableBitField(Expr *E) const;
2460
2461
  /// Return the highest ranked integer type, see C99 6.3.1.8p1.
2462
  ///
2463
  /// If \p LHS > \p RHS, returns 1.  If \p LHS == \p RHS, returns 0.  If
2464
  /// \p LHS < \p RHS, return -1.
2465
  int getIntegerTypeOrder(QualType LHS, QualType RHS) const;
2466
2467
  /// Compare the rank of the two specified floating point types,
2468
  /// ignoring the domain of the type (i.e. 'double' == '_Complex double').
2469
  ///
2470
  /// If \p LHS > \p RHS, returns 1.  If \p LHS == \p RHS, returns 0.  If
2471
  /// \p LHS < \p RHS, return -1.
2472
  int getFloatingTypeOrder(QualType LHS, QualType RHS) const;
2473
2474
  /// Compare the rank of two floating point types as above, but compare equal
2475
  /// if both types have the same floating-point semantics on the target (i.e.
2476
  /// long double and double on AArch64 will return 0).
2477
  int getFloatingTypeSemanticOrder(QualType LHS, QualType RHS) const;
2478
2479
  /// Return a real floating point or a complex type (based on
2480
  /// \p typeDomain/\p typeSize).
2481
  ///
2482
  /// \param typeDomain a real floating point or complex type.
2483
  /// \param typeSize a real floating point or complex type.
2484
  QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
2485
                                             QualType typeDomain) const;
2486
2487
1.47M
  unsigned getTargetAddressSpace(QualType T) const {
2488
1.47M
    return getTargetAddressSpace(T.getQualifiers());
2489
1.47M
  }
2490
2491
1.47M
  unsigned getTargetAddressSpace(Qualifiers Q) const {
2492
1.47M
    return getTargetAddressSpace(Q.getAddressSpace());
2493
1.47M
  }
2494
2495
  unsigned getTargetAddressSpace(LangAS AS) const;
2496
2497
  LangAS getLangASForBuiltinAddressSpace(unsigned AS) const;
2498
2499
  /// Get target-dependent integer value for null pointer which is used for
2500
  /// constant folding.
2501
  uint64_t getTargetNullPointerValue(QualType QT) const;
2502
2503
255
  bool addressSpaceMapManglingFor(LangAS AS) const {
2504
255
    return AddrSpaceMapMangling || 
isTargetAddressSpace(AS)79
;
2505
255
  }
2506
2507
private:
2508
  // Helper for integer ordering
2509
  unsigned getIntegerRank(const Type *T) const;
2510
2511
public:
2512
  //===--------------------------------------------------------------------===//
2513
  //                    Type Compatibility Predicates
2514
  //===--------------------------------------------------------------------===//
2515
2516
  /// Compatibility predicates used to check assignment expressions.
2517
  bool typesAreCompatible(QualType T1, QualType T2,
2518
                          bool CompareUnqualified = false); // C99 6.2.7p1
2519
2520
  bool propertyTypesAreCompatible(QualType, QualType);
2521
  bool typesAreBlockPointerCompatible(QualType, QualType);
2522
2523
1.61k
  bool isObjCIdType(QualType T) const {
2524
1.61k
    return T == getObjCIdType();
2525
1.61k
  }
2526
2527
1.32k
  bool isObjCClassType(QualType T) const {
2528
1.32k
    return T == getObjCClassType();
2529
1.32k
  }
2530
2531
2.44k
  bool isObjCSelType(QualType T) const {
2532
2.44k
    return T == getObjCSelType();
2533
2.44k
  }
2534
2535
  bool ObjCQualifiedIdTypesAreCompatible(const ObjCObjectPointerType *LHS,
2536
                                         const ObjCObjectPointerType *RHS,
2537
                                         bool ForCompare);
2538
2539
  bool ObjCQualifiedClassTypesAreCompatible(const ObjCObjectPointerType *LHS,
2540
                                            const ObjCObjectPointerType *RHS);
2541
2542
  // Check the safety of assignment from LHS to RHS
2543
  bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT,
2544
                               const ObjCObjectPointerType *RHSOPT);
2545
  bool canAssignObjCInterfaces(const ObjCObjectType *LHS,
2546
                               const ObjCObjectType *RHS);
2547
  bool canAssignObjCInterfacesInBlockPointer(
2548
                                          const ObjCObjectPointerType *LHSOPT,
2549
                                          const ObjCObjectPointerType *RHSOPT,
2550
                                          bool BlockReturnType);
2551
  bool areComparableObjCPointerTypes(QualType LHS, QualType RHS);
2552
  QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT,
2553
                                   const ObjCObjectPointerType *RHSOPT);
2554
  bool canBindObjCObjectType(QualType To, QualType From);
2555
2556
  // Functions for calculating composite types
2557
  QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false,
2558
                      bool Unqualified = false, bool BlockReturnType = false);
2559
  QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false,
2560
                              bool Unqualified = false);
2561
  QualType mergeFunctionParameterTypes(QualType, QualType,
2562
                                       bool OfBlockPointer = false,
2563
                                       bool Unqualified = false);
2564
  QualType mergeTransparentUnionType(QualType, QualType,
2565
                                     bool OfBlockPointer=false,
2566
                                     bool Unqualified = false);
2567
2568
  QualType mergeObjCGCQualifiers(QualType, QualType);
2569
2570
  /// This function merges the ExtParameterInfo lists of two functions. It
2571
  /// returns true if the lists are compatible. The merged list is returned in
2572
  /// NewParamInfos.
2573
  ///
2574
  /// \param FirstFnType The type of the first function.
2575
  ///
2576
  /// \param SecondFnType The type of the second function.
2577
  ///
2578
  /// \param CanUseFirst This flag is set to true if the first function's
2579
  /// ExtParameterInfo list can be used as the composite list of
2580
  /// ExtParameterInfo.
2581
  ///
2582
  /// \param CanUseSecond This flag is set to true if the second function's
2583
  /// ExtParameterInfo list can be used as the composite list of
2584
  /// ExtParameterInfo.
2585
  ///
2586
  /// \param NewParamInfos The composite list of ExtParameterInfo. The list is
2587
  /// empty if none of the flags are set.
2588
  ///
2589
  bool mergeExtParameterInfo(
2590
      const FunctionProtoType *FirstFnType,
2591
      const FunctionProtoType *SecondFnType,
2592
      bool &CanUseFirst, bool &CanUseSecond,
2593
      SmallVectorImpl<FunctionProtoType::ExtParameterInfo> &NewParamInfos);
2594
2595
  void ResetObjCLayout(const ObjCContainerDecl *CD);
2596
2597
  //===--------------------------------------------------------------------===//
2598
  //                    Integer Predicates
2599
  //===--------------------------------------------------------------------===//
2600
2601
  // The width of an integer, as defined in C99 6.2.6.2. This is the number
2602
  // of bits in an integer type excluding any padding bits.
2603
  unsigned getIntWidth(QualType T) const;
2604
2605
  // Per C99 6.2.5p6, for every signed integer type, there is a corresponding
2606
  // unsigned integer type.  This method takes a signed type, and returns the
2607
  // corresponding unsigned integer type.
2608
  // With the introduction of fixed point types in ISO N1169, this method also
2609
  // accepts fixed point types and returns the corresponding unsigned type for
2610
  // a given fixed point type.
2611
  QualType getCorrespondingUnsignedType(QualType T) const;
2612
2613
  // Per ISO N1169, this method accepts fixed point types and returns the
2614
  // corresponding saturated type for a given fixed point type.
2615
  QualType getCorrespondingSaturatedType(QualType Ty) const;
2616
2617
  // This method accepts fixed point types and returns the corresponding signed
2618
  // type. Unlike getCorrespondingUnsignedType(), this only accepts unsigned
2619
  // fixed point types because there are unsigned integer types like bool and
2620
  // char8_t that don't have signed equivalents.
2621
  QualType getCorrespondingSignedFixedPointType(QualType Ty) const;
2622
2623
  //===--------------------------------------------------------------------===//
2624
  //                    Integer Values
2625
  //===--------------------------------------------------------------------===//
2626
2627
  /// Make an APSInt of the appropriate width and signedness for the
2628
  /// given \p Value and integer \p Type.
2629
2.24M
  llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const {
2630
2.24M
    // If Type is a signed integer type larger than 64 bits, we need to be sure
2631
2.24M
    // to sign extend Res appropriately.
2632
2.24M
    llvm::APSInt Res(64, !Type->isSignedIntegerOrEnumerationType());
2633
2.24M
    Res = Value;
2634
2.24M
    unsigned Width = getIntWidth(Type);
2635
2.24M
    if (Width != Res.getBitWidth())
2636
1.98M
      return Res.extOrTrunc(Width);
2637
253k
    return Res;
2638
253k
  }
2639
2640
  bool isSentinelNullExpr(const Expr *E);
2641
2642
  /// Get the implementation of the ObjCInterfaceDecl \p D, or nullptr if
2643
  /// none exists.
2644
  ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D);
2645
2646
  /// Get the implementation of the ObjCCategoryDecl \p D, or nullptr if
2647
  /// none exists.
2648
  ObjCCategoryImplDecl *getObjCImplementation(ObjCCategoryDecl *D);
2649
2650
  /// Return true if there is at least one \@implementation in the TU.
2651
39
  bool AnyObjCImplementation() {
2652
39
    return !ObjCImpls.empty();
2653
39
  }
2654
2655
  /// Set the implementation of ObjCInterfaceDecl.
2656
  void setObjCImplementation(ObjCInterfaceDecl *IFaceD,
2657
                             ObjCImplementationDecl *ImplD);
2658
2659
  /// Set the implementation of ObjCCategoryDecl.
2660
  void setObjCImplementation(ObjCCategoryDecl *CatD,
2661
                             ObjCCategoryImplDecl *ImplD);
2662
2663
  /// Get the duplicate declaration of a ObjCMethod in the same
2664
  /// interface, or null if none exists.
2665
  const ObjCMethodDecl *
2666
  getObjCMethodRedeclaration(const ObjCMethodDecl *MD) const;
2667
2668
  void setObjCMethodRedeclaration(const ObjCMethodDecl *MD,
2669
                                  const ObjCMethodDecl *Redecl);
2670
2671
  /// Returns the Objective-C interface that \p ND belongs to if it is
2672
  /// an Objective-C method/property/ivar etc. that is part of an interface,
2673
  /// otherwise returns null.
2674
  const ObjCInterfaceDecl *getObjContainingInterface(const NamedDecl *ND) const;
2675
2676
  /// Set the copy initialization expression of a block var decl. \p CanThrow
2677
  /// indicates whether the copy expression can throw or not.
2678
  void setBlockVarCopyInit(const VarDecl* VD, Expr *CopyExpr, bool CanThrow);
2679
2680
  /// Get the copy initialization expression of the VarDecl \p VD, or
2681
  /// nullptr if none exists.
2682
  BlockVarCopyInit getBlockVarCopyInit(const VarDecl* VD) const;
2683
2684
  /// Allocate an uninitialized TypeSourceInfo.
2685
  ///
2686
  /// The caller should initialize the memory held by TypeSourceInfo using
2687
  /// the TypeLoc wrappers.
2688
  ///
2689
  /// \param T the type that will be the basis for type source info. This type
2690
  /// should refer to how the declarator was written in source code, not to
2691
  /// what type semantic analysis resolved the declarator to.
2692
  ///
2693
  /// \param Size the size of the type info to create, or 0 if the size
2694
  /// should be calculated based on the type.
2695
  TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0) const;
2696
2697
  /// Allocate a TypeSourceInfo where all locations have been
2698
  /// initialized to a given location, which defaults to the empty
2699
  /// location.
2700
  TypeSourceInfo *
2701
  getTrivialTypeSourceInfo(QualType T,
2702
                           SourceLocation Loc = SourceLocation()) const;
2703
2704
  /// Add a deallocation callback that will be invoked when the
2705
  /// ASTContext is destroyed.
2706
  ///
2707
  /// \param Callback A callback function that will be invoked on destruction.
2708
  ///
2709
  /// \param Data Pointer data that will be provided to the callback function
2710
  /// when it is called.
2711
  void AddDeallocation(void (*Callback)(void *), void *Data) const;
2712
2713
  /// If T isn't trivially destructible, calls AddDeallocation to register it
2714
  /// for destruction.
2715
773k
  template <typename T> void addDestruction(T *Ptr) const {
2716
773k
    if (!std::is_trivially_destructible<T>::value) {
2717
740k
      auto DestroyPtr = [](void *V) 
{ static_cast<T *>(V)->~T(); }289k
;
void clang::ASTContext::addDestruction<clang::APValue>(clang::APValue*) const::'lambda'(void*)::operator()(void*) const
Line
Count
Source
2717
4.45k
      auto DestroyPtr = [](void *V) { static_cast<T *>(V)->~T(); };
void clang::ASTContext::addDestruction<clang::FunctionTemplateDecl::Common>(clang::FunctionTemplateDecl::Common*) const::'lambda'(void*)::operator()(void*) const
Line
Count
Source
2717
185k
      auto DestroyPtr = [](void *V) { static_cast<T *>(V)->~T(); };
void clang::ASTContext::addDestruction<clang::ClassTemplateDecl::Common>(clang::ClassTemplateDecl::Common*) const::'lambda'(void*)::operator()(void*) const
Line
Count
Source
2717
98.2k
      auto DestroyPtr = [](void *V) { static_cast<T *>(V)->~T(); };
void clang::ASTContext::addDestruction<clang::VarTemplateDecl::Common>(clang::VarTemplateDecl::Common*) const::'lambda'(void*)::operator()(void*) const
Line
Count
Source
2717
1.37k
      auto DestroyPtr = [](void *V) { static_cast<T *>(V)->~T(); };
2718
740k
      AddDeallocation(DestroyPtr, Ptr);
2719
740k
    }
2720
773k
  }
void clang::ASTContext::addDestruction<clang::APValue>(clang::APValue*) const
Line
Count
Source
2715
11.7k
  template <typename T> void addDestruction(T *Ptr) const {
2716
11.7k
    if (!std::is_trivially_destructible<T>::value) {
2717
11.7k
      auto DestroyPtr = [](void *V) { static_cast<T *>(V)->~T(); };
2718
11.7k
      AddDeallocation(DestroyPtr, Ptr);
2719
11.7k
    }
2720
11.7k
  }
void clang::ASTContext::addDestruction<clang::FunctionTemplateDecl::Common>(clang::FunctionTemplateDecl::Common*) const
Line
Count
Source
2715
409k
  template <typename T> void addDestruction(T *Ptr) const {
2716
409k
    if (!std::is_trivially_destructible<T>::value) {
2717
409k
      auto DestroyPtr = [](void *V) { static_cast<T *>(V)->~T(); };
2718
409k
      AddDeallocation(DestroyPtr, Ptr);
2719
409k
    }
2720
409k
  }
void clang::ASTContext::addDestruction<clang::ClassTemplateDecl::Common>(clang::ClassTemplateDecl::Common*) const
Line
Count
Source
2715
318k
  template <typename T> void addDestruction(T *Ptr) const {
2716
318k
    if (!std::is_trivially_destructible<T>::value) {
2717
318k
      auto DestroyPtr = [](void *V) { static_cast<T *>(V)->~T(); };
2718
318k
      AddDeallocation(DestroyPtr, Ptr);
2719
318k
    }
2720
318k
  }
void clang::ASTContext::addDestruction<clang::RedeclarableTemplateDecl::CommonBase>(clang::RedeclarableTemplateDecl::CommonBase*) const
Line
Count
Source
2715
32.8k
  template <typename T> void addDestruction(T *Ptr) const {
2716
32.8k
    if (!std::is_trivially_destructible<T>::value) {
2717
0
      auto DestroyPtr = [](void *V) { static_cast<T *>(V)->~T(); };
2718
0
      AddDeallocation(DestroyPtr, Ptr);
2719
0
    }
2720
32.8k
  }
void clang::ASTContext::addDestruction<clang::VarTemplateDecl::Common>(clang::VarTemplateDecl::Common*) const
Line
Count
Source
2715
1.45k
  template <typename T> void addDestruction(T *Ptr) const {
2716
1.45k
    if (!std::is_trivially_destructible<T>::value) {
2717
1.45k
      auto DestroyPtr = [](void *V) { static_cast<T *>(V)->~T(); };
2718
1.45k
      AddDeallocation(DestroyPtr, Ptr);
2719
1.45k
    }
2720
1.45k
  }
2721
2722
  GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD) const;
2723
  GVALinkage GetGVALinkageForVariable(const VarDecl *VD);
2724
2725
  /// Determines if the decl can be CodeGen'ed or deserialized from PCH
2726
  /// lazily, only when used; this is only relevant for function or file scoped
2727
  /// var definitions.
2728
  ///
2729
  /// \returns true if the function/var must be CodeGen'ed/deserialized even if
2730
  /// it is not used.
2731
  bool DeclMustBeEmitted(const Decl *D);
2732
2733
  /// Visits all versions of a multiversioned function with the passed
2734
  /// predicate.
2735
  void forEachMultiversionedFunctionVersion(
2736
      const FunctionDecl *FD,
2737
      llvm::function_ref<void(FunctionDecl *)> Pred) const;
2738
2739
  const CXXConstructorDecl *
2740
  getCopyConstructorForExceptionObject(CXXRecordDecl *RD);
2741
2742
  void addCopyConstructorForExceptionObject(CXXRecordDecl *RD,
2743
                                            CXXConstructorDecl *CD);
2744
2745
  void addTypedefNameForUnnamedTagDecl(TagDecl *TD, TypedefNameDecl *TND);
2746
2747
  TypedefNameDecl *getTypedefNameForUnnamedTagDecl(const TagDecl *TD);
2748
2749
  void addDeclaratorForUnnamedTagDecl(TagDecl *TD, DeclaratorDecl *DD);
2750
2751
  DeclaratorDecl *getDeclaratorForUnnamedTagDecl(const TagDecl *TD);
2752
2753
  void setManglingNumber(const NamedDecl *ND, unsigned Number);
2754
  unsigned getManglingNumber(const NamedDecl *ND) const;
2755
2756
  void setStaticLocalNumber(const VarDecl *VD, unsigned Number);
2757
  unsigned getStaticLocalNumber(const VarDecl *VD) const;
2758
2759
  /// Retrieve the context for computing mangling numbers in the given
2760
  /// DeclContext.
2761
  MangleNumberingContext &getManglingNumberContext(const DeclContext *DC);
2762
  enum NeedExtraManglingDecl_t { NeedExtraManglingDecl };
2763
  MangleNumberingContext &getManglingNumberContext(NeedExtraManglingDecl_t,
2764
                                                   const Decl *D);
2765
2766
  std::unique_ptr<MangleNumberingContext> createMangleNumberingContext() const;
2767
2768
  /// Used by ParmVarDecl to store on the side the
2769
  /// index of the parameter when it exceeds the size of the normal bitfield.
2770
  void setParameterIndex(const ParmVarDecl *D, unsigned index);
2771
2772
  /// Used by ParmVarDecl to retrieve on the side the
2773
  /// index of the parameter when it exceeds the size of the normal bitfield.
2774
  unsigned getParameterIndex(const ParmVarDecl *D) const;
2775
2776
  /// Return a string representing the human readable name for the specified
2777
  /// function declaration or file name. Used by SourceLocExpr and
2778
  /// PredefinedExpr to cache evaluated results.
2779
  StringLiteral *getPredefinedStringLiteralFromCache(StringRef Key) const;
2780
2781
  /// Parses the target attributes passed in, and returns only the ones that are
2782
  /// valid feature names.
2783
  ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD) const;
2784
2785
  void getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
2786
                             const FunctionDecl *) const;
2787
  void getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
2788
                             GlobalDecl GD) const;
2789
2790
  //===--------------------------------------------------------------------===//
2791
  //                    Statistics
2792
  //===--------------------------------------------------------------------===//
2793
2794
  /// The number of implicitly-declared default constructors.
2795
  unsigned NumImplicitDefaultConstructors = 0;
2796
2797
  /// The number of implicitly-declared default constructors for
2798
  /// which declarations were built.
2799
  unsigned NumImplicitDefaultConstructorsDeclared = 0;
2800
2801
  /// The number of implicitly-declared copy constructors.
2802
  unsigned NumImplicitCopyConstructors = 0;
2803
2804
  /// The number of implicitly-declared copy constructors for
2805
  /// which declarations were built.
2806
  unsigned NumImplicitCopyConstructorsDeclared = 0;
2807
2808
  /// The number of implicitly-declared move constructors.
2809
  unsigned NumImplicitMoveConstructors = 0;
2810
2811
  /// The number of implicitly-declared move constructors for
2812
  /// which declarations were built.
2813
  unsigned NumImplicitMoveConstructorsDeclared = 0;
2814
2815
  /// The number of implicitly-declared copy assignment operators.
2816
  unsigned NumImplicitCopyAssignmentOperators = 0;
2817
2818
  /// The number of implicitly-declared copy assignment operators for
2819
  /// which declarations were built.
2820
  unsigned NumImplicitCopyAssignmentOperatorsDeclared = 0;
2821
2822
  /// The number of implicitly-declared move assignment operators.
2823
  unsigned NumImplicitMoveAssignmentOperators = 0;
2824
2825
  /// The number of implicitly-declared move assignment operators for
2826
  /// which declarations were built.
2827
  unsigned NumImplicitMoveAssignmentOperatorsDeclared = 0;
2828
2829
  /// The number of implicitly-declared destructors.
2830
  unsigned NumImplicitDestructors = 0;
2831
2832
  /// The number of implicitly-declared destructors for which
2833
  /// declarations were built.
2834
  unsigned NumImplicitDestructorsDeclared = 0;
2835
2836
public:
2837
  /// Initialize built-in types.
2838
  ///
2839
  /// This routine may only be invoked once for a given ASTContext object.
2840
  /// It is normally invoked after ASTContext construction.
2841
  ///
2842
  /// \param Target The target
2843
  void InitBuiltinTypes(const TargetInfo &Target,
2844
                        const TargetInfo *AuxTarget = nullptr);
2845
2846
private:
2847
  void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);
2848
2849
  class ObjCEncOptions {
2850
    unsigned Bits;
2851
2852
265
    ObjCEncOptions(unsigned Bits) : Bits(Bits) {}
2853
2854
  public:
2855
9.89k
    ObjCEncOptions() : Bits(0) {}
2856
14.7k
    ObjCEncOptions(const ObjCEncOptions &RHS) : Bits(RHS.Bits) {}
2857
2858
#define OPT_LIST(V)                                                            \
2859
  V(ExpandPointedToStructures, 0)                                              \
2860
  V(ExpandStructures, 1)                                                       \
2861
  V(IsOutermostType, 2)                                                        \
2862
  V(EncodingProperty, 3)                                                       \
2863
  V(IsStructField, 4)                                                          \
2864
  V(EncodeBlockParameters, 5)                                                  \
2865
  V(EncodeClassNames, 6)                                                       \
2866
2867
28.5k
#define V(N,I) ObjCEncOptions& set##N() { Bits |= 1 << I; return *this; }
clang::ASTContext::ObjCEncOptions::setExpandPointedToStructures()
Line
Count
Source
2867
8.42k
#define V(N,I) ObjCEncOptions& set##N() { Bits |= 1 << I; return *this; }
clang::ASTContext::ObjCEncOptions::setExpandStructures()
Line
Count
Source
2867
9.81k
#define V(N,I) ObjCEncOptions& set##N() { Bits |= 1 << I; return *this; }
clang::ASTContext::ObjCEncOptions::setIsOutermostType()
Line
Count
Source
2867
8.36k
#define V(N,I) ObjCEncOptions& set##N() { Bits |= 1 << I; return *this; }
clang::ASTContext::ObjCEncOptions::setEncodingProperty()
Line
Count
Source
2867
518
#define V(N,I) ObjCEncOptions& set##N() { Bits |= 1 << I; return *this; }
clang::ASTContext::ObjCEncOptions::setIsStructField()
Line
Count
Source
2867
781
#define V(N,I) ObjCEncOptions& set##N() { Bits |= 1 << I; return *this; }
clang::ASTContext::ObjCEncOptions::setEncodeBlockParameters()
Line
Count
Source
2867
317
#define V(N,I) ObjCEncOptions& set##N() { Bits |= 1 << I; return *this; }
clang::ASTContext::ObjCEncOptions::setEncodeClassNames()
Line
Count
Source
2867
317
#define V(N,I) ObjCEncOptions& set##N() { Bits |= 1 << I; return *this; }
2868
OPT_LIST(V)
2869
#undef V
2870
2871
3.06k
#define V(N,I) bool N() const { return Bits & 1 << I; }
clang::ASTContext::ObjCEncOptions::ExpandPointedToStructures() const
Line
Count
Source
2871
357
#define V(N,I) bool N() const { return Bits & 1 << I; }
clang::ASTContext::ObjCEncOptions::ExpandStructures() const
Line
Count
Source
2871
610
#define V(N,I) bool N() const { return Bits & 1 << I; }
clang::ASTContext::ObjCEncOptions::IsOutermostType() const
Line
Count
Source
2871
416
#define V(N,I) bool N() const { return Bits & 1 << I; }
clang::ASTContext::ObjCEncOptions::EncodingProperty() const
Line
Count
Source
2871
849
#define V(N,I) bool N() const { return Bits & 1 << I; }
clang::ASTContext::ObjCEncOptions::IsStructField() const
Line
Count
Source
2871
6
#define V(N,I) bool N() const { return Bits & 1 << I; }
clang::ASTContext::ObjCEncOptions::EncodeBlockParameters() const
Line
Count
Source
2871
73
#define V(N,I) bool N() const { return Bits & 1 << I; }
clang::ASTContext::ObjCEncOptions::EncodeClassNames() const
Line
Count
Source
2871
749
#define V(N,I) bool N() const { return Bits & 1 << I; }
2872
OPT_LIST(V)
2873
#undef V
2874
2875
#undef OPT_LIST
2876
2877
257
    LLVM_NODISCARD ObjCEncOptions keepingOnly(ObjCEncOptions Mask) const {
2878
257
      return Bits & Mask.Bits;
2879
257
    }
2880
2881
8
    LLVM_NODISCARD ObjCEncOptions forComponentType() const {
2882
8
      ObjCEncOptions Mask = ObjCEncOptions()
2883
8
                                .setIsOutermostType()
2884
8
                                .setIsStructField();
2885
8
      return Bits & ~Mask.Bits;
2886
8
    }
2887
  };
2888
2889
  // Return the Objective-C type encoding for a given type.
2890
  void getObjCEncodingForTypeImpl(QualType t, std::string &S,
2891
                                  ObjCEncOptions Options,
2892
                                  const FieldDecl *Field,
2893
                                  QualType *NotEncodedT = nullptr) const;
2894
2895
  // Adds the encoding of the structure's members.
2896
  void getObjCEncodingForStructureImpl(RecordDecl *RD, std::string &S,
2897
                                       const FieldDecl *Field,
2898
                                       bool includeVBases = true,
2899
                                       QualType *NotEncodedT=nullptr) const;
2900
2901
public:
2902
  // Adds the encoding of a method parameter or return type.
2903
  void getObjCEncodingForMethodParameter(Decl::ObjCDeclQualifier QT,
2904
                                         QualType T, std::string& S,
2905
                                         bool Extended) const;
2906
2907
  /// Returns true if this is an inline-initialized static data member
2908
  /// which is treated as a definition for MSVC compatibility.
2909
  bool isMSStaticDataMemberInlineDefinition(const VarDecl *VD) const;
2910
2911
  enum class InlineVariableDefinitionKind {
2912
    /// Not an inline variable.
2913
    None,
2914
2915
    /// Weak definition of inline variable.
2916
    Weak,
2917
2918
    /// Weak for now, might become strong later in this TU.
2919
    WeakUnknown,
2920
2921
    /// Strong definition.
2922
    Strong
2923
  };
2924
2925
  /// Determine whether a definition of this inline variable should
2926
  /// be treated as a weak or strong definition. For compatibility with
2927
  /// C++14 and before, for a constexpr static data member, if there is an
2928
  /// out-of-line declaration of the member, we may promote it from weak to
2929
  /// strong.
2930
  InlineVariableDefinitionKind
2931
  getInlineVariableDefinitionKind(const VarDecl *VD) const;
2932
2933
private:
2934
  friend class DeclarationNameTable;
2935
  friend class DeclContext;
2936
2937
  const ASTRecordLayout &
2938
  getObjCLayout(const ObjCInterfaceDecl *D,
2939
                const ObjCImplementationDecl *Impl) const;
2940
2941
  /// A set of deallocations that should be performed when the
2942
  /// ASTContext is destroyed.
2943
  // FIXME: We really should have a better mechanism in the ASTContext to
2944
  // manage running destructors for types which do variable sized allocation
2945
  // within the AST. In some places we thread the AST bump pointer allocator
2946
  // into the datastructures which avoids this mess during deallocation but is
2947
  // wasteful of memory, and here we require a lot of error prone book keeping
2948
  // in order to track and run destructors while we're tearing things down.
2949
  using DeallocationFunctionsAndArguments =
2950
      llvm::SmallVector<std::pair<void (*)(void *), void *>, 16>;
2951
  mutable DeallocationFunctionsAndArguments Deallocations;
2952
2953
  // FIXME: This currently contains the set of StoredDeclMaps used
2954
  // by DeclContext objects.  This probably should not be in ASTContext,
2955
  // but we include it here so that ASTContext can quickly deallocate them.
2956
  llvm::PointerIntPair<StoredDeclsMap *, 1> LastSDM;
2957
2958
  std::vector<Decl *> TraversalScope;
2959
2960
  std::unique_ptr<VTableContextBase> VTContext;
2961
2962
  void ReleaseDeclContextMaps();
2963
2964
public:
2965
  enum PragmaSectionFlag : unsigned {
2966
    PSF_None = 0,
2967
    PSF_Read = 0x1,
2968
    PSF_Write = 0x2,
2969
    PSF_Execute = 0x4,
2970
    PSF_Implicit = 0x8,
2971
    PSF_Invalid = 0x80000000U,
2972
  };
2973
2974
  struct SectionInfo {
2975
    DeclaratorDecl *Decl;
2976
    SourceLocation PragmaSectionLocation;
2977
    int SectionFlags;
2978
2979
78
    SectionInfo() = default;
2980
    SectionInfo(DeclaratorDecl *Decl,
2981
                SourceLocation PragmaSectionLocation,
2982
                int SectionFlags)
2983
        : Decl(Decl), PragmaSectionLocation(PragmaSectionLocation),
2984
78
          SectionFlags(SectionFlags) {}
2985
  };
2986
2987
  llvm::StringMap<SectionInfo> SectionInfos;
2988
};
2989
2990
/// Utility function for constructing a nullary selector.
2991
22.2k
inline Selector GetNullarySelector(StringRef name, ASTContext &Ctx) {
2992
22.2k
  IdentifierInfo* II = &Ctx.Idents.get(name);
2993
22.2k
  return Ctx.Selectors.getSelector(0, &II);
2994
22.2k
}
2995
2996
/// Utility function for constructing an unary selector.
2997
326
inline Selector GetUnarySelector(StringRef name, ASTContext &Ctx) {
2998
326
  IdentifierInfo* II = &Ctx.Idents.get(name);
2999
326
  return Ctx.Selectors.getSelector(1, &II);
3000
326
}
3001
3002
} // namespace clang
3003
3004
// operator new and delete aren't allowed inside namespaces.
3005
3006
/// Placement new for using the ASTContext's allocator.
3007
///
3008
/// This placement form of operator new uses the ASTContext's allocator for
3009
/// obtaining memory.
3010
///
3011
/// IMPORTANT: These are also declared in clang/AST/ASTContextAllocate.h!
3012
/// Any changes here need to also be made there.
3013
///
3014
/// We intentionally avoid using a nothrow specification here so that the calls
3015
/// to this operator will not perform a null check on the result -- the
3016
/// underlying allocator never returns null pointers.
3017
///
3018
/// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
3019
/// @code
3020
/// // Default alignment (8)
3021
/// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
3022
/// // Specific alignment
3023
/// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments);
3024
/// @endcode
3025
/// Memory allocated through this placement new operator does not need to be
3026
/// explicitly freed, as ASTContext will free all of this memory when it gets
3027
/// destroyed. Please note that you cannot use delete on the pointer.
3028
///
3029
/// @param Bytes The number of bytes to allocate. Calculated by the compiler.
3030
/// @param C The ASTContext that provides the allocator.
3031
/// @param Alignment The alignment of the allocated memory (if the underlying
3032
///                  allocator supports it).
3033
/// @return The allocated memory. Could be nullptr.
3034
inline void *operator new(size_t Bytes, const clang::ASTContext &C,
3035
163M
                          size_t Alignment /* = 8 */) {
3036
163M
  return C.Allocate(Bytes, Alignment);
3037
163M
}
3038
3039
/// Placement delete companion to the new above.
3040
///
3041
/// This operator is just a companion to the new above. There is no way of
3042
/// invoking it directly; see the new operator for more details. This operator
3043
/// is called implicitly by the compiler if a placement new expression using
3044
/// the ASTContext throws in the object constructor.
3045
0
inline void operator delete(void *Ptr, const clang::ASTContext &C, size_t) {
3046
0
  C.Deallocate(Ptr);
3047
0
}
3048
3049
/// This placement form of operator new[] uses the ASTContext's allocator for
3050
/// obtaining memory.
3051
///
3052
/// We intentionally avoid using a nothrow specification here so that the calls
3053
/// to this operator will not perform a null check on the result -- the
3054
/// underlying allocator never returns null pointers.
3055
///
3056
/// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
3057
/// @code
3058
/// // Default alignment (8)
3059
/// char *data = new (Context) char[10];
3060
/// // Specific alignment
3061
/// char *data = new (Context, 4) char[10];
3062
/// @endcode
3063
/// Memory allocated through this placement new[] operator does not need to be
3064
/// explicitly freed, as ASTContext will free all of this memory when it gets
3065
/// destroyed. Please note that you cannot use delete on the pointer.
3066
///
3067
/// @param Bytes The number of bytes to allocate. Calculated by the compiler.
3068
/// @param C The ASTContext that provides the allocator.
3069
/// @param Alignment The alignment of the allocated memory (if the underlying
3070
///                  allocator supports it).
3071
/// @return The allocated memory. Could be nullptr.
3072
inline void *operator new[](size_t Bytes, const clang::ASTContext& C,
3073
24.3M
                            size_t Alignment /* = 8 */) {
3074
24.3M
  return C.Allocate(Bytes, Alignment);
3075
24.3M
}
3076
3077
/// Placement delete[] companion to the new[] above.
3078
///
3079
/// This operator is just a companion to the new[] above. There is no way of
3080
/// invoking it directly; see the new[] operator for more details. This operator
3081
/// is called implicitly by the compiler if a placement new[] expression using
3082
/// the ASTContext throws in the object constructor.
3083
0
inline void operator delete[](void *Ptr, const clang::ASTContext &C, size_t) {
3084
0
  C.Deallocate(Ptr);
3085
0
}
3086
3087
/// Create the representation of a LazyGenerationalUpdatePtr.
3088
template <typename Owner, typename T,
3089
          void (clang::ExternalASTSource::*Update)(Owner)>
3090
typename clang::LazyGenerationalUpdatePtr<Owner, T, Update>::ValueType
3091
    clang::LazyGenerationalUpdatePtr<Owner, T, Update>::makeValue(
3092
32.1M
        const clang::ASTContext &Ctx, T Value) {
3093
32.1M
  // Note, this is implemented here so that ExternalASTSource.h doesn't need to
3094
32.1M
  // include ASTContext.h. We explicitly instantiate it for all relevant types
3095
32.1M
  // in ASTContext.cpp.
3096
32.1M
  if (auto *Source = Ctx.getExternalSource())
3097
6.85M
    return new (Ctx) LazyData(Source, Value);
3098
25.2M
  return Value;
3099
25.2M
}
3100
3101
#endif // LLVM_CLANG_AST_ASTCONTEXT_H