Coverage Report

Created: 2022-01-22 13:19

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