Coverage Report

Created: 2021-08-24 07:12

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