Coverage Report

Created: 2023-11-11 10:31

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