Coverage Report

Created: 2022-01-22 13:19

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