Coverage Report

Created: 2019-07-24 05:18

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