Coverage Report

Created: 2022-05-21 09:15

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/Type.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Type.cpp - Type representation and manipulation --------------------===//
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
//  This file implements type-related functionality.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/AST/Type.h"
14
#include "Linkage.h"
15
#include "clang/AST/ASTContext.h"
16
#include "clang/AST/Attr.h"
17
#include "clang/AST/CharUnits.h"
18
#include "clang/AST/Decl.h"
19
#include "clang/AST/DeclBase.h"
20
#include "clang/AST/DeclCXX.h"
21
#include "clang/AST/DeclObjC.h"
22
#include "clang/AST/DeclTemplate.h"
23
#include "clang/AST/DependenceFlags.h"
24
#include "clang/AST/Expr.h"
25
#include "clang/AST/NestedNameSpecifier.h"
26
#include "clang/AST/NonTrivialTypeVisitor.h"
27
#include "clang/AST/PrettyPrinter.h"
28
#include "clang/AST/TemplateBase.h"
29
#include "clang/AST/TemplateName.h"
30
#include "clang/AST/TypeVisitor.h"
31
#include "clang/Basic/AddressSpaces.h"
32
#include "clang/Basic/ExceptionSpecificationType.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/Specifiers.h"
38
#include "clang/Basic/TargetCXXABI.h"
39
#include "clang/Basic/TargetInfo.h"
40
#include "clang/Basic/Visibility.h"
41
#include "llvm/ADT/APInt.h"
42
#include "llvm/ADT/APSInt.h"
43
#include "llvm/ADT/ArrayRef.h"
44
#include "llvm/ADT/FoldingSet.h"
45
#include "llvm/ADT/None.h"
46
#include "llvm/ADT/SmallVector.h"
47
#include "llvm/Support/Casting.h"
48
#include "llvm/Support/ErrorHandling.h"
49
#include "llvm/Support/MathExtras.h"
50
#include <algorithm>
51
#include <cassert>
52
#include <cstdint>
53
#include <cstring>
54
#include <type_traits>
55
56
using namespace clang;
57
58
2.61k
bool Qualifiers::isStrictSupersetOf(Qualifiers Other) const {
59
2.61k
  return (*this != Other) &&
60
    // CVR qualifiers superset
61
2.61k
    
(((Mask & CVRMask) | (Other.Mask & CVRMask)) == (Mask & CVRMask))140
&&
62
    // ObjC GC qualifiers superset
63
2.61k
    
(94
(getObjCGCAttr() == Other.getObjCGCAttr())94
||
64
94
     
(0
hasObjCGCAttr()0
&&
!Other.hasObjCGCAttr()0
)) &&
65
    // Address space superset.
66
2.61k
    
(94
(getAddressSpace() == Other.getAddressSpace())94
||
67
94
     
(4
hasAddressSpace()4
&&
!Other.hasAddressSpace()2
)) &&
68
    // Lifetime qualifier superset.
69
2.61k
    
(92
(getObjCLifetime() == Other.getObjCLifetime())92
||
70
92
     
(36
hasObjCLifetime()36
&&
!Other.hasObjCLifetime()22
));
71
2.61k
}
72
73
11.7k
const IdentifierInfo* QualType::getBaseTypeIdentifier() const {
74
11.7k
  const Type* ty = getTypePtr();
75
11.7k
  NamedDecl *ND = nullptr;
76
11.7k
  if (ty->isPointerType() || ty->isReferenceType())
77
0
    return ty->getPointeeType().getBaseTypeIdentifier();
78
11.7k
  else if (ty->isRecordType())
79
11.5k
    ND = ty->castAs<RecordType>()->getDecl();
80
221
  else if (ty->isEnumeralType())
81
12
    ND = ty->castAs<EnumType>()->getDecl();
82
209
  else if (ty->getTypeClass() == Type::Typedef)
83
17
    ND = ty->castAs<TypedefType>()->getDecl();
84
192
  else if (ty->isArrayType())
85
0
    return ty->castAsArrayTypeUnsafe()->
86
0
        getElementType().getBaseTypeIdentifier();
87
88
11.7k
  if (ND)
89
11.5k
    return ND->getIdentifier();
90
192
  return nullptr;
91
11.7k
}
92
93
37
bool QualType::mayBeDynamicClass() const {
94
37
  const auto *ClassDecl = getTypePtr()->getPointeeCXXRecordDecl();
95
37
  return ClassDecl && 
ClassDecl->mayBeDynamicClass()26
;
96
37
}
97
98
18
bool QualType::mayBeNotDynamicClass() const {
99
18
  const auto *ClassDecl = getTypePtr()->getPointeeCXXRecordDecl();
100
18
  return !ClassDecl || 
ClassDecl->mayBeNonDynamicClass()13
;
101
18
}
102
103
23.2M
bool QualType::isConstant(QualType T, const ASTContext &Ctx) {
104
23.2M
  if (T.isConstQualified())
105
7.63M
    return true;
106
107
15.6M
  if (const ArrayType *AT = Ctx.getAsArrayType(T))
108
350k
    return AT->getElementType().isConstant(Ctx);
109
110
15.3M
  return T.getAddressSpace() == LangAS::opencl_constant;
111
15.6M
}
112
113
// C++ [temp.dep.type]p1:
114
//   A type is dependent if it is...
115
//     - an array type constructed from any dependent type or whose
116
//       size is specified by a constant expression that is
117
//       value-dependent,
118
ArrayType::ArrayType(TypeClass tc, QualType et, QualType can,
119
                     ArraySizeModifier sm, unsigned tq, const Expr *sz)
120
    // Note, we need to check for DependentSizedArrayType explicitly here
121
    // because we use a DependentSizedArrayType with no size expression as the
122
    // type of a dependent array of unknown bound with a dependent braced
123
    // initializer:
124
    //
125
    //   template<int ...N> int arr[] = {N...};
126
    : Type(tc, can,
127
           et->getDependence() |
128
               (sz ? toTypeDependence(
129
                         turnValueToTypeDependence(sz->getDependence()))
130
                   : TypeDependence::None) |
131
               (tc == VariableArray ? TypeDependence::VariablyModified
132
                                    : TypeDependence::None) |
133
               (tc == DependentSizedArray
134
                    ? TypeDependence::DependentInstantiation
135
                    : TypeDependence::None)),
136
627k
      ElementType(et) {
137
627k
  ArrayTypeBits.IndexTypeQuals = tq;
138
627k
  ArrayTypeBits.SizeModifier = sm;
139
627k
}
140
141
unsigned ConstantArrayType::getNumAddressingBits(const ASTContext &Context,
142
                                                 QualType ElementType,
143
255k
                                               const llvm::APInt &NumElements) {
144
255k
  uint64_t ElementSize = Context.getTypeSizeInChars(ElementType).getQuantity();
145
146
  // Fast path the common cases so we can avoid the conservative computation
147
  // below, which in common cases allocates "large" APSInt values, which are
148
  // slow.
149
150
  // If the element size is a power of 2, we can directly compute the additional
151
  // number of addressing bits beyond those required for the element count.
152
255k
  if (llvm::isPowerOf2_64(ElementSize)) {
153
242k
    return NumElements.getActiveBits() + llvm::Log2_64(ElementSize);
154
242k
  }
155
156
  // If both the element count and element size fit in 32-bits, we can do the
157
  // computation directly in 64-bits.
158
12.9k
  if ((ElementSize >> 32) == 0 && 
NumElements.getBitWidth() <= 6412.9k
&&
159
12.9k
      
(NumElements.getZExtValue() >> 32) == 012.9k
) {
160
12.9k
    uint64_t TotalSize = NumElements.getZExtValue() * ElementSize;
161
12.9k
    return 64 - llvm::countLeadingZeros(TotalSize);
162
12.9k
  }
163
164
  // Otherwise, use APSInt to handle arbitrary sized values.
165
2
  llvm::APSInt SizeExtended(NumElements, true);
166
2
  unsigned SizeTypeBits = Context.getTypeSize(Context.getSizeType());
167
2
  SizeExtended = SizeExtended.extend(std::max(SizeTypeBits,
168
2
                                              SizeExtended.getBitWidth()) * 2);
169
170
2
  llvm::APSInt TotalSize(llvm::APInt(SizeExtended.getBitWidth(), ElementSize));
171
2
  TotalSize *= SizeExtended;
172
173
2
  return TotalSize.getActiveBits();
174
12.9k
}
175
176
325k
unsigned ConstantArrayType::getMaxSizeBits(const ASTContext &Context) {
177
325k
  unsigned Bits = Context.getTypeSize(Context.getSizeType());
178
179
  // Limit the number of bits in size_t so that maximal bit size fits 64 bit
180
  // integer (see PR8256).  We can do this as currently there is no hardware
181
  // that supports full 64-bit virtual space.
182
325k
  if (Bits > 61)
183
309k
    Bits = 61;
184
185
325k
  return Bits;
186
325k
}
187
188
void ConstantArrayType::Profile(llvm::FoldingSetNodeID &ID,
189
                                const ASTContext &Context, QualType ET,
190
                                const llvm::APInt &ArraySize,
191
                                const Expr *SizeExpr, ArraySizeModifier SizeMod,
192
10.6M
                                unsigned TypeQuals) {
193
10.6M
  ID.AddPointer(ET.getAsOpaquePtr());
194
10.6M
  ID.AddInteger(ArraySize.getZExtValue());
195
10.6M
  ID.AddInteger(SizeMod);
196
10.6M
  ID.AddInteger(TypeQuals);
197
10.6M
  ID.AddBoolean(SizeExpr != nullptr);
198
10.6M
  if (SizeExpr)
199
244
    SizeExpr->Profile(ID, Context, true);
200
10.6M
}
201
202
DependentSizedArrayType::DependentSizedArrayType(const ASTContext &Context,
203
                                                 QualType et, QualType can,
204
                                                 Expr *e, ArraySizeModifier sm,
205
                                                 unsigned tq,
206
                                                 SourceRange brackets)
207
    : ArrayType(DependentSizedArray, et, can, sm, tq, e),
208
30.6k
      Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) {}
209
210
void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID,
211
                                      const ASTContext &Context,
212
                                      QualType ET,
213
                                      ArraySizeModifier SizeMod,
214
                                      unsigned TypeQuals,
215
37.2k
                                      Expr *E) {
216
37.2k
  ID.AddPointer(ET.getAsOpaquePtr());
217
37.2k
  ID.AddInteger(SizeMod);
218
37.2k
  ID.AddInteger(TypeQuals);
219
37.2k
  E->Profile(ID, Context, true);
220
37.2k
}
221
222
DependentVectorType::DependentVectorType(const ASTContext &Context,
223
                                         QualType ElementType,
224
                                         QualType CanonType, Expr *SizeExpr,
225
                                         SourceLocation Loc,
226
                                         VectorType::VectorKind VecKind)
227
    : Type(DependentVector, CanonType,
228
           TypeDependence::DependentInstantiation |
229
               ElementType->getDependence() |
230
               (SizeExpr ? toTypeDependence(SizeExpr->getDependence())
231
                         : TypeDependence::None)),
232
85
      Context(Context), ElementType(ElementType), SizeExpr(SizeExpr), Loc(Loc) {
233
85
  VectorTypeBits.VecKind = VecKind;
234
85
}
235
236
void DependentVectorType::Profile(llvm::FoldingSetNodeID &ID,
237
                                  const ASTContext &Context,
238
                                  QualType ElementType, const Expr *SizeExpr,
239
90
                                  VectorType::VectorKind VecKind) {
240
90
  ID.AddPointer(ElementType.getAsOpaquePtr());
241
90
  ID.AddInteger(VecKind);
242
90
  SizeExpr->Profile(ID, Context, true);
243
90
}
244
245
DependentSizedExtVectorType::DependentSizedExtVectorType(
246
    const ASTContext &Context, QualType ElementType, QualType can,
247
    Expr *SizeExpr, SourceLocation loc)
248
    : Type(DependentSizedExtVector, can,
249
           TypeDependence::DependentInstantiation |
250
               ElementType->getDependence() |
251
               (SizeExpr ? toTypeDependence(SizeExpr->getDependence())
252
                         : TypeDependence::None)),
253
42
      Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), loc(loc) {
254
42
}
255
256
void
257
DependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID,
258
                                     const ASTContext &Context,
259
50
                                     QualType ElementType, Expr *SizeExpr) {
260
50
  ID.AddPointer(ElementType.getAsOpaquePtr());
261
50
  SizeExpr->Profile(ID, Context, true);
262
50
}
263
264
DependentAddressSpaceType::DependentAddressSpaceType(const ASTContext &Context,
265
                                                     QualType PointeeType,
266
                                                     QualType can,
267
                                                     Expr *AddrSpaceExpr,
268
                                                     SourceLocation loc)
269
    : Type(DependentAddressSpace, can,
270
           TypeDependence::DependentInstantiation |
271
               PointeeType->getDependence() |
272
               (AddrSpaceExpr ? toTypeDependence(AddrSpaceExpr->getDependence())
273
                              : TypeDependence::None)),
274
      Context(Context), AddrSpaceExpr(AddrSpaceExpr), PointeeType(PointeeType),
275
88
      loc(loc) {}
276
277
void DependentAddressSpaceType::Profile(llvm::FoldingSetNodeID &ID,
278
                                        const ASTContext &Context,
279
                                        QualType PointeeType,
280
69
                                        Expr *AddrSpaceExpr) {
281
69
  ID.AddPointer(PointeeType.getAsOpaquePtr());
282
69
  AddrSpaceExpr->Profile(ID, Context, true);
283
69
}
284
285
MatrixType::MatrixType(TypeClass tc, QualType matrixType, QualType canonType,
286
                       const Expr *RowExpr, const Expr *ColumnExpr)
287
    : Type(tc, canonType,
288
           (RowExpr ? (matrixType->getDependence() | TypeDependence::Dependent |
289
                       TypeDependence::Instantiation |
290
                       (matrixType->isVariablyModifiedType()
291
                            ? TypeDependence::VariablyModified
292
                            : TypeDependence::None) |
293
                       (matrixType->containsUnexpandedParameterPack() ||
294
                                (RowExpr &&
295
                                 RowExpr->containsUnexpandedParameterPack()) ||
296
                                (ColumnExpr &&
297
                                 ColumnExpr->containsUnexpandedParameterPack())
298
                            ? TypeDependence::UnexpandedPack
299
                            : TypeDependence::None))
300
                    : matrixType->getDependence())),
301
492
      ElementType(matrixType) {}
302
303
ConstantMatrixType::ConstantMatrixType(QualType matrixType, unsigned nRows,
304
                                       unsigned nColumns, QualType canonType)
305
    : ConstantMatrixType(ConstantMatrix, matrixType, nRows, nColumns,
306
363
                         canonType) {}
Unexecuted instantiation: clang::ConstantMatrixType::ConstantMatrixType(clang::QualType, unsigned int, unsigned int, clang::QualType)
clang::ConstantMatrixType::ConstantMatrixType(clang::QualType, unsigned int, unsigned int, clang::QualType)
Line
Count
Source
306
363
                         canonType) {}
307
308
ConstantMatrixType::ConstantMatrixType(TypeClass tc, QualType matrixType,
309
                                       unsigned nRows, unsigned nColumns,
310
                                       QualType canonType)
311
    : MatrixType(tc, matrixType, canonType), NumRows(nRows),
312
363
      NumColumns(nColumns) {}
313
314
DependentSizedMatrixType::DependentSizedMatrixType(
315
    const ASTContext &CTX, QualType ElementType, QualType CanonicalType,
316
    Expr *RowExpr, Expr *ColumnExpr, SourceLocation loc)
317
    : MatrixType(DependentSizedMatrix, ElementType, CanonicalType, RowExpr,
318
                 ColumnExpr),
319
129
      Context(CTX), RowExpr(RowExpr), ColumnExpr(ColumnExpr), loc(loc) {}
320
321
void DependentSizedMatrixType::Profile(llvm::FoldingSetNodeID &ID,
322
                                       const ASTContext &CTX,
323
                                       QualType ElementType, Expr *RowExpr,
324
106
                                       Expr *ColumnExpr) {
325
106
  ID.AddPointer(ElementType.getAsOpaquePtr());
326
106
  RowExpr->Profile(ID, CTX, true);
327
106
  ColumnExpr->Profile(ID, CTX, true);
328
106
}
329
330
VectorType::VectorType(QualType vecType, unsigned nElements, QualType canonType,
331
                       VectorKind vecKind)
332
48.6k
    : VectorType(Vector, vecType, nElements, canonType, vecKind) {}
Unexecuted instantiation: clang::VectorType::VectorType(clang::QualType, unsigned int, clang::QualType, clang::VectorType::VectorKind)
clang::VectorType::VectorType(clang::QualType, unsigned int, clang::QualType, clang::VectorType::VectorKind)
Line
Count
Source
332
48.6k
    : VectorType(Vector, vecType, nElements, canonType, vecKind) {}
333
334
VectorType::VectorType(TypeClass tc, QualType vecType, unsigned nElements,
335
                       QualType canonType, VectorKind vecKind)
336
54.7k
    : Type(tc, canonType, vecType->getDependence()), ElementType(vecType) {
337
54.7k
  VectorTypeBits.VecKind = vecKind;
338
54.7k
  VectorTypeBits.NumElements = nElements;
339
54.7k
}
340
341
BitIntType::BitIntType(bool IsUnsigned, unsigned NumBits)
342
    : Type(BitInt, QualType{}, TypeDependence::None), IsUnsigned(IsUnsigned),
343
496
      NumBits(NumBits) {}
344
345
DependentBitIntType::DependentBitIntType(const ASTContext &Context,
346
                                         bool IsUnsigned, Expr *NumBitsExpr)
347
    : Type(DependentBitInt, QualType{},
348
           toTypeDependence(NumBitsExpr->getDependence())),
349
12
      Context(Context), ExprAndUnsigned(NumBitsExpr, IsUnsigned) {}
350
351
33
bool DependentBitIntType::isUnsigned() const {
352
33
  return ExprAndUnsigned.getInt();
353
33
}
354
355
60
clang::Expr *DependentBitIntType::getNumBitsExpr() const {
356
60
  return ExprAndUnsigned.getPointer();
357
60
}
358
359
void DependentBitIntType::Profile(llvm::FoldingSetNodeID &ID,
360
                                  const ASTContext &Context, bool IsUnsigned,
361
16
                                  Expr *NumBitsExpr) {
362
16
  ID.AddBoolean(IsUnsigned);
363
16
  NumBitsExpr->Profile(ID, Context, true);
364
16
}
365
366
/// getArrayElementTypeNoTypeQual - If this is an array type, return the
367
/// element type of the array, potentially with type qualifiers missing.
368
/// This method should never be used when type qualifiers are meaningful.
369
2.82k
const Type *Type::getArrayElementTypeNoTypeQual() const {
370
  // If this is directly an array type, return it.
371
2.82k
  if (const auto *ATy = dyn_cast<ArrayType>(this))
372
1.25k
    return ATy->getElementType().getTypePtr();
373
374
  // If the canonical form of this type isn't the right kind, reject it.
375
1.56k
  if (!isa<ArrayType>(CanonicalType))
376
1.53k
    return nullptr;
377
378
  // If this is a typedef for an array type, strip the typedef off without
379
  // losing all typedef information.
380
33
  return cast<ArrayType>(getUnqualifiedDesugaredType())
381
33
    ->getElementType().getTypePtr();
382
1.56k
}
383
384
/// getDesugaredType - Return the specified type with any "sugar" removed from
385
/// the type.  This takes off typedefs, typeof's etc.  If the outer level of
386
/// the type is already concrete, it returns it unmodified.  This is similar
387
/// to getting the canonical type, but it doesn't remove *all* typedefs.  For
388
/// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
389
/// concrete.
390
1.59M
QualType QualType::getDesugaredType(QualType T, const ASTContext &Context) {
391
1.59M
  SplitQualType split = getSplitDesugaredType(T);
392
1.59M
  return Context.getQualifiedType(split.Ty, split.Quals);
393
1.59M
}
394
395
QualType QualType::getSingleStepDesugaredTypeImpl(QualType type,
396
1.19k
                                                  const ASTContext &Context) {
397
1.19k
  SplitQualType split = type.split();
398
1.19k
  QualType desugar = split.Ty->getLocallyUnqualifiedSingleStepDesugaredType();
399
1.19k
  return Context.getQualifiedType(desugar, split.Quals);
400
1.19k
}
401
402
// Check that no type class is polymorphic. LLVM style RTTI should be used
403
// instead. If absolutely needed an exception can still be added here by
404
// defining the appropriate macro (but please don't do this).
405
#define TYPE(CLASS, BASE) \
406
  static_assert(!std::is_polymorphic<CLASS##Type>::value, \
407
                #CLASS "Type should not be polymorphic!");
408
#include "clang/AST/TypeNodes.inc"
409
410
// Check that no type class has a non-trival destructor. Types are
411
// allocated with the BumpPtrAllocator from ASTContext and therefore
412
// their destructor is not executed.
413
//
414
// FIXME: ConstantArrayType is not trivially destructible because of its
415
// APInt member. It should be replaced in favor of ASTContext allocation.
416
#define TYPE(CLASS, BASE)                                                      \
417
  static_assert(std::is_trivially_destructible<CLASS##Type>::value ||          \
418
                    std::is_same<CLASS##Type, ConstantArrayType>::value,       \
419
                #CLASS "Type should be trivially destructible!");
420
#include "clang/AST/TypeNodes.inc"
421
422
2.72M
QualType Type::getLocallyUnqualifiedSingleStepDesugaredType() const {
423
2.72M
  switch (getTypeClass()) {
424
0
#define ABSTRACT_TYPE(Class, Parent)
425
0
#define TYPE(Class, Parent) \
426
756k
  case Type::Class: { \
427
756k
    const auto *ty = cast<Class##Type>(this); \
428
2.72M
    if (!ty->isSugared()) 
return QualType(ty, 0)1.96M
; \
429
756k
    return ty->desugar(); \
430
756k
  }
431
2.72M
#include 
"clang/AST/TypeNodes.inc"0
432
2.72M
  }
433
0
  llvm_unreachable("bad type kind!");
434
0
}
435
436
54.8M
SplitQualType QualType::getSplitDesugaredType(QualType T) {
437
54.8M
  QualifierCollector Qs;
438
439
54.8M
  QualType Cur = T;
440
122M
  while (true) {
441
122M
    const Type *CurTy = Qs.strip(Cur);
442
122M
    switch (CurTy->getTypeClass()) {
443
0
#define ABSTRACT_TYPE(Class, Parent)
444
0
#define TYPE(Class, Parent) \
445
67.6M
    case Type::Class: { \
446
67.6M
      const auto *Ty = cast<Class##Type>(CurTy); \
447
122M
      if (!Ty->isSugared()) \
448
67.6M
        
return SplitQualType(Ty, Qs)54.8M
; \
449
67.6M
      Cur = Ty->desugar(); \
450
67.6M
      break; \
451
67.6M
    }
452
122M
#include 
"clang/AST/TypeNodes.inc"0
453
122M
    }
454
122M
  }
455
54.8M
}
456
457
28.4k
SplitQualType QualType::getSplitUnqualifiedTypeImpl(QualType type) {
458
28.4k
  SplitQualType split = type.split();
459
460
  // All the qualifiers we've seen so far.
461
28.4k
  Qualifiers quals = split.Quals;
462
463
  // The last type node we saw with any nodes inside it.
464
28.4k
  const Type *lastTypeWithQuals = split.Ty;
465
466
47.5k
  while (true) {
467
47.5k
    QualType next;
468
469
    // Do a single-step desugar, aborting the loop if the type isn't
470
    // sugared.
471
47.5k
    switch (split.Ty->getTypeClass()) {
472
0
#define ABSTRACT_TYPE(Class, Parent)
473
0
#define TYPE(Class, Parent) \
474
19.1k
    case Type::Class: { \
475
19.1k
      const auto *ty = cast<Class##Type>(split.Ty); \
476
47.5k
      if (!ty->isSugared()) 
goto done28.4k
; \
477
19.1k
      next = ty->desugar(); \
478
19.1k
      break; \
479
19.1k
    }
480
47.5k
#include 
"clang/AST/TypeNodes.inc"0
481
47.5k
    }
482
483
    // Otherwise, split the underlying type.  If that yields qualifiers,
484
    // update the information.
485
19.1k
    split = next.split();
486
19.1k
    if (!split.Quals.empty()) {
487
8.81k
      lastTypeWithQuals = split.Ty;
488
8.81k
      quals.addConsistentQualifiers(split.Quals);
489
8.81k
    }
490
19.1k
  }
491
492
28.4k
 done:
493
28.4k
  return SplitQualType(lastTypeWithQuals, quals);
494
28.4k
}
495
496
34
QualType QualType::IgnoreParens(QualType T) {
497
  // FIXME: this seems inherently un-qualifiers-safe.
498
68
  while (const auto *PT = T->getAs<ParenType>())
499
34
    T = PT->getInnerType();
500
34
  return T;
501
34
}
502
503
/// This will check for a T (which should be a Type which can act as
504
/// sugar, such as a TypedefType) by removing any existing sugar until it
505
/// reaches a T or a non-sugared type.
506
49.5M
template<typename T> static const T *getAsSugar(const Type *Cur) {
507
65.8M
  while (true) {
508
65.8M
    if (const auto *Sugar = dyn_cast<T>(Cur))
509
5.60M
      return Sugar;
510
60.2M
    switch (Cur->getTypeClass()) {
511
0
#define ABSTRACT_TYPE(Class, Parent)
512
0
#define TYPE(Class, Parent) \
513
16.2M
    case Type::Class: { \
514
16.2M
      const auto *Ty = cast<Class##Type>(Cur); \
515
60.2M
      if (!Ty->isSugared()) 
return 043.9M
; \
516
16.2M
      Cur = Ty->desugar().getTypePtr(); \
517
16.2M
      break; \
518
16.2M
    }
519
60.2M
#include 
"clang/AST/TypeNodes.inc"0
520
60.2M
    }
521
60.2M
  }
522
49.5M
}
Type.cpp:clang::TypedefType const* getAsSugar<clang::TypedefType>(clang::Type const*)
Line
Count
Source
506
9.02M
template<typename T> static const T *getAsSugar(const Type *Cur) {
507
9.25M
  while (true) {
508
9.25M
    if (const auto *Sugar = dyn_cast<T>(Cur))
509
3.86M
      return Sugar;
510
5.38M
    switch (Cur->getTypeClass()) {
511
0
#define ABSTRACT_TYPE(Class, Parent)
512
0
#define TYPE(Class, Parent) \
513
0
    case Type::Class: { \
514
0
      const auto *Ty = cast<Class##Type>(Cur); \
515
0
      if (!Ty->isSugared()) return 0; \
516
0
      Cur = Ty->desugar().getTypePtr(); \
517
0
      break; \
518
0
    }
519
0
#include "clang/AST/TypeNodes.inc"
520
5.38M
    }
521
5.38M
  }
522
9.02M
}
Type.cpp:clang::TemplateSpecializationType const* getAsSugar<clang::TemplateSpecializationType>(clang::Type const*)
Line
Count
Source
506
1.50M
template<typename T> static const T *getAsSugar(const Type *Cur) {
507
1.55M
  while (true) {
508
1.55M
    if (const auto *Sugar = dyn_cast<T>(Cur))
509
1.04M
      return Sugar;
510
509k
    switch (Cur->getTypeClass()) {
511
0
#define ABSTRACT_TYPE(Class, Parent)
512
0
#define TYPE(Class, Parent) \
513
0
    case Type::Class: { \
514
0
      const auto *Ty = cast<Class##Type>(Cur); \
515
0
      if (!Ty->isSugared()) return 0; \
516
0
      Cur = Ty->desugar().getTypePtr(); \
517
0
      break; \
518
0
    }
519
0
#include "clang/AST/TypeNodes.inc"
520
509k
    }
521
509k
  }
522
1.50M
}
Type.cpp:clang::AttributedType const* getAsSugar<clang::AttributedType>(clang::Type const*)
Line
Count
Source
506
39.0M
template<typename T> static const T *getAsSugar(const Type *Cur) {
507
55.0M
  while (true) {
508
55.0M
    if (const auto *Sugar = dyn_cast<T>(Cur))
509
700k
      return Sugar;
510
54.3M
    switch (Cur->getTypeClass()) {
511
0
#define ABSTRACT_TYPE(Class, Parent)
512
0
#define TYPE(Class, Parent) \
513
0
    case Type::Class: { \
514
0
      const auto *Ty = cast<Class##Type>(Cur); \
515
0
      if (!Ty->isSugared()) return 0; \
516
0
      Cur = Ty->desugar().getTypePtr(); \
517
0
      break; \
518
0
    }
519
0
#include "clang/AST/TypeNodes.inc"
520
54.3M
    }
521
54.3M
  }
522
39.0M
}
523
524
9.02M
template <> const TypedefType *Type::getAs() const {
525
9.02M
  return getAsSugar<TypedefType>(this);
526
9.02M
}
527
528
1.50M
template <> const TemplateSpecializationType *Type::getAs() const {
529
1.50M
  return getAsSugar<TemplateSpecializationType>(this);
530
1.50M
}
531
532
39.0M
template <> const AttributedType *Type::getAs() const {
533
39.0M
  return getAsSugar<AttributedType>(this);
534
39.0M
}
535
536
/// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic
537
/// sugar off the given type.  This should produce an object of the
538
/// same dynamic type as the canonical type.
539
61.5M
const Type *Type::getUnqualifiedDesugaredType() const {
540
61.5M
  const Type *Cur = this;
541
542
112M
  while (true) {
543
112M
    switch (Cur->getTypeClass()) {
544
0
#define ABSTRACT_TYPE(Class, Parent)
545
0
#define TYPE(Class, Parent) \
546
51.3M
    case Class: { \
547
51.3M
      const auto *Ty = cast<Class##Type>(Cur); \
548
112M
      if (!Ty->isSugared()) 
return Cur61.5M
; \
549
51.3M
      Cur = Ty->desugar().getTypePtr(); \
550
51.3M
      break; \
551
51.3M
    }
552
112M
#include 
"clang/AST/TypeNodes.inc"0
553
112M
    }
554
112M
  }
555
61.5M
}
556
557
2.34k
bool Type::isClassType() const {
558
2.34k
  if (const auto *RT = getAs<RecordType>())
559
52
    return RT->getDecl()->isClass();
560
2.29k
  return false;
561
2.34k
}
562
563
2.26M
bool Type::isStructureType() const {
564
2.26M
  if (const auto *RT = getAs<RecordType>())
565
136k
    return RT->getDecl()->isStruct();
566
2.13M
  return false;
567
2.26M
}
568
569
1.00k
bool Type::isObjCBoxableRecordType() const {
570
1.00k
  if (const auto *RT = getAs<RecordType>())
571
141
    return RT->getDecl()->hasAttr<ObjCBoxableAttr>();
572
863
  return false;
573
1.00k
}
574
575
79
bool Type::isInterfaceType() const {
576
79
  if (const auto *RT = getAs<RecordType>())
577
3
    return RT->getDecl()->isInterface();
578
76
  return false;
579
79
}
580
581
883k
bool Type::isStructureOrClassType() const {
582
883k
  if (const auto *RT = getAs<RecordType>()) {
583
128k
    RecordDecl *RD = RT->getDecl();
584
128k
    return RD->isStruct() || 
RD->isClass()26.7k
||
RD->isInterface()386
;
585
128k
  }
586
755k
  return false;
587
883k
}
588
589
433k
bool Type::isVoidPointerType() const {
590
433k
  if (const auto *PT = getAs<PointerType>())
591
427k
    return PT->getPointeeType()->isVoidType();
592
5.64k
  return false;
593
433k
}
594
595
1.26M
bool Type::isUnionType() const {
596
1.26M
  if (const auto *RT = getAs<RecordType>())
597
499k
    return RT->getDecl()->isUnion();
598
760k
  return false;
599
1.26M
}
600
601
974k
bool Type::isComplexType() const {
602
974k
  if (const auto *CT = dyn_cast<ComplexType>(CanonicalType))
603
1.80k
    return CT->getElementType()->isFloatingType();
604
972k
  return false;
605
974k
}
606
607
948k
bool Type::isComplexIntegerType() const {
608
  // Check for GCC complex integer extension.
609
948k
  return getAsComplexIntegerType();
610
948k
}
611
612
12
bool Type::isScopedEnumeralType() const {
613
12
  if (const auto *ET = getAs<EnumType>())
614
1
    return ET->getDecl()->isScoped();
615
11
  return false;
616
12
}
617
618
948k
const ComplexType *Type::getAsComplexIntegerType() const {
619
948k
  if (const auto *Complex = getAs<ComplexType>())
620
516
    if (Complex->getElementType()->isIntegerType())
621
434
      return Complex;
622
948k
  return nullptr;
623
948k
}
624
625
11.9M
QualType Type::getPointeeType() const {
626
11.9M
  if (const auto *PT = getAs<PointerType>())
627
9.86M
    return PT->getPointeeType();
628
2.06M
  if (const auto *OPT = getAs<ObjCObjectPointerType>())
629
897k
    return OPT->getPointeeType();
630
1.17M
  if (const auto *BPT = getAs<BlockPointerType>())
631
3.53k
    return BPT->getPointeeType();
632
1.16M
  if (const auto *RT = getAs<ReferenceType>())
633
885k
    return RT->getPointeeType();
634
283k
  if (const auto *MPT = getAs<MemberPointerType>())
635
299
    return MPT->getPointeeType();
636
283k
  if (const auto *DT = getAs<DecayedType>())
637
0
    return DT->getPointeeType();
638
283k
  return {};
639
283k
}
640
641
50.6k
const RecordType *Type::getAsStructureType() const {
642
  // If this is directly a structure type, return it.
643
50.6k
  if (const auto *RT = dyn_cast<RecordType>(this)) {
644
20.2k
    if (RT->getDecl()->isStruct())
645
19.7k
      return RT;
646
20.2k
  }
647
648
  // If the canonical form of this type isn't the right kind, reject it.
649
30.9k
  if (const auto *RT = dyn_cast<RecordType>(CanonicalType)) {
650
6.08k
    if (!RT->getDecl()->isStruct())
651
802
      return nullptr;
652
653
    // If this is a typedef for a structure type, strip the typedef off without
654
    // losing all typedef information.
655
5.27k
    return cast<RecordType>(getUnqualifiedDesugaredType());
656
6.08k
  }
657
24.8k
  return nullptr;
658
30.9k
}
659
660
4.22M
const RecordType *Type::getAsUnionType() const {
661
  // If this is directly a union type, return it.
662
4.22M
  if (const auto *RT = dyn_cast<RecordType>(this)) {
663
17.9k
    if (RT->getDecl()->isUnion())
664
1.08k
      return RT;
665
17.9k
  }
666
667
  // If the canonical form of this type isn't the right kind, reject it.
668
4.22M
  if (const auto *RT = dyn_cast<RecordType>(CanonicalType)) {
669
19.3k
    if (!RT->getDecl()->isUnion())
670
19.1k
      return nullptr;
671
672
    // If this is a typedef for a union type, strip the typedef off without
673
    // losing all typedef information.
674
144
    return cast<RecordType>(getUnqualifiedDesugaredType());
675
19.3k
  }
676
677
4.20M
  return nullptr;
678
4.22M
}
679
680
bool Type::isObjCIdOrObjectKindOfType(const ASTContext &ctx,
681
15.0k
                                      const ObjCObjectType *&bound) const {
682
15.0k
  bound = nullptr;
683
684
15.0k
  const auto *OPT = getAs<ObjCObjectPointerType>();
685
15.0k
  if (!OPT)
686
27
    return false;
687
688
  // Easy case: id.
689
14.9k
  if (OPT->isObjCIdType())
690
1.90k
    return true;
691
692
  // If it's not a __kindof type, reject it now.
693
13.0k
  if (!OPT->isKindOfType())
694
13.0k
    return false;
695
696
  // If it's Class or qualified Class, it's not an object type.
697
19
  if (OPT->isObjCClassType() || OPT->isObjCQualifiedClassType())
698
3
    return false;
699
700
  // Figure out the type bound for the __kindof type.
701
16
  bound = OPT->getObjectType()->stripObjCKindOfTypeAndQuals(ctx)
702
16
            ->getAs<ObjCObjectType>();
703
16
  return true;
704
19
}
705
706
13.3k
bool Type::isObjCClassOrClassKindOfType() const {
707
13.3k
  const auto *OPT = getAs<ObjCObjectPointerType>();
708
13.3k
  if (!OPT)
709
2
    return false;
710
711
  // Easy case: Class.
712
13.3k
  if (OPT->isObjCClassType())
713
490
    return true;
714
715
  // If it's not a __kindof type, reject it now.
716
12.8k
  if (!OPT->isKindOfType())
717
12.8k
    return false;
718
719
  // If it's Class or qualified Class, it's a class __kindof type.
720
6
  return OPT->isObjCClassType() || OPT->isObjCQualifiedClassType();
721
12.8k
}
722
723
ObjCTypeParamType::ObjCTypeParamType(const ObjCTypeParamDecl *D, QualType can,
724
                                     ArrayRef<ObjCProtocolDecl *> protocols)
725
    : Type(ObjCTypeParam, can, toSemanticDependence(can->getDependence())),
726
71.3k
      OTPDecl(const_cast<ObjCTypeParamDecl *>(D)) {
727
71.3k
  initialize(protocols);
728
71.3k
}
729
730
ObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base,
731
                               ArrayRef<QualType> typeArgs,
732
                               ArrayRef<ObjCProtocolDecl *> protocols,
733
                               bool isKindOf)
734
112k
    : Type(ObjCObject, Canonical, Base->getDependence()), BaseType(Base) {
735
112k
  ObjCObjectTypeBits.IsKindOf = isKindOf;
736
737
112k
  ObjCObjectTypeBits.NumTypeArgs = typeArgs.size();
738
112k
  assert(getTypeArgsAsWritten().size() == typeArgs.size() &&
739
112k
         "bitfield overflow in type argument count");
740
112k
  if (!typeArgs.empty())
741
40.4k
    memcpy(getTypeArgStorage(), typeArgs.data(),
742
40.4k
           typeArgs.size() * sizeof(QualType));
743
744
112k
  for (auto typeArg : typeArgs) {
745
49.2k
    addDependence(typeArg->getDependence() & ~TypeDependence::VariablyModified);
746
49.2k
  }
747
  // Initialize the protocol qualifiers. The protocol storage is known
748
  // after we set number of type arguments.
749
112k
  initialize(protocols);
750
112k
}
751
752
145k
bool ObjCObjectType::isSpecialized() const {
753
  // If we have type arguments written here, the type is specialized.
754
145k
  if (ObjCObjectTypeBits.NumTypeArgs > 0)
755
1.95k
    return true;
756
757
  // Otherwise, check whether the base type is specialized.
758
143k
  if (const auto objcObject = getBaseType()->getAs<ObjCObjectType>()) {
759
    // Terminate when we reach an interface type.
760
141k
    if (isa<ObjCInterfaceType>(objcObject))
761
141k
      return false;
762
763
1
    return objcObject->isSpecialized();
764
141k
  }
765
766
  // Not specialized.
767
1.97k
  return false;
768
143k
}
769
770
6.96k
ArrayRef<QualType> ObjCObjectType::getTypeArgs() const {
771
  // We have type arguments written on this type.
772
6.96k
  if (isSpecializedAsWritten())
773
948
    return getTypeArgsAsWritten();
774
775
  // Look at the base type, which might have type arguments.
776
6.01k
  if (const auto objcObject = getBaseType()->getAs<ObjCObjectType>()) {
777
    // Terminate when we reach an interface type.
778
6.01k
    if (isa<ObjCInterfaceType>(objcObject))
779
6.01k
      return {};
780
781
0
    return objcObject->getTypeArgs();
782
6.01k
  }
783
784
  // No type arguments.
785
1
  return {};
786
6.01k
}
787
788
56.0k
bool ObjCObjectType::isKindOfType() const {
789
56.0k
  if (isKindOfTypeAsWritten())
790
222
    return true;
791
792
  // Look at the base type, which might have type arguments.
793
55.8k
  if (const auto objcObject = getBaseType()->getAs<ObjCObjectType>()) {
794
    // Terminate when we reach an interface type.
795
33.7k
    if (isa<ObjCInterfaceType>(objcObject))
796
33.7k
      return false;
797
798
0
    return objcObject->isKindOfType();
799
33.7k
  }
800
801
  // Not a "__kindof" type.
802
22.0k
  return false;
803
55.8k
}
804
805
QualType ObjCObjectType::stripObjCKindOfTypeAndQuals(
806
175
           const ASTContext &ctx) const {
807
175
  if (!isKindOfType() && 
qual_empty()105
)
808
66
    return QualType(this, 0);
809
810
  // Recursively strip __kindof.
811
109
  SplitQualType splitBaseType = getBaseType().split();
812
109
  QualType baseType(splitBaseType.Ty, 0);
813
109
  if (const auto *baseObj = splitBaseType.Ty->getAs<ObjCObjectType>())
814
66
    baseType = baseObj->stripObjCKindOfTypeAndQuals(ctx);
815
816
109
  return ctx.getObjCObjectType(ctx.getQualifiedType(baseType,
817
109
                                                    splitBaseType.Quals),
818
109
                               getTypeArgsAsWritten(),
819
109
                               /*protocols=*/{},
820
109
                               /*isKindOf=*/false);
821
175
}
822
823
3.82M
ObjCInterfaceDecl *ObjCInterfaceType::getDecl() const {
824
3.82M
  ObjCInterfaceDecl *Canon = Decl->getCanonicalDecl();
825
3.82M
  if (ObjCInterfaceDecl *Def = Canon->getDefinition())
826
3.67M
    return Def;
827
151k
  return Canon;
828
3.82M
}
829
830
const ObjCObjectPointerType *ObjCObjectPointerType::stripObjCKindOfTypeAndQuals(
831
2.70k
                               const ASTContext &ctx) const {
832
2.70k
  if (!isKindOfType() && 
qual_empty()2.65k
)
833
2.61k
    return this;
834
835
93
  QualType obj = getObjectType()->stripObjCKindOfTypeAndQuals(ctx);
836
93
  return ctx.getObjCObjectPointerType(obj)->castAs<ObjCObjectPointerType>();
837
2.70k
}
838
839
namespace {
840
841
/// Visitor used to perform a simple type transformation that does not change
842
/// the semantics of the type.
843
template <typename Derived>
844
struct SimpleTransformVisitor : public TypeVisitor<Derived, QualType> {
845
  ASTContext &Ctx;
846
847
20.0k
  QualType recurse(QualType type) {
848
    // Split out the qualifiers from the type.
849
20.0k
    SplitQualType splitType = type.split();
850
851
    // Visit the type itself.
852
20.0k
    QualType result = static_cast<Derived *>(this)->Visit(splitType.Ty);
853
20.0k
    if (result.isNull())
854
0
      return result;
855
856
    // Reconstruct the transformed type by applying the local qualifiers
857
    // from the split type.
858
20.0k
    return Ctx.getQualifiedType(result, splitType.Quals);
859
20.0k
  }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::recurse(clang::QualType)
Line
Count
Source
847
19.5k
  QualType recurse(QualType type) {
848
    // Split out the qualifiers from the type.
849
19.5k
    SplitQualType splitType = type.split();
850
851
    // Visit the type itself.
852
19.5k
    QualType result = static_cast<Derived *>(this)->Visit(splitType.Ty);
853
19.5k
    if (result.isNull())
854
0
      return result;
855
856
    // Reconstruct the transformed type by applying the local qualifiers
857
    // from the split type.
858
19.5k
    return Ctx.getQualifiedType(result, splitType.Quals);
859
19.5k
  }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::recurse(clang::QualType)
Line
Count
Source
847
484
  QualType recurse(QualType type) {
848
    // Split out the qualifiers from the type.
849
484
    SplitQualType splitType = type.split();
850
851
    // Visit the type itself.
852
484
    QualType result = static_cast<Derived *>(this)->Visit(splitType.Ty);
853
484
    if (result.isNull())
854
0
      return result;
855
856
    // Reconstruct the transformed type by applying the local qualifiers
857
    // from the split type.
858
484
    return Ctx.getQualifiedType(result, splitType.Quals);
859
484
  }
860
861
public:
862
7.96k
  explicit SimpleTransformVisitor(ASTContext &ctx) : Ctx(ctx) {}
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::SimpleTransformVisitor(clang::ASTContext&)
Line
Count
Source
862
7.74k
  explicit SimpleTransformVisitor(ASTContext &ctx) : Ctx(ctx) {}
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::SimpleTransformVisitor(clang::ASTContext&)
Line
Count
Source
862
219
  explicit SimpleTransformVisitor(ASTContext &ctx) : Ctx(ctx) {}
863
864
  // None of the clients of this transformation can occur where
865
  // there are dependent types, so skip dependent types.
866
#define TYPE(Class, Base)
867
#define DEPENDENT_TYPE(Class, Base) \
868
0
  QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitDependentSizedArrayType(clang::DependentSizedArrayType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitDependentAddressSpaceType(clang::DependentAddressSpaceType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitDependentBitIntType(clang::DependentBitIntType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitDependentNameType(clang::DependentNameType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitDependentSizedExtVectorType(clang::DependentSizedExtVectorType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitDependentTemplateSpecializationType(clang::DependentTemplateSpecializationType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitDependentVectorType(clang::DependentVectorType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitInjectedClassNameType(clang::InjectedClassNameType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitDependentSizedMatrixType(clang::DependentSizedMatrixType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitPackExpansionType(clang::PackExpansionType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitSubstTemplateTypeParmPackType(clang::SubstTemplateTypeParmPackType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitTemplateTypeParmType(clang::TemplateTypeParmType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitUnresolvedUsingType(clang::UnresolvedUsingType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitDependentSizedArrayType(clang::DependentSizedArrayType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitDependentAddressSpaceType(clang::DependentAddressSpaceType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitDependentBitIntType(clang::DependentBitIntType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitDependentNameType(clang::DependentNameType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitDependentSizedExtVectorType(clang::DependentSizedExtVectorType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitDependentTemplateSpecializationType(clang::DependentTemplateSpecializationType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitDependentVectorType(clang::DependentVectorType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitInjectedClassNameType(clang::InjectedClassNameType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitDependentSizedMatrixType(clang::DependentSizedMatrixType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitPackExpansionType(clang::PackExpansionType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitSubstTemplateTypeParmPackType(clang::SubstTemplateTypeParmPackType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitTemplateTypeParmType(clang::TemplateTypeParmType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitUnresolvedUsingType(clang::UnresolvedUsingType const*)
869
#include "clang/AST/TypeNodes.inc"
870
871
#define TRIVIAL_TYPE_CLASS(Class) \
872
4.00k
  QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitBuiltinType(clang::BuiltinType const*)
Line
Count
Source
872
3.75k
  QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitObjCInterfaceType(clang::ObjCInterfaceType const*)
Line
Count
Source
872
28
  QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitEnumType(clang::EnumType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitRecordType(clang::RecordType const*)
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitBuiltinType(clang::BuiltinType const*)
Line
Count
Source
872
66
  QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitObjCInterfaceType(clang::ObjCInterfaceType const*)
Line
Count
Source
872
154
  QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitEnumType(clang::EnumType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitRecordType(clang::RecordType const*)
873
#define SUGARED_TYPE_CLASS(Class) \
874
1.99k
  QualType Visit##Class##Type(const Class##Type *T) { \
875
1.99k
    if (!T->isSugared()) \
876
1.99k
      
return QualType(T, 0)0
; \
877
1.99k
    QualType desugaredType = recurse(T->desugar()); \
878
1.99k
    if (desugaredType.isNull()) \
879
1.99k
      
return {}0
; \
880
1.99k
    if (desugaredType.getAsOpaquePtr() == T->desugar().getAsOpaquePtr()) \
881
1.99k
      
return QualType(T, 0)1.99k
; \
882
1.99k
    
return desugaredType1
; \
883
1.99k
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitDecltypeType(clang::DecltypeType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitElaboratedType(clang::ElaboratedType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitMacroQualifiedType(clang::MacroQualifiedType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitTemplateSpecializationType(clang::TemplateSpecializationType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitTypeOfExprType(clang::TypeOfExprType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitTypeOfType(clang::TypeOfType const*)
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitTypedefType(clang::TypedefType const*)
Line
Count
Source
874
1.97k
  QualType Visit##Class##Type(const Class##Type *T) { \
875
1.97k
    if (!T->isSugared()) \
876
1.97k
      
return QualType(T, 0)0
; \
877
1.97k
    QualType desugaredType = recurse(T->desugar()); \
878
1.97k
    if (desugaredType.isNull()) \
879
1.97k
      
return {}0
; \
880
1.97k
    if (desugaredType.getAsOpaquePtr() == T->desugar().getAsOpaquePtr()) \
881
1.97k
      
return QualType(T, 0)1.97k
; \
882
1.97k
    
return desugaredType1
; \
883
1.97k
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitUnaryTransformType(clang::UnaryTransformType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitDecltypeType(clang::DecltypeType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitElaboratedType(clang::ElaboratedType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitMacroQualifiedType(clang::MacroQualifiedType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitObjCTypeParamType(clang::ObjCTypeParamType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitTemplateSpecializationType(clang::TemplateSpecializationType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitTypeOfExprType(clang::TypeOfExprType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitTypeOfType(clang::TypeOfType const*)
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitTypedefType(clang::TypedefType const*)
Line
Count
Source
874
26
  QualType Visit##Class##Type(const Class##Type *T) { \
875
26
    if (!T->isSugared()) \
876
26
      
return QualType(T, 0)0
; \
877
26
    QualType desugaredType = recurse(T->desugar()); \
878
26
    if (desugaredType.isNull()) \
879
26
      
return {}0
; \
880
26
    if (desugaredType.getAsOpaquePtr() == T->desugar().getAsOpaquePtr()) \
881
26
      return QualType(T, 0); \
882
26
    
return desugaredType0
; \
883
26
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitUnaryTransformType(clang::UnaryTransformType const*)
884
885
  TRIVIAL_TYPE_CLASS(Builtin)
886
887
0
  QualType VisitComplexType(const ComplexType *T) {
888
0
    QualType elementType = recurse(T->getElementType());
889
0
    if (elementType.isNull())
890
0
      return {};
891
892
0
    if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
893
0
      return QualType(T, 0);
894
895
0
    return Ctx.getComplexType(elementType);
896
0
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitComplexType(clang::ComplexType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitComplexType(clang::ComplexType const*)
897
898
44
  QualType VisitPointerType(const PointerType *T) {
899
44
    QualType pointeeType = recurse(T->getPointeeType());
900
44
    if (pointeeType.isNull())
901
0
      return {};
902
903
44
    if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
904
34
      return QualType(T, 0);
905
906
10
    return Ctx.getPointerType(pointeeType);
907
44
  }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitPointerType(clang::PointerType const*)
Line
Count
Source
898
33
  QualType VisitPointerType(const PointerType *T) {
899
33
    QualType pointeeType = recurse(T->getPointeeType());
900
33
    if (pointeeType.isNull())
901
0
      return {};
902
903
33
    if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
904
23
      return QualType(T, 0);
905
906
10
    return Ctx.getPointerType(pointeeType);
907
33
  }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitPointerType(clang::PointerType const*)
Line
Count
Source
898
11
  QualType VisitPointerType(const PointerType *T) {
899
11
    QualType pointeeType = recurse(T->getPointeeType());
900
11
    if (pointeeType.isNull())
901
0
      return {};
902
903
11
    if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
904
11
      return QualType(T, 0);
905
906
0
    return Ctx.getPointerType(pointeeType);
907
11
  }
908
909
11
  QualType VisitBlockPointerType(const BlockPointerType *T) {
910
11
    QualType pointeeType = recurse(T->getPointeeType());
911
11
    if (pointeeType.isNull())
912
0
      return {};
913
914
11
    if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
915
8
      return QualType(T, 0);
916
917
3
    return Ctx.getBlockPointerType(pointeeType);
918
11
  }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitBlockPointerType(clang::BlockPointerType const*)
Line
Count
Source
909
9
  QualType VisitBlockPointerType(const BlockPointerType *T) {
910
9
    QualType pointeeType = recurse(T->getPointeeType());
911
9
    if (pointeeType.isNull())
912
0
      return {};
913
914
9
    if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
915
6
      return QualType(T, 0);
916
917
3
    return Ctx.getBlockPointerType(pointeeType);
918
9
  }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitBlockPointerType(clang::BlockPointerType const*)
Line
Count
Source
909
2
  QualType VisitBlockPointerType(const BlockPointerType *T) {
910
2
    QualType pointeeType = recurse(T->getPointeeType());
911
2
    if (pointeeType.isNull())
912
0
      return {};
913
914
2
    if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
915
2
      return QualType(T, 0);
916
917
0
    return Ctx.getBlockPointerType(pointeeType);
918
2
  }
919
920
0
  QualType VisitLValueReferenceType(const LValueReferenceType *T) {
921
0
    QualType pointeeType = recurse(T->getPointeeTypeAsWritten());
922
0
    if (pointeeType.isNull())
923
0
      return {};
924
925
0
    if (pointeeType.getAsOpaquePtr()
926
0
          == T->getPointeeTypeAsWritten().getAsOpaquePtr())
927
0
      return QualType(T, 0);
928
929
0
    return Ctx.getLValueReferenceType(pointeeType, T->isSpelledAsLValue());
930
0
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitLValueReferenceType(clang::LValueReferenceType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitLValueReferenceType(clang::LValueReferenceType const*)
931
932
0
  QualType VisitRValueReferenceType(const RValueReferenceType *T) {
933
0
    QualType pointeeType = recurse(T->getPointeeTypeAsWritten());
934
0
    if (pointeeType.isNull())
935
0
      return {};
936
937
0
    if (pointeeType.getAsOpaquePtr()
938
0
          == T->getPointeeTypeAsWritten().getAsOpaquePtr())
939
0
      return QualType(T, 0);
940
941
0
    return Ctx.getRValueReferenceType(pointeeType);
942
0
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitRValueReferenceType(clang::RValueReferenceType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitRValueReferenceType(clang::RValueReferenceType const*)
943
944
0
  QualType VisitMemberPointerType(const MemberPointerType *T) {
945
0
    QualType pointeeType = recurse(T->getPointeeType());
946
0
    if (pointeeType.isNull())
947
0
      return {};
948
949
0
    if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
950
0
      return QualType(T, 0);
951
952
0
    return Ctx.getMemberPointerType(pointeeType, T->getClass());
953
0
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitMemberPointerType(clang::MemberPointerType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitMemberPointerType(clang::MemberPointerType const*)
954
955
0
  QualType VisitConstantArrayType(const ConstantArrayType *T) {
956
0
    QualType elementType = recurse(T->getElementType());
957
0
    if (elementType.isNull())
958
0
      return {};
959
960
0
    if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
961
0
      return QualType(T, 0);
962
963
0
    return Ctx.getConstantArrayType(elementType, T->getSize(), T->getSizeExpr(),
964
0
                                    T->getSizeModifier(),
965
0
                                    T->getIndexTypeCVRQualifiers());
966
0
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitConstantArrayType(clang::ConstantArrayType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitConstantArrayType(clang::ConstantArrayType const*)
967
968
0
  QualType VisitVariableArrayType(const VariableArrayType *T) {
969
0
    QualType elementType = recurse(T->getElementType());
970
0
    if (elementType.isNull())
971
0
      return {};
972
973
0
    if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
974
0
      return QualType(T, 0);
975
976
0
    return Ctx.getVariableArrayType(elementType, T->getSizeExpr(),
977
0
                                    T->getSizeModifier(),
978
0
                                    T->getIndexTypeCVRQualifiers(),
979
0
                                    T->getBracketsRange());
980
0
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitVariableArrayType(clang::VariableArrayType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitVariableArrayType(clang::VariableArrayType const*)
981
982
0
  QualType VisitIncompleteArrayType(const IncompleteArrayType *T) {
983
0
    QualType elementType = recurse(T->getElementType());
984
0
    if (elementType.isNull())
985
0
      return {};
986
987
0
    if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
988
0
      return QualType(T, 0);
989
990
0
    return Ctx.getIncompleteArrayType(elementType, T->getSizeModifier(),
991
0
                                      T->getIndexTypeCVRQualifiers());
992
0
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitIncompleteArrayType(clang::IncompleteArrayType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitIncompleteArrayType(clang::IncompleteArrayType const*)
993
994
0
  QualType VisitVectorType(const VectorType *T) {
995
0
    QualType elementType = recurse(T->getElementType());
996
0
    if (elementType.isNull())
997
0
      return {};
998
999
0
    if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
1000
0
      return QualType(T, 0);
1001
1002
0
    return Ctx.getVectorType(elementType, T->getNumElements(),
1003
0
                             T->getVectorKind());
1004
0
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitVectorType(clang::VectorType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitVectorType(clang::VectorType const*)
1005
1006
0
  QualType VisitExtVectorType(const ExtVectorType *T) {
1007
0
    QualType elementType = recurse(T->getElementType());
1008
0
    if (elementType.isNull())
1009
0
      return {};
1010
1011
0
    if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
1012
0
      return QualType(T, 0);
1013
1014
0
    return Ctx.getExtVectorType(elementType, T->getNumElements());
1015
0
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitExtVectorType(clang::ExtVectorType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitExtVectorType(clang::ExtVectorType const*)
1016
1017
0
  QualType VisitConstantMatrixType(const ConstantMatrixType *T) {
1018
0
    QualType elementType = recurse(T->getElementType());
1019
0
    if (elementType.isNull())
1020
0
      return {};
1021
0
    if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
1022
0
      return QualType(T, 0);
1023
1024
0
    return Ctx.getConstantMatrixType(elementType, T->getNumRows(),
1025
0
                                     T->getNumColumns());
1026
0
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitConstantMatrixType(clang::ConstantMatrixType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitConstantMatrixType(clang::ConstantMatrixType const*)
1027
1028
0
  QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1029
0
    QualType returnType = recurse(T->getReturnType());
1030
0
    if (returnType.isNull())
1031
0
      return {};
1032
1033
0
    if (returnType.getAsOpaquePtr() == T->getReturnType().getAsOpaquePtr())
1034
0
      return QualType(T, 0);
1035
1036
0
    return Ctx.getFunctionNoProtoType(returnType, T->getExtInfo());
1037
0
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitFunctionNoProtoType(clang::FunctionNoProtoType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitFunctionNoProtoType(clang::FunctionNoProtoType const*)
1038
1039
13
  QualType VisitFunctionProtoType(const FunctionProtoType *T) {
1040
13
    QualType returnType = recurse(T->getReturnType());
1041
13
    if (returnType.isNull())
1042
0
      return {};
1043
1044
    // Transform parameter types.
1045
13
    SmallVector<QualType, 4> paramTypes;
1046
13
    bool paramChanged = false;
1047
18
    for (auto paramType : T->getParamTypes()) {
1048
18
      QualType newParamType = recurse(paramType);
1049
18
      if (newParamType.isNull())
1050
0
        return {};
1051
1052
18
      if (newParamType.getAsOpaquePtr() != paramType.getAsOpaquePtr())
1053
10
        paramChanged = true;
1054
1055
18
      paramTypes.push_back(newParamType);
1056
18
    }
1057
1058
    // Transform extended info.
1059
13
    FunctionProtoType::ExtProtoInfo info = T->getExtProtoInfo();
1060
13
    bool exceptionChanged = false;
1061
13
    if (info.ExceptionSpec.Type == EST_Dynamic) {
1062
0
      SmallVector<QualType, 4> exceptionTypes;
1063
0
      for (auto exceptionType : info.ExceptionSpec.Exceptions) {
1064
0
        QualType newExceptionType = recurse(exceptionType);
1065
0
        if (newExceptionType.isNull())
1066
0
          return {};
1067
1068
0
        if (newExceptionType.getAsOpaquePtr() != exceptionType.getAsOpaquePtr())
1069
0
          exceptionChanged = true;
1070
1071
0
        exceptionTypes.push_back(newExceptionType);
1072
0
      }
1073
1074
0
      if (exceptionChanged) {
1075
0
        info.ExceptionSpec.Exceptions =
1076
0
            llvm::makeArrayRef(exceptionTypes).copy(Ctx);
1077
0
      }
1078
0
    }
1079
1080
13
    if (returnType.getAsOpaquePtr() == T->getReturnType().getAsOpaquePtr() &&
1081
13
        !paramChanged && 
!exceptionChanged8
)
1082
8
      return QualType(T, 0);
1083
1084
5
    return Ctx.getFunctionType(returnType, paramTypes, info);
1085
13
  }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitFunctionProtoType(clang::FunctionProtoType const*)
Line
Count
Source
1039
11
  QualType VisitFunctionProtoType(const FunctionProtoType *T) {
1040
11
    QualType returnType = recurse(T->getReturnType());
1041
11
    if (returnType.isNull())
1042
0
      return {};
1043
1044
    // Transform parameter types.
1045
11
    SmallVector<QualType, 4> paramTypes;
1046
11
    bool paramChanged = false;
1047
16
    for (auto paramType : T->getParamTypes()) {
1048
16
      QualType newParamType = recurse(paramType);
1049
16
      if (newParamType.isNull())
1050
0
        return {};
1051
1052
16
      if (newParamType.getAsOpaquePtr() != paramType.getAsOpaquePtr())
1053
10
        paramChanged = true;
1054
1055
16
      paramTypes.push_back(newParamType);
1056
16
    }
1057
1058
    // Transform extended info.
1059
11
    FunctionProtoType::ExtProtoInfo info = T->getExtProtoInfo();
1060
11
    bool exceptionChanged = false;
1061
11
    if (info.ExceptionSpec.Type == EST_Dynamic) {
1062
0
      SmallVector<QualType, 4> exceptionTypes;
1063
0
      for (auto exceptionType : info.ExceptionSpec.Exceptions) {
1064
0
        QualType newExceptionType = recurse(exceptionType);
1065
0
        if (newExceptionType.isNull())
1066
0
          return {};
1067
1068
0
        if (newExceptionType.getAsOpaquePtr() != exceptionType.getAsOpaquePtr())
1069
0
          exceptionChanged = true;
1070
1071
0
        exceptionTypes.push_back(newExceptionType);
1072
0
      }
1073
1074
0
      if (exceptionChanged) {
1075
0
        info.ExceptionSpec.Exceptions =
1076
0
            llvm::makeArrayRef(exceptionTypes).copy(Ctx);
1077
0
      }
1078
0
    }
1079
1080
11
    if (returnType.getAsOpaquePtr() == T->getReturnType().getAsOpaquePtr() &&
1081
11
        !paramChanged && 
!exceptionChanged6
)
1082
6
      return QualType(T, 0);
1083
1084
5
    return Ctx.getFunctionType(returnType, paramTypes, info);
1085
11
  }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitFunctionProtoType(clang::FunctionProtoType const*)
Line
Count
Source
1039
2
  QualType VisitFunctionProtoType(const FunctionProtoType *T) {
1040
2
    QualType returnType = recurse(T->getReturnType());
1041
2
    if (returnType.isNull())
1042
0
      return {};
1043
1044
    // Transform parameter types.
1045
2
    SmallVector<QualType, 4> paramTypes;
1046
2
    bool paramChanged = false;
1047
2
    for (auto paramType : T->getParamTypes()) {
1048
2
      QualType newParamType = recurse(paramType);
1049
2
      if (newParamType.isNull())
1050
0
        return {};
1051
1052
2
      if (newParamType.getAsOpaquePtr() != paramType.getAsOpaquePtr())
1053
0
        paramChanged = true;
1054
1055
2
      paramTypes.push_back(newParamType);
1056
2
    }
1057
1058
    // Transform extended info.
1059
2
    FunctionProtoType::ExtProtoInfo info = T->getExtProtoInfo();
1060
2
    bool exceptionChanged = false;
1061
2
    if (info.ExceptionSpec.Type == EST_Dynamic) {
1062
0
      SmallVector<QualType, 4> exceptionTypes;
1063
0
      for (auto exceptionType : info.ExceptionSpec.Exceptions) {
1064
0
        QualType newExceptionType = recurse(exceptionType);
1065
0
        if (newExceptionType.isNull())
1066
0
          return {};
1067
1068
0
        if (newExceptionType.getAsOpaquePtr() != exceptionType.getAsOpaquePtr())
1069
0
          exceptionChanged = true;
1070
1071
0
        exceptionTypes.push_back(newExceptionType);
1072
0
      }
1073
1074
0
      if (exceptionChanged) {
1075
0
        info.ExceptionSpec.Exceptions =
1076
0
            llvm::makeArrayRef(exceptionTypes).copy(Ctx);
1077
0
      }
1078
0
    }
1079
1080
2
    if (returnType.getAsOpaquePtr() == T->getReturnType().getAsOpaquePtr() &&
1081
2
        !paramChanged && !exceptionChanged)
1082
2
      return QualType(T, 0);
1083
1084
0
    return Ctx.getFunctionType(returnType, paramTypes, info);
1085
2
  }
1086
1087
13
  QualType VisitParenType(const ParenType *T) {
1088
13
    QualType innerType = recurse(T->getInnerType());
1089
13
    if (innerType.isNull())
1090
0
      return {};
1091
1092
13
    if (innerType.getAsOpaquePtr() == T->getInnerType().getAsOpaquePtr())
1093
8
      return QualType(T, 0);
1094
1095
5
    return Ctx.getParenType(innerType);
1096
13
  }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitParenType(clang::ParenType const*)
Line
Count
Source
1087
11
  QualType VisitParenType(const ParenType *T) {
1088
11
    QualType innerType = recurse(T->getInnerType());
1089
11
    if (innerType.isNull())
1090
0
      return {};
1091
1092
11
    if (innerType.getAsOpaquePtr() == T->getInnerType().getAsOpaquePtr())
1093
6
      return QualType(T, 0);
1094
1095
5
    return Ctx.getParenType(innerType);
1096
11
  }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitParenType(clang::ParenType const*)
Line
Count
Source
1087
2
  QualType VisitParenType(const ParenType *T) {
1088
2
    QualType innerType = recurse(T->getInnerType());
1089
2
    if (innerType.isNull())
1090
0
      return {};
1091
1092
2
    if (innerType.getAsOpaquePtr() == T->getInnerType().getAsOpaquePtr())
1093
2
      return QualType(T, 0);
1094
1095
0
    return Ctx.getParenType(innerType);
1096
2
  }
1097
1098
  SUGARED_TYPE_CLASS(Typedef)
1099
  SUGARED_TYPE_CLASS(ObjCTypeParam)
1100
  SUGARED_TYPE_CLASS(MacroQualified)
1101
1102
0
  QualType VisitAdjustedType(const AdjustedType *T) {
1103
0
    QualType originalType = recurse(T->getOriginalType());
1104
0
    if (originalType.isNull())
1105
0
      return {};
1106
1107
0
    QualType adjustedType = recurse(T->getAdjustedType());
1108
0
    if (adjustedType.isNull())
1109
0
      return {};
1110
1111
0
    if (originalType.getAsOpaquePtr()
1112
0
          == T->getOriginalType().getAsOpaquePtr() &&
1113
0
        adjustedType.getAsOpaquePtr() == T->getAdjustedType().getAsOpaquePtr())
1114
0
      return QualType(T, 0);
1115
1116
0
    return Ctx.getAdjustedType(originalType, adjustedType);
1117
0
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitAdjustedType(clang::AdjustedType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitAdjustedType(clang::AdjustedType const*)
1118
1119
0
  QualType VisitDecayedType(const DecayedType *T) {
1120
0
    QualType originalType = recurse(T->getOriginalType());
1121
0
    if (originalType.isNull())
1122
0
      return {};
1123
1124
0
    if (originalType.getAsOpaquePtr()
1125
0
          == T->getOriginalType().getAsOpaquePtr())
1126
0
      return QualType(T, 0);
1127
1128
0
    return Ctx.getDecayedType(originalType);
1129
0
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitDecayedType(clang::DecayedType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitDecayedType(clang::DecayedType const*)
1130
1131
  SUGARED_TYPE_CLASS(TypeOfExpr)
1132
  SUGARED_TYPE_CLASS(TypeOf)
1133
  SUGARED_TYPE_CLASS(Decltype)
1134
  SUGARED_TYPE_CLASS(UnaryTransform)
1135
  TRIVIAL_TYPE_CLASS(Record)
1136
  TRIVIAL_TYPE_CLASS(Enum)
1137
1138
  // FIXME: Non-trivial to implement, but important for C++
1139
  SUGARED_TYPE_CLASS(Elaborated)
1140
1141
3.86k
  QualType VisitAttributedType(const AttributedType *T) {
1142
3.86k
    QualType modifiedType = recurse(T->getModifiedType());
1143
3.86k
    if (modifiedType.isNull())
1144
0
      return {};
1145
1146
3.86k
    QualType equivalentType = recurse(T->getEquivalentType());
1147
3.86k
    if (equivalentType.isNull())
1148
0
      return {};
1149
1150
3.86k
    if (modifiedType.getAsOpaquePtr()
1151
3.86k
          == T->getModifiedType().getAsOpaquePtr() &&
1152
3.86k
        equivalentType.getAsOpaquePtr()
1153
409
          == T->getEquivalentType().getAsOpaquePtr())
1154
409
      return QualType(T, 0);
1155
1156
3.45k
    return Ctx.getAttributedType(T->getAttrKind(), modifiedType,
1157
3.45k
                                 equivalentType);
1158
3.86k
  }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitAttributedType(clang::AttributedType const*)
Line
Count
Source
1141
3.85k
  QualType VisitAttributedType(const AttributedType *T) {
1142
3.85k
    QualType modifiedType = recurse(T->getModifiedType());
1143
3.85k
    if (modifiedType.isNull())
1144
0
      return {};
1145
1146
3.85k
    QualType equivalentType = recurse(T->getEquivalentType());
1147
3.85k
    if (equivalentType.isNull())
1148
0
      return {};
1149
1150
3.85k
    if (modifiedType.getAsOpaquePtr()
1151
3.85k
          == T->getModifiedType().getAsOpaquePtr() &&
1152
3.85k
        equivalentType.getAsOpaquePtr()
1153
399
          == T->getEquivalentType().getAsOpaquePtr())
1154
399
      return QualType(T, 0);
1155
1156
3.45k
    return Ctx.getAttributedType(T->getAttrKind(), modifiedType,
1157
3.45k
                                 equivalentType);
1158
3.85k
  }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitAttributedType(clang::AttributedType const*)
Line
Count
Source
1141
10
  QualType VisitAttributedType(const AttributedType *T) {
1142
10
    QualType modifiedType = recurse(T->getModifiedType());
1143
10
    if (modifiedType.isNull())
1144
0
      return {};
1145
1146
10
    QualType equivalentType = recurse(T->getEquivalentType());
1147
10
    if (equivalentType.isNull())
1148
0
      return {};
1149
1150
10
    if (modifiedType.getAsOpaquePtr()
1151
10
          == T->getModifiedType().getAsOpaquePtr() &&
1152
10
        equivalentType.getAsOpaquePtr()
1153
10
          == T->getEquivalentType().getAsOpaquePtr())
1154
10
      return QualType(T, 0);
1155
1156
0
    return Ctx.getAttributedType(T->getAttrKind(), modifiedType,
1157
0
                                 equivalentType);
1158
10
  }
1159
1160
0
  QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
1161
0
    QualType replacementType = recurse(T->getReplacementType());
1162
0
    if (replacementType.isNull())
1163
0
      return {};
1164
1165
0
    if (replacementType.getAsOpaquePtr()
1166
0
          == T->getReplacementType().getAsOpaquePtr())
1167
0
      return QualType(T, 0);
1168
1169
0
    return Ctx.getSubstTemplateTypeParmType(T->getReplacedParameter(),
1170
0
                                            replacementType);
1171
0
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitSubstTemplateTypeParmType(clang::SubstTemplateTypeParmType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitSubstTemplateTypeParmType(clang::SubstTemplateTypeParmType const*)
1172
1173
  // FIXME: Non-trivial to implement, but important for C++
1174
  SUGARED_TYPE_CLASS(TemplateSpecialization)
1175
1176
0
  QualType VisitAutoType(const AutoType *T) {
1177
0
    if (!T->isDeduced())
1178
0
      return QualType(T, 0);
1179
1180
0
    QualType deducedType = recurse(T->getDeducedType());
1181
0
    if (deducedType.isNull())
1182
0
      return {};
1183
1184
0
    if (deducedType.getAsOpaquePtr()
1185
0
          == T->getDeducedType().getAsOpaquePtr())
1186
0
      return QualType(T, 0);
1187
1188
0
    return Ctx.getAutoType(deducedType, T->getKeyword(),
1189
0
                           T->isDependentType(), /*IsPack=*/false,
1190
0
                           T->getTypeConstraintConcept(),
1191
0
                           T->getTypeConstraintArguments());
1192
0
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitAutoType(clang::AutoType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitAutoType(clang::AutoType const*)
1193
1194
840
  QualType VisitObjCObjectType(const ObjCObjectType *T) {
1195
840
    QualType baseType = recurse(T->getBaseType());
1196
840
    if (baseType.isNull())
1197
0
      return {};
1198
1199
    // Transform type arguments.
1200
840
    bool typeArgChanged = false;
1201
840
    SmallVector<QualType, 4> typeArgs;
1202
840
    for (auto typeArg : T->getTypeArgsAsWritten()) {
1203
6
      QualType newTypeArg = recurse(typeArg);
1204
6
      if (newTypeArg.isNull())
1205
0
        return {};
1206
1207
6
      if (newTypeArg.getAsOpaquePtr() != typeArg.getAsOpaquePtr())
1208
2
        typeArgChanged = true;
1209
1210
6
      typeArgs.push_back(newTypeArg);
1211
6
    }
1212
1213
840
    if (baseType.getAsOpaquePtr() == T->getBaseType().getAsOpaquePtr() &&
1214
840
        !typeArgChanged)
1215
838
      return QualType(T, 0);
1216
1217
2
    return Ctx.getObjCObjectType(baseType, typeArgs,
1218
2
                                 llvm::makeArrayRef(T->qual_begin(),
1219
2
                                                    T->getNumProtocols()),
1220
2
                                 T->isKindOfTypeAsWritten());
1221
840
  }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitObjCObjectType(clang::ObjCObjectType const*)
Line
Count
Source
1194
813
  QualType VisitObjCObjectType(const ObjCObjectType *T) {
1195
813
    QualType baseType = recurse(T->getBaseType());
1196
813
    if (baseType.isNull())
1197
0
      return {};
1198
1199
    // Transform type arguments.
1200
813
    bool typeArgChanged = false;
1201
813
    SmallVector<QualType, 4> typeArgs;
1202
813
    for (auto typeArg : T->getTypeArgsAsWritten()) {
1203
2
      QualType newTypeArg = recurse(typeArg);
1204
2
      if (newTypeArg.isNull())
1205
0
        return {};
1206
1207
2
      if (newTypeArg.getAsOpaquePtr() != typeArg.getAsOpaquePtr())
1208
0
        typeArgChanged = true;
1209
1210
2
      typeArgs.push_back(newTypeArg);
1211
2
    }
1212
1213
813
    if (baseType.getAsOpaquePtr() == T->getBaseType().getAsOpaquePtr() &&
1214
813
        !typeArgChanged)
1215
813
      return QualType(T, 0);
1216
1217
0
    return Ctx.getObjCObjectType(baseType, typeArgs,
1218
0
                                 llvm::makeArrayRef(T->qual_begin(),
1219
0
                                                    T->getNumProtocols()),
1220
0
                                 T->isKindOfTypeAsWritten());
1221
813
  }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitObjCObjectType(clang::ObjCObjectType const*)
Line
Count
Source
1194
27
  QualType VisitObjCObjectType(const ObjCObjectType *T) {
1195
27
    QualType baseType = recurse(T->getBaseType());
1196
27
    if (baseType.isNull())
1197
0
      return {};
1198
1199
    // Transform type arguments.
1200
27
    bool typeArgChanged = false;
1201
27
    SmallVector<QualType, 4> typeArgs;
1202
27
    for (auto typeArg : T->getTypeArgsAsWritten()) {
1203
4
      QualType newTypeArg = recurse(typeArg);
1204
4
      if (newTypeArg.isNull())
1205
0
        return {};
1206
1207
4
      if (newTypeArg.getAsOpaquePtr() != typeArg.getAsOpaquePtr())
1208
2
        typeArgChanged = true;
1209
1210
4
      typeArgs.push_back(newTypeArg);
1211
4
    }
1212
1213
27
    if (baseType.getAsOpaquePtr() == T->getBaseType().getAsOpaquePtr() &&
1214
27
        !typeArgChanged)
1215
25
      return QualType(T, 0);
1216
1217
2
    return Ctx.getObjCObjectType(baseType, typeArgs,
1218
2
                                 llvm::makeArrayRef(T->qual_begin(),
1219
2
                                                    T->getNumProtocols()),
1220
2
                                 T->isKindOfTypeAsWritten());
1221
27
  }
1222
1223
  TRIVIAL_TYPE_CLASS(ObjCInterface)
1224
1225
1.38k
  QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1226
1.38k
    QualType pointeeType = recurse(T->getPointeeType());
1227
1.38k
    if (pointeeType.isNull())
1228
0
      return {};
1229
1230
1.38k
    if (pointeeType.getAsOpaquePtr()
1231
1.38k
          == T->getPointeeType().getAsOpaquePtr())
1232
995
      return QualType(T, 0);
1233
1234
386
    return Ctx.getObjCObjectPointerType(pointeeType);
1235
1.38k
  }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitObjCObjectPointerType(clang::ObjCObjectPointerType const*)
Line
Count
Source
1225
1.21k
  QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1226
1.21k
    QualType pointeeType = recurse(T->getPointeeType());
1227
1.21k
    if (pointeeType.isNull())
1228
0
      return {};
1229
1230
1.21k
    if (pointeeType.getAsOpaquePtr()
1231
1.21k
          == T->getPointeeType().getAsOpaquePtr())
1232
836
      return QualType(T, 0);
1233
1234
376
    return Ctx.getObjCObjectPointerType(pointeeType);
1235
1.21k
  }
Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitObjCObjectPointerType(clang::ObjCObjectPointerType const*)
Line
Count
Source
1225
169
  QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1226
169
    QualType pointeeType = recurse(T->getPointeeType());
1227
169
    if (pointeeType.isNull())
1228
0
      return {};
1229
1230
169
    if (pointeeType.getAsOpaquePtr()
1231
169
          == T->getPointeeType().getAsOpaquePtr())
1232
159
      return QualType(T, 0);
1233
1234
10
    return Ctx.getObjCObjectPointerType(pointeeType);
1235
169
  }
1236
1237
0
  QualType VisitAtomicType(const AtomicType *T) {
1238
0
    QualType valueType = recurse(T->getValueType());
1239
0
    if (valueType.isNull())
1240
0
      return {};
1241
1242
0
    if (valueType.getAsOpaquePtr()
1243
0
          == T->getValueType().getAsOpaquePtr())
1244
0
      return QualType(T, 0);
1245
1246
0
    return Ctx.getAtomicType(valueType);
1247
0
  }
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::SubstObjCTypeArgsVisitor>::VisitAtomicType(clang::AtomicType const*)
Unexecuted instantiation: Type.cpp:(anonymous namespace)::SimpleTransformVisitor<(anonymous namespace)::StripObjCKindOfTypeVisitor>::VisitAtomicType(clang::AtomicType const*)
1248
1249
#undef TRIVIAL_TYPE_CLASS
1250
#undef SUGARED_TYPE_CLASS
1251
};
1252
1253
struct SubstObjCTypeArgsVisitor
1254
    : public SimpleTransformVisitor<SubstObjCTypeArgsVisitor> {
1255
  using BaseType = SimpleTransformVisitor<SubstObjCTypeArgsVisitor>;
1256
1257
  ArrayRef<QualType> TypeArgs;
1258
  ObjCSubstitutionContext SubstContext;
1259
1260
  SubstObjCTypeArgsVisitor(ASTContext &ctx, ArrayRef<QualType> typeArgs,
1261
                           ObjCSubstitutionContext context)
1262
7.74k
      : BaseType(ctx), TypeArgs(typeArgs), SubstContext(context) {}
1263
1264
7.42k
  QualType VisitObjCTypeParamType(const ObjCTypeParamType *OTPTy) {
1265
    // Replace an Objective-C type parameter reference with the corresponding
1266
    // type argument.
1267
7.42k
    ObjCTypeParamDecl *typeParam = OTPTy->getDecl();
1268
    // If we have type arguments, use them.
1269
7.42k
    if (!TypeArgs.empty()) {
1270
341
      QualType argType = TypeArgs[typeParam->getIndex()];
1271
341
      if (OTPTy->qual_empty())
1272
340
        return argType;
1273
1274
      // Apply protocol lists if exists.
1275
1
      bool hasError;
1276
1
      SmallVector<ObjCProtocolDecl *, 8> protocolsVec;
1277
1
      protocolsVec.append(OTPTy->qual_begin(), OTPTy->qual_end());
1278
1
      ArrayRef<ObjCProtocolDecl *> protocolsToApply = protocolsVec;
1279
1
      return Ctx.applyObjCProtocolQualifiers(
1280
1
          argType, protocolsToApply, hasError, true/*allowOnPointerType*/);
1281
341
    }
1282
1283
7.08k
    switch (SubstContext) {
1284
321
    case ObjCSubstitutionContext::Ordinary:
1285
6.48k
    case ObjCSubstitutionContext::Parameter:
1286
6.48k
    case ObjCSubstitutionContext::Superclass:
1287
      // Substitute the bound.
1288
6.48k
      return typeParam->getUnderlyingType();
1289
1290
570
    case ObjCSubstitutionContext::Result:
1291
603
    case ObjCSubstitutionContext::Property: {
1292
      // Substitute the __kindof form of the underlying type.
1293
603
      const auto *objPtr =
1294
603
          typeParam->getUnderlyingType()->castAs<ObjCObjectPointerType>();
1295
1296
      // __kindof types, id, and Class don't need an additional
1297
      // __kindof.
1298
603
      if (objPtr->isKindOfType() || objPtr->isObjCIdOrClassType())
1299
564
        return typeParam->getUnderlyingType();
1300
1301
      // Add __kindof.
1302
39
      const auto *obj = objPtr->getObjectType();
1303
39
      QualType resultTy = Ctx.getObjCObjectType(
1304
39
          obj->getBaseType(), obj->getTypeArgsAsWritten(), obj->getProtocols(),
1305
39
          /*isKindOf=*/true);
1306
1307
      // Rebuild object pointer type.
1308
39
      return Ctx.getObjCObjectPointerType(resultTy);
1309
603
    }
1310
7.08k
    }
1311
0
    llvm_unreachable("Unexpected ObjCSubstitutionContext!");
1312
0
  }
1313
1314
0
  QualType VisitFunctionType(const FunctionType *funcType) {
1315
0
    // If we have a function type, update the substitution context
1316
0
    // appropriately.
1317
0
1318
0
    //Substitute result type.
1319
0
    QualType returnType = funcType->getReturnType().substObjCTypeArgs(
1320
0
        Ctx, TypeArgs, ObjCSubstitutionContext::Result);
1321
0
    if (returnType.isNull())
1322
0
      return {};
1323
0
1324
0
    // Handle non-prototyped functions, which only substitute into the result
1325
0
    // type.
1326
0
    if (isa<FunctionNoProtoType>(funcType)) {
1327
0
      // If the return type was unchanged, do nothing.
1328
0
      if (returnType.getAsOpaquePtr() ==
1329
0
          funcType->getReturnType().getAsOpaquePtr())
1330
0
        return BaseType::VisitFunctionType(funcType);
1331
0
1332
0
      // Otherwise, build a new type.
1333
0
      return Ctx.getFunctionNoProtoType(returnType, funcType->getExtInfo());
1334
0
    }
1335
0
1336
0
    const auto *funcProtoType = cast<FunctionProtoType>(funcType);
1337
0
1338
0
    // Transform parameter types.
1339
0
    SmallVector<QualType, 4> paramTypes;
1340
0
    bool paramChanged = false;
1341
0
    for (auto paramType : funcProtoType->getParamTypes()) {
1342
0
      QualType newParamType = paramType.substObjCTypeArgs(
1343
0
          Ctx, TypeArgs, ObjCSubstitutionContext::Parameter);
1344
0
      if (newParamType.isNull())
1345
0
        return {};
1346
0
1347
0
      if (newParamType.getAsOpaquePtr() != paramType.getAsOpaquePtr())
1348
0
        paramChanged = true;
1349
0
1350
0
      paramTypes.push_back(newParamType);
1351
0
    }
1352
0
1353
0
    // Transform extended info.
1354
0
    FunctionProtoType::ExtProtoInfo info = funcProtoType->getExtProtoInfo();
1355
0
    bool exceptionChanged = false;
1356
0
    if (info.ExceptionSpec.Type == EST_Dynamic) {
1357
0
      SmallVector<QualType, 4> exceptionTypes;
1358
0
      for (auto exceptionType : info.ExceptionSpec.Exceptions) {
1359
0
        QualType newExceptionType = exceptionType.substObjCTypeArgs(
1360
0
            Ctx, TypeArgs, ObjCSubstitutionContext::Ordinary);
1361
0
        if (newExceptionType.isNull())
1362
0
          return {};
1363
0
1364
0
        if (newExceptionType.getAsOpaquePtr() != exceptionType.getAsOpaquePtr())
1365
0
          exceptionChanged = true;
1366
0
1367
0
        exceptionTypes.push_back(newExceptionType);
1368
0
      }
1369
0
1370
0
      if (exceptionChanged) {
1371
0
        info.ExceptionSpec.Exceptions =
1372
0
            llvm::makeArrayRef(exceptionTypes).copy(Ctx);
1373
0
      }
1374
0
    }
1375
0
1376
0
    if (returnType.getAsOpaquePtr() ==
1377
0
            funcProtoType->getReturnType().getAsOpaquePtr() &&
1378
0
        !paramChanged && !exceptionChanged)
1379
0
      return BaseType::VisitFunctionType(funcType);
1380
0
1381
0
    return Ctx.getFunctionType(returnType, paramTypes, info);
1382
0
  }
1383
1384
1.21k
  QualType VisitObjCObjectType(const ObjCObjectType *objcObjectType) {
1385
    // Substitute into the type arguments of a specialized Objective-C object
1386
    // type.
1387
1.21k
    if (objcObjectType->isSpecializedAsWritten()) {
1388
401
      SmallVector<QualType, 4> newTypeArgs;
1389
401
      bool anyChanged = false;
1390
404
      for (auto typeArg : objcObjectType->getTypeArgsAsWritten()) {
1391
404
        QualType newTypeArg = typeArg.substObjCTypeArgs(
1392
404
            Ctx, TypeArgs, ObjCSubstitutionContext::Ordinary);
1393
404
        if (newTypeArg.isNull())
1394
0
          return {};
1395
1396
404
        if (newTypeArg.getAsOpaquePtr() != typeArg.getAsOpaquePtr()) {
1397
          // If we're substituting based on an unspecialized context type,
1398
          // produce an unspecialized type.
1399
402
          ArrayRef<ObjCProtocolDecl *> protocols(
1400
402
              objcObjectType->qual_begin(), objcObjectType->getNumProtocols());
1401
402
          if (TypeArgs.empty() &&
1402
402
              
SubstContext != ObjCSubstitutionContext::Superclass321
) {
1403
321
            return Ctx.getObjCObjectType(
1404
321
                objcObjectType->getBaseType(), {}, protocols,
1405
321
                objcObjectType->isKindOfTypeAsWritten());
1406
321
          }
1407
1408
81
          anyChanged = true;
1409
81
        }
1410
1411
83
        newTypeArgs.push_back(newTypeArg);
1412
83
      }
1413
1414
80
      if (anyChanged) {
1415
78
        ArrayRef<ObjCProtocolDecl *> protocols(
1416
78
            objcObjectType->qual_begin(), objcObjectType->getNumProtocols());
1417
78
        return Ctx.getObjCObjectType(objcObjectType->getBaseType(), newTypeArgs,
1418
78
                                     protocols,
1419
78
                                     objcObjectType->isKindOfTypeAsWritten());
1420
78
      }
1421
80
    }
1422
1423
813
    return BaseType::VisitObjCObjectType(objcObjectType);
1424
1.21k
  }
1425
1426
3.85k
  QualType VisitAttributedType(const AttributedType *attrType) {
1427
3.85k
    QualType newType = BaseType::VisitAttributedType(attrType);
1428
3.85k
    if (newType.isNull())
1429
0
      return {};
1430
1431
3.85k
    const auto *newAttrType = dyn_cast<AttributedType>(newType.getTypePtr());
1432
3.85k
    if (!newAttrType || newAttrType->getAttrKind() != attr::ObjCKindOf)
1433
3.83k
      return newType;
1434
1435
    // Find out if it's an Objective-C object or object pointer type;
1436
22
    QualType newEquivType = newAttrType->getEquivalentType();
1437
22
    const ObjCObjectPointerType *ptrType =
1438
22
        newEquivType->getAs<ObjCObjectPointerType>();
1439
22
    const ObjCObjectType *objType = ptrType
1440
22
                                        ? ptrType->getObjectType()
1441
22
                                        : 
newEquivType->getAs<ObjCObjectType>()0
;
1442
22
    if (!objType)
1443
0
      return newType;
1444
1445
    // Rebuild the "equivalent" type, which pushes __kindof down into
1446
    // the object type.
1447
22
    newEquivType = Ctx.getObjCObjectType(
1448
22
        objType->getBaseType(), objType->getTypeArgsAsWritten(),
1449
22
        objType->getProtocols(),
1450
        // There is no need to apply kindof on an unqualified id type.
1451
22
        /*isKindOf=*/objType->isObjCUnqualifiedId() ? 
false0
: true);
1452
1453
    // If we started with an object pointer type, rebuild it.
1454
22
    if (ptrType)
1455
22
      newEquivType = Ctx.getObjCObjectPointerType(newEquivType);
1456
1457
    // Rebuild the attributed type.
1458
22
    return Ctx.getAttributedType(newAttrType->getAttrKind(),
1459
22
                                 newAttrType->getModifiedType(), newEquivType);
1460
22
  }
1461
};
1462
1463
struct StripObjCKindOfTypeVisitor
1464
    : public SimpleTransformVisitor<StripObjCKindOfTypeVisitor> {
1465
  using BaseType = SimpleTransformVisitor<StripObjCKindOfTypeVisitor>;
1466
1467
219
  explicit StripObjCKindOfTypeVisitor(ASTContext &ctx) : BaseType(ctx) {}
1468
1469
42
  QualType VisitObjCObjectType(const ObjCObjectType *objType) {
1470
42
    if (!objType->isKindOfType())
1471
27
      return BaseType::VisitObjCObjectType(objType);
1472
1473
15
    QualType baseType = objType->getBaseType().stripObjCKindOfType(Ctx);
1474
15
    return Ctx.getObjCObjectType(baseType, objType->getTypeArgsAsWritten(),
1475
15
                                 objType->getProtocols(),
1476
15
                                 /*isKindOf=*/false);
1477
42
  }
1478
};
1479
1480
} // namespace
1481
1482
/// Substitute the given type arguments for Objective-C type
1483
/// parameters within the given type, recursively.
1484
QualType QualType::substObjCTypeArgs(ASTContext &ctx,
1485
                                     ArrayRef<QualType> typeArgs,
1486
7.74k
                                     ObjCSubstitutionContext context) const {
1487
7.74k
  SubstObjCTypeArgsVisitor visitor(ctx, typeArgs, context);
1488
7.74k
  return visitor.recurse(*this);
1489
7.74k
}
1490
1491
QualType QualType::substObjCMemberType(QualType objectType,
1492
                                       const DeclContext *dc,
1493
32.2k
                                       ObjCSubstitutionContext context) const {
1494
32.2k
  if (auto subs = objectType->getObjCSubstitutions(dc))
1495
3.36k
    return substObjCTypeArgs(dc->getParentASTContext(), *subs, context);
1496
1497
28.8k
  return *this;
1498
32.2k
}
1499
1500
219
QualType QualType::stripObjCKindOfType(const ASTContext &constCtx) const {
1501
  // FIXME: Because ASTContext::getAttributedType() is non-const.
1502
219
  auto &ctx = const_cast<ASTContext &>(constCtx);
1503
219
  StripObjCKindOfTypeVisitor visitor(ctx);
1504
219
  return visitor.recurse(*this);
1505
219
}
1506
1507
1.01M
QualType QualType::getAtomicUnqualifiedType() const {
1508
1.01M
  if (const auto AT = getTypePtr()->getAs<AtomicType>())
1509
666
    return AT->getValueType().getUnqualifiedType();
1510
1.01M
  return getUnqualifiedType();
1511
1.01M
}
1512
1513
Optional<ArrayRef<QualType>> Type::getObjCSubstitutions(
1514
56.7k
                               const DeclContext *dc) const {
1515
  // Look through method scopes.
1516
56.7k
  if (const auto method = dyn_cast<ObjCMethodDecl>(dc))
1517
221
    dc = method->getDeclContext();
1518
1519
  // Find the class or category in which the type we're substituting
1520
  // was declared.
1521
56.7k
  const auto *dcClassDecl = dyn_cast<ObjCInterfaceDecl>(dc);
1522
56.7k
  const ObjCCategoryDecl *dcCategoryDecl = nullptr;
1523
56.7k
  ObjCTypeParamList *dcTypeParams = nullptr;
1524
56.7k
  if (dcClassDecl) {
1525
    // If the class does not have any type parameters, there's no
1526
    // substitution to do.
1527
39.7k
    dcTypeParams = dcClassDecl->getTypeParamList();
1528
39.7k
    if (!dcTypeParams)
1529
33.7k
      return None;
1530
39.7k
  } else {
1531
    // If we are in neither a class nor a category, there's no
1532
    // substitution to perform.
1533
16.9k
    dcCategoryDecl = dyn_cast<ObjCCategoryDecl>(dc);
1534
16.9k
    if (!dcCategoryDecl)
1535
7.32k
      return None;
1536
1537
    // If the category does not have any type parameters, there's no
1538
    // substitution to do.
1539
9.62k
    dcTypeParams = dcCategoryDecl->getTypeParamList();
1540
9.62k
    if (!dcTypeParams)
1541
8.89k
      return None;
1542
1543
728
    dcClassDecl = dcCategoryDecl->getClassInterface();
1544
728
    if (!dcClassDecl)
1545
0
      return None;
1546
728
  }
1547
6.74k
  assert(dcTypeParams && "No substitutions to perform");
1548
0
  assert(dcClassDecl && "No class context");
1549
1550
  // Find the underlying object type.
1551
0
  const ObjCObjectType *objectType;
1552
6.74k
  if (const auto *objectPointerType = getAs<ObjCObjectPointerType>()) {
1553
6.29k
    objectType = objectPointerType->getObjectType();
1554
6.29k
  } else 
if (453
getAs<BlockPointerType>()453
) {
1555
8
    ASTContext &ctx = dc->getParentASTContext();
1556
8
    objectType = ctx.getObjCObjectType(ctx.ObjCBuiltinIdTy, {}, {})
1557
8
                   ->castAs<ObjCObjectType>();
1558
445
  } else {
1559
445
    objectType = getAs<ObjCObjectType>();
1560
445
  }
1561
1562
  /// Extract the class from the receiver object type.
1563
6.74k
  ObjCInterfaceDecl *curClassDecl = objectType ? objectType->getInterface()
1564
6.74k
                                               : 
nullptr0
;
1565
6.74k
  if (!curClassDecl) {
1566
    // If we don't have a context type (e.g., this is "id" or some
1567
    // variant thereof), substitute the bounds.
1568
84
    return llvm::ArrayRef<QualType>();
1569
84
  }
1570
1571
  // Follow the superclass chain until we've mapped the receiver type
1572
  // to the same class as the context.
1573
11.4k
  
while (6.66k
curClassDecl != dcClassDecl) {
1574
    // Map to the superclass type.
1575
9.08k
    QualType superType = objectType->getSuperClassType();
1576
9.08k
    if (superType.isNull()) {
1577
4.32k
      objectType = nullptr;
1578
4.32k
      break;
1579
4.32k
    }
1580
1581
4.75k
    objectType = superType->castAs<ObjCObjectType>();
1582
4.75k
    curClassDecl = objectType->getInterface();
1583
4.75k
  }
1584
1585
  // If we don't have a receiver type, or the receiver type does not
1586
  // have type arguments, substitute in the defaults.
1587
6.66k
  if (!objectType || 
objectType->isUnspecialized()2.33k
) {
1588
6.20k
    return llvm::ArrayRef<QualType>();
1589
6.20k
  }
1590
1591
  // The receiver type has the type arguments we want.
1592
459
  return objectType->getTypeArgs();
1593
6.66k
}
1594
1595
9
bool Type::acceptsObjCTypeParams() const {
1596
9
  if (auto *IfaceT = getAsObjCInterfaceType()) {
1597
2
    if (auto *ID = IfaceT->getInterface()) {
1598
2
      if (ID->getTypeParamList())
1599
1
        return true;
1600
2
    }
1601
2
  }
1602
1603
8
  return false;
1604
9
}
1605
1606
326
void ObjCObjectType::computeSuperClassTypeSlow() const {
1607
  // Retrieve the class declaration for this type. If there isn't one
1608
  // (e.g., this is some variant of "id" or "Class"), then there is no
1609
  // superclass type.
1610
326
  ObjCInterfaceDecl *classDecl = getInterface();
1611
326
  if (!classDecl) {
1612
0
    CachedSuperClassType.setInt(true);
1613
0
    return;
1614
0
  }
1615
1616
  // Extract the superclass type.
1617
326
  const ObjCObjectType *superClassObjTy = classDecl->getSuperClassType();
1618
326
  if (!superClassObjTy) {
1619
50
    CachedSuperClassType.setInt(true);
1620
50
    return;
1621
50
  }
1622
1623
276
  ObjCInterfaceDecl *superClassDecl = superClassObjTy->getInterface();
1624
276
  if (!superClassDecl) {
1625
0
    CachedSuperClassType.setInt(true);
1626
0
    return;
1627
0
  }
1628
1629
  // If the superclass doesn't have type parameters, then there is no
1630
  // substitution to perform.
1631
276
  QualType superClassType(superClassObjTy, 0);
1632
276
  ObjCTypeParamList *superClassTypeParams = superClassDecl->getTypeParamList();
1633
276
  if (!superClassTypeParams) {
1634
139
    CachedSuperClassType.setPointerAndInt(
1635
139
      superClassType->castAs<ObjCObjectType>(), true);
1636
139
    return;
1637
139
  }
1638
1639
  // If the superclass reference is unspecialized, return it.
1640
137
  if (superClassObjTy->isUnspecialized()) {
1641
6
    CachedSuperClassType.setPointerAndInt(superClassObjTy, true);
1642
6
    return;
1643
6
  }
1644
1645
  // If the subclass is not parameterized, there aren't any type
1646
  // parameters in the superclass reference to substitute.
1647
131
  ObjCTypeParamList *typeParams = classDecl->getTypeParamList();
1648
131
  if (!typeParams) {
1649
7
    CachedSuperClassType.setPointerAndInt(
1650
7
      superClassType->castAs<ObjCObjectType>(), true);
1651
7
    return;
1652
7
  }
1653
1654
  // If the subclass type isn't specialized, return the unspecialized
1655
  // superclass.
1656
124
  if (isUnspecialized()) {
1657
99
    QualType unspecializedSuper
1658
99
      = classDecl->getASTContext().getObjCInterfaceType(
1659
99
          superClassObjTy->getInterface());
1660
99
    CachedSuperClassType.setPointerAndInt(
1661
99
      unspecializedSuper->castAs<ObjCObjectType>(),
1662
99
      true);
1663
99
    return;
1664
99
  }
1665
1666
  // Substitute the provided type arguments into the superclass type.
1667
25
  ArrayRef<QualType> typeArgs = getTypeArgs();
1668
25
  assert(typeArgs.size() == typeParams->size());
1669
0
  CachedSuperClassType.setPointerAndInt(
1670
25
    superClassType.substObjCTypeArgs(classDecl->getASTContext(), typeArgs,
1671
25
                                     ObjCSubstitutionContext::Superclass)
1672
25
      ->castAs<ObjCObjectType>(),
1673
25
    true);
1674
25
}
1675
1676
29.4k
const ObjCInterfaceType *ObjCObjectPointerType::getInterfaceType() const {
1677
29.4k
  if (auto interfaceDecl = getObjectType()->getInterface()) {
1678
24.9k
    return interfaceDecl->getASTContext().getObjCInterfaceType(interfaceDecl)
1679
24.9k
             ->castAs<ObjCInterfaceType>();
1680
24.9k
  }
1681
1682
4.49k
  return nullptr;
1683
29.4k
}
1684
1685
0
QualType ObjCObjectPointerType::getSuperClassType() const {
1686
0
  QualType superObjectType = getObjectType()->getSuperClassType();
1687
0
  if (superObjectType.isNull())
1688
0
    return superObjectType;
1689
1690
0
  ASTContext &ctx = getInterfaceDecl()->getASTContext();
1691
0
  return ctx.getObjCObjectPointerType(superObjectType);
1692
0
}
1693
1694
525
const ObjCObjectType *Type::getAsObjCQualifiedInterfaceType() const {
1695
  // There is no sugar for ObjCObjectType's, just return the canonical
1696
  // type pointer if it is the right class.  There is no typedef information to
1697
  // return and these cannot be Address-space qualified.
1698
525
  if (const auto *T = getAs<ObjCObjectType>())
1699
451
    if (T->getNumProtocols() && 
T->getInterface()53
)
1700
53
      return T;
1701
472
  return nullptr;
1702
525
}
1703
1704
522
bool Type::isObjCQualifiedInterfaceType() const {
1705
522
  return getAsObjCQualifiedInterfaceType() != nullptr;
1706
522
}
1707
1708
12.8k
const ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const {
1709
  // There is no sugar for ObjCQualifiedIdType's, just return the canonical
1710
  // type pointer if it is the right class.
1711
12.8k
  if (const auto *OPT = getAs<ObjCObjectPointerType>()) {
1712
12.8k
    if (OPT->isObjCQualifiedIdType())
1713
231
      return OPT;
1714
12.8k
  }
1715
12.6k
  return nullptr;
1716
12.8k
}
1717
1718
10
const ObjCObjectPointerType *Type::getAsObjCQualifiedClassType() const {
1719
  // There is no sugar for ObjCQualifiedClassType's, just return the canonical
1720
  // type pointer if it is the right class.
1721
10
  if (const auto *OPT = getAs<ObjCObjectPointerType>()) {
1722
10
    if (OPT->isObjCQualifiedClassType())
1723
10
      return OPT;
1724
10
  }
1725
0
  return nullptr;
1726
10
}
1727
1728
7.82k
const ObjCObjectType *Type::getAsObjCInterfaceType() const {
1729
7.82k
  if (const auto *OT = getAs<ObjCObjectType>()) {
1730
4.72k
    if (OT->getInterface())
1731
4.72k
      return OT;
1732
4.72k
  }
1733
3.10k
  return nullptr;
1734
7.82k
}
1735
1736
13.9k
const ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const {
1737
13.9k
  if (const auto *OPT = getAs<ObjCObjectPointerType>()) {
1738
13.9k
    if (OPT->getInterfaceType())
1739
13.5k
      return OPT;
1740
13.9k
  }
1741
370
  return nullptr;
1742
13.9k
}
1743
1744
1.06M
const CXXRecordDecl *Type::getPointeeCXXRecordDecl() const {
1745
1.06M
  QualType PointeeType;
1746
1.06M
  if (const auto *PT = getAs<PointerType>())
1747
630k
    PointeeType = PT->getPointeeType();
1748
433k
  else if (const auto *RT = getAs<ReferenceType>())
1749
11.4k
    PointeeType = RT->getPointeeType();
1750
422k
  else
1751
422k
    return nullptr;
1752
1753
642k
  if (const auto *RT = PointeeType->getAs<RecordType>())
1754
560k
    return dyn_cast<CXXRecordDecl>(RT->getDecl());
1755
1756
81.2k
  return nullptr;
1757
642k
}
1758
1759
106M
CXXRecordDecl *Type::getAsCXXRecordDecl() const {
1760
106M
  return dyn_cast_or_null<CXXRecordDecl>(getAsTagDecl());
1761
106M
}
1762
1763
171M
RecordDecl *Type::getAsRecordDecl() const {
1764
171M
  return dyn_cast_or_null<RecordDecl>(getAsTagDecl());
1765
171M
}
1766
1767
282M
TagDecl *Type::getAsTagDecl() const {
1768
282M
  if (const auto *TT = getAs<TagType>())
1769
28.4M
    return TT->getDecl();
1770
254M
  if (const auto *Injected = getAs<InjectedClassNameType>())
1771
652k
    return Injected->getDecl();
1772
1773
253M
  return nullptr;
1774
254M
}
1775
1776
2.70M
bool Type::hasAttr(attr::Kind AK) const {
1777
2.70M
  const Type *Cur = this;
1778
2.70M
  while (const auto *AT = Cur->getAs<AttributedType>()) {
1779
13.0k
    if (AT->getAttrKind() == AK)
1780
12.3k
      return true;
1781
723
    Cur = AT->getEquivalentType().getTypePtr();
1782
723
  }
1783
2.69M
  return false;
1784
2.70M
}
1785
1786
namespace {
1787
1788
  class GetContainedDeducedTypeVisitor :
1789
    public TypeVisitor<GetContainedDeducedTypeVisitor, Type*> {
1790
    bool Syntactic;
1791
1792
  public:
1793
    GetContainedDeducedTypeVisitor(bool Syntactic = false)
1794
131M
        : Syntactic(Syntactic) {}
1795
1796
    using TypeVisitor<GetContainedDeducedTypeVisitor, Type*>::Visit;
1797
1798
9.04M
    Type *Visit(QualType T) {
1799
9.04M
      if (T.isNull())
1800
0
        return nullptr;
1801
9.04M
      return Visit(T.getTypePtr());
1802
9.04M
    }
1803
1804
    // The deduced type itself.
1805
290k
    Type *VisitDeducedType(const DeducedType *AT) {
1806
290k
      return const_cast<DeducedType*>(AT);
1807
290k
    }
1808
1809
    // Only these types can contain the desired 'auto' type.
1810
1.63M
    Type *VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
1811
1.63M
      return Visit(T->getReplacementType());
1812
1.63M
    }
1813
1814
1.95M
    Type *VisitElaboratedType(const ElaboratedType *T) {
1815
1.95M
      return Visit(T->getNamedType());
1816
1.95M
    }
1817
1818
738k
    Type *VisitPointerType(const PointerType *T) {
1819
738k
      return Visit(T->getPointeeType());
1820
738k
    }
1821
1822
3.00k
    Type *VisitBlockPointerType(const BlockPointerType *T) {
1823
3.00k
      return Visit(T->getPointeeType());
1824
3.00k
    }
1825
1826
568k
    Type *VisitReferenceType(const ReferenceType *T) {
1827
568k
      return Visit(T->getPointeeTypeAsWritten());
1828
568k
    }
1829
1830
6.36k
    Type *VisitMemberPointerType(const MemberPointerType *T) {
1831
6.36k
      return Visit(T->getPointeeType());
1832
6.36k
    }
1833
1834
177k
    Type *VisitArrayType(const ArrayType *T) {
1835
177k
      return Visit(T->getElementType());
1836
177k
    }
1837
1838
    Type *VisitDependentSizedExtVectorType(
1839
24
      const DependentSizedExtVectorType *T) {
1840
24
      return Visit(T->getElementType());
1841
24
    }
1842
1843
270k
    Type *VisitVectorType(const VectorType *T) {
1844
270k
      return Visit(T->getElementType());
1845
270k
    }
1846
1847
31
    Type *VisitDependentSizedMatrixType(const DependentSizedMatrixType *T) {
1848
31
      return Visit(T->getElementType());
1849
31
    }
1850
1851
17
    Type *VisitConstantMatrixType(const ConstantMatrixType *T) {
1852
17
      return Visit(T->getElementType());
1853
17
    }
1854
1855
664k
    Type *VisitFunctionProtoType(const FunctionProtoType *T) {
1856
664k
      if (Syntactic && 
T->hasTrailingReturn()98
)
1857
37
        return const_cast<FunctionProtoType*>(T);
1858
664k
      return VisitFunctionType(T);
1859
664k
    }
1860
1861
664k
    Type *VisitFunctionType(const FunctionType *T) {
1862
664k
      return Visit(T->getReturnType());
1863
664k
    }
1864
1865
30.9k
    Type *VisitParenType(const ParenType *T) {
1866
30.9k
      return Visit(T->getInnerType());
1867
30.9k
    }
1868
1869
2.42M
    Type *VisitAttributedType(const AttributedType *T) {
1870
2.42M
      return Visit(T->getModifiedType());
1871
2.42M
    }
1872
1873
565k
    Type *VisitMacroQualifiedType(const MacroQualifiedType *T) {
1874
565k
      return Visit(T->getUnderlyingType());
1875
565k
    }
1876
1877
1.60k
    Type *VisitAdjustedType(const AdjustedType *T) {
1878
1.60k
      return Visit(T->getOriginalType());
1879
1.60k
    }
1880
1881
437
    Type *VisitPackExpansionType(const PackExpansionType *T) {
1882
437
      return Visit(T->getPattern());
1883
437
    }
1884
  };
1885
1886
} // namespace
1887
1888
131M
DeducedType *Type::getContainedDeducedType() const {
1889
131M
  return cast_or_null<DeducedType>(
1890
131M
      GetContainedDeducedTypeVisitor().Visit(this));
1891
131M
}
1892
1893
25.1k
bool Type::hasAutoForTrailingReturnType() const {
1894
25.1k
  return isa_and_nonnull<FunctionType>(
1895
25.1k
      GetContainedDeducedTypeVisitor(true).Visit(this));
1896
25.1k
}
1897
1898
7.30M
bool Type::hasIntegerRepresentation() const {
1899
7.30M
  if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
1900
101k
    return VT->getElementType()->isIntegerType();
1901
7.20M
  if (CanonicalType->isVLSTBuiltinType()) {
1902
986
    const auto *VT = cast<BuiltinType>(CanonicalType);
1903
986
    return VT->getKind() == BuiltinType::SveBool ||
1904
986
           
(945
VT->getKind() >= BuiltinType::SveInt8945
&&
1905
945
            VT->getKind() <= BuiltinType::SveUint64);
1906
986
  }
1907
1908
7.20M
  return isIntegerType();
1909
7.20M
}
1910
1911
/// Determine whether this type is an integral type.
1912
///
1913
/// This routine determines whether the given type is an integral type per
1914
/// C++ [basic.fundamental]p7. Although the C standard does not define the
1915
/// term "integral type", it has a similar term "integer type", and in C++
1916
/// the two terms are equivalent. However, C's "integer type" includes
1917
/// enumeration types, while C++'s "integer type" does not. The \c ASTContext
1918
/// parameter is used to determine whether we should be following the C or
1919
/// C++ rules when determining whether this type is an integral/integer type.
1920
///
1921
/// For cases where C permits "an integer type" and C++ permits "an integral
1922
/// type", use this routine.
1923
///
1924
/// For cases where C permits "an integer type" and C++ permits "an integral
1925
/// or enumeration type", use \c isIntegralOrEnumerationType() instead.
1926
///
1927
/// \param Ctx The context in which this type occurs.
1928
///
1929
/// \returns true if the type is considered an integral type, false otherwise.
1930
16.5M
bool Type::isIntegralType(const ASTContext &Ctx) const {
1931
16.5M
  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1932
16.1M
    return BT->getKind() >= BuiltinType::Bool &&
1933
16.1M
           
BT->getKind() <= BuiltinType::Int12816.1M
;
1934
1935
  // Complete enum types are integral in C.
1936
441k
  if (!Ctx.getLangOpts().CPlusPlus)
1937
323k
    if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
1938
452
      return ET->getDecl()->isComplete();
1939
1940
440k
  return isBitIntType();
1941
441k
}
1942
1943
33.4M
bool Type::isIntegralOrUnscopedEnumerationType() const {
1944
33.4M
  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1945
20.6M
    return BT->getKind() >= BuiltinType::Bool &&
1946
20.6M
           
BT->getKind() <= BuiltinType::Int12820.3M
;
1947
1948
12.7M
  if (isBitIntType())
1949
494
    return true;
1950
1951
12.7M
  return isUnscopedEnumerationType();
1952
12.7M
}
1953
1954
20.4M
bool Type::isUnscopedEnumerationType() const {
1955
20.4M
  if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
1956
9.65M
    return !ET->getDecl()->isScoped();
1957
1958
10.8M
  return false;
1959
20.4M
}
1960
1961
379k
bool Type::isCharType() const {
1962
379k
  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1963
226k
    return BT->getKind() == BuiltinType::Char_U ||
1964
226k
           
BT->getKind() == BuiltinType::UChar226k
||
1965
226k
           
BT->getKind() == BuiltinType::Char_S218k
||
1966
226k
           
BT->getKind() == BuiltinType::SChar169k
;
1967
152k
  return false;
1968
379k
}
1969
1970
1.96k
bool Type::isWideCharType() const {
1971
1.96k
  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1972
1.95k
    return BT->getKind() == BuiltinType::WChar_S ||
1973
1.95k
           
BT->getKind() == BuiltinType::WChar_U1.90k
;
1974
14
  return false;
1975
1.96k
}
1976
1977
2.13k
bool Type::isChar8Type() const {
1978
2.13k
  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
1979
1.80k
    return BT->getKind() == BuiltinType::Char8;
1980
332
  return false;
1981
2.13k
}
1982
1983
1.59k
bool Type::isChar16Type() const {
1984
1.59k
  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1985
1.58k
    return BT->getKind() == BuiltinType::Char16;
1986
14
  return false;
1987
1.59k
}
1988
1989
1.57k
bool Type::isChar32Type() const {
1990
1.57k
  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1991
1.56k
    return BT->getKind() == BuiltinType::Char32;
1992
14
  return false;
1993
1.57k
}
1994
1995
/// Determine whether this type is any of the built-in character
1996
/// types.
1997
3.65M
bool Type::isAnyCharacterType() const {
1998
3.65M
  const auto *BT = dyn_cast<BuiltinType>(CanonicalType);
1999
3.65M
  if (!BT) 
return false115k
;
2000
3.54M
  switch (BT->getKind()) {
2001
3.53M
  default: return false;
2002
3
  case BuiltinType::Char_U:
2003
118
  case BuiltinType::UChar:
2004
118
  case BuiltinType::WChar_U:
2005
272
  case BuiltinType::Char8:
2006
686
  case BuiltinType::Char16:
2007
1.13k
  case BuiltinType::Char32:
2008
2.24k
  case BuiltinType::Char_S:
2009
2.25k
  case BuiltinType::SChar:
2010
2.71k
  case BuiltinType::WChar_S:
2011
2.71k
    return true;
2012
3.54M
  }
2013
3.54M
}
2014
2015
/// isSignedIntegerType - Return true if this is an integer type that is
2016
/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
2017
/// an enum decl which has a signed representation
2018
595k
bool Type::isSignedIntegerType() const {
2019
595k
  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2020
595k
    return BT->getKind() >= BuiltinType::Char_S &&
2021
595k
           
BT->getKind() <= BuiltinType::Int128225k
;
2022
595k
  }
2023
2024
648
  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
2025
    // Incomplete enum types are not treated as integer types.
2026
    // FIXME: In C++, enum types are never integer types.
2027
329
    if (ET->getDecl()->isComplete() && 
!ET->getDecl()->isScoped()322
)
2028
322
      return ET->getDecl()->getIntegerType()->isSignedIntegerType();
2029
329
  }
2030
2031
326
  if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2032
165
    return IT->isSigned();
2033
161
  if (const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2034
0
    return IT->isSigned();
2035
2036
161
  return false;
2037
161
}
2038
2039
28.3M
bool Type::isSignedIntegerOrEnumerationType() const {
2040
28.3M
  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2041
27.7M
    return BT->getKind() >= BuiltinType::Char_S &&
2042
27.7M
           
BT->getKind() <= BuiltinType::Int12818.6M
;
2043
27.7M
  }
2044
2045
633k
  if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2046
254k
    if (ET->getDecl()->isComplete())
2047
254k
      return ET->getDecl()->getIntegerType()->isSignedIntegerType();
2048
254k
  }
2049
2050
379k
  if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2051
653
    return IT->isSigned();
2052
378k
  if (const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2053
0
    return IT->isSigned();
2054
2055
378k
  return false;
2056
378k
}
2057
2058
6.62M
bool Type::hasSignedIntegerRepresentation() const {
2059
6.62M
  if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
2060
209k
    return VT->getElementType()->isSignedIntegerOrEnumerationType();
2061
6.41M
  else
2062
6.41M
    return isSignedIntegerOrEnumerationType();
2063
6.62M
}
2064
2065
/// isUnsignedIntegerType - Return true if this is an integer type that is
2066
/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
2067
/// decl which has an unsigned representation
2068
6.80M
bool Type::isUnsignedIntegerType() const {
2069
6.80M
  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2070
6.79M
    return BT->getKind() >= BuiltinType::Bool &&
2071
6.79M
           
BT->getKind() <= BuiltinType::UInt1286.79M
;
2072
6.79M
  }
2073
2074
6.31k
  if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2075
    // Incomplete enum types are not treated as integer types.
2076
    // FIXME: In C++, enum types are never integer types.
2077
27
    if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
2078
27
      return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
2079
27
  }
2080
2081
6.28k
  if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2082
108
    return IT->isUnsigned();
2083
6.17k
  if (const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2084
0
    return IT->isUnsigned();
2085
2086
6.17k
  return false;
2087
6.17k
}
2088
2089
17.9M
bool Type::isUnsignedIntegerOrEnumerationType() const {
2090
17.9M
  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2091
17.9M
    return BT->getKind() >= BuiltinType::Bool &&
2092
17.9M
    
BT->getKind() <= BuiltinType::UInt12817.9M
;
2093
17.9M
  }
2094
2095
36.7k
  if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2096
6.40k
    if (ET->getDecl()->isComplete())
2097
6.40k
      return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
2098
6.40k
  }
2099
2100
30.3k
  if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2101
235
    return IT->isUnsigned();
2102
30.1k
  if (const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2103
0
    return IT->isUnsigned();
2104
2105
30.1k
  return false;
2106
30.1k
}
2107
2108
917k
bool Type::hasUnsignedIntegerRepresentation() const {
2109
917k
  if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
2110
25.8k
    return VT->getElementType()->isUnsignedIntegerOrEnumerationType();
2111
892k
  if (const auto *VT = dyn_cast<MatrixType>(CanonicalType))
2112
17
    return VT->getElementType()->isUnsignedIntegerOrEnumerationType();
2113
892k
  if (CanonicalType->isVLSTBuiltinType()) {
2114
162
    const auto *VT = cast<BuiltinType>(CanonicalType);
2115
162
    return VT->getKind() >= BuiltinType::SveUint8 &&
2116
162
           
VT->getKind() <= BuiltinType::SveUint6496
;
2117
162
  }
2118
891k
  return isUnsignedIntegerOrEnumerationType();
2119
892k
}
2120
2121
13.5M
bool Type::isFloatingType() const {
2122
13.5M
  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2123
13.2M
    return BT->getKind() >= BuiltinType::Half &&
2124
13.2M
           
BT->getKind() <= BuiltinType::Ibm1285.73M
;
2125
381k
  if (const auto *CT = dyn_cast<ComplexType>(CanonicalType))
2126
2.30k
    return CT->getElementType()->isFloatingType();
2127
378k
  return false;
2128
381k
}
2129
2130
11.1M
bool Type::hasFloatingRepresentation() const {
2131
11.1M
  if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
2132
34.2k
    return VT->getElementType()->isFloatingType();
2133
11.1M
  else
2134
11.1M
    return isFloatingType();
2135
11.1M
}
2136
2137
13.0M
bool Type::isRealFloatingType() const {
2138
13.0M
  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2139
5.73M
    return BT->isFloatingPoint();
2140
7.32M
  return false;
2141
13.0M
}
2142
2143
255k
bool Type::isRealType() const {
2144
255k
  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2145
224k
    return BT->getKind() >= BuiltinType::Bool &&
2146
224k
           
BT->getKind() <= BuiltinType::Ibm128224k
;
2147
30.7k
  if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
2148
68
      return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped();
2149
30.6k
  return isBitIntType();
2150
30.7k
}
2151
2152
10.1M
bool Type::isArithmeticType() const {
2153
10.1M
  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2154
9.21M
    return BT->getKind() >= BuiltinType::Bool &&
2155
9.21M
           
BT->getKind() <= BuiltinType::Ibm1289.13M
&&
2156
9.21M
           
BT->getKind() != BuiltinType::BFloat169.13M
;
2157
958k
  if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
2158
    // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
2159
    // If a body isn't seen by the time we get here, return false.
2160
    //
2161
    // C++0x: Enumerations are not arithmetic types. For now, just return
2162
    // false for scoped enumerations since that will disable any
2163
    // unwanted implicit conversions.
2164
139k
    return !ET->getDecl()->isScoped() && 
ET->getDecl()->isComplete()132k
;
2165
819k
  return isa<ComplexType>(CanonicalType) || 
isBitIntType()815k
;
2166
958k
}
2167
2168
1.03M
Type::ScalarTypeKind Type::getScalarTypeKind() const {
2169
1.03M
  assert(isScalarType());
2170
2171
0
  const Type *T = CanonicalType.getTypePtr();
2172
1.03M
  if (const auto *BT = dyn_cast<BuiltinType>(T)) {
2173
785k
    if (BT->getKind() == BuiltinType::Bool) 
return STK_Bool198k
;
2174
586k
    if (BT->getKind() == BuiltinType::NullPtr) 
return STK_CPointer32
;
2175
586k
    if (BT->isInteger()) 
return STK_Integral549k
;
2176
36.8k
    if (BT->isFloatingPoint()) 
return STK_Floating36.2k
;
2177
589
    if (BT->isFixedPointType()) return STK_FixedPoint;
2178
0
    llvm_unreachable("unknown scalar builtin type");
2179
253k
  } else if (isa<PointerType>(T)) {
2180
239k
    return STK_CPointer;
2181
239k
  } else 
if (13.5k
isa<BlockPointerType>(T)13.5k
) {
2182
93
    return STK_BlockPointer;
2183
13.4k
  } else if (isa<ObjCObjectPointerType>(T)) {
2184
7.56k
    return STK_ObjCObjectPointer;
2185
7.56k
  } else 
if (5.90k
isa<MemberPointerType>(T)5.90k
) {
2186
111
    return STK_MemberPointer;
2187
5.79k
  } else if (isa<EnumType>(T)) {
2188
4.49k
    assert(cast<EnumType>(T)->getDecl()->isComplete());
2189
0
    return STK_Integral;
2190
4.49k
  } else 
if (const auto *1.30k
CT1.30k
= dyn_cast<ComplexType>(T)) {
2191
1.25k
    if (CT->getElementType()->isRealFloatingType())
2192
989
      return STK_FloatingComplex;
2193
261
    return STK_IntegralComplex;
2194
1.25k
  } else 
if (51
isBitIntType()51
) {
2195
51
    return STK_Integral;
2196
51
  }
2197
2198
0
  llvm_unreachable("unknown scalar type");
2199
0
}
2200
2201
/// Determines whether the type is a C++ aggregate type or C
2202
/// aggregate or union type.
2203
///
2204
/// An aggregate type is an array or a class type (struct, union, or
2205
/// class) that has no user-declared constructors, no private or
2206
/// protected non-static data members, no base classes, and no virtual
2207
/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type
2208
/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also
2209
/// includes union types.
2210
117k
bool Type::isAggregateType() const {
2211
117k
  if (const auto *Record = dyn_cast<RecordType>(CanonicalType)) {
2212
89.9k
    if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl()))
2213
78.0k
      return ClassDecl->isAggregate();
2214
2215
11.9k
    return true;
2216
89.9k
  }
2217
2218
27.5k
  return isa<ArrayType>(CanonicalType);
2219
117k
}
2220
2221
/// isConstantSizeType - Return true if this is not a variable sized type,
2222
/// according to the rules of C99 6.7.5p3.  It is not legal to call this on
2223
/// incomplete types or dependent types.
2224
5.65M
bool Type::isConstantSizeType() const {
2225
5.65M
  assert(!isIncompleteType() && "This doesn't make sense for incomplete types");
2226
0
  assert(!isDependentType() && "This doesn't make sense for dependent types");
2227
  // The VAT must have a size, as it is known to be complete.
2228
0
  return !isa<VariableArrayType>(CanonicalType);
2229
5.65M
}
2230
2231
/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1)
2232
/// - a type that can describe objects, but which lacks information needed to
2233
/// determine its size.
2234
100M
bool Type::isIncompleteType(NamedDecl **Def) const {
2235
100M
  if (Def)
2236
54.1M
    *Def = nullptr;
2237
2238
100M
  switch (CanonicalType->getTypeClass()) {
2239
24.4M
  default: return false;
2240
45.3M
  case Builtin:
2241
    // Void is the only incomplete builtin type.  Per C99 6.2.5p19, it can never
2242
    // be completed.
2243
45.3M
    return isVoidType();
2244
7.29M
  case Enum: {
2245
7.29M
    EnumDecl *EnumD = cast<EnumType>(CanonicalType)->getDecl();
2246
7.29M
    if (Def)
2247
7.03M
      *Def = EnumD;
2248
7.29M
    return !EnumD->isComplete();
2249
0
  }
2250
23.2M
  case Record: {
2251
    // A tagged type (struct/union/enum/class) is incomplete if the decl is a
2252
    // forward declaration, but not a full definition (C99 6.2.5p22).
2253
23.2M
    RecordDecl *Rec = cast<RecordType>(CanonicalType)->getDecl();
2254
23.2M
    if (Def)
2255
16.5M
      *Def = Rec;
2256
23.2M
    return !Rec->isCompleteDefinition();
2257
0
  }
2258
453k
  case ConstantArray:
2259
468k
  case VariableArray:
2260
    // An array is incomplete if its element type is incomplete
2261
    // (C++ [dcl.array]p1).
2262
    // We don't handle dependent-sized arrays (dependent types are never treated
2263
    // as incomplete).
2264
468k
    return cast<ArrayType>(CanonicalType)->getElementType()
2265
468k
             ->isIncompleteType(Def);
2266
2.66k
  case IncompleteArray:
2267
    // An array of unknown size is an incomplete type (C99 6.2.5p22).
2268
2.66k
    return true;
2269
15.5k
  case MemberPointer: {
2270
    // Member pointers in the MS ABI have special behavior in
2271
    // RequireCompleteType: they attach a MSInheritanceAttr to the CXXRecordDecl
2272
    // to indicate which inheritance model to use.
2273
15.5k
    auto *MPTy = cast<MemberPointerType>(CanonicalType);
2274
15.5k
    const Type *ClassTy = MPTy->getClass();
2275
    // Member pointers with dependent class types don't get special treatment.
2276
15.5k
    if (ClassTy->isDependentType())
2277
825
      return false;
2278
14.7k
    const CXXRecordDecl *RD = ClassTy->getAsCXXRecordDecl();
2279
14.7k
    ASTContext &Context = RD->getASTContext();
2280
    // Member pointers not in the MS ABI don't get special treatment.
2281
14.7k
    if (!Context.getTargetInfo().getCXXABI().isMicrosoft())
2282
10.9k
      return false;
2283
    // The inheritance attribute might only be present on the most recent
2284
    // CXXRecordDecl, use that one.
2285
3.78k
    RD = RD->getMostRecentNonInjectedDecl();
2286
    // Nothing interesting to do if the inheritance attribute is already set.
2287
3.78k
    if (RD->hasAttr<MSInheritanceAttr>())
2288
3.76k
      return false;
2289
17
    return true;
2290
3.78k
  }
2291
271
  case ObjCObject:
2292
271
    return cast<ObjCObjectType>(CanonicalType)->getBaseType()
2293
271
             ->isIncompleteType(Def);
2294
134k
  case ObjCInterface: {
2295
    // ObjC interfaces are incomplete if they are @class, not @interface.
2296
134k
    ObjCInterfaceDecl *Interface
2297
134k
      = cast<ObjCInterfaceType>(CanonicalType)->getDecl();
2298
134k
    if (Def)
2299
134k
      *Def = Interface;
2300
134k
    return !Interface->hasDefinition();
2301
3.78k
  }
2302
100M
  }
2303
100M
}
2304
2305
21.7M
bool Type::isSizelessBuiltinType() const {
2306
21.7M
  if (const BuiltinType *BT = getAs<BuiltinType>()) {
2307
6.34M
    switch (BT->getKind()) {
2308
      // SVE Types
2309
199k
#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2310
199k
#include 
"clang/Basic/AArch64SVEACLETypes.def"0
2311
325k
#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2312
199k
#include 
"clang/Basic/RISCVVTypes.def"4.92k
2313
4.93k
      return true;
2314
6.33M
    default:
2315
6.33M
      return false;
2316
6.34M
    }
2317
6.34M
  }
2318
15.3M
  return false;
2319
21.7M
}
2320
2321
1.80M
bool Type::isSizelessType() const { return isSizelessBuiltinType(); }
2322
2323
17.5M
bool Type::isVLSTBuiltinType() const {
2324
17.5M
  if (const BuiltinType *BT = getAs<BuiltinType>()) {
2325
16.5M
    switch (BT->getKind()) {
2326
1.67k
    case BuiltinType::SveInt8:
2327
3.00k
    case BuiltinType::SveInt16:
2328
4.59k
    case BuiltinType::SveInt32:
2329
6.07k
    case BuiltinType::SveInt64:
2330
7.32k
    case BuiltinType::SveUint8:
2331
8.54k
    case BuiltinType::SveUint16:
2332
9.75k
    case BuiltinType::SveUint32:
2333
10.9k
    case BuiltinType::SveUint64:
2334
12.0k
    case BuiltinType::SveFloat16:
2335
13.1k
    case BuiltinType::SveFloat32:
2336
14.5k
    case BuiltinType::SveFloat64:
2337
14.6k
    case BuiltinType::SveBFloat16:
2338
15.2k
    case BuiltinType::SveBool:
2339
15.2k
      return true;
2340
16.5M
    default:
2341
16.5M
      return false;
2342
16.5M
    }
2343
16.5M
  }
2344
1.03M
  return false;
2345
17.5M
}
2346
2347
3.05k
QualType Type::getSveEltType(const ASTContext &Ctx) const {
2348
3.05k
  assert(isVLSTBuiltinType() && "unsupported type!");
2349
2350
0
  const BuiltinType *BTy = getAs<BuiltinType>();
2351
3.05k
  if (BTy->getKind() == BuiltinType::SveBool)
2352
    // Represent predicates as i8 rather than i1 to avoid any layout issues.
2353
    // The type is bitcasted to a scalable predicate type when casting between
2354
    // scalable and fixed-length vectors.
2355
149
    return Ctx.UnsignedCharTy;
2356
2.90k
  else
2357
2.90k
    return Ctx.getBuiltinVectorTypeInfo(BTy).ElementType;
2358
3.05k
}
2359
2360
1.14M
bool QualType::isPODType(const ASTContext &Context) const {
2361
  // C++11 has a more relaxed definition of POD.
2362
1.14M
  if (Context.getLangOpts().CPlusPlus11)
2363
1.13M
    return isCXX11PODType(Context);
2364
2365
13.0k
  return isCXX98PODType(Context);
2366
1.14M
}
2367
2368
2.31M
bool QualType::isCXX98PODType(const ASTContext &Context) const {
2369
  // The compiler shouldn't query this for incomplete types, but the user might.
2370
  // We return false for that case. Except for incomplete arrays of PODs, which
2371
  // are PODs according to the standard.
2372
2.31M
  if (isNull())
2373
0
    return false;
2374
2375
2.31M
  if ((*this)->isIncompleteArrayType())
2376
90
    return Context.getBaseElementType(*this).isCXX98PODType(Context);
2377
2378
2.31M
  if ((*this)->isIncompleteType())
2379
1.46k
    return false;
2380
2381
2.31M
  if (hasNonTrivialObjCLifetime())
2382
28
    return false;
2383
2384
2.31M
  QualType CanonicalType = getTypePtr()->CanonicalType;
2385
2.31M
  switch (CanonicalType->getTypeClass()) {
2386
    // Everything not explicitly mentioned is not POD.
2387
261k
  default: return false;
2388
0
  case Type::VariableArray:
2389
507
  case Type::ConstantArray:
2390
    // IncompleteArray is handled above.
2391
507
    return Context.getBaseElementType(*this).isCXX98PODType(Context);
2392
2393
15.2k
  case Type::ObjCObjectPointer:
2394
15.2k
  case Type::BlockPointer:
2395
1.23M
  case Type::Builtin:
2396
1.23M
  case Type::Complex:
2397
1.70M
  case Type::Pointer:
2398
1.70M
  case Type::MemberPointer:
2399
1.71M
  case Type::Vector:
2400
1.71M
  case Type::ExtVector:
2401
1.71M
  case Type::BitInt:
2402
1.71M
    return true;
2403
2404
2.84k
  case Type::Enum:
2405
2.84k
    return true;
2406
2407
337k
  case Type::Record:
2408
337k
    if (const auto *ClassDecl =
2409
337k
            dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl()))
2410
335k
      return ClassDecl->isPOD();
2411
2412
    // C struct/union is POD.
2413
2.72k
    return true;
2414
2.31M
  }
2415
2.31M
}
2416
2417
2.08k
bool QualType::isTrivialType(const ASTContext &Context) const {
2418
  // The compiler shouldn't query this for incomplete types, but the user might.
2419
  // We return false for that case. Except for incomplete arrays of PODs, which
2420
  // are PODs according to the standard.
2421
2.08k
  if (isNull())
2422
0
    return false;
2423
2424
2.08k
  if ((*this)->isArrayType())
2425
20
    return Context.getBaseElementType(*this).isTrivialType(Context);
2426
2427
2.06k
  if ((*this)->isSizelessBuiltinType())
2428
4
    return true;
2429
2430
  // Return false for incomplete types after skipping any incomplete array
2431
  // types which are expressly allowed by the standard and thus our API.
2432
2.05k
  if ((*this)->isIncompleteType())
2433
15
    return false;
2434
2435
2.04k
  if (hasNonTrivialObjCLifetime())
2436
4
    return false;
2437
2438
2.03k
  QualType CanonicalType = getTypePtr()->CanonicalType;
2439
2.03k
  if (CanonicalType->isDependentType())
2440
0
    return false;
2441
2442
  // C++0x [basic.types]p9:
2443
  //   Scalar types, trivial class types, arrays of such types, and
2444
  //   cv-qualified versions of these types are collectively called trivial
2445
  //   types.
2446
2447
  // As an extension, Clang treats vector types as Scalar types.
2448
2.03k
  if (CanonicalType->isScalarType() || 
CanonicalType->isVectorType()803
)
2449
1.25k
    return true;
2450
785
  if (const auto *RT = CanonicalType->getAs<RecordType>()) {
2451
748
    if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
2452
      // C++11 [class]p6:
2453
      //   A trivial class is a class that has a default constructor,
2454
      //   has no non-trivial default constructors, and is trivially
2455
      //   copyable.
2456
748
      return ClassDecl->hasDefaultConstructor() &&
2457
748
             
!ClassDecl->hasNonTrivialDefaultConstructor()404
&&
2458
748
             
ClassDecl->isTriviallyCopyable()325
;
2459
748
    }
2460
2461
0
    return true;
2462
748
  }
2463
2464
  // No other types can match.
2465
37
  return false;
2466
785
}
2467
2468
370k
bool QualType::isTriviallyCopyableType(const ASTContext &Context) const {
2469
370k
  if ((*this)->isArrayType())
2470
42.9k
    return Context.getBaseElementType(*this).isTriviallyCopyableType(Context);
2471
2472
327k
  if (hasNonTrivialObjCLifetime())
2473
39
    return false;
2474
2475
  // C++11 [basic.types]p9 - See Core 2094
2476
  //   Scalar types, trivially copyable class types, arrays of such types, and
2477
  //   cv-qualified versions of these types are collectively
2478
  //   called trivially copyable types.
2479
2480
327k
  QualType CanonicalType = getCanonicalType();
2481
327k
  if (CanonicalType->isDependentType())
2482
26.4k
    return false;
2483
2484
300k
  if (CanonicalType->isSizelessBuiltinType())
2485
7
    return true;
2486
2487
  // Return false for incomplete types after skipping any incomplete array types
2488
  // which are expressly allowed by the standard and thus our API.
2489
300k
  if (CanonicalType->isIncompleteType())
2490
30
    return false;
2491
2492
  // As an extension, Clang treats vector types as Scalar types.
2493
300k
  if (CanonicalType->isScalarType() || 
CanonicalType->isVectorType()40.6k
)
2494
269k
    return true;
2495
2496
31.4k
  if (const auto *RT = CanonicalType->getAs<RecordType>()) {
2497
31.3k
    if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
2498
31.0k
      if (!ClassDecl->isTriviallyCopyable()) 
return false26.8k
;
2499
31.0k
    }
2500
2501
4.53k
    return true;
2502
31.3k
  }
2503
2504
  // No other types can match.
2505
104
  return false;
2506
31.4k
}
2507
2508
101
bool QualType::isTriviallyRelocatableType(const ASTContext &Context) const {
2509
101
  QualType BaseElementType = Context.getBaseElementType(*this);
2510
2511
101
  if (BaseElementType->isIncompleteType()) {
2512
3
    return false;
2513
98
  } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
2514
78
    return RD->canPassInRegisters();
2515
78
  } else {
2516
20
    switch (isNonTrivialToPrimitiveDestructiveMove()) {
2517
17
    case PCK_Trivial:
2518
17
      return !isDestructedType();
2519
1
    case PCK_ARCStrong:
2520
1
      return true;
2521
2
    default:
2522
2
      return false;
2523
20
    }
2524
20
  }
2525
101
}
2526
2527
3.15M
bool QualType::isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const {
2528
3.15M
  return !Context.getLangOpts().ObjCAutoRefCount &&
2529
3.15M
         
Context.getLangOpts().ObjCWeak3.15M
&&
2530
3.15M
         
getObjCLifetime() != Qualifiers::OCL_Weak125
;
2531
3.15M
}
2532
2533
151k
bool QualType::hasNonTrivialToPrimitiveDefaultInitializeCUnion(const RecordDecl *RD) {
2534
151k
  return RD->hasNonTrivialToPrimitiveDefaultInitializeCUnion();
2535
151k
}
2536
2537
709k
bool QualType::hasNonTrivialToPrimitiveDestructCUnion(const RecordDecl *RD) {
2538
709k
  return RD->hasNonTrivialToPrimitiveDestructCUnion();
2539
709k
}
2540
2541
632k
bool QualType::hasNonTrivialToPrimitiveCopyCUnion(const RecordDecl *RD) {
2542
632k
  return RD->hasNonTrivialToPrimitiveCopyCUnion();
2543
632k
}
2544
2545
QualType::PrimitiveDefaultInitializeKind
2546
1.89M
QualType::isNonTrivialToPrimitiveDefaultInitialize() const {
2547
1.89M
  if (const auto *RT =
2548
1.89M
          getTypePtr()->getBaseElementTypeUnsafe()->getAs<RecordType>())
2549
539k
    if (RT->getDecl()->isNonTrivialToPrimitiveDefaultInitialize())
2550
123
      return PDIK_Struct;
2551
2552
1.89M
  switch (getQualifiers().getObjCLifetime()) {
2553
161
  case Qualifiers::OCL_Strong:
2554
161
    return PDIK_ARCStrong;
2555
45
  case Qualifiers::OCL_Weak:
2556
45
    return PDIK_ARCWeak;
2557
1.89M
  default:
2558
1.89M
    return PDIK_Trivial;
2559
1.89M
  }
2560
1.89M
}
2561
2562
1.86M
QualType::PrimitiveCopyKind QualType::isNonTrivialToPrimitiveCopy() const {
2563
1.86M
  if (const auto *RT =
2564
1.86M
          getTypePtr()->getBaseElementTypeUnsafe()->getAs<RecordType>())
2565
541k
    if (RT->getDecl()->isNonTrivialToPrimitiveCopy())
2566
219
      return PCK_Struct;
2567
2568
1.86M
  Qualifiers Qs = getQualifiers();
2569
1.86M
  switch (Qs.getObjCLifetime()) {
2570
574
  case Qualifiers::OCL_Strong:
2571
574
    return PCK_ARCStrong;
2572
258
  case Qualifiers::OCL_Weak:
2573
258
    return PCK_ARCWeak;
2574
1.86M
  default:
2575
1.86M
    return Qs.hasVolatile() ? 
PCK_VolatileTrivial2.55k
:
PCK_Trivial1.85M
;
2576
1.86M
  }
2577
1.86M
}
2578
2579
QualType::PrimitiveCopyKind
2580
1.09k
QualType::isNonTrivialToPrimitiveDestructiveMove() const {
2581
1.09k
  return isNonTrivialToPrimitiveCopy();
2582
1.09k
}
2583
2584
16.5M
bool Type::isLiteralType(const ASTContext &Ctx) const {
2585
16.5M
  if (isDependentType())
2586
201k
    return false;
2587
2588
  // C++1y [basic.types]p10:
2589
  //   A type is a literal type if it is:
2590
  //   -- cv void; or
2591
16.3M
  if (Ctx.getLangOpts().CPlusPlus14 && 
isVoidType()3.16M
)
2592
4.50k
    return true;
2593
2594
  // C++11 [basic.types]p10:
2595
  //   A type is a literal type if it is:
2596
  //   [...]
2597
  //   -- an array of literal type other than an array of runtime bound; or
2598
16.3M
  if (isVariableArrayType())
2599
3
    return false;
2600
16.3M
  const Type *BaseTy = getBaseElementTypeUnsafe();
2601
16.3M
  assert(BaseTy && "NULL element type");
2602
2603
  // Return false for incomplete types after skipping any incomplete array
2604
  // types; those are expressly allowed by the standard and thus our API.
2605
16.3M
  if (BaseTy->isIncompleteType())
2606
9.31k
    return false;
2607
2608
  // C++11 [basic.types]p10:
2609
  //   A type is a literal type if it is:
2610
  //    -- a scalar type; or
2611
  // As an extension, Clang treats vector types and complex types as
2612
  // literal types.
2613
16.3M
  if (BaseTy->isScalarType() || 
BaseTy->isVectorType()1.92M
||
2614
16.3M
      
BaseTy->isAnyComplexType()1.26M
)
2615
15.0M
    return true;
2616
  //    -- a reference type; or
2617
1.26M
  if (BaseTy->isReferenceType())
2618
370k
    return true;
2619
  //    -- a class type that has all of the following properties:
2620
897k
  if (const auto *RT = BaseTy->getAs<RecordType>()) {
2621
    //    -- a trivial destructor,
2622
    //    -- every constructor call and full-expression in the
2623
    //       brace-or-equal-initializers for non-static data members (if any)
2624
    //       is a constant expression,
2625
    //    -- it is an aggregate type or has at least one constexpr
2626
    //       constructor or constructor template that is not a copy or move
2627
    //       constructor, and
2628
    //    -- all non-static data members and base classes of literal types
2629
    //
2630
    // We resolve DR1361 by ignoring the second bullet.
2631
840k
    if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl()))
2632
840k
      return ClassDecl->isLiteral();
2633
2634
147
    return true;
2635
840k
  }
2636
2637
  // We treat _Atomic T as a literal type if T is a literal type.
2638
57.1k
  if (const auto *AT = BaseTy->getAs<AtomicType>())
2639
1.39k
    return AT->getValueType()->isLiteralType(Ctx);
2640
2641
  // If this type hasn't been deduced yet, then conservatively assume that
2642
  // it'll work out to be a literal type.
2643
55.7k
  if (isa<AutoType>(BaseTy->getCanonicalTypeInternal()))
2644
0
    return true;
2645
2646
55.7k
  return false;
2647
55.7k
}
2648
2649
1.75M
bool Type::isStructuralType() const {
2650
  // C++20 [temp.param]p6:
2651
  //   A structural type is one of the following:
2652
  //   -- a scalar type; or
2653
  //   -- a vector type [Clang extension]; or
2654
1.75M
  if (isScalarType() || 
isVectorType()262k
)
2655
1.49M
    return true;
2656
  //   -- an lvalue reference type; or
2657
258k
  if (isLValueReferenceType())
2658
189k
    return true;
2659
  //  -- a literal class type [...under some conditions]
2660
69.2k
  if (const CXXRecordDecl *RD = getAsCXXRecordDecl())
2661
338
    return RD->isStructural();
2662
68.9k
  return false;
2663
69.2k
}
2664
2665
1.16k
bool Type::isStandardLayoutType() const {
2666
1.16k
  if (isDependentType())
2667
0
    return false;
2668
2669
  // C++0x [basic.types]p9:
2670
  //   Scalar types, standard-layout class types, arrays of such types, and
2671
  //   cv-qualified versions of these types are collectively called
2672
  //   standard-layout types.
2673
1.16k
  const Type *BaseTy = getBaseElementTypeUnsafe();
2674
1.16k
  assert(BaseTy && "NULL element type");
2675
2676
  // Return false for incomplete types after skipping any incomplete array
2677
  // types which are expressly allowed by the standard and thus our API.
2678
1.16k
  if (BaseTy->isIncompleteType())
2679
6
    return false;
2680
2681
  // As an extension, Clang treats vector types as Scalar types.
2682
1.15k
  if (BaseTy->isScalarType() || 
BaseTy->isVectorType()405
)
return true775
;
2683
381
  if (const auto *RT = BaseTy->getAs<RecordType>()) {
2684
377
    if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl()))
2685
265
      if (!ClassDecl->isStandardLayout())
2686
105
        return false;
2687
2688
    // Default to 'true' for non-C++ class types.
2689
    // FIXME: This is a bit dubious, but plain C structs should trivially meet
2690
    // all the requirements of standard layout classes.
2691
272
    return true;
2692
377
  }
2693
2694
  // No other types can match.
2695
4
  return false;
2696
381
}
2697
2698
// This is effectively the intersection of isTrivialType and
2699
// isStandardLayoutType. We implement it directly to avoid redundant
2700
// conversions from a type to a CXXRecordDecl.
2701
1.13M
bool QualType::isCXX11PODType(const ASTContext &Context) const {
2702
1.13M
  const Type *ty = getTypePtr();
2703
1.13M
  if (ty->isDependentType())
2704
22.5k
    return false;
2705
2706
1.11M
  if (hasNonTrivialObjCLifetime())
2707
47
    return false;
2708
2709
  // C++11 [basic.types]p9:
2710
  //   Scalar types, POD classes, arrays of such types, and cv-qualified
2711
  //   versions of these types are collectively called trivial types.
2712
1.11M
  const Type *BaseTy = ty->getBaseElementTypeUnsafe();
2713
1.11M
  assert(BaseTy && "NULL element type");
2714
2715
1.11M
  if (BaseTy->isSizelessBuiltinType())
2716
39
    return true;
2717
2718
  // Return false for incomplete types after skipping any incomplete array
2719
  // types which are expressly allowed by the standard and thus our API.
2720
1.11M
  if (BaseTy->isIncompleteType())
2721
73.8k
    return false;
2722
2723
  // As an extension, Clang treats vector types as Scalar types.
2724
1.03M
  if (BaseTy->isScalarType() || 
BaseTy->isVectorType()99.2k
)
return true939k
;
2725
98.7k
  if (const auto *RT = BaseTy->getAs<RecordType>()) {
2726
76.9k
    if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
2727
      // C++11 [class]p10:
2728
      //   A POD struct is a non-union class that is both a trivial class [...]
2729
76.9k
      if (!ClassDecl->isTrivial()) 
return false47.3k
;
2730
2731
      // C++11 [class]p10:
2732
      //   A POD struct is a non-union class that is both a trivial class and
2733
      //   a standard-layout class [...]
2734
29.6k
      if (!ClassDecl->isStandardLayout()) 
return false329
;
2735
2736
      // C++11 [class]p10:
2737
      //   A POD struct is a non-union class that is both a trivial class and
2738
      //   a standard-layout class, and has no non-static data members of type
2739
      //   non-POD struct, non-POD union (or array of such types). [...]
2740
      //
2741
      // We don't directly query the recursive aspect as the requirements for
2742
      // both standard-layout classes and trivial classes apply recursively
2743
      // already.
2744
29.6k
    }
2745
2746
29.2k
    return true;
2747
76.9k
  }
2748
2749
  // No other types can match.
2750
21.8k
  return false;
2751
98.7k
}
2752
2753
1.59k
bool Type::isNothrowT() const {
2754
1.59k
  if (const auto *RD = getAsCXXRecordDecl()) {
2755
1.56k
    IdentifierInfo *II = RD->getIdentifier();
2756
1.56k
    if (II && II->isStr("nothrow_t") && 
RD->isInStdNamespace()1.49k
)
2757
1.49k
      return true;
2758
1.56k
  }
2759
98
  return false;
2760
1.59k
}
2761
2762
18.6k
bool Type::isAlignValT() const {
2763
18.6k
  if (const auto *ET = getAs<EnumType>()) {
2764
10.5k
    IdentifierInfo *II = ET->getDecl()->getIdentifier();
2765
10.5k
    if (II && II->isStr("align_val_t") && ET->getDecl()->isInStdNamespace())
2766
10.5k
      return true;
2767
10.5k
  }
2768
8.07k
  return false;
2769
18.6k
}
2770
2771
5.10k
bool Type::isStdByteType() const {
2772
5.10k
  if (const auto *ET = getAs<EnumType>()) {
2773
37
    IdentifierInfo *II = ET->getDecl()->getIdentifier();
2774
37
    if (II && 
II->isStr("byte")35
&&
ET->getDecl()->isInStdNamespace()13
)
2775
10
      return true;
2776
37
  }
2777
5.09k
  return false;
2778
5.10k
}
2779
2780
22.4M
bool Type::isPromotableIntegerType() const {
2781
22.4M
  if (const auto *BT = getAs<BuiltinType>())
2782
13.9M
    switch (BT->getKind()) {
2783
57.3k
    case BuiltinType::Bool:
2784
213k
    case BuiltinType::Char_S:
2785
214k
    case BuiltinType::Char_U:
2786
225k
    case BuiltinType::SChar:
2787
354k
    case BuiltinType::UChar:
2788
384k
    case BuiltinType::Short:
2789
436k
    case BuiltinType::UShort:
2790
440k
    case BuiltinType::WChar_S:
2791
440k
    case BuiltinType::WChar_U:
2792
440k
    case BuiltinType::Char8:
2793
444k
    case BuiltinType::Char16:
2794
447k
    case BuiltinType::Char32:
2795
447k
      return true;
2796
13.4M
    default:
2797
13.4M
      return false;
2798
13.9M
    }
2799
2800
  // Enumerated types are promotable to their compatible integer types
2801
  // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2).
2802
8.47M
  if (const auto *ET = getAs<EnumType>()){
2803
8.21M
    if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull()
2804
8.21M
        || 
ET->getDecl()->isScoped()8.21M
)
2805
132k
      return false;
2806
2807
8.07M
    return true;
2808
8.21M
  }
2809
2810
259k
  return false;
2811
8.47M
}
2812
2813
5.75k
bool Type::isSpecifierType() const {
2814
  // Note that this intentionally does not use the canonical type.
2815
5.75k
  switch (getTypeClass()) {
2816
2.09k
  case Builtin:
2817
2.10k
  case Record:
2818
2.10k
  case Enum:
2819
2.10k
  case Typedef:
2820
2.10k
  case Complex:
2821
2.10k
  case TypeOfExpr:
2822
2.10k
  case TypeOf:
2823
3.33k
  case TemplateTypeParm:
2824
5.14k
  case SubstTemplateTypeParm:
2825
5.15k
  case TemplateSpecialization:
2826
5.33k
  case Elaborated:
2827
5.33k
  case DependentName:
2828
5.33k
  case DependentTemplateSpecialization:
2829
5.33k
  case ObjCInterface:
2830
5.33k
  case ObjCObject:
2831
5.33k
    return true;
2832
421
  default:
2833
421
    return false;
2834
5.75k
  }
2835
5.75k
}
2836
2837
ElaboratedTypeKeyword
2838
2.88M
TypeWithKeyword::getKeywordForTypeSpec(unsigned TypeSpec) {
2839
2.88M
  switch (TypeSpec) {
2840
0
  default: return ETK_None;
2841
173k
  case TST_typename: return ETK_Typename;
2842
15.3k
  case TST_class: return ETK_Class;
2843
1.81M
  case TST_struct: return ETK_Struct;
2844
0
  case TST_interface: return ETK_Interface;
2845
60.8k
  case TST_union: return ETK_Union;
2846
828k
  case TST_enum: return ETK_Enum;
2847
2.88M
  }
2848
2.88M
}
2849
2850
TagTypeKind
2851
2.96M
TypeWithKeyword::getTagTypeKindForTypeSpec(unsigned TypeSpec) {
2852
2.96M
  switch(TypeSpec) {
2853
209k
  case TST_class: return TTK_Class;
2854
1.82M
  case TST_struct: return TTK_Struct;
2855
34
  case TST_interface: return TTK_Interface;
2856
47.1k
  case TST_union: return TTK_Union;
2857
879k
  case TST_enum: return TTK_Enum;
2858
2.96M
  }
2859
2860
0
  llvm_unreachable("Type specifier is not a tag type kind.");
2861
0
}
2862
2863
ElaboratedTypeKeyword
2864
174k
TypeWithKeyword::getKeywordForTagTypeKind(TagTypeKind Kind) {
2865
174k
  switch (Kind) {
2866
37.2k
  case TTK_Class: return ETK_Class;
2867
130k
  case TTK_Struct: return ETK_Struct;
2868
1
  case TTK_Interface: return ETK_Interface;
2869
5.34k
  case TTK_Union: return ETK_Union;
2870
1.04k
  case TTK_Enum: return ETK_Enum;
2871
174k
  }
2872
0
  llvm_unreachable("Unknown tag type kind.");
2873
0
}
2874
2875
TagTypeKind
2876
1.49k
TypeWithKeyword::getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword) {
2877
1.49k
  switch (Keyword) {
2878
1.22k
  case ETK_Class: return TTK_Class;
2879
246
  case ETK_Struct: return TTK_Struct;
2880
0
  case ETK_Interface: return TTK_Interface;
2881
6
  case ETK_Union: return TTK_Union;
2882
18
  case ETK_Enum: return TTK_Enum;
2883
0
  case ETK_None: // Fall through.
2884
0
  case ETK_Typename:
2885
0
    llvm_unreachable("Elaborated type keyword is not a tag type kind.");
2886
1.49k
  }
2887
0
  llvm_unreachable("Unknown elaborated type keyword.");
2888
0
}
2889
2890
bool
2891
12.4k
TypeWithKeyword::KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword) {
2892
12.4k
  switch (Keyword) {
2893
0
  case ETK_None:
2894
783
  case ETK_Typename:
2895
783
    return false;
2896
10.2k
  case ETK_Class:
2897
11.5k
  case ETK_Struct:
2898
11.5k
  case ETK_Interface:
2899
11.5k
  case ETK_Union:
2900
11.6k
  case ETK_Enum:
2901
11.6k
    return true;
2902
12.4k
  }
2903
0
  llvm_unreachable("Unknown elaborated type keyword.");
2904
0
}
2905
2906
174k
StringRef TypeWithKeyword::getKeywordName(ElaboratedTypeKeyword Keyword) {
2907
174k
  switch (Keyword) {
2908
1.27k
  case ETK_None: return {};
2909
650
  case ETK_Typename: return "typename";
2910
33.8k
  case ETK_Class:  return "class";
2911
131k
  case ETK_Struct: return "struct";
2912
1
  case ETK_Interface: return "__interface";
2913
5.45k
  case ETK_Union:  return "union";
2914
1.72k
  case ETK_Enum:   return "enum";
2915
174k
  }
2916
2917
0
  llvm_unreachable("Unknown elaborated type keyword.");
2918
0
}
2919
2920
DependentTemplateSpecializationType::DependentTemplateSpecializationType(
2921
    ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
2922
    const IdentifierInfo *Name, ArrayRef<TemplateArgument> Args, QualType Canon)
2923
    : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon,
2924
                      TypeDependence::DependentInstantiation |
2925
                          (NNS ? toTypeDependence(NNS->getDependence())
2926
                               : TypeDependence::None)),
2927
65.6k
      NNS(NNS), Name(Name) {
2928
65.6k
  DependentTemplateSpecializationTypeBits.NumArgs = Args.size();
2929
65.6k
  assert((!NNS || NNS->isDependent()) &&
2930
65.6k
         "DependentTemplateSpecializatonType requires dependent qualifier");
2931
0
  TemplateArgument *ArgBuffer = getArgBuffer();
2932
96.9k
  for (const TemplateArgument &Arg : Args) {
2933
96.9k
    addDependence(toTypeDependence(Arg.getDependence() &
2934
96.9k
                                   TemplateArgumentDependence::UnexpandedPack));
2935
2936
96.9k
    new (ArgBuffer++) TemplateArgument(Arg);
2937
96.9k
  }
2938
65.6k
}
2939
2940
void
2941
DependentTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
2942
                                             const ASTContext &Context,
2943
                                             ElaboratedTypeKeyword Keyword,
2944
                                             NestedNameSpecifier *Qualifier,
2945
                                             const IdentifierInfo *Name,
2946
185k
                                             ArrayRef<TemplateArgument> Args) {
2947
185k
  ID.AddInteger(Keyword);
2948
185k
  ID.AddPointer(Qualifier);
2949
185k
  ID.AddPointer(Name);
2950
185k
  for (const TemplateArgument &Arg : Args)
2951
259k
    Arg.Profile(ID, Context);
2952
185k
}
2953
2954
12.4k
bool Type::isElaboratedTypeSpecifier() const {
2955
12.4k
  ElaboratedTypeKeyword Keyword;
2956
12.4k
  if (const auto *Elab = dyn_cast<ElaboratedType>(this))
2957
11.6k
    Keyword = Elab->getKeyword();
2958
871
  else if (const auto *DepName = dyn_cast<DependentNameType>(this))
2959
785
    Keyword = DepName->getKeyword();
2960
86
  else if (const auto *DepTST =
2961
86
               dyn_cast<DependentTemplateSpecializationType>(this))
2962
0
    Keyword = DepTST->getKeyword();
2963
86
  else
2964
86
    return false;
2965
2966
12.4k
  return TypeWithKeyword::KeywordIsTagTypeKind(Keyword);
2967
12.4k
}
2968
2969
5.86k
const char *Type::getTypeClassName() const {
2970
5.86k
  switch (TypeBits.TC) {
2971
0
#define ABSTRACT_TYPE(Derived, Base)
2972
5.86k
#define TYPE(Derived, Base) case Derived: return #Derived;
2973
5.86k
#include 
"clang/AST/TypeNodes.inc"0
2974
5.86k
  }
2975
2976
0
  llvm_unreachable("Invalid type class.");
2977
0
}
2978
2979
1.22M
StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
2980
1.22M
  switch (getKind()) {
2981
145k
  case Void:
2982
145k
    return "void";
2983
65.9k
  case Bool:
2984
65.9k
    return Policy.Bool ? 
"bool"64.7k
:
"_Bool"1.24k
;
2985
328k
  case Char_S:
2986
328k
    return "char";
2987
241
  case Char_U:
2988
241
    return "char";
2989
3.98k
  case SChar:
2990
3.98k
    return "signed char";
2991
8.54k
  case Short:
2992
8.54k
    return "short";
2993
372k
  case Int:
2994
372k
    return "int";
2995
19.7k
  case Long:
2996
19.7k
    return "long";
2997
27.0k
  case LongLong:
2998
27.0k
    return "long long";
2999
2.46k
  case Int128:
3000
2.46k
    return "__int128";
3001
23.8k
  case UChar:
3002
23.8k
    return "unsigned char";
3003
5.87k
  case UShort:
3004
5.87k
    return "unsigned short";
3005
31.0k
  case UInt:
3006
31.0k
    return "unsigned int";
3007
29.8k
  case ULong:
3008
29.8k
    return "unsigned long";
3009
5.96k
  case ULongLong:
3010
5.96k
    return "unsigned long long";
3011
1.10k
  case UInt128:
3012
1.10k
    return "unsigned __int128";
3013
682
  case Half:
3014
682
    return Policy.Half ? 
"half"182
:
"__fp16"500
;
3015
306
  case BFloat16:
3016
306
    return "__bf16";
3017
30.9k
  case Float:
3018
30.9k
    return "float";
3019
36.9k
  case Double:
3020
36.9k
    return "double";
3021
5.82k
  case LongDouble:
3022
5.82k
    return "long double";
3023
75
  case ShortAccum:
3024
75
    return "short _Accum";
3025
139
  case Accum:
3026
139
    return "_Accum";
3027
45
  case LongAccum:
3028
45
    return "long _Accum";
3029
28
  case UShortAccum:
3030
28
    return "unsigned short _Accum";
3031
22
  case UAccum:
3032
22
    return "unsigned _Accum";
3033
16
  case ULongAccum:
3034
16
    return "unsigned long _Accum";
3035
35
  case BuiltinType::ShortFract:
3036
35
    return "short _Fract";
3037
39
  case BuiltinType::Fract:
3038
39
    return "_Fract";
3039
33
  case BuiltinType::LongFract:
3040
33
    return "long _Fract";
3041
20
  case BuiltinType::UShortFract:
3042
20
    return "unsigned short _Fract";
3043
22
  case BuiltinType::UFract:
3044
22
    return "unsigned _Fract";
3045
20
  case BuiltinType::ULongFract:
3046
20
    return "unsigned long _Fract";
3047
17
  case BuiltinType::SatShortAccum:
3048
17
    return "_Sat short _Accum";
3049
17
  case BuiltinType::SatAccum:
3050
17
    return "_Sat _Accum";
3051
17
  case BuiltinType::SatLongAccum:
3052
17
    return "_Sat long _Accum";
3053
8
  case BuiltinType::SatUShortAccum:
3054
8
    return "_Sat unsigned short _Accum";
3055
8
  case BuiltinType::SatUAccum:
3056
8
    return "_Sat unsigned _Accum";
3057
8
  case BuiltinType::SatULongAccum:
3058
8
    return "_Sat unsigned long _Accum";
3059
17
  case BuiltinType::SatShortFract:
3060
17
    return "_Sat short _Fract";
3061
17
  case BuiltinType::SatFract:
3062
17
    return "_Sat _Fract";
3063
17
  case BuiltinType::SatLongFract:
3064
17
    return "_Sat long _Fract";
3065
8
  case BuiltinType::SatUShortFract:
3066
8
    return "_Sat unsigned short _Fract";
3067
8
  case BuiltinType::SatUFract:
3068
8
    return "_Sat unsigned _Fract";
3069
8
  case BuiltinType::SatULongFract:
3070
8
    return "_Sat unsigned long _Fract";
3071
923
  case Float16:
3072
923
    return "_Float16";
3073
209
  case Float128:
3074
209
    return "__float128";
3075
114
  case Ibm128:
3076
114
    return "__ibm128";
3077
19.9k
  case WChar_S:
3078
19.9k
  case WChar_U:
3079
19.9k
    return Policy.MSWChar ? 
"__wchar_t"8
:
"wchar_t"19.9k
;
3080
334
  case Char8:
3081
334
    return "char8_t";
3082
9.42k
  case Char16:
3083
9.42k
    return "char16_t";
3084
9.43k
  case Char32:
3085
9.43k
    return "char32_t";
3086
4.06k
  case NullPtr:
3087
4.06k
    return "std::nullptr_t";
3088
295
  case Overload:
3089
295
    return "<overloaded function type>";
3090
441
  case BoundMember:
3091
441
    return "<bound member function type>";
3092
10
  case PseudoObject:
3093
10
    return "<pseudo-object type>";
3094
479
  case Dependent:
3095
479
    return "<dependent type>";
3096
28
  case UnknownAny:
3097
28
    return "<unknown type>";
3098
0
  case ARCUnbridgedCast:
3099
0
    return "<ARC unbridged cast type>";
3100
71
  case BuiltinFn:
3101
71
    return "<builtin fn type>";
3102
6.22k
  case ObjCId:
3103
6.22k
    return "id";
3104
1.17k
  case ObjCClass:
3105
1.17k
    return "Class";
3106
643
  case ObjCSel:
3107
643
    return "SEL";
3108
0
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3109
780
  case Id: \
3110
780
    return "__" #Access " " #ImgType "_t";
3111
643
#include "clang/Basic/OpenCLImageTypes.def"
3112
221
  case OCLSampler:
3113
221
    return "sampler_t";
3114
39
  case OCLEvent:
3115
39
    return "event_t";
3116
76
  case OCLClkEvent:
3117
76
    return "clk_event_t";
3118
67
  case OCLQueue:
3119
67
    return "queue_t";
3120
93
  case OCLReserveID:
3121
93
    return "reserve_id_t";
3122
0
  case IncompleteMatrixIdx:
3123
0
    return "<incomplete matrix index type>";
3124
8
  case OMPArraySection:
3125
8
    return "<OpenMP array section type>";
3126
0
  case OMPArrayShaping:
3127
0
    return "<OpenMP array shaping type>";
3128
0
  case OMPIterator:
3129
0
    return "<OpenMP iterator type>";
3130
0
#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3131
332
  case Id: \
3132
332
    return #ExtType;
3133
0
#include "clang/Basic/OpenCLExtensionTypes.def"
3134
0
#define SVE_TYPE(Name, Id, SingletonId) \
3135
26.1k
  case Id: \
3136
26.1k
    return Name;
3137
26
#include "clang/Basic/AArch64SVEACLETypes.def"
3138
0
#define PPC_VECTOR_TYPE(Name, Id, Size) \
3139
218
  case Id: \
3140
218
    return #Name;
3141
1.71k
#include "clang/Basic/PPCTypes.def"
3142
0
#define RVV_TYPE(Name, Id, SingletonId)                                        \
3143
132
  case Id:                                                                     \
3144
132
    return Name;
3145
1.22M
#include 
"clang/Basic/RISCVVTypes.def"116
3146
1.22M
  }
3147
3148
0
  llvm_unreachable("Invalid builtin type.");
3149
0
}
3150
3151
16.3M
QualType QualType::getNonPackExpansionType() const {
3152
  // We never wrap type sugar around a PackExpansionType.
3153
16.3M
  if (auto *PET = dyn_cast<PackExpansionType>(getTypePtr()))
3154
27.3k
    return PET->getPattern();
3155
16.2M
  return *this;
3156
16.3M
}
3157
3158
15.8M
QualType QualType::getNonLValueExprType(const ASTContext &Context) const {
3159
15.8M
  if (const auto *RefType = getTypePtr()->getAs<ReferenceType>())
3160
470k
    return RefType->getPointeeType();
3161
3162
  // C++0x [basic.lval]:
3163
  //   Class prvalues can have cv-qualified types; non-class prvalues always
3164
  //   have cv-unqualified types.
3165
  //
3166
  // See also C99 6.3.2.1p2.
3167
15.3M
  if (!Context.getLangOpts().CPlusPlus ||
3168
15.3M
      
(4.32M
!getTypePtr()->isDependentType()4.32M
&&
!getTypePtr()->isRecordType()4.13M
))
3169
14.9M
    return getUnqualifiedType();
3170
3171
457k
  return *this;
3172
15.3M
}
3173
3174
304
StringRef FunctionType::getNameForCallConv(CallingConv CC) {
3175
304
  switch (CC) {
3176
119
  case CC_C: return "cdecl";
3177
80
  case CC_X86StdCall: return "stdcall";
3178
32
  case CC_X86FastCall: return "fastcall";
3179
10
  case CC_X86ThisCall: return "thiscall";
3180
1
  case CC_X86Pascal: return "pascal";
3181
22
  case CC_X86VectorCall: return "vectorcall";
3182
3
  case CC_Win64: return "ms_abi";
3183
0
  case CC_X86_64SysV: return "sysv_abi";
3184
1
  case CC_X86RegCall : return "regcall";
3185
0
  case CC_AAPCS: return "aapcs";
3186
0
  case CC_AAPCS_VFP: return "aapcs-vfp";
3187
3
  case CC_AArch64VectorCall: return "aarch64_vector_pcs";
3188
3
  case CC_AArch64SVEPCS: return "aarch64_sve_pcs";
3189
0
  case CC_AMDGPUKernelCall: return "amdgpu_kernel";
3190
0
  case CC_IntelOclBicc: return "intel_ocl_bicc";
3191
0
  case CC_SpirFunction: return "spir_function";
3192
0
  case CC_OpenCLKernel: return "opencl_kernel";
3193
8
  case CC_Swift: return "swiftcall";
3194
8
  case CC_SwiftAsync: return "swiftasynccall";
3195
6
  case CC_PreserveMost: return "preserve_most";
3196
8
  case CC_PreserveAll: return "preserve_all";
3197
304
  }
3198
3199
0
  llvm_unreachable("Invalid calling convention.");
3200
0
}
3201
3202
FunctionProtoType::FunctionProtoType(QualType result, ArrayRef<QualType> params,
3203
                                     QualType canonical,
3204
                                     const ExtProtoInfo &epi)
3205
    : FunctionType(FunctionProto, result, canonical, result->getDependence(),
3206
15.4M
                   epi.ExtInfo) {
3207
15.4M
  FunctionTypeBits.FastTypeQuals = epi.TypeQuals.getFastQualifiers();
3208
15.4M
  FunctionTypeBits.RefQualifier = epi.RefQualifier;
3209
15.4M
  FunctionTypeBits.NumParams = params.size();
3210
15.4M
  assert(getNumParams() == params.size() && "NumParams overflow!");
3211
0
  FunctionTypeBits.ExceptionSpecType = epi.ExceptionSpec.Type;
3212
15.4M
  FunctionTypeBits.HasExtParameterInfos = !!epi.ExtParameterInfos;
3213
15.4M
  FunctionTypeBits.Variadic = epi.Variadic;
3214
15.4M
  FunctionTypeBits.HasTrailingReturn = epi.HasTrailingReturn;
3215
3216
  // Fill in the extra trailing bitfields if present.
3217
15.4M
  if (hasExtraBitfields(epi.ExceptionSpec.Type)) {
3218
624
    auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
3219
624
    ExtraBits.NumExceptionType = epi.ExceptionSpec.Exceptions.size();
3220
624
  }
3221
3222
  // Fill in the trailing argument array.
3223
15.4M
  auto *argSlot = getTrailingObjects<QualType>();
3224
46.6M
  for (unsigned i = 0; i != getNumParams(); 
++i31.1M
) {
3225
31.1M
    addDependence(params[i]->getDependence() &
3226
31.1M
                  ~TypeDependence::VariablyModified);
3227
31.1M
    argSlot[i] = params[i];
3228
31.1M
  }
3229
3230
  // Fill in the exception type array if present.
3231
15.4M
  if (getExceptionSpecType() == EST_Dynamic) {
3232
624
    assert(hasExtraBitfields() && "missing trailing extra bitfields!");
3233
0
    auto *exnSlot =
3234
624
        reinterpret_cast<QualType *>(getTrailingObjects<ExceptionType>());
3235
624
    unsigned I = 0;
3236
706
    for (QualType ExceptionType : epi.ExceptionSpec.Exceptions) {
3237
      // Note that, before C++17, a dependent exception specification does
3238
      // *not* make a type dependent; it's not even part of the C++ type
3239
      // system.
3240
706
      addDependence(
3241
706
          ExceptionType->getDependence() &
3242
706
          (TypeDependence::Instantiation | TypeDependence::UnexpandedPack));
3243
3244
706
      exnSlot[I++] = ExceptionType;
3245
706
    }
3246
624
  }
3247
  // Fill in the Expr * in the exception specification if present.
3248
15.4M
  else if (isComputedNoexcept(getExceptionSpecType())) {
3249
262k
    assert(epi.ExceptionSpec.NoexceptExpr && "computed noexcept with no expr");
3250
0
    assert((getExceptionSpecType() == EST_DependentNoexcept) ==
3251
262k
           epi.ExceptionSpec.NoexceptExpr->isValueDependent());
3252
3253
    // Store the noexcept expression and context.
3254
0
    *getTrailingObjects<Expr *>() = epi.ExceptionSpec.NoexceptExpr;
3255
3256
262k
    addDependence(
3257
262k
        toTypeDependence(epi.ExceptionSpec.NoexceptExpr->getDependence()) &
3258
262k
        (TypeDependence::Instantiation | TypeDependence::UnexpandedPack));
3259
262k
  }
3260
  // Fill in the FunctionDecl * in the exception specification if present.
3261
15.1M
  else if (getExceptionSpecType() == EST_Uninstantiated) {
3262
    // Store the function decl from which we will resolve our
3263
    // exception specification.
3264
83.0k
    auto **slot = getTrailingObjects<FunctionDecl *>();
3265
83.0k
    slot[0] = epi.ExceptionSpec.SourceDecl;
3266
83.0k
    slot[1] = epi.ExceptionSpec.SourceTemplate;
3267
    // This exception specification doesn't make the type dependent, because
3268
    // it's not instantiated as part of instantiating the type.
3269
15.1M
  } else if (getExceptionSpecType() == EST_Unevaluated) {
3270
    // Store the function decl from which we will resolve our
3271
    // exception specification.
3272
538k
    auto **slot = getTrailingObjects<FunctionDecl *>();
3273
538k
    slot[0] = epi.ExceptionSpec.SourceDecl;
3274
538k
  }
3275
3276
  // If this is a canonical type, and its exception specification is dependent,
3277
  // then it's a dependent type. This only happens in C++17 onwards.
3278
15.4M
  if (isCanonicalUnqualified()) {
3279
7.00M
    if (getExceptionSpecType() == EST_Dynamic ||
3280
7.00M
        
getExceptionSpecType() == EST_DependentNoexcept7.00M
) {
3281
1.99k
      assert(hasDependentExceptionSpec() && "type should not be canonical");
3282
0
      addDependence(TypeDependence::DependentInstantiation);
3283
1.99k
    }
3284
8.43M
  } else if (getCanonicalTypeInternal()->isDependentType()) {
3285
    // Ask our canonical type whether our exception specification was dependent.
3286
2.05M
    addDependence(TypeDependence::DependentInstantiation);
3287
2.05M
  }
3288
3289
  // Fill in the extra parameter info if present.
3290
15.4M
  if (epi.ExtParameterInfos) {
3291
13.3k
    auto *extParamInfos = getTrailingObjects<ExtParameterInfo>();
3292
54.6k
    for (unsigned i = 0; i != getNumParams(); 
++i41.3k
)
3293
41.3k
      extParamInfos[i] = epi.ExtParameterInfos[i];
3294
13.3k
  }
3295
3296
15.4M
  if (epi.TypeQuals.hasNonFastQualifiers()) {
3297
623
    FunctionTypeBits.HasExtQuals = 1;
3298
623
    *getTrailingObjects<Qualifiers>() = epi.TypeQuals;
3299
15.4M
  } else {
3300
15.4M
    FunctionTypeBits.HasExtQuals = 0;
3301
15.4M
  }
3302
3303
  // Fill in the Ellipsis location info if present.
3304
15.4M
  if (epi.Variadic) {
3305
118k
    auto &EllipsisLoc = *getTrailingObjects<SourceLocation>();
3306
118k
    EllipsisLoc = epi.EllipsisLoc;
3307
118k
  }
3308
15.4M
}
3309
3310
33.5k
bool FunctionProtoType::hasDependentExceptionSpec() const {
3311
33.5k
  if (Expr *NE = getNoexceptExpr())
3312
2.04k
    return NE->isValueDependent();
3313
31.4k
  for (QualType ET : exceptions())
3314
    // A pack expansion with a non-dependent pattern is still dependent,
3315
    // because we don't know whether the pattern is in the exception spec
3316
    // or not (that depends on whether the pack has 0 expansions).
3317
224
    if (ET->isDependentType() || 
ET->getAs<PackExpansionType>()217
)
3318
7
      return true;
3319
31.4k
  return false;
3320
31.4k
}
3321
3322
41.1k
bool FunctionProtoType::hasInstantiationDependentExceptionSpec() const {
3323
41.1k
  if (Expr *NE = getNoexceptExpr())
3324
5
    return NE->isInstantiationDependent();
3325
41.1k
  for (QualType ET : exceptions())
3326
25
    if (ET->isInstantiationDependentType())
3327
17
      return true;
3328
41.1k
  return false;
3329
41.1k
}
3330
3331
1.84M
CanThrowResult FunctionProtoType::canThrow() const {
3332
1.84M
  switch (getExceptionSpecType()) {
3333
0
  case EST_Unparsed:
3334
0
  case EST_Unevaluated:
3335
0
    llvm_unreachable("should not call this with unresolved exception specs");
3336
3337
1.79k
  case EST_DynamicNone:
3338
435k
  case EST_BasicNoexcept:
3339
454k
  case EST_NoexceptTrue:
3340
454k
  case EST_NoThrow:
3341
454k
    return CT_Cannot;
3342
3343
1.37M
  case EST_None:
3344
1.37M
  case EST_MSAny:
3345
1.38M
  case EST_NoexceptFalse:
3346
1.38M
    return CT_Can;
3347
3348
684
  case EST_Dynamic:
3349
    // A dynamic exception specification is throwing unless every exception
3350
    // type is an (unexpanded) pack expansion type.
3351
688
    for (unsigned I = 0; I != getNumExceptions(); 
++I4
)
3352
685
      if (!getExceptionType(I)->getAs<PackExpansionType>())
3353
681
        return CT_Can;
3354
3
    return CT_Dependent;
3355
3356
4
  case EST_Uninstantiated:
3357
13.3k
  case EST_DependentNoexcept:
3358
13.3k
    return CT_Dependent;
3359
1.84M
  }
3360
3361
0
  llvm_unreachable("unexpected exception specification kind");
3362
0
}
3363
3364
88.7k
bool FunctionProtoType::isTemplateVariadic() const {
3365
119k
  for (unsigned ArgIdx = getNumParams(); ArgIdx; 
--ArgIdx30.6k
)
3366
33.5k
    if (isa<PackExpansionType>(getParamType(ArgIdx - 1)))
3367
2.87k
      return true;
3368
3369
85.8k
  return false;
3370
88.7k
}
3371
3372
void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result,
3373
                                const QualType *ArgTys, unsigned NumParams,
3374
                                const ExtProtoInfo &epi,
3375
93.8M
                                const ASTContext &Context, bool Canonical) {
3376
  // We have to be careful not to get ambiguous profile encodings.
3377
  // Note that valid type pointers are never ambiguous with anything else.
3378
  //
3379
  // The encoding grammar begins:
3380
  //      type type* bool int bool
3381
  // If that final bool is true, then there is a section for the EH spec:
3382
  //      bool type*
3383
  // This is followed by an optional "consumed argument" section of the
3384
  // same length as the first type sequence:
3385
  //      bool*
3386
  // Finally, we have the ext info and trailing return type flag:
3387
  //      int bool
3388
  //
3389
  // There is no ambiguity between the consumed arguments and an empty EH
3390
  // spec because of the leading 'bool' which unambiguously indicates
3391
  // whether the following bool is the EH spec or part of the arguments.
3392
3393
93.8M
  ID.AddPointer(Result.getAsOpaquePtr());
3394
302M
  for (unsigned i = 0; i != NumParams; 
++i208M
)
3395
208M
    ID.AddPointer(ArgTys[i].getAsOpaquePtr());
3396
  // This method is relatively performance sensitive, so as a performance
3397
  // shortcut, use one AddInteger call instead of four for the next four
3398
  // fields.
3399
93.8M
  assert(!(unsigned(epi.Variadic) & ~1) &&
3400
93.8M
         !(unsigned(epi.RefQualifier) & ~3) &&
3401
93.8M
         !(unsigned(epi.ExceptionSpec.Type) & ~15) &&
3402
93.8M
         "Values larger than expected.");
3403
0
  ID.AddInteger(unsigned(epi.Variadic) +
3404
93.8M
                (epi.RefQualifier << 1) +
3405
93.8M
                (epi.ExceptionSpec.Type << 3));
3406
93.8M
  ID.Add(epi.TypeQuals);
3407
93.8M
  if (epi.ExceptionSpec.Type == EST_Dynamic) {
3408
2.00k
    for (QualType Ex : epi.ExceptionSpec.Exceptions)
3409
2.19k
      ID.AddPointer(Ex.getAsOpaquePtr());
3410
93.8M
  } else if (isComputedNoexcept(epi.ExceptionSpec.Type)) {
3411
1.11M
    epi.ExceptionSpec.NoexceptExpr->Profile(ID, Context, Canonical);
3412
92.7M
  } else if (epi.ExceptionSpec.Type == EST_Uninstantiated ||
3413
92.7M
             
epi.ExceptionSpec.Type == EST_Unevaluated92.4M
) {
3414
1.46M
    ID.AddPointer(epi.ExceptionSpec.SourceDecl->getCanonicalDecl());
3415
1.46M
  }
3416
93.8M
  if (epi.ExtParameterInfos) {
3417
235k
    for (unsigned i = 0; i != NumParams; 
++i178k
)
3418
178k
      ID.AddInteger(epi.ExtParameterInfos[i].getOpaqueValue());
3419
57.2k
  }
3420
93.8M
  epi.ExtInfo.Profile(ID);
3421
93.8M
  ID.AddBoolean(epi.HasTrailingReturn);
3422
93.8M
}
3423
3424
void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID,
3425
51.5M
                                const ASTContext &Ctx) {
3426
51.5M
  Profile(ID, getReturnType(), param_type_begin(), getNumParams(),
3427
51.5M
          getExtProtoInfo(), Ctx, isCanonicalUnqualified());
3428
51.5M
}
3429
3430
TypedefType::TypedefType(TypeClass tc, const TypedefNameDecl *D,
3431
                         QualType underlying, QualType can)
3432
    : Type(tc, can, toSemanticDependence(underlying->getDependence())),
3433
2.96M
      Decl(const_cast<TypedefNameDecl *>(D)) {
3434
2.96M
  assert(!isa<TypedefType>(can) && "Invalid canonical type");
3435
2.96M
}
3436
3437
107M
QualType TypedefType::desugar() const {
3438
107M
  return getDecl()->getUnderlyingType();
3439
107M
}
3440
3441
UsingType::UsingType(const UsingShadowDecl *Found, QualType Underlying,
3442
                     QualType Canon)
3443
    : Type(Using, Canon, toSemanticDependence(Underlying->getDependence())),
3444
26.0k
      Found(const_cast<UsingShadowDecl *>(Found)) {
3445
26.0k
  assert(Underlying == getUnderlyingType());
3446
26.0k
}
3447
3448
1.24M
QualType UsingType::getUnderlyingType() const {
3449
1.24M
  return QualType(cast<TypeDecl>(Found->getTargetDecl())->getTypeForDecl(), 0);
3450
1.24M
}
3451
3452
425k
QualType MacroQualifiedType::desugar() const { return getUnderlyingType(); }
3453
3454
90
QualType MacroQualifiedType::getModifiedType() const {
3455
  // Step over MacroQualifiedTypes from the same macro to find the type
3456
  // ultimately qualified by the macro qualifier.
3457
90
  QualType Inner = cast<AttributedType>(getUnderlyingType())->getModifiedType();
3458
106
  while (auto *InnerMQT = dyn_cast<MacroQualifiedType>(Inner)) {
3459
16
    if (InnerMQT->getMacroIdentifier() != getMacroIdentifier())
3460
0
      break;
3461
16
    Inner = InnerMQT->getModifiedType();
3462
16
  }
3463
90
  return Inner;
3464
90
}
3465
3466
TypeOfExprType::TypeOfExprType(Expr *E, QualType can)
3467
    : Type(TypeOfExpr, can,
3468
           toTypeDependence(E->getDependence()) |
3469
               (E->getType()->getDependence() &
3470
                TypeDependence::VariablyModified)),
3471
3.11k
      TOExpr(E) {}
3472
3473
27.1k
bool TypeOfExprType::isSugared() const {
3474
27.1k
  return !TOExpr->isTypeDependent();
3475
27.1k
}
3476
3477
13.7k
QualType TypeOfExprType::desugar() const {
3478
13.7k
  if (isSugared())
3479
13.7k
    return getUnderlyingExpr()->getType();
3480
3481
0
  return QualType(this, 0);
3482
13.7k
}
3483
3484
void DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID,
3485
2.08k
                                      const ASTContext &Context, Expr *E) {
3486
2.08k
  E->Profile(ID, Context, true);
3487
2.08k
}
3488
3489
DecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can)
3490
    // C++11 [temp.type]p2: "If an expression e involves a template parameter,
3491
    // decltype(e) denotes a unique dependent type." Hence a decltype type is
3492
    // type-dependent even if its expression is only instantiation-dependent.
3493
    : Type(Decltype, can,
3494
           toTypeDependence(E->getDependence()) |
3495
               (E->isInstantiationDependent() ? TypeDependence::Dependent
3496
                                              : TypeDependence::None) |
3497
               (E->getType()->getDependence() &
3498
                TypeDependence::VariablyModified)),
3499
283k
      E(E), UnderlyingType(underlyingType) {}
3500
3501
208k
bool DecltypeType::isSugared() const { return !E->isInstantiationDependent(); }
3502
3503
99.6k
QualType DecltypeType::desugar() const {
3504
99.6k
  if (isSugared())
3505
99.6k
    return getUnderlyingType();
3506
3507
0
  return QualType(this, 0);
3508
99.6k
}
3509
3510
DependentDecltypeType::DependentDecltypeType(const ASTContext &Context, Expr *E)
3511
79.6k
    : DecltypeType(E, Context.DependentTy), Context(Context) {}
3512
3513
void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID,
3514
232k
                                    const ASTContext &Context, Expr *E) {
3515
232k
  E->Profile(ID, Context, true);
3516
232k
}
3517
3518
UnaryTransformType::UnaryTransformType(QualType BaseType,
3519
                                       QualType UnderlyingType, UTTKind UKind,
3520
                                       QualType CanonicalType)
3521
    : Type(UnaryTransform, CanonicalType, BaseType->getDependence()),
3522
2.46k
      BaseType(BaseType), UnderlyingType(UnderlyingType), UKind(UKind) {}
3523
3524
DependentUnaryTransformType::DependentUnaryTransformType(const ASTContext &C,
3525
                                                         QualType BaseType,
3526
                                                         UTTKind UKind)
3527
487
     : UnaryTransformType(BaseType, C.DependentTy, UKind, QualType()) {}
3528
3529
TagType::TagType(TypeClass TC, const TagDecl *D, QualType can)
3530
    : Type(TC, can,
3531
           D->isDependentType() ? TypeDependence::DependentInstantiation
3532
                                : TypeDependence::None),
3533
4.31M
      decl(const_cast<TagDecl *>(D)) {}
3534
3535
183M
static TagDecl *getInterestingTagDecl(TagDecl *decl) {
3536
193M
  for (auto I : decl->redecls()) {
3537
193M
    if (I->isCompleteDefinition() || 
I->isBeingDefined()33.6M
)
3538
177M
      return I;
3539
193M
  }
3540
  // If there's no definition (not even in progress), return what we have.
3541
6.55M
  return decl;
3542
183M
}
3543
3544
180M
TagDecl *TagType::getDecl() const {
3545
180M
  return getInterestingTagDecl(decl);
3546
180M
}
3547
3548
2.95M
bool TagType::isBeingDefined() const {
3549
2.95M
  return getDecl()->isBeingDefined();
3550
2.95M
}
3551
3552
1.75k
bool RecordType::hasConstFields() const {
3553
1.75k
  std::vector<const RecordType*> RecordTypeList;
3554
1.75k
  RecordTypeList.push_back(this);
3555
1.75k
  unsigned NextToCheckIndex = 0;
3556
3557
3.60k
  while (RecordTypeList.size() > NextToCheckIndex) {
3558
1.86k
    for (FieldDecl *FD :
3559
3.15k
         RecordTypeList[NextToCheckIndex]->getDecl()->fields()) {
3560
3.15k
      QualType FieldTy = FD->getType();
3561
3.15k
      if (FieldTy.isConstQualified())
3562
11
        return true;
3563
3.14k
      FieldTy = FieldTy.getCanonicalType();
3564
3.14k
      if (const auto *FieldRecTy = FieldTy->getAs<RecordType>()) {
3565
127
        if (!llvm::is_contained(RecordTypeList, FieldRecTy))
3566
115
          RecordTypeList.push_back(FieldRecTy);
3567
127
      }
3568
3.14k
    }
3569
1.85k
    ++NextToCheckIndex;
3570
1.85k
  }
3571
1.73k
  return false;
3572
1.75k
}
3573
3574
23
bool AttributedType::isQualifier() const {
3575
  // FIXME: Generate this with TableGen.
3576
23
  switch (getAttrKind()) {
3577
  // These are type qualifiers in the traditional C sense: they annotate
3578
  // something about a specific value/variable of a type.  (They aren't
3579
  // always part of the canonical type, though.)
3580
0
  case attr::ObjCGC:
3581
17
  case attr::ObjCOwnership:
3582
17
  case attr::ObjCInertUnsafeUnretained:
3583
18
  case attr::TypeNonNull:
3584
19
  case attr::TypeNullable:
3585
19
  case attr::TypeNullableResult:
3586
19
  case attr::TypeNullUnspecified:
3587
19
  case attr::LifetimeBound:
3588
23
  case attr::AddressSpace:
3589
23
    return true;
3590
3591
  // All other type attributes aren't qualifiers; they rewrite the modified
3592
  // type to be a semantically different type.
3593
0
  default:
3594
0
    return false;
3595
23
  }
3596
23
}
3597
3598
2.40k
bool AttributedType::isMSTypeSpec() const {
3599
  // FIXME: Generate this with TableGen?
3600
2.40k
  switch (getAttrKind()) {
3601
2.38k
  default: return false;
3602
10
  case attr::Ptr32:
3603
14
  case attr::Ptr64:
3604
18
  case attr::SPtr:
3605
22
  case attr::UPtr:
3606
22
    return true;
3607
2.40k
  }
3608
0
  llvm_unreachable("invalid attr kind");
3609
0
}
3610
3611
1.37k
bool AttributedType::isCallingConv() const {
3612
  // FIXME: Generate this with TableGen.
3613
1.37k
  switch (getAttrKind()) {
3614
923
  default: return false;
3615
0
  case attr::Pcs:
3616
193
  case attr::CDecl:
3617
240
  case attr::FastCall:
3618
305
  case attr::StdCall:
3619
340
  case attr::ThisCall:
3620
342
  case attr::RegCall:
3621
345
  case attr::SwiftCall:
3622
348
  case attr::SwiftAsyncCall:
3623
382
  case attr::VectorCall:
3624
385
  case attr::AArch64VectorPcs:
3625
388
  case attr::AArch64SVEPcs:
3626
388
  case attr::AMDGPUKernelCall:
3627
388
  case attr::Pascal:
3628
397
  case attr::MSABI:
3629
404
  case attr::SysVABI:
3630
404
  case attr::IntelOclBicc:
3631
430
  case attr::PreserveMost:
3632
456
  case attr::PreserveAll:
3633
456
    return true;
3634
1.37k
  }
3635
0
  llvm_unreachable("invalid attr kind");
3636
0
}
3637
3638
2.87M
CXXRecordDecl *InjectedClassNameType::getDecl() const {
3639
2.87M
  return cast<CXXRecordDecl>(getInterestingTagDecl(Decl));
3640
2.87M
}
3641
3642
586k
IdentifierInfo *TemplateTypeParmType::getIdentifier() const {
3643
586k
  return isCanonicalUnqualified() ? 
nullptr4.40k
:
getDecl()->getIdentifier()581k
;
3644
586k
}
3645
3646
SubstTemplateTypeParmPackType::SubstTemplateTypeParmPackType(
3647
    const TemplateTypeParmType *Param, QualType Canon,
3648
    const TemplateArgument &ArgPack)
3649
    : Type(SubstTemplateTypeParmPack, Canon,
3650
           TypeDependence::DependentInstantiation |
3651
               TypeDependence::UnexpandedPack),
3652
14.2k
      Replaced(Param), Arguments(ArgPack.pack_begin()) {
3653
14.2k
  SubstTemplateTypeParmPackTypeBits.NumArgs = ArgPack.pack_size();
3654
14.2k
}
3655
3656
88.9k
TemplateArgument SubstTemplateTypeParmPackType::getArgumentPack() const {
3657
88.9k
  return TemplateArgument(llvm::makeArrayRef(Arguments, getNumArgs()));
3658
88.9k
}
3659
3660
45.6k
void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID) {
3661
45.6k
  Profile(ID, getReplacedParameter(), getArgumentPack());
3662
45.6k
}
3663
3664
void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID,
3665
                                           const TemplateTypeParmType *Replaced,
3666
95.9k
                                            const TemplateArgument &ArgPack) {
3667
95.9k
  ID.AddPointer(Replaced);
3668
95.9k
  ID.AddInteger(ArgPack.pack_size());
3669
95.9k
  for (const auto &P : ArgPack.pack_elements())
3670
219k
    ID.AddPointer(P.getAsType().getAsOpaquePtr());
3671
95.9k
}
3672
3673
bool TemplateSpecializationType::anyDependentTemplateArguments(
3674
5.58M
    const TemplateArgumentListInfo &Args, ArrayRef<TemplateArgument> Converted) {
3675
5.58M
  return anyDependentTemplateArguments(Args.arguments(), Converted);
3676
5.58M
}
3677
3678
bool TemplateSpecializationType::anyDependentTemplateArguments(
3679
5.58M
    ArrayRef<TemplateArgumentLoc> Args, ArrayRef<TemplateArgument> Converted) {
3680
5.58M
  for (const TemplateArgument &Arg : Converted)
3681
7.29M
    if (Arg.isDependent())
3682
3.30M
      return true;
3683
2.28M
  return false;
3684
5.58M
}
3685
3686
bool TemplateSpecializationType::anyInstantiationDependentTemplateArguments(
3687
136
      ArrayRef<TemplateArgumentLoc> Args) {
3688
136
  for (const TemplateArgumentLoc &ArgLoc : Args) {
3689
63
    if (ArgLoc.getArgument().isInstantiationDependent())
3690
18
      return true;
3691
63
  }
3692
118
  return false;
3693
136
}
3694
3695
TemplateSpecializationType::TemplateSpecializationType(
3696
    TemplateName T, ArrayRef<TemplateArgument> Args, QualType Canon,
3697
    QualType AliasedType)
3698
    : Type(TemplateSpecialization, Canon.isNull() ? QualType(this, 0) : Canon,
3699
           (Canon.isNull()
3700
                ? TypeDependence::DependentInstantiation
3701
                : toSemanticDependence(Canon->getDependence())) |
3702
               (toTypeDependence(T.getDependence()) &
3703
                TypeDependence::UnexpandedPack)),
3704
11.8M
      Template(T) {
3705
11.8M
  TemplateSpecializationTypeBits.NumArgs = Args.size();
3706
11.8M
  TemplateSpecializationTypeBits.TypeAlias = !AliasedType.isNull();
3707
3708
11.8M
  assert(!T.getAsDependentTemplateName() &&
3709
11.8M
         "Use DependentTemplateSpecializationType for dependent template-name");
3710
0
  assert((T.getKind() == TemplateName::Template ||
3711
11.8M
          T.getKind() == TemplateName::SubstTemplateTemplateParm ||
3712
11.8M
          T.getKind() == TemplateName::SubstTemplateTemplateParmPack ||
3713
11.8M
          T.getKind() == TemplateName::UsingTemplate) &&
3714
11.8M
         "Unexpected template name for TemplateSpecializationType");
3715
3716
0
  auto *TemplateArgs = reinterpret_cast<TemplateArgument *>(this + 1);
3717
20.1M
  for (const TemplateArgument &Arg : Args) {
3718
    // Update instantiation-dependent, variably-modified, and error bits.
3719
    // If the canonical type exists and is non-dependent, the template
3720
    // specialization type can be non-dependent even if one of the type
3721
    // arguments is. Given:
3722
    //   template<typename T> using U = int;
3723
    // U<T> is always non-dependent, irrespective of the type T.
3724
    // However, U<Ts> contains an unexpanded parameter pack, even though
3725
    // its expansion (and thus its desugared type) doesn't.
3726
20.1M
    addDependence(toTypeDependence(Arg.getDependence()) &
3727
20.1M
                  ~TypeDependence::Dependent);
3728
20.1M
    if (Arg.getKind() == TemplateArgument::Type)
3729
15.4M
      addDependence(Arg.getAsType()->getDependence() &
3730
15.4M
                    TypeDependence::VariablyModified);
3731
20.1M
    new (TemplateArgs++) TemplateArgument(Arg);
3732
20.1M
  }
3733
3734
  // Store the aliased type if this is a type alias template specialization.
3735
11.8M
  if (isTypeAlias()) {
3736
1.04M
    auto *Begin = reinterpret_cast<TemplateArgument *>(this + 1);
3737
1.04M
    *reinterpret_cast<QualType*>(Begin + getNumArgs()) = AliasedType;
3738
1.04M
  }
3739
11.8M
}
3740
3741
void
3742
TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
3743
                                    TemplateName T,
3744
                                    ArrayRef<TemplateArgument> Args,
3745
12.9M
                                    const ASTContext &Context) {
3746
12.9M
  T.Profile(ID);
3747
12.9M
  for (const TemplateArgument &Arg : Args)
3748
23.4M
    Arg.Profile(ID, Context);
3749
12.9M
}
3750
3751
QualType
3752
163k
QualifierCollector::apply(const ASTContext &Context, QualType QT) const {
3753
163k
  if (!hasNonFastQualifiers())
3754
157k
    return QT.withFastQualifiers(getFastQualifiers());
3755
3756
6.03k
  return Context.getQualifiedType(QT, *this);
3757
163k
}
3758
3759
QualType
3760
72.1k
QualifierCollector::apply(const ASTContext &Context, const Type *T) const {
3761
72.1k
  if (!hasNonFastQualifiers())
3762
72.1k
    return QualType(T, getFastQualifiers());
3763
3764
0
  return Context.getQualifiedType(T, *this);
3765
72.1k
}
3766
3767
void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID,
3768
                                 QualType BaseType,
3769
                                 ArrayRef<QualType> typeArgs,
3770
                                 ArrayRef<ObjCProtocolDecl *> protocols,
3771
541k
                                 bool isKindOf) {
3772
541k
  ID.AddPointer(BaseType.getAsOpaquePtr());
3773
541k
  ID.AddInteger(typeArgs.size());
3774
541k
  for (auto typeArg : typeArgs)
3775
495k
    ID.AddPointer(typeArg.getAsOpaquePtr());
3776
541k
  ID.AddInteger(protocols.size());
3777
541k
  for (auto proto : protocols)
3778
77.8k
    ID.AddPointer(proto);
3779
541k
  ID.AddBoolean(isKindOf);
3780
541k
}
3781
3782
301k
void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) {
3783
301k
  Profile(ID, getBaseType(), getTypeArgsAsWritten(),
3784
301k
          llvm::makeArrayRef(qual_begin(), getNumProtocols()),
3785
301k
          isKindOfTypeAsWritten());
3786
301k
}
3787
3788
void ObjCTypeParamType::Profile(llvm::FoldingSetNodeID &ID,
3789
                                const ObjCTypeParamDecl *OTPDecl,
3790
                                QualType CanonicalType,
3791
194k
                                ArrayRef<ObjCProtocolDecl *> protocols) {
3792
194k
  ID.AddPointer(OTPDecl);
3793
194k
  ID.AddPointer(CanonicalType.getAsOpaquePtr());
3794
194k
  ID.AddInteger(protocols.size());
3795
194k
  for (auto proto : protocols)
3796
9.01k
    ID.AddPointer(proto);
3797
194k
}
3798
3799
123k
void ObjCTypeParamType::Profile(llvm::FoldingSetNodeID &ID) {
3800
123k
  Profile(ID, getDecl(), getCanonicalTypeInternal(),
3801
123k
          llvm::makeArrayRef(qual_begin(), getNumProtocols()));
3802
123k
}
3803
3804
namespace {
3805
3806
/// The cached properties of a type.
3807
class CachedProperties {
3808
  Linkage L;
3809
  bool local;
3810
3811
public:
3812
5.19M
  CachedProperties(Linkage L, bool local) : L(L), local(local) {}
3813
3814
1.94M
  Linkage getLinkage() const { return L; }
3815
5.19M
  bool hasLocalOrUnnamedType() const { return local; }
3816
3817
1.62M
  friend CachedProperties merge(CachedProperties L, CachedProperties R) {
3818
1.62M
    Linkage MergedLinkage = minLinkage(L.L, R.L);
3819
1.62M
    return CachedProperties(MergedLinkage, L.hasLocalOrUnnamedType() ||
3820
1.62M
                                               
R.hasLocalOrUnnamedType()1.62M
);
3821
1.62M
  }
3822
};
3823
3824
} // namespace
3825
3826
static CachedProperties computeCachedProperties(const Type *T);
3827
3828
namespace clang {
3829
3830
/// The type-property cache.  This is templated so as to be
3831
/// instantiated at an internal type to prevent unnecessary symbol
3832
/// leakage.
3833
template <class Private> class TypePropertyCache {
3834
public:
3835
3.11M
  static CachedProperties get(QualType T) {
3836
3.11M
    return get(T.getTypePtr());
3837
3.11M
  }
3838
3839
3.11M
  static CachedProperties get(const Type *T) {
3840
3.11M
    ensure(T);
3841
3.11M
    return CachedProperties(T->TypeBits.getLinkage(),
3842
3.11M
                            T->TypeBits.hasLocalOrUnnamedType());
3843
3.11M
  }
3844
3845
9.95M
  static void ensure(const Type *T) {
3846
    // If the cache is valid, we're okay.
3847
9.95M
    if (T->TypeBits.isCacheValid()) 
return6.67M
;
3848
3849
    // If this type is non-canonical, ask its canonical type for the
3850
    // relevant information.
3851
3.28M
    if (!T->isCanonicalUnqualified()) {
3852
1.33M
      const Type *CT = T->getCanonicalTypeInternal().getTypePtr();
3853
1.33M
      ensure(CT);
3854
1.33M
      T->TypeBits.CacheValid = true;
3855
1.33M
      T->TypeBits.CachedLinkage = CT->TypeBits.CachedLinkage;
3856
1.33M
      T->TypeBits.CachedLocalOrUnnamed = CT->TypeBits.CachedLocalOrUnnamed;
3857
1.33M
      return;
3858
1.33M
    }
3859
3860
    // Compute the cached properties and then set the cache.
3861
1.94M
    CachedProperties Result = computeCachedProperties(T);
3862
1.94M
    T->TypeBits.CacheValid = true;
3863
1.94M
    T->TypeBits.CachedLinkage = Result.getLinkage();
3864
1.94M
    T->TypeBits.CachedLocalOrUnnamed = Result.hasLocalOrUnnamedType();
3865
1.94M
  }
3866
};
3867
3868
} // namespace clang
3869
3870
// Instantiate the friend template at a private class.  In a
3871
// reasonable implementation, these symbols will be internal.
3872
// It is terrible that this is the best way to accomplish this.
3873
namespace {
3874
3875
class Private {};
3876
3877
} // namespace
3878
3879
using Cache = TypePropertyCache<Private>;
3880
3881
1.94M
static CachedProperties computeCachedProperties(const Type *T) {
3882
1.94M
  switch (T->getTypeClass()) {
3883
0
#define TYPE(Class,Base)
3884
0
#define NON_CANONICAL_TYPE(Class,Base) case Type::Class:
3885
0
#include "clang/AST/TypeNodes.inc"
3886
0
    llvm_unreachable("didn't expect a non-canonical type here");
3887
3888
0
#define TYPE(Class,Base)
3889
710k
#define DEPENDENT_TYPE(Class,Base) case Type::Class:
3890
502k
#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class:
3891
126k
#include 
"clang/AST/TypeNodes.inc"0
3892
    // Treat instantiation-dependent types as external.
3893
126k
    if (!T->isInstantiationDependentType()) 
T->dump()0
;
3894
126k
    assert(T->isInstantiationDependentType());
3895
0
    return CachedProperties(ExternalLinkage, false);
3896
3897
490
  case Type::Auto:
3898
517
  case Type::DeducedTemplateSpecialization:
3899
    // Give non-deduced 'auto' types external linkage. We should only see them
3900
    // here in error recovery.
3901
517
    return CachedProperties(ExternalLinkage, false);
3902
3903
137
  case Type::BitInt:
3904
142k
  case Type::Builtin:
3905
    // C++ [basic.link]p8:
3906
    //   A type is said to have linkage if and only if:
3907
    //     - it is a fundamental type (3.9.1); or
3908
142k
    return CachedProperties(ExternalLinkage, false);
3909
3910
181k
  case Type::Record:
3911
187k
  case Type::Enum: {
3912
187k
    const TagDecl *Tag = cast<TagType>(T)->getDecl();
3913
3914
    // C++ [basic.link]p8:
3915
    //     - it is a class or enumeration type that is named (or has a name
3916
    //       for linkage purposes (7.1.3)) and the name has linkage; or
3917
    //     -  it is a specialization of a class template (14); or
3918
187k
    Linkage L = Tag->getLinkageInternal();
3919
187k
    bool IsLocalOrUnnamed =
3920
187k
      Tag->getDeclContext()->isFunctionOrMethod() ||
3921
187k
      
!Tag->hasNameForLinkage()186k
;
3922
187k
    return CachedProperties(L, IsLocalOrUnnamed);
3923
181k
  }
3924
3925
    // C++ [basic.link]p8:
3926
    //   - it is a compound type (3.9.2) other than a class or enumeration,
3927
    //     compounded exclusively from types that have linkage; or
3928
167
  case Type::Complex:
3929
167
    return Cache::get(cast<ComplexType>(T)->getElementType());
3930
112k
  case Type::Pointer:
3931
112k
    return Cache::get(cast<PointerType>(T)->getPointeeType());
3932
328
  case Type::BlockPointer:
3933
328
    return Cache::get(cast<BlockPointerType>(T)->getPointeeType());
3934
195k
  case Type::LValueReference:
3935
245k
  case Type::RValueReference:
3936
245k
    return Cache::get(cast<ReferenceType>(T)->getPointeeType());
3937
2.09k
  case Type::MemberPointer: {
3938
2.09k
    const auto *MPT = cast<MemberPointerType>(T);
3939
2.09k
    return merge(Cache::get(MPT->getClass()),
3940
2.09k
                 Cache::get(MPT->getPointeeType()));
3941
195k
  }
3942
3.80k
  case Type::ConstantArray:
3943
4.54k
  case Type::IncompleteArray:
3944
4.59k
  case Type::VariableArray:
3945
4.59k
    return Cache::get(cast<ArrayType>(T)->getElementType());
3946
2.06k
  case Type::Vector:
3947
2.34k
  case Type::ExtVector:
3948
2.34k
    return Cache::get(cast<VectorType>(T)->getElementType());
3949
71
  case Type::ConstantMatrix:
3950
71
    return Cache::get(cast<ConstantMatrixType>(T)->getElementType());
3951
14
  case Type::FunctionNoProto:
3952
14
    return Cache::get(cast<FunctionType>(T)->getReturnType());
3953
1.11M
  case Type::FunctionProto: {
3954
1.11M
    const auto *FPT = cast<FunctionProtoType>(T);
3955
1.11M
    CachedProperties result = Cache::get(FPT->getReturnType());
3956
1.11M
    for (const auto &ai : FPT->param_types())
3957
1.62M
      result = merge(result, Cache::get(ai));
3958
1.11M
    return result;
3959
2.06k
  }
3960
417
  case Type::ObjCInterface: {
3961
417
    Linkage L = cast<ObjCInterfaceType>(T)->getDecl()->getLinkageInternal();
3962
417
    return CachedProperties(L, false);
3963
2.06k
  }
3964
1.52k
  case Type::ObjCObject:
3965
1.52k
    return Cache::get(cast<ObjCObjectType>(T)->getBaseType());
3966
1.91k
  case Type::ObjCObjectPointer:
3967
1.91k
    return Cache::get(cast<ObjCObjectPointerType>(T)->getPointeeType());
3968
215
  case Type::Atomic:
3969
215
    return Cache::get(cast<AtomicType>(T)->getValueType());
3970
49
  case Type::Pipe:
3971
49
    return Cache::get(cast<PipeType>(T)->getElementType());
3972
1.94M
  }
3973
3974
0
  llvm_unreachable("unhandled type class");
3975
0
}
3976
3977
/// Determine the linkage of this type.
3978
5.50M
Linkage Type::getLinkage() const {
3979
5.50M
  Cache::ensure(this);
3980
5.50M
  return TypeBits.getLinkage();
3981
5.50M
}
3982
3983
7.86k
bool Type::hasUnnamedOrLocalType() const {
3984
7.86k
  Cache::ensure(this);
3985
7.86k
  return TypeBits.hasLocalOrUnnamedType();
3986
7.86k
}
3987
3988
1.98M
LinkageInfo LinkageComputer::computeTypeLinkageInfo(const Type *T) {
3989
1.98M
  switch (T->getTypeClass()) {
3990
0
#define TYPE(Class,Base)
3991
0
#define NON_CANONICAL_TYPE(Class,Base) case Type::Class:
3992
0
#include "clang/AST/TypeNodes.inc"
3993
0
    llvm_unreachable("didn't expect a non-canonical type here");
3994
3995
0
#define TYPE(Class,Base)
3996
0
#define DEPENDENT_TYPE(Class,Base) case Type::Class:
3997
0
#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class:
3998
0
#include "clang/AST/TypeNodes.inc"
3999
    // Treat instantiation-dependent types as external.
4000
0
    assert(T->isInstantiationDependentType());
4001
0
    return LinkageInfo::external();
4002
4003
124
  case Type::BitInt:
4004
773k
  case Type::Builtin:
4005
773k
    return LinkageInfo::external();
4006
4007
0
  case Type::Auto:
4008
0
  case Type::DeducedTemplateSpecialization:
4009
0
    return LinkageInfo::external();
4010
4011
835k
  case Type::Record:
4012
838k
  case Type::Enum:
4013
838k
    return getDeclLinkageAndVisibility(cast<TagType>(T)->getDecl());
4014
4015
43
  case Type::Complex:
4016
43
    return computeTypeLinkageInfo(cast<ComplexType>(T)->getElementType());
4017
244k
  case Type::Pointer:
4018
244k
    return computeTypeLinkageInfo(cast<PointerType>(T)->getPointeeType());
4019
88
  case Type::BlockPointer:
4020
88
    return computeTypeLinkageInfo(cast<BlockPointerType>(T)->getPointeeType());
4021
52.3k
  case Type::LValueReference:
4022
55.7k
  case Type::RValueReference:
4023
55.7k
    return computeTypeLinkageInfo(cast<ReferenceType>(T)->getPointeeType());
4024
5.17k
  case Type::MemberPointer: {
4025
5.17k
    const auto *MPT = cast<MemberPointerType>(T);
4026
5.17k
    LinkageInfo LV = computeTypeLinkageInfo(MPT->getClass());
4027
5.17k
    LV.merge(computeTypeLinkageInfo(MPT->getPointeeType()));
4028
5.17k
    return LV;
4029
52.3k
  }
4030
6.34k
  case Type::ConstantArray:
4031
12.5k
  case Type::IncompleteArray:
4032
12.5k
  case Type::VariableArray:
4033
12.5k
    return computeTypeLinkageInfo(cast<ArrayType>(T)->getElementType());
4034
215
  case Type::Vector:
4035
256
  case Type::ExtVector:
4036
256
    return computeTypeLinkageInfo(cast<VectorType>(T)->getElementType());
4037
0
  case Type::ConstantMatrix:
4038
0
    return computeTypeLinkageInfo(
4039
0
        cast<ConstantMatrixType>(T)->getElementType());
4040
0
  case Type::FunctionNoProto:
4041
0
    return computeTypeLinkageInfo(cast<FunctionType>(T)->getReturnType());
4042
52.3k
  case Type::FunctionProto: {
4043
52.3k
    const auto *FPT = cast<FunctionProtoType>(T);
4044
52.3k
    LinkageInfo LV = computeTypeLinkageInfo(FPT->getReturnType());
4045
52.3k
    for (const auto &ai : FPT->param_types())
4046
45.1k
      LV.merge(computeTypeLinkageInfo(ai));
4047
52.3k
    return LV;
4048
215
  }
4049
623
  case Type::ObjCInterface:
4050
623
    return getDeclLinkageAndVisibility(cast<ObjCInterfaceType>(T)->getDecl());
4051
136
  case Type::ObjCObject:
4052
136
    return computeTypeLinkageInfo(cast<ObjCObjectType>(T)->getBaseType());
4053
737
  case Type::ObjCObjectPointer:
4054
737
    return computeTypeLinkageInfo(
4055
737
        cast<ObjCObjectPointerType>(T)->getPointeeType());
4056
105
  case Type::Atomic:
4057
105
    return computeTypeLinkageInfo(cast<AtomicType>(T)->getValueType());
4058
0
  case Type::Pipe:
4059
0
    return computeTypeLinkageInfo(cast<PipeType>(T)->getElementType());
4060
1.98M
  }
4061
4062
0
  llvm_unreachable("unhandled type class");
4063
0
}
4064
4065
163k
bool Type::isLinkageValid() const {
4066
163k
  if (!TypeBits.isCacheValid())
4067
163k
    return true;
4068
4069
0
  Linkage L = LinkageComputer{}
4070
0
                  .computeTypeLinkageInfo(getCanonicalTypeInternal())
4071
0
                  .getLinkage();
4072
0
  return L == TypeBits.getLinkage();
4073
163k
}
4074
4075
1.56M
LinkageInfo LinkageComputer::getTypeLinkageAndVisibility(const Type *T) {
4076
1.56M
  if (!T->isCanonicalUnqualified())
4077
80.5k
    return computeTypeLinkageInfo(T->getCanonicalTypeInternal());
4078
4079
1.48M
  LinkageInfo LV = computeTypeLinkageInfo(T);
4080
1.48M
  assert(LV.getLinkage() == T->getLinkage());
4081
0
  return LV;
4082
1.56M
}
4083
4084
2.10k
LinkageInfo Type::getLinkageAndVisibility() const {
4085
2.10k
  return LinkageComputer{}.getTypeLinkageAndVisibility(this);
4086
2.10k
}
4087
4088
Optional<NullabilityKind>
4089
36.2M
Type::getNullability(const ASTContext &Context) const {
4090
36.2M
  QualType Type(this, 0);
4091
36.2M
  while (const auto *AT = Type->getAs<AttributedType>()) {
4092
    // Check whether this is an attributed type with nullability
4093
    // information.
4094
685k
    if (auto Nullability = AT->getImmediateNullability())
4095
668k
      return Nullability;
4096
4097
16.3k
    Type = AT->getEquivalentType();
4098
16.3k
  }
4099
35.6M
  return None;
4100
36.2M
}
4101
4102
114M
bool Type::canHaveNullability(bool ResultIfUnknown) const {
4103
114M
  QualType type = getCanonicalTypeInternal();
4104
4105
114M
  switch (type->getTypeClass()) {
4106
  // We'll only see canonical types here.
4107
0
#define NON_CANONICAL_TYPE(Class, Parent)       \
4108
0
  case Type::Class:                             \
4109
0
    llvm_unreachable("non-canonical type");
4110
0
#define TYPE(Class, Parent)
4111
0
#include "clang/AST/TypeNodes.inc"
4112
4113
  // Pointer types.
4114
4.13M
  case Type::Pointer:
4115
4.26M
  case Type::BlockPointer:
4116
4.26M
  case Type::MemberPointer:
4117
7.19M
  case Type::ObjCObjectPointer:
4118
7.19M
    return true;
4119
4120
  // Dependent types that could instantiate to pointer types.
4121
403
  case Type::UnresolvedUsing:
4122
1.56k
  case Type::TypeOfExpr:
4123
1.56k
  case Type::TypeOf:
4124
50.8k
  case Type::Decltype:
4125
51.8k
  case Type::UnaryTransform:
4126
4.07M
  case Type::TemplateTypeParm:
4127
4.07M
  case Type::SubstTemplateTypeParmPack:
4128
5.27M
  case Type::DependentName:
4129
5.31M
  case Type::DependentTemplateSpecialization:
4130
5.35M
  case Type::Auto:
4131
5.35M
    return ResultIfUnknown;
4132
4133
  // Dependent template specializations can instantiate to pointer
4134
  // types unless they're known to be specializations of a class
4135
  // template.
4136
1.00M
  case Type::TemplateSpecialization:
4137
1.00M
    if (TemplateDecl *templateDecl
4138
1.00M
          = cast<TemplateSpecializationType>(type.getTypePtr())
4139
1.00M
              ->getTemplateName().getAsTemplateDecl()) {
4140
1.00M
      if (isa<ClassTemplateDecl>(templateDecl))
4141
996k
        return false;
4142
1.00M
    }
4143
13.2k
    return ResultIfUnknown;
4144
4145
82.1M
  case Type::Builtin:
4146
82.1M
    switch (cast<BuiltinType>(type.getTypePtr())->getKind()) {
4147
      // Signed, unsigned, and floating-point types cannot have nullability.
4148
395M
#define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
4149
338M
#define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
4150
201M
#define FLOATING_TYPE(Id, SingletonId) case BuiltinType::Id:
4151
0
#define BUILTIN_TYPE(Id, SingletonId)
4152
25.6M
#include 
"clang/AST/BuiltinTypes.def"0
4153
25.6M
      return false;
4154
4155
    // Dependent types that could instantiate to a pointer type.
4156
5.65k
    case BuiltinType::Dependent:
4157
5.65k
    case BuiltinType::Overload:
4158
5.65k
    case BuiltinType::BoundMember:
4159
5.65k
    case BuiltinType::PseudoObject:
4160
5.71k
    case BuiltinType::UnknownAny:
4161
5.71k
    case BuiltinType::ARCUnbridgedCast:
4162
5.71k
      return ResultIfUnknown;
4163
4164
3.82M
    case BuiltinType::Void:
4165
3.82M
    case BuiltinType::ObjCId:
4166
3.82M
    case BuiltinType::ObjCClass:
4167
3.82M
    case BuiltinType::ObjCSel:
4168
3.82M
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
4169
137M
    case BuiltinType::Id:
4170
137M
#include 
"clang/Basic/OpenCLImageTypes.def"3.82M
4171
137M
#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
4172
137M
    
case BuiltinType::Id:46.0M
4173
137M
#include 
"clang/Basic/OpenCLExtensionTypes.def"3.83M
4174
46.0M
    case BuiltinType::OCLSampler:
4175
3.84M
    case BuiltinType::OCLEvent:
4176
3.84M
    case BuiltinType::OCLClkEvent:
4177
3.84M
    case BuiltinType::OCLQueue:
4178
3.84M
    case BuiltinType::OCLReserveID:
4179
3.84M
#define SVE_TYPE(Name, Id, SingletonId) \
4180
1.82G
    case BuiltinType::Id:
4181
1.82G
#include 
"clang/Basic/AArch64SVEACLETypes.def"3.84M
4182
1.82G
#define PPC_VECTOR_TYPE(Name, Id, Size) \
4183
1.82G
    
case BuiltinType::Id:112M
4184
1.82G
#include 
"clang/Basic/PPCTypes.def"56.3M
4185
3.72G
#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
4186
3.72G
#include 
"clang/Basic/RISCVVTypes.def"56.3M
4187
3.72G
    case BuiltinType::BuiltinFn:
4188
56.4M
    case BuiltinType::NullPtr:
4189
56.4M
    case BuiltinType::IncompleteMatrixIdx:
4190
56.4M
    case BuiltinType::OMPArraySection:
4191
56.4M
    case BuiltinType::OMPArrayShaping:
4192
56.4M
    case BuiltinType::OMPIterator:
4193
56.4M
      return false;
4194
82.1M
    }
4195
0
    llvm_unreachable("unknown builtin type");
4196
4197
  // Non-pointer types.
4198
8.43k
  case Type::Complex:
4199
27.3k
  case Type::LValueReference:
4200
27.5k
  case Type::RValueReference:
4201
108k
  case Type::ConstantArray:
4202
128k
  case Type::IncompleteArray:
4203
128k
  case Type::VariableArray:
4204
128k
  case Type::DependentSizedArray:
4205
128k
  case Type::DependentVector:
4206
128k
  case Type::DependentSizedExtVector:
4207
11.9M
  case Type::Vector:
4208
12.3M
  case Type::ExtVector:
4209
12.3M
  case Type::ConstantMatrix:
4210
12.3M
  case Type::DependentSizedMatrix:
4211
12.3M
  case Type::DependentAddressSpace:
4212
12.3M
  case Type::FunctionProto:
4213
12.3M
  case Type::FunctionNoProto:
4214
16.3M
  case Type::Record:
4215
16.3M
  case Type::DeducedTemplateSpecialization:
4216
17.1M
  case Type::Enum:
4217
17.4M
  case Type::InjectedClassName:
4218
17.4M
  case Type::PackExpansion:
4219
17.5M
  case Type::ObjCObject:
4220
18.6M
  case Type::ObjCInterface:
4221
18.6M
  case Type::Atomic:
4222
18.6M
  case Type::Pipe:
4223
18.6M
  case Type::BitInt:
4224
18.6M
  case Type::DependentBitInt:
4225
18.6M
    return false;
4226
114M
  }
4227
0
  llvm_unreachable("bad type kind!");
4228
0
}
4229
4230
llvm::Optional<NullabilityKind>
4231
1.03M
AttributedType::getImmediateNullability() const {
4232
1.03M
  if (getAttrKind() == attr::TypeNonNull)
4233
355k
    return NullabilityKind::NonNull;
4234
684k
  if (getAttrKind() == attr::TypeNullable)
4235
616k
    return NullabilityKind::Nullable;
4236
67.2k
  if (getAttrKind() == attr::TypeNullUnspecified)
4237
49.0k
    return NullabilityKind::Unspecified;
4238
18.2k
  if (getAttrKind() == attr::TypeNullableResult)
4239
47
    return NullabilityKind::NullableResult;
4240
18.1k
  return None;
4241
18.2k
}
4242
4243
728k
Optional<NullabilityKind> AttributedType::stripOuterNullability(QualType &T) {
4244
728k
  QualType AttrTy = T;
4245
728k
  if (auto MacroTy = dyn_cast<MacroQualifiedType>(T))
4246
58
    AttrTy = MacroTy->getUnderlyingType();
4247
4248
728k
  if (auto attributed = dyn_cast<AttributedType>(AttrTy)) {
4249
350k
    if (auto nullability = attributed->getImmediateNullability()) {
4250
350k
      T = attributed->getModifiedType();
4251
350k
      return nullability;
4252
350k
    }
4253
350k
  }
4254
4255
377k
  return None;
4256
728k
}
4257
4258
469
bool Type::isBlockCompatibleObjCPointerType(ASTContext &ctx) const {
4259
469
  const auto *objcPtr = getAs<ObjCObjectPointerType>();
4260
469
  if (!objcPtr)
4261
32
    return false;
4262
4263
437
  if (objcPtr->isObjCIdType()) {
4264
    // id is always okay.
4265
282
    return true;
4266
282
  }
4267
4268
  // Blocks are NSObjects.
4269
155
  if (ObjCInterfaceDecl *iface = objcPtr->getInterfaceDecl()) {
4270
131
    if (iface->getIdentifier() != ctx.getNSObjectName())
4271
114
      return false;
4272
4273
    // Continue to check qualifiers, below.
4274
131
  } else 
if (24
objcPtr->isObjCQualifiedIdType()24
) {
4275
    // Continue to check qualifiers, below.
4276
21
  } else {
4277
3
    return false;
4278
3
  }
4279
4280
  // Check protocol qualifiers.
4281
51
  
for (ObjCProtocolDecl *proto : objcPtr->quals())38
{
4282
    // Blocks conform to NSObject and NSCopying.
4283
51
    if (proto->getIdentifier() != ctx.getNSObjectName() &&
4284
51
        
proto->getIdentifier() != ctx.getNSCopyingName()33
)
4285
14
      return false;
4286
51
  }
4287
4288
24
  return true;
4289
38
}
4290
4291
24.4k
Qualifiers::ObjCLifetime Type::getObjCARCImplicitLifetime() const {
4292
24.4k
  if (isObjCARCImplicitlyUnretainedType())
4293
218
    return Qualifiers::OCL_ExplicitNone;
4294
24.2k
  return Qualifiers::OCL_Strong;
4295
24.4k
}
4296
4297
30.0k
bool Type::isObjCARCImplicitlyUnretainedType() const {
4298
30.0k
  assert(isObjCLifetimeType() &&
4299
30.0k
         "cannot query implicit lifetime for non-inferrable type");
4300
4301
0
  const Type *canon = getCanonicalTypeInternal().getTypePtr();
4302
4303
  // Walk down to the base type.  We don't care about qualifiers for this.
4304
30.1k
  while (const auto *array = dyn_cast<ArrayType>(canon))
4305
89
    canon = array->getElementType().getTypePtr();
4306
4307
30.0k
  if (const auto *opt = dyn_cast<ObjCObjectPointerType>(canon)) {
4308
    // Class and Class<Protocol> don't require retention.
4309
28.6k
    if (opt->getObjectType()->isObjCClass())
4310
256
      return true;
4311
28.6k
  }
4312
4313
29.8k
  return false;
4314
30.0k
}
4315
4316
2.79M
bool Type::isObjCNSObjectType() const {
4317
2.79M
  const Type *cur = this;
4318
3.15M
  while (
true3.15M
) {
4319
3.15M
    if (const auto *typedefType = dyn_cast<TypedefType>(cur))
4320
837k
      return typedefType->getDecl()->hasAttr<ObjCNSObjectAttr>();
4321
4322
    // Single-step desugar until we run out of sugar.
4323
2.32M
    QualType next = cur->getLocallyUnqualifiedSingleStepDesugaredType();
4324
2.32M
    if (next.getTypePtr() == cur) 
return false1.95M
;
4325
366k
    cur = next.getTypePtr();
4326
366k
  }
4327
2.79M
}
4328
4329
12.1k
bool Type::isObjCIndependentClassType() const {
4330
12.1k
  if (const auto *typedefType = dyn_cast<TypedefType>(this))
4331
2.76k
    return typedefType->getDecl()->hasAttr<ObjCIndependentClassAttr>();
4332
9.42k
  return false;
4333
12.1k
}
4334
4335
3.15M
bool Type::isObjCRetainableType() const {
4336
3.15M
  return isObjCObjectPointerType() ||
4337
3.15M
         
isBlockPointerType()2.78M
||
4338
3.15M
         
isObjCNSObjectType()2.78M
;
4339
3.15M
}
4340
4341
541
bool Type::isObjCIndirectLifetimeType() const {
4342
541
  if (isObjCLifetimeType())
4343
182
    return true;
4344
359
  if (const auto *OPT = getAs<PointerType>())
4345
181
    return OPT->getPointeeType()->isObjCIndirectLifetimeType();
4346
178
  if (const auto *Ref = getAs<ReferenceType>())
4347
0
    return Ref->getPointeeType()->isObjCIndirectLifetimeType();
4348
178
  if (const auto *MemPtr = getAs<MemberPointerType>())
4349
0
    return MemPtr->getPointeeType()->isObjCIndirectLifetimeType();
4350
178
  return false;
4351
178
}
4352
4353
/// Returns true if objects of this type have lifetime semantics under
4354
/// ARC.
4355
253k
bool Type::isObjCLifetimeType() const {
4356
253k
  const Type *type = this;
4357
257k
  while (const ArrayType *array = type->getAsArrayTypeUnsafe())
4358
3.63k
    type = array->getElementType().getTypePtr();
4359
253k
  return type->isObjCRetainableType();
4360
253k
}
4361
4362
/// Determine whether the given type T is a "bridgable" Objective-C type,
4363
/// which is either an Objective-C object pointer type or an
4364
12.0M
bool Type::isObjCARCBridgableType() const {
4365
12.0M
  return isObjCObjectPointerType() || 
isBlockPointerType()11.8M
;
4366
12.0M
}
4367
4368
/// Determine whether the given type T is a "bridgeable" C type.
4369
504
bool Type::isCARCBridgableType() const {
4370
504
  const auto *Pointer = getAs<PointerType>();
4371
504
  if (!Pointer)
4372
2
    return false;
4373
4374
502
  QualType Pointee = Pointer->getPointeeType();
4375
502
  return Pointee->isVoidType() || 
Pointee->isRecordType()251
;
4376
504
}
4377
4378
/// Check if the specified type is the CUDA device builtin surface type.
4379
11.3k
bool Type::isCUDADeviceBuiltinSurfaceType() const {
4380
11.3k
  if (const auto *RT = getAs<RecordType>())
4381
456
    return RT->getDecl()->hasAttr<CUDADeviceBuiltinSurfaceTypeAttr>();
4382
10.9k
  return false;
4383
11.3k
}
4384
4385
/// Check if the specified type is the CUDA device builtin texture type.
4386
11.3k
bool Type::isCUDADeviceBuiltinTextureType() const {
4387
11.3k
  if (const auto *RT = getAs<RecordType>())
4388
448
    return RT->getDecl()->hasAttr<CUDADeviceBuiltinTextureTypeAttr>();
4389
10.9k
  return false;
4390
11.3k
}
4391
4392
251
bool Type::hasSizedVLAType() const {
4393
251
  if (!isVariablyModifiedType()) 
return false73
;
4394
4395
178
  if (const auto *ptr = getAs<PointerType>())
4396
82
    return ptr->getPointeeType()->hasSizedVLAType();
4397
96
  if (const auto *ref = getAs<ReferenceType>())
4398
1
    return ref->getPointeeType()->hasSizedVLAType();
4399
95
  if (const ArrayType *arr = getAsArrayTypeUnsafe()) {
4400
90
    if (isa<VariableArrayType>(arr) &&
4401
90
        cast<VariableArrayType>(arr)->getSizeExpr())
4402
0
      return true;
4403
4404
90
    return arr->getElementType()->hasSizedVLAType();
4405
90
  }
4406
4407
5
  return false;
4408
95
}
4409
4410
19.2M
QualType::DestructionKind QualType::isDestructedTypeImpl(QualType type) {
4411
19.2M
  switch (type.getObjCLifetime()) {
4412
19.1M
  case Qualifiers::OCL_None:
4413
19.1M
  case Qualifiers::OCL_ExplicitNone:
4414
19.1M
  case Qualifiers::OCL_Autoreleasing:
4415
19.1M
    break;
4416
4417
6.56k
  case Qualifiers::OCL_Strong:
4418
6.56k
    return DK_objc_strong_lifetime;
4419
1.96k
  case Qualifiers::OCL_Weak:
4420
1.96k
    return DK_objc_weak_lifetime;
4421
19.2M
  }
4422
4423
19.1M
  if (const auto *RT =
4424
19.1M
          type->getBaseElementTypeUnsafe()->getAs<RecordType>()) {
4425
1.02M
    const RecordDecl *RD = RT->getDecl();
4426
1.02M
    if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
4427
      /// Check if this is a C++ object with a non-trivial destructor.
4428
428k
      if (CXXRD->hasDefinition() && 
!CXXRD->hasTrivialDestructor()428k
)
4429
78.8k
        return DK_cxx_destructor;
4430
591k
    } else {
4431
      /// Check if this is a C struct that is non-trivial to destroy or an array
4432
      /// that contains such a struct.
4433
591k
      if (RD->isNonTrivialToPrimitiveDestroy())
4434
616
        return DK_nontrivial_c_struct;
4435
591k
    }
4436
1.02M
  }
4437
4438
19.1M
  return DK_none;
4439
19.1M
}
4440
4441
5.06k
CXXRecordDecl *MemberPointerType::getMostRecentCXXRecordDecl() const {
4442
5.06k
  return getClass()->getAsCXXRecordDecl()->getMostRecentNonInjectedDecl();
4443
5.06k
}
4444
4445
void clang::FixedPointValueToString(SmallVectorImpl<char> &Str,
4446
147
                                    llvm::APSInt Val, unsigned Scale) {
4447
147
  llvm::FixedPointSemantics FXSema(Val.getBitWidth(), Scale, Val.isSigned(),
4448
147
                                   /*IsSaturated=*/false,
4449
147
                                   /*HasUnsignedPadding=*/false);
4450
147
  llvm::APFixedPoint(Val, FXSema).toString(Str);
4451
147
}
4452
4453
AutoType::AutoType(QualType DeducedAsType, AutoTypeKeyword Keyword,
4454
                   TypeDependence ExtraDependence, QualType Canon,
4455
                   ConceptDecl *TypeConstraintConcept,
4456
                   ArrayRef<TemplateArgument> TypeConstraintArgs)
4457
47.2k
    : DeducedType(Auto, DeducedAsType, ExtraDependence, Canon) {
4458
47.2k
  AutoTypeBits.Keyword = (unsigned)Keyword;
4459
47.2k
  AutoTypeBits.NumArgs = TypeConstraintArgs.size();
4460
47.2k
  this->TypeConstraintConcept = TypeConstraintConcept;
4461
47.2k
  if (TypeConstraintConcept) {
4462
176
    TemplateArgument *ArgBuffer = getArgBuffer();
4463
176
    for (const TemplateArgument &Arg : TypeConstraintArgs) {
4464
122
      addDependence(
4465
122
          toSyntacticDependence(toTypeDependence(Arg.getDependence())));
4466
4467
122
      new (ArgBuffer++) TemplateArgument(Arg);
4468
122
    }
4469
176
  }
4470
47.2k
}
4471
4472
void AutoType::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4473
                      QualType Deduced, AutoTypeKeyword Keyword,
4474
                      bool IsDependent, ConceptDecl *CD,
4475
155k
                      ArrayRef<TemplateArgument> Arguments) {
4476
155k
  ID.AddPointer(Deduced.getAsOpaquePtr());
4477
155k
  ID.AddInteger((unsigned)Keyword);
4478
155k
  ID.AddBoolean(IsDependent);
4479
155k
  ID.AddPointer(CD);
4480
155k
  for (const TemplateArgument &Arg : Arguments)
4481
316
    Arg.Profile(ID, Context);
4482
155k
}