Coverage Report

Created: 2020-02-25 14:32

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