Coverage Report

Created: 2021-01-19 06:58

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