clang  5.0.0
Type.cpp
Go to the documentation of this file.
1 //===--- Type.cpp - Type representation and manipulation ------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements type-related functionality.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/Type.h"
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/Attr.h"
17 #include "clang/AST/CharUnits.h"
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/DeclObjC.h"
20 #include "clang/AST/DeclTemplate.h"
21 #include "clang/AST/Expr.h"
23 #include "clang/AST/TypeVisitor.h"
24 #include "clang/Basic/Specifiers.h"
25 #include "clang/Basic/TargetInfo.h"
26 #include "llvm/ADT/APSInt.h"
27 #include "llvm/ADT/StringExtras.h"
28 #include <algorithm>
29 using namespace clang;
30 
32  return (*this != Other) &&
33  // CVR qualifiers superset
34  (((Mask & CVRMask) | (Other.Mask & CVRMask)) == (Mask & CVRMask)) &&
35  // ObjC GC qualifiers superset
36  ((getObjCGCAttr() == Other.getObjCGCAttr()) ||
37  (hasObjCGCAttr() && !Other.hasObjCGCAttr())) &&
38  // Address space superset.
39  ((getAddressSpace() == Other.getAddressSpace()) ||
40  (hasAddressSpace()&& !Other.hasAddressSpace())) &&
41  // Lifetime qualifier superset.
42  ((getObjCLifetime() == Other.getObjCLifetime()) ||
43  (hasObjCLifetime() && !Other.hasObjCLifetime()));
44 }
45 
47  const Type* ty = getTypePtr();
48  NamedDecl *ND = nullptr;
49  if (ty->isPointerType() || ty->isReferenceType())
51  else if (ty->isRecordType())
52  ND = ty->getAs<RecordType>()->getDecl();
53  else if (ty->isEnumeralType())
54  ND = ty->getAs<EnumType>()->getDecl();
55  else if (ty->getTypeClass() == Type::Typedef)
56  ND = ty->getAs<TypedefType>()->getDecl();
57  else if (ty->isArrayType())
58  return ty->castAsArrayTypeUnsafe()->
59  getElementType().getBaseTypeIdentifier();
60 
61  if (ND)
62  return ND->getIdentifier();
63  return nullptr;
64 }
65 
66 bool QualType::isConstant(QualType T, const ASTContext &Ctx) {
67  if (T.isConstQualified())
68  return true;
69 
70  if (const ArrayType *AT = Ctx.getAsArrayType(T))
71  return AT->getElementType().isConstant(Ctx);
72 
74 }
75 
77  QualType ElementType,
78  const llvm::APInt &NumElements) {
79  uint64_t ElementSize = Context.getTypeSizeInChars(ElementType).getQuantity();
80 
81  // Fast path the common cases so we can avoid the conservative computation
82  // below, which in common cases allocates "large" APSInt values, which are
83  // slow.
84 
85  // If the element size is a power of 2, we can directly compute the additional
86  // number of addressing bits beyond those required for the element count.
87  if (llvm::isPowerOf2_64(ElementSize)) {
88  return NumElements.getActiveBits() + llvm::Log2_64(ElementSize);
89  }
90 
91  // If both the element count and element size fit in 32-bits, we can do the
92  // computation directly in 64-bits.
93  if ((ElementSize >> 32) == 0 && NumElements.getBitWidth() <= 64 &&
94  (NumElements.getZExtValue() >> 32) == 0) {
95  uint64_t TotalSize = NumElements.getZExtValue() * ElementSize;
96  return 64 - llvm::countLeadingZeros(TotalSize);
97  }
98 
99  // Otherwise, use APSInt to handle arbitrary sized values.
100  llvm::APSInt SizeExtended(NumElements, true);
101  unsigned SizeTypeBits = Context.getTypeSize(Context.getSizeType());
102  SizeExtended = SizeExtended.extend(std::max(SizeTypeBits,
103  SizeExtended.getBitWidth()) * 2);
104 
105  llvm::APSInt TotalSize(llvm::APInt(SizeExtended.getBitWidth(), ElementSize));
106  TotalSize *= SizeExtended;
107 
108  return TotalSize.getActiveBits();
109 }
110 
112  unsigned Bits = Context.getTypeSize(Context.getSizeType());
113 
114  // Limit the number of bits in size_t so that maximal bit size fits 64 bit
115  // integer (see PR8256). We can do this as currently there is no hardware
116  // that supports full 64-bit virtual space.
117  if (Bits > 61)
118  Bits = 61;
119 
120  return Bits;
121 }
122 
123 DependentSizedArrayType::DependentSizedArrayType(const ASTContext &Context,
124  QualType et, QualType can,
125  Expr *e, ArraySizeModifier sm,
126  unsigned tq,
127  SourceRange brackets)
128  : ArrayType(DependentSizedArray, et, can, sm, tq,
129  (et->containsUnexpandedParameterPack() ||
130  (e && e->containsUnexpandedParameterPack()))),
131  Context(Context), SizeExpr((Stmt*) e), Brackets(brackets)
132 {
133 }
134 
135 void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID,
136  const ASTContext &Context,
137  QualType ET,
138  ArraySizeModifier SizeMod,
139  unsigned TypeQuals,
140  Expr *E) {
141  ID.AddPointer(ET.getAsOpaquePtr());
142  ID.AddInteger(SizeMod);
143  ID.AddInteger(TypeQuals);
144  E->Profile(ID, Context, true);
145 }
146 
147 DependentSizedExtVectorType::DependentSizedExtVectorType(const
149  QualType ElementType,
150  QualType can,
151  Expr *SizeExpr,
152  SourceLocation loc)
153  : Type(DependentSizedExtVector, can, /*Dependent=*/true,
154  /*InstantiationDependent=*/true,
155  ElementType->isVariablyModifiedType(),
156  (ElementType->containsUnexpandedParameterPack() ||
157  (SizeExpr && SizeExpr->containsUnexpandedParameterPack()))),
158  Context(Context), SizeExpr(SizeExpr), ElementType(ElementType),
159  loc(loc)
160 {
161 }
162 
163 void
164 DependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID,
165  const ASTContext &Context,
166  QualType ElementType, Expr *SizeExpr) {
167  ID.AddPointer(ElementType.getAsOpaquePtr());
168  SizeExpr->Profile(ID, Context, true);
169 }
170 
171 VectorType::VectorType(QualType vecType, unsigned nElements, QualType canonType,
172  VectorKind vecKind)
173  : VectorType(Vector, vecType, nElements, canonType, vecKind) {}
174 
175 VectorType::VectorType(TypeClass tc, QualType vecType, unsigned nElements,
176  QualType canonType, VectorKind vecKind)
177  : Type(tc, canonType, vecType->isDependentType(),
178  vecType->isInstantiationDependentType(),
179  vecType->isVariablyModifiedType(),
180  vecType->containsUnexpandedParameterPack()),
181  ElementType(vecType)
182 {
183  VectorTypeBits.VecKind = vecKind;
184  VectorTypeBits.NumElements = nElements;
185 }
186 
187 /// getArrayElementTypeNoTypeQual - If this is an array type, return the
188 /// element type of the array, potentially with type qualifiers missing.
189 /// This method should never be used when type qualifiers are meaningful.
191  // If this is directly an array type, return it.
192  if (const ArrayType *ATy = dyn_cast<ArrayType>(this))
193  return ATy->getElementType().getTypePtr();
194 
195  // If the canonical form of this type isn't the right kind, reject it.
196  if (!isa<ArrayType>(CanonicalType))
197  return nullptr;
198 
199  // If this is a typedef for an array type, strip the typedef off without
200  // losing all typedef information.
201  return cast<ArrayType>(getUnqualifiedDesugaredType())
202  ->getElementType().getTypePtr();
203 }
204 
205 /// getDesugaredType - Return the specified type with any "sugar" removed from
206 /// the type. This takes off typedefs, typeof's etc. If the outer level of
207 /// the type is already concrete, it returns it unmodified. This is similar
208 /// to getting the canonical type, but it doesn't remove *all* typedefs. For
209 /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
210 /// concrete.
213  return Context.getQualifiedType(split.Ty, split.Quals);
214 }
215 
216 QualType QualType::getSingleStepDesugaredTypeImpl(QualType type,
217  const ASTContext &Context) {
218  SplitQualType split = type.split();
220  return Context.getQualifiedType(desugar, split.Quals);
221 }
222 
224  switch (getTypeClass()) {
225 #define ABSTRACT_TYPE(Class, Parent)
226 #define TYPE(Class, Parent) \
227  case Type::Class: { \
228  const Class##Type *ty = cast<Class##Type>(this); \
229  if (!ty->isSugared()) return QualType(ty, 0); \
230  return ty->desugar(); \
231  }
232 #include "clang/AST/TypeNodes.def"
233  }
234  llvm_unreachable("bad type kind!");
235 }
236 
239 
240  QualType Cur = T;
241  while (true) {
242  const Type *CurTy = Qs.strip(Cur);
243  switch (CurTy->getTypeClass()) {
244 #define ABSTRACT_TYPE(Class, Parent)
245 #define TYPE(Class, Parent) \
246  case Type::Class: { \
247  const Class##Type *Ty = cast<Class##Type>(CurTy); \
248  if (!Ty->isSugared()) \
249  return SplitQualType(Ty, Qs); \
250  Cur = Ty->desugar(); \
251  break; \
252  }
253 #include "clang/AST/TypeNodes.def"
254  }
255  }
256 }
257 
258 SplitQualType QualType::getSplitUnqualifiedTypeImpl(QualType type) {
259  SplitQualType split = type.split();
260 
261  // All the qualifiers we've seen so far.
262  Qualifiers quals = split.Quals;
263 
264  // The last type node we saw with any nodes inside it.
265  const Type *lastTypeWithQuals = split.Ty;
266 
267  while (true) {
268  QualType next;
269 
270  // Do a single-step desugar, aborting the loop if the type isn't
271  // sugared.
272  switch (split.Ty->getTypeClass()) {
273 #define ABSTRACT_TYPE(Class, Parent)
274 #define TYPE(Class, Parent) \
275  case Type::Class: { \
276  const Class##Type *ty = cast<Class##Type>(split.Ty); \
277  if (!ty->isSugared()) goto done; \
278  next = ty->desugar(); \
279  break; \
280  }
281 #include "clang/AST/TypeNodes.def"
282  }
283 
284  // Otherwise, split the underlying type. If that yields qualifiers,
285  // update the information.
286  split = next.split();
287  if (!split.Quals.empty()) {
288  lastTypeWithQuals = split.Ty;
289  quals.addConsistentQualifiers(split.Quals);
290  }
291  }
292 
293  done:
294  return SplitQualType(lastTypeWithQuals, quals);
295 }
296 
298  // FIXME: this seems inherently un-qualifiers-safe.
299  while (const ParenType *PT = T->getAs<ParenType>())
300  T = PT->getInnerType();
301  return T;
302 }
303 
304 /// \brief This will check for a T (which should be a Type which can act as
305 /// sugar, such as a TypedefType) by removing any existing sugar until it
306 /// reaches a T or a non-sugared type.
307 template<typename T> static const T *getAsSugar(const Type *Cur) {
308  while (true) {
309  if (const T *Sugar = dyn_cast<T>(Cur))
310  return Sugar;
311  switch (Cur->getTypeClass()) {
312 #define ABSTRACT_TYPE(Class, Parent)
313 #define TYPE(Class, Parent) \
314  case Type::Class: { \
315  const Class##Type *Ty = cast<Class##Type>(Cur); \
316  if (!Ty->isSugared()) return 0; \
317  Cur = Ty->desugar().getTypePtr(); \
318  break; \
319  }
320 #include "clang/AST/TypeNodes.def"
321  }
322  }
323 }
324 
325 template <> const TypedefType *Type::getAs() const {
326  return getAsSugar<TypedefType>(this);
327 }
328 
329 template <> const TemplateSpecializationType *Type::getAs() const {
330  return getAsSugar<TemplateSpecializationType>(this);
331 }
332 
333 template <> const AttributedType *Type::getAs() const {
334  return getAsSugar<AttributedType>(this);
335 }
336 
337 /// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic
338 /// sugar off the given type. This should produce an object of the
339 /// same dynamic type as the canonical type.
341  const Type *Cur = this;
342 
343  while (true) {
344  switch (Cur->getTypeClass()) {
345 #define ABSTRACT_TYPE(Class, Parent)
346 #define TYPE(Class, Parent) \
347  case Class: { \
348  const Class##Type *Ty = cast<Class##Type>(Cur); \
349  if (!Ty->isSugared()) return Cur; \
350  Cur = Ty->desugar().getTypePtr(); \
351  break; \
352  }
353 #include "clang/AST/TypeNodes.def"
354  }
355  }
356 }
357 bool Type::isClassType() const {
358  if (const RecordType *RT = getAs<RecordType>())
359  return RT->getDecl()->isClass();
360  return false;
361 }
362 bool Type::isStructureType() const {
363  if (const RecordType *RT = getAs<RecordType>())
364  return RT->getDecl()->isStruct();
365  return false;
366 }
368  if (const RecordType *RT = getAs<RecordType>())
369  return RT->getDecl()->hasAttr<ObjCBoxableAttr>();
370  return false;
371 }
372 bool Type::isInterfaceType() const {
373  if (const RecordType *RT = getAs<RecordType>())
374  return RT->getDecl()->isInterface();
375  return false;
376 }
378  if (const RecordType *RT = getAs<RecordType>()) {
379  RecordDecl *RD = RT->getDecl();
380  return RD->isStruct() || RD->isClass() || RD->isInterface();
381  }
382  return false;
383 }
385  if (const PointerType *PT = getAs<PointerType>())
386  return PT->getPointeeType()->isVoidType();
387  return false;
388 }
389 
390 bool Type::isUnionType() const {
391  if (const RecordType *RT = getAs<RecordType>())
392  return RT->getDecl()->isUnion();
393  return false;
394 }
395 
396 bool Type::isComplexType() const {
397  if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
398  return CT->getElementType()->isFloatingType();
399  return false;
400 }
401 
403  // Check for GCC complex integer extension.
404  return getAsComplexIntegerType();
405 }
406 
408  if (const ComplexType *Complex = getAs<ComplexType>())
409  if (Complex->getElementType()->isIntegerType())
410  return Complex;
411  return nullptr;
412 }
413 
415  if (const PointerType *PT = getAs<PointerType>())
416  return PT->getPointeeType();
417  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
418  return OPT->getPointeeType();
419  if (const BlockPointerType *BPT = getAs<BlockPointerType>())
420  return BPT->getPointeeType();
421  if (const ReferenceType *RT = getAs<ReferenceType>())
422  return RT->getPointeeType();
423  if (const MemberPointerType *MPT = getAs<MemberPointerType>())
424  return MPT->getPointeeType();
425  if (const DecayedType *DT = getAs<DecayedType>())
426  return DT->getPointeeType();
427  return QualType();
428 }
429 
431  // If this is directly a structure type, return it.
432  if (const RecordType *RT = dyn_cast<RecordType>(this)) {
433  if (RT->getDecl()->isStruct())
434  return RT;
435  }
436 
437  // If the canonical form of this type isn't the right kind, reject it.
438  if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
439  if (!RT->getDecl()->isStruct())
440  return nullptr;
441 
442  // If this is a typedef for a structure type, strip the typedef off without
443  // losing all typedef information.
444  return cast<RecordType>(getUnqualifiedDesugaredType());
445  }
446  return nullptr;
447 }
448 
450  // If this is directly a union type, return it.
451  if (const RecordType *RT = dyn_cast<RecordType>(this)) {
452  if (RT->getDecl()->isUnion())
453  return RT;
454  }
455 
456  // If the canonical form of this type isn't the right kind, reject it.
457  if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
458  if (!RT->getDecl()->isUnion())
459  return nullptr;
460 
461  // If this is a typedef for a union type, strip the typedef off without
462  // losing all typedef information.
463  return cast<RecordType>(getUnqualifiedDesugaredType());
464  }
465 
466  return nullptr;
467 }
468 
470  const ObjCObjectType *&bound) const {
471  bound = nullptr;
472 
473  const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>();
474  if (!OPT)
475  return false;
476 
477  // Easy case: id.
478  if (OPT->isObjCIdType())
479  return true;
480 
481  // If it's not a __kindof type, reject it now.
482  if (!OPT->isKindOfType())
483  return false;
484 
485  // If it's Class or qualified Class, it's not an object type.
486  if (OPT->isObjCClassType() || OPT->isObjCQualifiedClassType())
487  return false;
488 
489  // Figure out the type bound for the __kindof type.
490  bound = OPT->getObjectType()->stripObjCKindOfTypeAndQuals(ctx)
491  ->getAs<ObjCObjectType>();
492  return true;
493 }
494 
496  const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>();
497  if (!OPT)
498  return false;
499 
500  // Easy case: Class.
501  if (OPT->isObjCClassType())
502  return true;
503 
504  // If it's not a __kindof type, reject it now.
505  if (!OPT->isKindOfType())
506  return false;
507 
508  // If it's Class or qualified Class, it's a class __kindof type.
509  return OPT->isObjCClassType() || OPT->isObjCQualifiedClassType();
510 }
511 
512 /// Was this type written with the special inert-in-MRC __unsafe_unretained
513 /// qualifier?
514 ///
515 /// This approximates the answer to the following question: if this
516 /// translation unit were compiled in ARC, would this type be qualified
517 /// with __unsafe_unretained?
519  const Type *cur = this;
520  while (true) {
521  if (auto attributed = dyn_cast<AttributedType>(cur)) {
522  if (attributed->getAttrKind() ==
524  return true;
525  }
526 
527  // Single-step desugar until we run out of sugar.
529  if (next.getTypePtr() == cur) return false;
530  cur = next.getTypePtr();
531  }
532 }
533 
534 ObjCTypeParamType::ObjCTypeParamType(const ObjCTypeParamDecl *D,
535  QualType can,
537  : Type(ObjCTypeParam, can, can->isDependentType(),
538  can->isInstantiationDependentType(),
539  can->isVariablyModifiedType(),
540  /*ContainsUnexpandedParameterPack=*/false),
541  OTPDecl(const_cast<ObjCTypeParamDecl*>(D))
542 {
543  initialize(protocols);
544 }
545 
547  ArrayRef<QualType> typeArgs,
549  bool isKindOf)
550  : Type(ObjCObject, Canonical, Base->isDependentType(),
551  Base->isInstantiationDependentType(),
552  Base->isVariablyModifiedType(),
553  Base->containsUnexpandedParameterPack()),
554  BaseType(Base)
555 {
556  ObjCObjectTypeBits.IsKindOf = isKindOf;
557 
558  ObjCObjectTypeBits.NumTypeArgs = typeArgs.size();
559  assert(getTypeArgsAsWritten().size() == typeArgs.size() &&
560  "bitfield overflow in type argument count");
561  if (!typeArgs.empty())
562  memcpy(getTypeArgStorage(), typeArgs.data(),
563  typeArgs.size() * sizeof(QualType));
564 
565  for (auto typeArg : typeArgs) {
566  if (typeArg->isDependentType())
567  setDependent();
568  else if (typeArg->isInstantiationDependentType())
570 
571  if (typeArg->containsUnexpandedParameterPack())
573  }
574  // Initialize the protocol qualifiers. The protocol storage is known
575  // after we set number of type arguments.
576  initialize(protocols);
577 }
578 
580  // If we have type arguments written here, the type is specialized.
581  if (ObjCObjectTypeBits.NumTypeArgs > 0)
582  return true;
583 
584  // Otherwise, check whether the base type is specialized.
585  if (auto objcObject = getBaseType()->getAs<ObjCObjectType>()) {
586  // Terminate when we reach an interface type.
587  if (isa<ObjCInterfaceType>(objcObject))
588  return false;
589 
590  return objcObject->isSpecialized();
591  }
592 
593  // Not specialized.
594  return false;
595 }
596 
598  // We have type arguments written on this type.
600  return getTypeArgsAsWritten();
601 
602  // Look at the base type, which might have type arguments.
603  if (auto objcObject = getBaseType()->getAs<ObjCObjectType>()) {
604  // Terminate when we reach an interface type.
605  if (isa<ObjCInterfaceType>(objcObject))
606  return { };
607 
608  return objcObject->getTypeArgs();
609  }
610 
611  // No type arguments.
612  return { };
613 }
614 
616  if (isKindOfTypeAsWritten())
617  return true;
618 
619  // Look at the base type, which might have type arguments.
620  if (auto objcObject = getBaseType()->getAs<ObjCObjectType>()) {
621  // Terminate when we reach an interface type.
622  if (isa<ObjCInterfaceType>(objcObject))
623  return false;
624 
625  return objcObject->isKindOfType();
626  }
627 
628  // Not a "__kindof" type.
629  return false;
630 }
631 
633  const ASTContext &ctx) const {
634  if (!isKindOfType() && qual_empty())
635  return QualType(this, 0);
636 
637  // Recursively strip __kindof.
638  SplitQualType splitBaseType = getBaseType().split();
639  QualType baseType(splitBaseType.Ty, 0);
640  if (const ObjCObjectType *baseObj
641  = splitBaseType.Ty->getAs<ObjCObjectType>()) {
642  baseType = baseObj->stripObjCKindOfTypeAndQuals(ctx);
643  }
644 
645  return ctx.getObjCObjectType(ctx.getQualifiedType(baseType,
646  splitBaseType.Quals),
648  /*protocols=*/{ },
649  /*isKindOf=*/false);
650 }
651 
653  const ASTContext &ctx) const {
654  if (!isKindOfType() && qual_empty())
655  return this;
656 
659 }
660 
661 namespace {
662 
663 template<typename F>
664 QualType simpleTransform(ASTContext &ctx, QualType type, F &&f);
665 
666 /// Visitor used by simpleTransform() to perform the transformation.
667 template<typename F>
668 struct SimpleTransformVisitor
669  : public TypeVisitor<SimpleTransformVisitor<F>, QualType> {
670  ASTContext &Ctx;
671  F &&TheFunc;
672 
673  QualType recurse(QualType type) {
674  return simpleTransform(Ctx, type, std::move(TheFunc));
675  }
676 
677 public:
678  SimpleTransformVisitor(ASTContext &ctx, F &&f) : Ctx(ctx), TheFunc(std::move(f)) { }
679 
680  // None of the clients of this transformation can occur where
681  // there are dependent types, so skip dependent types.
682 #define TYPE(Class, Base)
683 #define DEPENDENT_TYPE(Class, Base) \
684  QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); }
685 #include "clang/AST/TypeNodes.def"
686 
687 #define TRIVIAL_TYPE_CLASS(Class) \
688  QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); }
689 
690  TRIVIAL_TYPE_CLASS(Builtin)
691 
692  QualType VisitComplexType(const ComplexType *T) {
693  QualType elementType = recurse(T->getElementType());
694  if (elementType.isNull())
695  return QualType();
696 
697  if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
698  return QualType(T, 0);
699 
700  return Ctx.getComplexType(elementType);
701  }
702 
703  QualType VisitPointerType(const PointerType *T) {
704  QualType pointeeType = recurse(T->getPointeeType());
705  if (pointeeType.isNull())
706  return QualType();
707 
708  if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
709  return QualType(T, 0);
710 
711  return Ctx.getPointerType(pointeeType);
712  }
713 
714  QualType VisitBlockPointerType(const BlockPointerType *T) {
715  QualType pointeeType = recurse(T->getPointeeType());
716  if (pointeeType.isNull())
717  return QualType();
718 
719  if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
720  return QualType(T, 0);
721 
722  return Ctx.getBlockPointerType(pointeeType);
723  }
724 
725  QualType VisitLValueReferenceType(const LValueReferenceType *T) {
726  QualType pointeeType = recurse(T->getPointeeTypeAsWritten());
727  if (pointeeType.isNull())
728  return QualType();
729 
730  if (pointeeType.getAsOpaquePtr()
732  return QualType(T, 0);
733 
734  return Ctx.getLValueReferenceType(pointeeType, T->isSpelledAsLValue());
735  }
736 
737  QualType VisitRValueReferenceType(const RValueReferenceType *T) {
738  QualType pointeeType = recurse(T->getPointeeTypeAsWritten());
739  if (pointeeType.isNull())
740  return QualType();
741 
742  if (pointeeType.getAsOpaquePtr()
744  return QualType(T, 0);
745 
746  return Ctx.getRValueReferenceType(pointeeType);
747  }
748 
749  QualType VisitMemberPointerType(const MemberPointerType *T) {
750  QualType pointeeType = recurse(T->getPointeeType());
751  if (pointeeType.isNull())
752  return QualType();
753 
754  if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
755  return QualType(T, 0);
756 
757  return Ctx.getMemberPointerType(pointeeType, T->getClass());
758  }
759 
760  QualType VisitConstantArrayType(const ConstantArrayType *T) {
761  QualType elementType = recurse(T->getElementType());
762  if (elementType.isNull())
763  return QualType();
764 
765  if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
766  return QualType(T, 0);
767 
768  return Ctx.getConstantArrayType(elementType, T->getSize(),
769  T->getSizeModifier(),
771  }
772 
773  QualType VisitVariableArrayType(const VariableArrayType *T) {
774  QualType elementType = recurse(T->getElementType());
775  if (elementType.isNull())
776  return QualType();
777 
778  if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
779  return QualType(T, 0);
780 
781  return Ctx.getVariableArrayType(elementType, T->getSizeExpr(),
782  T->getSizeModifier(),
784  T->getBracketsRange());
785  }
786 
787  QualType VisitIncompleteArrayType(const IncompleteArrayType *T) {
788  QualType elementType = recurse(T->getElementType());
789  if (elementType.isNull())
790  return QualType();
791 
792  if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
793  return QualType(T, 0);
794 
795  return Ctx.getIncompleteArrayType(elementType, T->getSizeModifier(),
797  }
798 
799  QualType VisitVectorType(const VectorType *T) {
800  QualType elementType = recurse(T->getElementType());
801  if (elementType.isNull())
802  return QualType();
803 
804  if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
805  return QualType(T, 0);
806 
807  return Ctx.getVectorType(elementType, T->getNumElements(),
808  T->getVectorKind());
809  }
810 
811  QualType VisitExtVectorType(const ExtVectorType *T) {
812  QualType elementType = recurse(T->getElementType());
813  if (elementType.isNull())
814  return QualType();
815 
816  if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
817  return QualType(T, 0);
818 
819  return Ctx.getExtVectorType(elementType, T->getNumElements());
820  }
821 
822  QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
823  QualType returnType = recurse(T->getReturnType());
824  if (returnType.isNull())
825  return QualType();
826 
827  if (returnType.getAsOpaquePtr() == T->getReturnType().getAsOpaquePtr())
828  return QualType(T, 0);
829 
830  return Ctx.getFunctionNoProtoType(returnType, T->getExtInfo());
831  }
832 
833  QualType VisitFunctionProtoType(const FunctionProtoType *T) {
834  QualType returnType = recurse(T->getReturnType());
835  if (returnType.isNull())
836  return QualType();
837 
838  // Transform parameter types.
839  SmallVector<QualType, 4> paramTypes;
840  bool paramChanged = false;
841  for (auto paramType : T->getParamTypes()) {
842  QualType newParamType = recurse(paramType);
843  if (newParamType.isNull())
844  return QualType();
845 
846  if (newParamType.getAsOpaquePtr() != paramType.getAsOpaquePtr())
847  paramChanged = true;
848 
849  paramTypes.push_back(newParamType);
850  }
851 
852  // Transform extended info.
854  bool exceptionChanged = false;
855  if (info.ExceptionSpec.Type == EST_Dynamic) {
856  SmallVector<QualType, 4> exceptionTypes;
857  for (auto exceptionType : info.ExceptionSpec.Exceptions) {
858  QualType newExceptionType = recurse(exceptionType);
859  if (newExceptionType.isNull())
860  return QualType();
861 
862  if (newExceptionType.getAsOpaquePtr()
863  != exceptionType.getAsOpaquePtr())
864  exceptionChanged = true;
865 
866  exceptionTypes.push_back(newExceptionType);
867  }
868 
869  if (exceptionChanged) {
871  llvm::makeArrayRef(exceptionTypes).copy(Ctx);
872  }
873  }
874 
875  if (returnType.getAsOpaquePtr() == T->getReturnType().getAsOpaquePtr() &&
876  !paramChanged && !exceptionChanged)
877  return QualType(T, 0);
878 
879  return Ctx.getFunctionType(returnType, paramTypes, info);
880  }
881 
882  QualType VisitParenType(const ParenType *T) {
883  QualType innerType = recurse(T->getInnerType());
884  if (innerType.isNull())
885  return QualType();
886 
887  if (innerType.getAsOpaquePtr() == T->getInnerType().getAsOpaquePtr())
888  return QualType(T, 0);
889 
890  return Ctx.getParenType(innerType);
891  }
892 
893  TRIVIAL_TYPE_CLASS(Typedef)
894  TRIVIAL_TYPE_CLASS(ObjCTypeParam)
895 
896  QualType VisitAdjustedType(const AdjustedType *T) {
897  QualType originalType = recurse(T->getOriginalType());
898  if (originalType.isNull())
899  return QualType();
900 
901  QualType adjustedType = recurse(T->getAdjustedType());
902  if (adjustedType.isNull())
903  return QualType();
904 
905  if (originalType.getAsOpaquePtr()
906  == T->getOriginalType().getAsOpaquePtr() &&
907  adjustedType.getAsOpaquePtr() == T->getAdjustedType().getAsOpaquePtr())
908  return QualType(T, 0);
909 
910  return Ctx.getAdjustedType(originalType, adjustedType);
911  }
912 
913  QualType VisitDecayedType(const DecayedType *T) {
914  QualType originalType = recurse(T->getOriginalType());
915  if (originalType.isNull())
916  return QualType();
917 
918  if (originalType.getAsOpaquePtr()
920  return QualType(T, 0);
921 
922  return Ctx.getDecayedType(originalType);
923  }
924 
925  TRIVIAL_TYPE_CLASS(TypeOfExpr)
926  TRIVIAL_TYPE_CLASS(TypeOf)
927  TRIVIAL_TYPE_CLASS(Decltype)
928  TRIVIAL_TYPE_CLASS(UnaryTransform)
929  TRIVIAL_TYPE_CLASS(Record)
930  TRIVIAL_TYPE_CLASS(Enum)
931 
932  // FIXME: Non-trivial to implement, but important for C++
933  TRIVIAL_TYPE_CLASS(Elaborated)
934 
935  QualType VisitAttributedType(const AttributedType *T) {
936  QualType modifiedType = recurse(T->getModifiedType());
937  if (modifiedType.isNull())
938  return QualType();
939 
940  QualType equivalentType = recurse(T->getEquivalentType());
941  if (equivalentType.isNull())
942  return QualType();
943 
944  if (modifiedType.getAsOpaquePtr()
945  == T->getModifiedType().getAsOpaquePtr() &&
946  equivalentType.getAsOpaquePtr()
947  == T->getEquivalentType().getAsOpaquePtr())
948  return QualType(T, 0);
949 
950  return Ctx.getAttributedType(T->getAttrKind(), modifiedType,
951  equivalentType);
952  }
953 
954  QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
955  QualType replacementType = recurse(T->getReplacementType());
956  if (replacementType.isNull())
957  return QualType();
958 
959  if (replacementType.getAsOpaquePtr()
961  return QualType(T, 0);
962 
964  replacementType);
965  }
966 
967  // FIXME: Non-trivial to implement, but important for C++
968  TRIVIAL_TYPE_CLASS(TemplateSpecialization)
969 
970  QualType VisitAutoType(const AutoType *T) {
971  if (!T->isDeduced())
972  return QualType(T, 0);
973 
974  QualType deducedType = recurse(T->getDeducedType());
975  if (deducedType.isNull())
976  return QualType();
977 
978  if (deducedType.getAsOpaquePtr()
979  == T->getDeducedType().getAsOpaquePtr())
980  return QualType(T, 0);
981 
982  return Ctx.getAutoType(deducedType, T->getKeyword(),
983  T->isDependentType());
984  }
985 
986  // FIXME: Non-trivial to implement, but important for C++
987  TRIVIAL_TYPE_CLASS(PackExpansion)
988 
989  QualType VisitObjCObjectType(const ObjCObjectType *T) {
990  QualType baseType = recurse(T->getBaseType());
991  if (baseType.isNull())
992  return QualType();
993 
994  // Transform type arguments.
995  bool typeArgChanged = false;
996  SmallVector<QualType, 4> typeArgs;
997  for (auto typeArg : T->getTypeArgsAsWritten()) {
998  QualType newTypeArg = recurse(typeArg);
999  if (newTypeArg.isNull())
1000  return QualType();
1001 
1002  if (newTypeArg.getAsOpaquePtr() != typeArg.getAsOpaquePtr())
1003  typeArgChanged = true;
1004 
1005  typeArgs.push_back(newTypeArg);
1006  }
1007 
1008  if (baseType.getAsOpaquePtr() == T->getBaseType().getAsOpaquePtr() &&
1009  !typeArgChanged)
1010  return QualType(T, 0);
1011 
1012  return Ctx.getObjCObjectType(baseType, typeArgs,
1013  llvm::makeArrayRef(T->qual_begin(),
1014  T->getNumProtocols()),
1015  T->isKindOfTypeAsWritten());
1016  }
1017 
1018  TRIVIAL_TYPE_CLASS(ObjCInterface)
1019 
1020  QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1021  QualType pointeeType = recurse(T->getPointeeType());
1022  if (pointeeType.isNull())
1023  return QualType();
1024 
1025  if (pointeeType.getAsOpaquePtr()
1026  == T->getPointeeType().getAsOpaquePtr())
1027  return QualType(T, 0);
1028 
1029  return Ctx.getObjCObjectPointerType(pointeeType);
1030  }
1031 
1032  QualType VisitAtomicType(const AtomicType *T) {
1033  QualType valueType = recurse(T->getValueType());
1034  if (valueType.isNull())
1035  return QualType();
1036 
1037  if (valueType.getAsOpaquePtr()
1038  == T->getValueType().getAsOpaquePtr())
1039  return QualType(T, 0);
1040 
1041  return Ctx.getAtomicType(valueType);
1042  }
1043 
1044 #undef TRIVIAL_TYPE_CLASS
1045 };
1046 
1047 /// Perform a simple type transformation that does not change the
1048 /// semantics of the type.
1049 template<typename F>
1050 QualType simpleTransform(ASTContext &ctx, QualType type, F &&f) {
1051  // Transform the type. If it changed, return the transformed result.
1052  QualType transformed = f(type);
1053  if (transformed.getAsOpaquePtr() != type.getAsOpaquePtr())
1054  return transformed;
1055 
1056  // Split out the qualifiers from the type.
1057  SplitQualType splitType = type.split();
1058 
1059  // Visit the type itself.
1060  SimpleTransformVisitor<F> visitor(ctx, std::forward<F>(f));
1061  QualType result = visitor.Visit(splitType.Ty);
1062  if (result.isNull())
1063  return result;
1064 
1065  // Reconstruct the transformed type by applying the local qualifiers
1066  // from the split type.
1067  return ctx.getQualifiedType(result, splitType.Quals);
1068 }
1069 
1070 } // end anonymous namespace
1071 
1072 /// Substitute the given type arguments for Objective-C type
1073 /// parameters within the given type, recursively.
1075  ASTContext &ctx,
1076  ArrayRef<QualType> typeArgs,
1077  ObjCSubstitutionContext context) const {
1078  return simpleTransform(ctx, *this,
1079  [&](QualType type) -> QualType {
1080  SplitQualType splitType = type.split();
1081 
1082  // Replace an Objective-C type parameter reference with the corresponding
1083  // type argument.
1084  if (const auto *OTPTy = dyn_cast<ObjCTypeParamType>(splitType.Ty)) {
1085  if (auto *typeParam = dyn_cast<ObjCTypeParamDecl>(OTPTy->getDecl())) {
1086  // If we have type arguments, use them.
1087  if (!typeArgs.empty()) {
1088  QualType argType = typeArgs[typeParam->getIndex()];
1089  if (OTPTy->qual_empty())
1090  return ctx.getQualifiedType(argType, splitType.Quals);
1091 
1092  // Apply protocol lists if exists.
1093  bool hasError;
1094  SmallVector<ObjCProtocolDecl*, 8> protocolsVec;
1095  protocolsVec.append(OTPTy->qual_begin(),
1096  OTPTy->qual_end());
1097  ArrayRef<ObjCProtocolDecl *> protocolsToApply = protocolsVec;
1098  QualType resultTy = ctx.applyObjCProtocolQualifiers(argType,
1099  protocolsToApply, hasError, true/*allowOnPointerType*/);
1100 
1101  return ctx.getQualifiedType(resultTy, splitType.Quals);
1102  }
1103 
1104  switch (context) {
1108  // Substitute the bound.
1109  return ctx.getQualifiedType(typeParam->getUnderlyingType(),
1110  splitType.Quals);
1111 
1114  // Substitute the __kindof form of the underlying type.
1115  const auto *objPtr = typeParam->getUnderlyingType()
1116  ->castAs<ObjCObjectPointerType>();
1117 
1118  // __kindof types, id, and Class don't need an additional
1119  // __kindof.
1120  if (objPtr->isKindOfType() || objPtr->isObjCIdOrClassType())
1121  return ctx.getQualifiedType(typeParam->getUnderlyingType(),
1122  splitType.Quals);
1123 
1124  // Add __kindof.
1125  const auto *obj = objPtr->getObjectType();
1126  QualType resultTy = ctx.getObjCObjectType(obj->getBaseType(),
1127  obj->getTypeArgsAsWritten(),
1128  obj->getProtocols(),
1129  /*isKindOf=*/true);
1130 
1131  // Rebuild object pointer type.
1132  resultTy = ctx.getObjCObjectPointerType(resultTy);
1133  return ctx.getQualifiedType(resultTy, splitType.Quals);
1134  }
1135  }
1136  }
1137  }
1138 
1139  // If we have a function type, update the context appropriately.
1140  if (const auto *funcType = dyn_cast<FunctionType>(splitType.Ty)) {
1141  // Substitute result type.
1142  QualType returnType = funcType->getReturnType().substObjCTypeArgs(
1143  ctx,
1144  typeArgs,
1146  if (returnType.isNull())
1147  return QualType();
1148 
1149  // Handle non-prototyped functions, which only substitute into the result
1150  // type.
1151  if (isa<FunctionNoProtoType>(funcType)) {
1152  // If the return type was unchanged, do nothing.
1153  if (returnType.getAsOpaquePtr()
1154  == funcType->getReturnType().getAsOpaquePtr())
1155  return type;
1156 
1157  // Otherwise, build a new type.
1158  return ctx.getFunctionNoProtoType(returnType, funcType->getExtInfo());
1159  }
1160 
1161  const auto *funcProtoType = cast<FunctionProtoType>(funcType);
1162 
1163  // Transform parameter types.
1164  SmallVector<QualType, 4> paramTypes;
1165  bool paramChanged = false;
1166  for (auto paramType : funcProtoType->getParamTypes()) {
1167  QualType newParamType = paramType.substObjCTypeArgs(
1168  ctx,
1169  typeArgs,
1171  if (newParamType.isNull())
1172  return QualType();
1173 
1174  if (newParamType.getAsOpaquePtr() != paramType.getAsOpaquePtr())
1175  paramChanged = true;
1176 
1177  paramTypes.push_back(newParamType);
1178  }
1179 
1180  // Transform extended info.
1181  FunctionProtoType::ExtProtoInfo info = funcProtoType->getExtProtoInfo();
1182  bool exceptionChanged = false;
1183  if (info.ExceptionSpec.Type == EST_Dynamic) {
1184  SmallVector<QualType, 4> exceptionTypes;
1185  for (auto exceptionType : info.ExceptionSpec.Exceptions) {
1186  QualType newExceptionType = exceptionType.substObjCTypeArgs(
1187  ctx,
1188  typeArgs,
1190  if (newExceptionType.isNull())
1191  return QualType();
1192 
1193  if (newExceptionType.getAsOpaquePtr()
1194  != exceptionType.getAsOpaquePtr())
1195  exceptionChanged = true;
1196 
1197  exceptionTypes.push_back(newExceptionType);
1198  }
1199 
1200  if (exceptionChanged) {
1201  info.ExceptionSpec.Exceptions =
1202  llvm::makeArrayRef(exceptionTypes).copy(ctx);
1203  }
1204  }
1205 
1206  if (returnType.getAsOpaquePtr()
1207  == funcProtoType->getReturnType().getAsOpaquePtr() &&
1208  !paramChanged && !exceptionChanged)
1209  return type;
1210 
1211  return ctx.getFunctionType(returnType, paramTypes, info);
1212  }
1213 
1214  // Substitute into the type arguments of a specialized Objective-C object
1215  // type.
1216  if (const auto *objcObjectType = dyn_cast<ObjCObjectType>(splitType.Ty)) {
1217  if (objcObjectType->isSpecializedAsWritten()) {
1218  SmallVector<QualType, 4> newTypeArgs;
1219  bool anyChanged = false;
1220  for (auto typeArg : objcObjectType->getTypeArgsAsWritten()) {
1221  QualType newTypeArg = typeArg.substObjCTypeArgs(
1222  ctx, typeArgs,
1224  if (newTypeArg.isNull())
1225  return QualType();
1226 
1227  if (newTypeArg.getAsOpaquePtr() != typeArg.getAsOpaquePtr()) {
1228  // If we're substituting based on an unspecialized context type,
1229  // produce an unspecialized type.
1230  ArrayRef<ObjCProtocolDecl *> protocols(
1231  objcObjectType->qual_begin(),
1232  objcObjectType->getNumProtocols());
1233  if (typeArgs.empty() &&
1235  return ctx.getObjCObjectType(
1236  objcObjectType->getBaseType(), { },
1237  protocols,
1238  objcObjectType->isKindOfTypeAsWritten());
1239  }
1240 
1241  anyChanged = true;
1242  }
1243 
1244  newTypeArgs.push_back(newTypeArg);
1245  }
1246 
1247  if (anyChanged) {
1248  ArrayRef<ObjCProtocolDecl *> protocols(
1249  objcObjectType->qual_begin(),
1250  objcObjectType->getNumProtocols());
1251  return ctx.getObjCObjectType(objcObjectType->getBaseType(),
1252  newTypeArgs, protocols,
1253  objcObjectType->isKindOfTypeAsWritten());
1254  }
1255  }
1256 
1257  return type;
1258  }
1259 
1260  return type;
1261  });
1262 }
1263 
1265  const DeclContext *dc,
1266  ObjCSubstitutionContext context) const {
1267  if (auto subs = objectType->getObjCSubstitutions(dc))
1268  return substObjCTypeArgs(dc->getParentASTContext(), *subs, context);
1269 
1270  return *this;
1271 }
1272 
1274  // FIXME: Because ASTContext::getAttributedType() is non-const.
1275  auto &ctx = const_cast<ASTContext &>(constCtx);
1276  return simpleTransform(ctx, *this,
1277  [&](QualType type) -> QualType {
1278  SplitQualType splitType = type.split();
1279  if (auto *objType = splitType.Ty->getAs<ObjCObjectType>()) {
1280  if (!objType->isKindOfType())
1281  return type;
1282 
1283  QualType baseType
1284  = objType->getBaseType().stripObjCKindOfType(ctx);
1285  return ctx.getQualifiedType(
1286  ctx.getObjCObjectType(baseType,
1287  objType->getTypeArgsAsWritten(),
1288  objType->getProtocols(),
1289  /*isKindOf=*/false),
1290  splitType.Quals);
1291  }
1292 
1293  return type;
1294  });
1295 }
1296 
1298  if (auto AT = getTypePtr()->getAs<AtomicType>())
1299  return AT->getValueType().getUnqualifiedType();
1300  return getUnqualifiedType();
1301 }
1302 
1304  const DeclContext *dc) const {
1305  // Look through method scopes.
1306  if (auto method = dyn_cast<ObjCMethodDecl>(dc))
1307  dc = method->getDeclContext();
1308 
1309  // Find the class or category in which the type we're substituting
1310  // was declared.
1311  const ObjCInterfaceDecl *dcClassDecl = dyn_cast<ObjCInterfaceDecl>(dc);
1312  const ObjCCategoryDecl *dcCategoryDecl = nullptr;
1313  ObjCTypeParamList *dcTypeParams = nullptr;
1314  if (dcClassDecl) {
1315  // If the class does not have any type parameters, there's no
1316  // substitution to do.
1317  dcTypeParams = dcClassDecl->getTypeParamList();
1318  if (!dcTypeParams)
1319  return None;
1320  } else {
1321  // If we are in neither a class nor a category, there's no
1322  // substitution to perform.
1323  dcCategoryDecl = dyn_cast<ObjCCategoryDecl>(dc);
1324  if (!dcCategoryDecl)
1325  return None;
1326 
1327  // If the category does not have any type parameters, there's no
1328  // substitution to do.
1329  dcTypeParams = dcCategoryDecl->getTypeParamList();
1330  if (!dcTypeParams)
1331  return None;
1332 
1333  dcClassDecl = dcCategoryDecl->getClassInterface();
1334  if (!dcClassDecl)
1335  return None;
1336  }
1337  assert(dcTypeParams && "No substitutions to perform");
1338  assert(dcClassDecl && "No class context");
1339 
1340  // Find the underlying object type.
1341  const ObjCObjectType *objectType;
1342  if (const auto *objectPointerType = getAs<ObjCObjectPointerType>()) {
1343  objectType = objectPointerType->getObjectType();
1344  } else if (getAs<BlockPointerType>()) {
1345  ASTContext &ctx = dc->getParentASTContext();
1346  objectType = ctx.getObjCObjectType(ctx.ObjCBuiltinIdTy, { }, { })
1347  ->castAs<ObjCObjectType>();
1348  } else {
1349  objectType = getAs<ObjCObjectType>();
1350  }
1351 
1352  /// Extract the class from the receiver object type.
1353  ObjCInterfaceDecl *curClassDecl = objectType ? objectType->getInterface()
1354  : nullptr;
1355  if (!curClassDecl) {
1356  // If we don't have a context type (e.g., this is "id" or some
1357  // variant thereof), substitute the bounds.
1358  return llvm::ArrayRef<QualType>();
1359  }
1360 
1361  // Follow the superclass chain until we've mapped the receiver type
1362  // to the same class as the context.
1363  while (curClassDecl != dcClassDecl) {
1364  // Map to the superclass type.
1365  QualType superType = objectType->getSuperClassType();
1366  if (superType.isNull()) {
1367  objectType = nullptr;
1368  break;
1369  }
1370 
1371  objectType = superType->castAs<ObjCObjectType>();
1372  curClassDecl = objectType->getInterface();
1373  }
1374 
1375  // If we don't have a receiver type, or the receiver type does not
1376  // have type arguments, substitute in the defaults.
1377  if (!objectType || objectType->isUnspecialized()) {
1378  return llvm::ArrayRef<QualType>();
1379  }
1380 
1381  // The receiver type has the type arguments we want.
1382  return objectType->getTypeArgs();
1383 }
1384 
1385 bool Type::acceptsObjCTypeParams() const {
1386  if (auto *IfaceT = getAsObjCInterfaceType()) {
1387  if (auto *ID = IfaceT->getInterface()) {
1388  if (ID->getTypeParamList())
1389  return true;
1390  }
1391  }
1392 
1393  return false;
1394 }
1395 
1397  // Retrieve the class declaration for this type. If there isn't one
1398  // (e.g., this is some variant of "id" or "Class"), then there is no
1399  // superclass type.
1400  ObjCInterfaceDecl *classDecl = getInterface();
1401  if (!classDecl) {
1402  CachedSuperClassType.setInt(true);
1403  return;
1404  }
1405 
1406  // Extract the superclass type.
1407  const ObjCObjectType *superClassObjTy = classDecl->getSuperClassType();
1408  if (!superClassObjTy) {
1409  CachedSuperClassType.setInt(true);
1410  return;
1411  }
1412 
1413  ObjCInterfaceDecl *superClassDecl = superClassObjTy->getInterface();
1414  if (!superClassDecl) {
1415  CachedSuperClassType.setInt(true);
1416  return;
1417  }
1418 
1419  // If the superclass doesn't have type parameters, then there is no
1420  // substitution to perform.
1421  QualType superClassType(superClassObjTy, 0);
1422  ObjCTypeParamList *superClassTypeParams = superClassDecl->getTypeParamList();
1423  if (!superClassTypeParams) {
1424  CachedSuperClassType.setPointerAndInt(
1425  superClassType->castAs<ObjCObjectType>(), true);
1426  return;
1427  }
1428 
1429  // If the superclass reference is unspecialized, return it.
1430  if (superClassObjTy->isUnspecialized()) {
1431  CachedSuperClassType.setPointerAndInt(superClassObjTy, true);
1432  return;
1433  }
1434 
1435  // If the subclass is not parameterized, there aren't any type
1436  // parameters in the superclass reference to substitute.
1437  ObjCTypeParamList *typeParams = classDecl->getTypeParamList();
1438  if (!typeParams) {
1439  CachedSuperClassType.setPointerAndInt(
1440  superClassType->castAs<ObjCObjectType>(), true);
1441  return;
1442  }
1443 
1444  // If the subclass type isn't specialized, return the unspecialized
1445  // superclass.
1446  if (isUnspecialized()) {
1447  QualType unspecializedSuper
1448  = classDecl->getASTContext().getObjCInterfaceType(
1449  superClassObjTy->getInterface());
1450  CachedSuperClassType.setPointerAndInt(
1451  unspecializedSuper->castAs<ObjCObjectType>(),
1452  true);
1453  return;
1454  }
1455 
1456  // Substitute the provided type arguments into the superclass type.
1457  ArrayRef<QualType> typeArgs = getTypeArgs();
1458  assert(typeArgs.size() == typeParams->size());
1459  CachedSuperClassType.setPointerAndInt(
1460  superClassType.substObjCTypeArgs(classDecl->getASTContext(), typeArgs,
1462  ->castAs<ObjCObjectType>(),
1463  true);
1464 }
1465 
1467  if (auto interfaceDecl = getObjectType()->getInterface()) {
1468  return interfaceDecl->getASTContext().getObjCInterfaceType(interfaceDecl)
1470  }
1471 
1472  return nullptr;
1473 }
1474 
1476  QualType superObjectType = getObjectType()->getSuperClassType();
1477  if (superObjectType.isNull())
1478  return superObjectType;
1479 
1481  return ctx.getObjCObjectPointerType(superObjectType);
1482 }
1483 
1485  // There is no sugar for ObjCObjectType's, just return the canonical
1486  // type pointer if it is the right class. There is no typedef information to
1487  // return and these cannot be Address-space qualified.
1488  if (const ObjCObjectType *T = getAs<ObjCObjectType>())
1489  if (T->getNumProtocols() && T->getInterface())
1490  return T;
1491  return nullptr;
1492 }
1493 
1495  return getAsObjCQualifiedInterfaceType() != nullptr;
1496 }
1497 
1499  // There is no sugar for ObjCQualifiedIdType's, just return the canonical
1500  // type pointer if it is the right class.
1501  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) {
1502  if (OPT->isObjCQualifiedIdType())
1503  return OPT;
1504  }
1505  return nullptr;
1506 }
1507 
1509  // There is no sugar for ObjCQualifiedClassType's, just return the canonical
1510  // type pointer if it is the right class.
1511  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) {
1512  if (OPT->isObjCQualifiedClassType())
1513  return OPT;
1514  }
1515  return nullptr;
1516 }
1517 
1519  if (const ObjCObjectType *OT = getAs<ObjCObjectType>()) {
1520  if (OT->getInterface())
1521  return OT;
1522  }
1523  return nullptr;
1524 }
1526  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) {
1527  if (OPT->getInterfaceType())
1528  return OPT;
1529  }
1530  return nullptr;
1531 }
1532 
1534  QualType PointeeType;
1535  if (const PointerType *PT = getAs<PointerType>())
1536  PointeeType = PT->getPointeeType();
1537  else if (const ReferenceType *RT = getAs<ReferenceType>())
1538  PointeeType = RT->getPointeeType();
1539  else
1540  return nullptr;
1541 
1542  if (const RecordType *RT = PointeeType->getAs<RecordType>())
1543  return dyn_cast<CXXRecordDecl>(RT->getDecl());
1544 
1545  return nullptr;
1546 }
1547 
1549  return dyn_cast_or_null<CXXRecordDecl>(getAsTagDecl());
1550 }
1551 
1553  if (const auto *TT = getAs<TagType>())
1554  return cast<TagDecl>(TT->getDecl());
1555  if (const auto *Injected = getAs<InjectedClassNameType>())
1556  return Injected->getDecl();
1557 
1558  return nullptr;
1559 }
1560 
1561 namespace {
1562  class GetContainedDeducedTypeVisitor :
1563  public TypeVisitor<GetContainedDeducedTypeVisitor, Type*> {
1564  bool Syntactic;
1565  public:
1566  GetContainedDeducedTypeVisitor(bool Syntactic = false)
1567  : Syntactic(Syntactic) {}
1568 
1570  Type *Visit(QualType T) {
1571  if (T.isNull())
1572  return nullptr;
1573  return Visit(T.getTypePtr());
1574  }
1575 
1576  // The deduced type itself.
1577  Type *VisitDeducedType(const DeducedType *AT) {
1578  return const_cast<DeducedType*>(AT);
1579  }
1580 
1581  // Only these types can contain the desired 'auto' type.
1582  Type *VisitElaboratedType(const ElaboratedType *T) {
1583  return Visit(T->getNamedType());
1584  }
1585  Type *VisitPointerType(const PointerType *T) {
1586  return Visit(T->getPointeeType());
1587  }
1588  Type *VisitBlockPointerType(const BlockPointerType *T) {
1589  return Visit(T->getPointeeType());
1590  }
1591  Type *VisitReferenceType(const ReferenceType *T) {
1592  return Visit(T->getPointeeTypeAsWritten());
1593  }
1594  Type *VisitMemberPointerType(const MemberPointerType *T) {
1595  return Visit(T->getPointeeType());
1596  }
1597  Type *VisitArrayType(const ArrayType *T) {
1598  return Visit(T->getElementType());
1599  }
1600  Type *VisitDependentSizedExtVectorType(
1601  const DependentSizedExtVectorType *T) {
1602  return Visit(T->getElementType());
1603  }
1604  Type *VisitVectorType(const VectorType *T) {
1605  return Visit(T->getElementType());
1606  }
1607  Type *VisitFunctionProtoType(const FunctionProtoType *T) {
1608  if (Syntactic && T->hasTrailingReturn())
1609  return const_cast<FunctionProtoType*>(T);
1610  return VisitFunctionType(T);
1611  }
1612  Type *VisitFunctionType(const FunctionType *T) {
1613  return Visit(T->getReturnType());
1614  }
1615  Type *VisitParenType(const ParenType *T) {
1616  return Visit(T->getInnerType());
1617  }
1618  Type *VisitAttributedType(const AttributedType *T) {
1619  return Visit(T->getModifiedType());
1620  }
1621  Type *VisitAdjustedType(const AdjustedType *T) {
1622  return Visit(T->getOriginalType());
1623  }
1624  };
1625 }
1626 
1628  return cast_or_null<DeducedType>(
1629  GetContainedDeducedTypeVisitor().Visit(this));
1630 }
1631 
1633  return dyn_cast_or_null<FunctionType>(
1634  GetContainedDeducedTypeVisitor(true).Visit(this));
1635 }
1636 
1638  if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
1639  return VT->getElementType()->isIntegerType();
1640  else
1641  return isIntegerType();
1642 }
1643 
1644 /// \brief Determine whether this type is an integral type.
1645 ///
1646 /// This routine determines whether the given type is an integral type per
1647 /// C++ [basic.fundamental]p7. Although the C standard does not define the
1648 /// term "integral type", it has a similar term "integer type", and in C++
1649 /// the two terms are equivalent. However, C's "integer type" includes
1650 /// enumeration types, while C++'s "integer type" does not. The \c ASTContext
1651 /// parameter is used to determine whether we should be following the C or
1652 /// C++ rules when determining whether this type is an integral/integer type.
1653 ///
1654 /// For cases where C permits "an integer type" and C++ permits "an integral
1655 /// type", use this routine.
1656 ///
1657 /// For cases where C permits "an integer type" and C++ permits "an integral
1658 /// or enumeration type", use \c isIntegralOrEnumerationType() instead.
1659 ///
1660 /// \param Ctx The context in which this type occurs.
1661 ///
1662 /// \returns true if the type is considered an integral type, false otherwise.
1663 bool Type::isIntegralType(const ASTContext &Ctx) const {
1664  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
1665  return BT->getKind() >= BuiltinType::Bool &&
1666  BT->getKind() <= BuiltinType::Int128;
1667 
1668  // Complete enum types are integral in C.
1669  if (!Ctx.getLangOpts().CPlusPlus)
1670  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
1671  return ET->getDecl()->isComplete();
1672 
1673  return false;
1674 }
1675 
1676 
1678  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
1679  return BT->getKind() >= BuiltinType::Bool &&
1680  BT->getKind() <= BuiltinType::Int128;
1681 
1682  // Check for a complete enum type; incomplete enum types are not properly an
1683  // enumeration type in the sense required here.
1684  // C++0x: However, if the underlying type of the enum is fixed, it is
1685  // considered complete.
1686  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
1687  return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped();
1688 
1689  return false;
1690 }
1691 
1692 
1693 
1694 bool Type::isCharType() const {
1695  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
1696  return BT->getKind() == BuiltinType::Char_U ||
1697  BT->getKind() == BuiltinType::UChar ||
1698  BT->getKind() == BuiltinType::Char_S ||
1699  BT->getKind() == BuiltinType::SChar;
1700  return false;
1701 }
1702 
1703 bool Type::isWideCharType() const {
1704  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
1705  return BT->getKind() == BuiltinType::WChar_S ||
1706  BT->getKind() == BuiltinType::WChar_U;
1707  return false;
1708 }
1709 
1710 bool Type::isChar16Type() const {
1711  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
1712  return BT->getKind() == BuiltinType::Char16;
1713  return false;
1714 }
1715 
1716 bool Type::isChar32Type() const {
1717  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
1718  return BT->getKind() == BuiltinType::Char32;
1719  return false;
1720 }
1721 
1722 /// \brief Determine whether this type is any of the built-in character
1723 /// types.
1725  const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType);
1726  if (!BT) return false;
1727  switch (BT->getKind()) {
1728  default: return false;
1729  case BuiltinType::Char_U:
1730  case BuiltinType::UChar:
1731  case BuiltinType::WChar_U:
1732  case BuiltinType::Char16:
1733  case BuiltinType::Char32:
1734  case BuiltinType::Char_S:
1735  case BuiltinType::SChar:
1736  case BuiltinType::WChar_S:
1737  return true;
1738  }
1739 }
1740 
1741 /// isSignedIntegerType - Return true if this is an integer type that is
1742 /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
1743 /// an enum decl which has a signed representation
1745  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
1746  return BT->getKind() >= BuiltinType::Char_S &&
1747  BT->getKind() <= BuiltinType::Int128;
1748  }
1749 
1750  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
1751  // Incomplete enum types are not treated as integer types.
1752  // FIXME: In C++, enum types are never integer types.
1753  if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
1754  return ET->getDecl()->getIntegerType()->isSignedIntegerType();
1755  }
1756 
1757  return false;
1758 }
1759 
1761  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
1762  return BT->getKind() >= BuiltinType::Char_S &&
1763  BT->getKind() <= BuiltinType::Int128;
1764  }
1765 
1766  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
1767  if (ET->getDecl()->isComplete())
1768  return ET->getDecl()->getIntegerType()->isSignedIntegerType();
1769  }
1770 
1771  return false;
1772 }
1773 
1775  if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
1776  return VT->getElementType()->isSignedIntegerOrEnumerationType();
1777  else
1779 }
1780 
1781 /// isUnsignedIntegerType - Return true if this is an integer type that is
1782 /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
1783 /// decl which has an unsigned representation
1785  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
1786  return BT->getKind() >= BuiltinType::Bool &&
1787  BT->getKind() <= BuiltinType::UInt128;
1788  }
1789 
1790  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
1791  // Incomplete enum types are not treated as integer types.
1792  // FIXME: In C++, enum types are never integer types.
1793  if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
1794  return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
1795  }
1796 
1797  return false;
1798 }
1799 
1801  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
1802  return BT->getKind() >= BuiltinType::Bool &&
1803  BT->getKind() <= BuiltinType::UInt128;
1804  }
1805 
1806  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
1807  if (ET->getDecl()->isComplete())
1808  return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
1809  }
1810 
1811  return false;
1812 }
1813 
1815  if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
1816  return VT->getElementType()->isUnsignedIntegerOrEnumerationType();
1817  else
1819 }
1820 
1821 bool Type::isFloatingType() const {
1822  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
1823  return BT->getKind() >= BuiltinType::Half &&
1824  BT->getKind() <= BuiltinType::Float128;
1825  if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
1826  return CT->getElementType()->isFloatingType();
1827  return false;
1828 }
1829 
1831  if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
1832  return VT->getElementType()->isFloatingType();
1833  else
1834  return isFloatingType();
1835 }
1836 
1838  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
1839  return BT->isFloatingPoint();
1840  return false;
1841 }
1842 
1843 bool Type::isRealType() const {
1844  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
1845  return BT->getKind() >= BuiltinType::Bool &&
1846  BT->getKind() <= BuiltinType::Float128;
1847  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
1848  return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped();
1849  return false;
1850 }
1851 
1853  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
1854  return BT->getKind() >= BuiltinType::Bool &&
1855  BT->getKind() <= BuiltinType::Float128;
1856  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
1857  // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
1858  // If a body isn't seen by the time we get here, return false.
1859  //
1860  // C++0x: Enumerations are not arithmetic types. For now, just return
1861  // false for scoped enumerations since that will disable any
1862  // unwanted implicit conversions.
1863  return !ET->getDecl()->isScoped() && ET->getDecl()->isComplete();
1864  return isa<ComplexType>(CanonicalType);
1865 }
1866 
1868  assert(isScalarType());
1869 
1870  const Type *T = CanonicalType.getTypePtr();
1871  if (const BuiltinType *BT = dyn_cast<BuiltinType>(T)) {
1872  if (BT->getKind() == BuiltinType::Bool) return STK_Bool;
1873  if (BT->getKind() == BuiltinType::NullPtr) return STK_CPointer;
1874  if (BT->isInteger()) return STK_Integral;
1875  if (BT->isFloatingPoint()) return STK_Floating;
1876  llvm_unreachable("unknown scalar builtin type");
1877  } else if (isa<PointerType>(T)) {
1878  return STK_CPointer;
1879  } else if (isa<BlockPointerType>(T)) {
1880  return STK_BlockPointer;
1881  } else if (isa<ObjCObjectPointerType>(T)) {
1882  return STK_ObjCObjectPointer;
1883  } else if (isa<MemberPointerType>(T)) {
1884  return STK_MemberPointer;
1885  } else if (isa<EnumType>(T)) {
1886  assert(cast<EnumType>(T)->getDecl()->isComplete());
1887  return STK_Integral;
1888  } else if (const ComplexType *CT = dyn_cast<ComplexType>(T)) {
1889  if (CT->getElementType()->isRealFloatingType())
1890  return STK_FloatingComplex;
1891  return STK_IntegralComplex;
1892  }
1893 
1894  llvm_unreachable("unknown scalar type");
1895 }
1896 
1897 /// \brief Determines whether the type is a C++ aggregate type or C
1898 /// aggregate or union type.
1899 ///
1900 /// An aggregate type is an array or a class type (struct, union, or
1901 /// class) that has no user-declared constructors, no private or
1902 /// protected non-static data members, no base classes, and no virtual
1903 /// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type
1904 /// subsumes the notion of C aggregates (C99 6.2.5p21) because it also
1905 /// includes union types.
1907  if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) {
1908  if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl()))
1909  return ClassDecl->isAggregate();
1910 
1911  return true;
1912  }
1913 
1914  return isa<ArrayType>(CanonicalType);
1915 }
1916 
1917 /// isConstantSizeType - Return true if this is not a variable sized type,
1918 /// according to the rules of C99 6.7.5p3. It is not legal to call this on
1919 /// incomplete types or dependent types.
1921  assert(!isIncompleteType() && "This doesn't make sense for incomplete types");
1922  assert(!isDependentType() && "This doesn't make sense for dependent types");
1923  // The VAT must have a size, as it is known to be complete.
1924  return !isa<VariableArrayType>(CanonicalType);
1925 }
1926 
1927 /// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1)
1928 /// - a type that can describe objects, but which lacks information needed to
1929 /// determine its size.
1931  if (Def)
1932  *Def = nullptr;
1933 
1934  switch (CanonicalType->getTypeClass()) {
1935  default: return false;
1936  case Builtin:
1937  // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never
1938  // be completed.
1939  return isVoidType();
1940  case Enum: {
1941  EnumDecl *EnumD = cast<EnumType>(CanonicalType)->getDecl();
1942  if (Def)
1943  *Def = EnumD;
1944 
1945  // An enumeration with fixed underlying type is complete (C++0x 7.2p3).
1946  if (EnumD->isFixed())
1947  return false;
1948 
1949  return !EnumD->isCompleteDefinition();
1950  }
1951  case Record: {
1952  // A tagged type (struct/union/enum/class) is incomplete if the decl is a
1953  // forward declaration, but not a full definition (C99 6.2.5p22).
1954  RecordDecl *Rec = cast<RecordType>(CanonicalType)->getDecl();
1955  if (Def)
1956  *Def = Rec;
1957  return !Rec->isCompleteDefinition();
1958  }
1959  case ConstantArray:
1960  // An array is incomplete if its element type is incomplete
1961  // (C++ [dcl.array]p1).
1962  // We don't handle variable arrays (they're not allowed in C++) or
1963  // dependent-sized arrays (dependent types are never treated as incomplete).
1964  return cast<ArrayType>(CanonicalType)->getElementType()
1965  ->isIncompleteType(Def);
1966  case IncompleteArray:
1967  // An array of unknown size is an incomplete type (C99 6.2.5p22).
1968  return true;
1969  case MemberPointer: {
1970  // Member pointers in the MS ABI have special behavior in
1971  // RequireCompleteType: they attach a MSInheritanceAttr to the CXXRecordDecl
1972  // to indicate which inheritance model to use.
1973  auto *MPTy = cast<MemberPointerType>(CanonicalType);
1974  const Type *ClassTy = MPTy->getClass();
1975  // Member pointers with dependent class types don't get special treatment.
1976  if (ClassTy->isDependentType())
1977  return false;
1978  const CXXRecordDecl *RD = ClassTy->getAsCXXRecordDecl();
1979  ASTContext &Context = RD->getASTContext();
1980  // Member pointers not in the MS ABI don't get special treatment.
1981  if (!Context.getTargetInfo().getCXXABI().isMicrosoft())
1982  return false;
1983  // The inheritance attribute might only be present on the most recent
1984  // CXXRecordDecl, use that one.
1985  RD = RD->getMostRecentDecl();
1986  // Nothing interesting to do if the inheritance attribute is already set.
1987  if (RD->hasAttr<MSInheritanceAttr>())
1988  return false;
1989  return true;
1990  }
1991  case ObjCObject:
1992  return cast<ObjCObjectType>(CanonicalType)->getBaseType()
1993  ->isIncompleteType(Def);
1994  case ObjCInterface: {
1995  // ObjC interfaces are incomplete if they are @class, not @interface.
1996  ObjCInterfaceDecl *Interface
1997  = cast<ObjCInterfaceType>(CanonicalType)->getDecl();
1998  if (Def)
1999  *Def = Interface;
2000  return !Interface->hasDefinition();
2001  }
2002  }
2003 }
2004 
2005 bool QualType::isPODType(const ASTContext &Context) const {
2006  // C++11 has a more relaxed definition of POD.
2007  if (Context.getLangOpts().CPlusPlus11)
2008  return isCXX11PODType(Context);
2009 
2010  return isCXX98PODType(Context);
2011 }
2012 
2013 bool QualType::isCXX98PODType(const ASTContext &Context) const {
2014  // The compiler shouldn't query this for incomplete types, but the user might.
2015  // We return false for that case. Except for incomplete arrays of PODs, which
2016  // are PODs according to the standard.
2017  if (isNull())
2018  return 0;
2019 
2020  if ((*this)->isIncompleteArrayType())
2021  return Context.getBaseElementType(*this).isCXX98PODType(Context);
2022 
2023  if ((*this)->isIncompleteType())
2024  return false;
2025 
2027  return false;
2028 
2029  QualType CanonicalType = getTypePtr()->CanonicalType;
2030  switch (CanonicalType->getTypeClass()) {
2031  // Everything not explicitly mentioned is not POD.
2032  default: return false;
2033  case Type::VariableArray:
2034  case Type::ConstantArray:
2035  // IncompleteArray is handled above.
2036  return Context.getBaseElementType(*this).isCXX98PODType(Context);
2037 
2038  case Type::ObjCObjectPointer:
2039  case Type::BlockPointer:
2040  case Type::Builtin:
2041  case Type::Complex:
2042  case Type::Pointer:
2043  case Type::MemberPointer:
2044  case Type::Vector:
2045  case Type::ExtVector:
2046  return true;
2047 
2048  case Type::Enum:
2049  return true;
2050 
2051  case Type::Record:
2052  if (CXXRecordDecl *ClassDecl
2053  = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl()))
2054  return ClassDecl->isPOD();
2055 
2056  // C struct/union is POD.
2057  return true;
2058  }
2059 }
2060 
2061 bool QualType::isTrivialType(const ASTContext &Context) const {
2062  // The compiler shouldn't query this for incomplete types, but the user might.
2063  // We return false for that case. Except for incomplete arrays of PODs, which
2064  // are PODs according to the standard.
2065  if (isNull())
2066  return 0;
2067 
2068  if ((*this)->isArrayType())
2069  return Context.getBaseElementType(*this).isTrivialType(Context);
2070 
2071  // Return false for incomplete types after skipping any incomplete array
2072  // types which are expressly allowed by the standard and thus our API.
2073  if ((*this)->isIncompleteType())
2074  return false;
2075 
2077  return false;
2078 
2079  QualType CanonicalType = getTypePtr()->CanonicalType;
2080  if (CanonicalType->isDependentType())
2081  return false;
2082 
2083  // C++0x [basic.types]p9:
2084  // Scalar types, trivial class types, arrays of such types, and
2085  // cv-qualified versions of these types are collectively called trivial
2086  // types.
2087 
2088  // As an extension, Clang treats vector types as Scalar types.
2089  if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
2090  return true;
2091  if (const RecordType *RT = CanonicalType->getAs<RecordType>()) {
2092  if (const CXXRecordDecl *ClassDecl =
2093  dyn_cast<CXXRecordDecl>(RT->getDecl())) {
2094  // C++11 [class]p6:
2095  // A trivial class is a class that has a default constructor,
2096  // has no non-trivial default constructors, and is trivially
2097  // copyable.
2098  return ClassDecl->hasDefaultConstructor() &&
2099  !ClassDecl->hasNonTrivialDefaultConstructor() &&
2100  ClassDecl->isTriviallyCopyable();
2101  }
2102 
2103  return true;
2104  }
2105 
2106  // No other types can match.
2107  return false;
2108 }
2109 
2110 bool QualType::isTriviallyCopyableType(const ASTContext &Context) const {
2111  if ((*this)->isArrayType())
2112  return Context.getBaseElementType(*this).isTriviallyCopyableType(Context);
2113 
2115  return false;
2116 
2117  // C++11 [basic.types]p9 - See Core 2094
2118  // Scalar types, trivially copyable class types, arrays of such types, and
2119  // cv-qualified versions of these types are collectively
2120  // called trivially copyable types.
2121 
2122  QualType CanonicalType = getCanonicalType();
2123  if (CanonicalType->isDependentType())
2124  return false;
2125 
2126  // Return false for incomplete types after skipping any incomplete array types
2127  // which are expressly allowed by the standard and thus our API.
2128  if (CanonicalType->isIncompleteType())
2129  return false;
2130 
2131  // As an extension, Clang treats vector types as Scalar types.
2132  if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
2133  return true;
2134 
2135  if (const RecordType *RT = CanonicalType->getAs<RecordType>()) {
2136  if (const CXXRecordDecl *ClassDecl =
2137  dyn_cast<CXXRecordDecl>(RT->getDecl())) {
2138  if (!ClassDecl->isTriviallyCopyable()) return false;
2139  }
2140 
2141  return true;
2142  }
2143 
2144  // No other types can match.
2145  return false;
2146 }
2147 
2149  return !Context.getLangOpts().ObjCAutoRefCount &&
2150  Context.getLangOpts().ObjCWeak &&
2152 }
2153 
2154 bool Type::isLiteralType(const ASTContext &Ctx) const {
2155  if (isDependentType())
2156  return false;
2157 
2158  // C++1y [basic.types]p10:
2159  // A type is a literal type if it is:
2160  // -- cv void; or
2161  if (Ctx.getLangOpts().CPlusPlus14 && isVoidType())
2162  return true;
2163 
2164  // C++11 [basic.types]p10:
2165  // A type is a literal type if it is:
2166  // [...]
2167  // -- an array of literal type other than an array of runtime bound; or
2168  if (isVariableArrayType())
2169  return false;
2170  const Type *BaseTy = getBaseElementTypeUnsafe();
2171  assert(BaseTy && "NULL element type");
2172 
2173  // Return false for incomplete types after skipping any incomplete array
2174  // types; those are expressly allowed by the standard and thus our API.
2175  if (BaseTy->isIncompleteType())
2176  return false;
2177 
2178  // C++11 [basic.types]p10:
2179  // A type is a literal type if it is:
2180  // -- a scalar type; or
2181  // As an extension, Clang treats vector types and complex types as
2182  // literal types.
2183  if (BaseTy->isScalarType() || BaseTy->isVectorType() ||
2184  BaseTy->isAnyComplexType())
2185  return true;
2186  // -- a reference type; or
2187  if (BaseTy->isReferenceType())
2188  return true;
2189  // -- a class type that has all of the following properties:
2190  if (const RecordType *RT = BaseTy->getAs<RecordType>()) {
2191  // -- a trivial destructor,
2192  // -- every constructor call and full-expression in the
2193  // brace-or-equal-initializers for non-static data members (if any)
2194  // is a constant expression,
2195  // -- it is an aggregate type or has at least one constexpr
2196  // constructor or constructor template that is not a copy or move
2197  // constructor, and
2198  // -- all non-static data members and base classes of literal types
2199  //
2200  // We resolve DR1361 by ignoring the second bullet.
2201  if (const CXXRecordDecl *ClassDecl =
2202  dyn_cast<CXXRecordDecl>(RT->getDecl()))
2203  return ClassDecl->isLiteral();
2204 
2205  return true;
2206  }
2207 
2208  // We treat _Atomic T as a literal type if T is a literal type.
2209  if (const AtomicType *AT = BaseTy->getAs<AtomicType>())
2210  return AT->getValueType()->isLiteralType(Ctx);
2211 
2212  // If this type hasn't been deduced yet, then conservatively assume that
2213  // it'll work out to be a literal type.
2214  if (isa<AutoType>(BaseTy->getCanonicalTypeInternal()))
2215  return true;
2216 
2217  return false;
2218 }
2219 
2221  if (isDependentType())
2222  return false;
2223 
2224  // C++0x [basic.types]p9:
2225  // Scalar types, standard-layout class types, arrays of such types, and
2226  // cv-qualified versions of these types are collectively called
2227  // standard-layout types.
2228  const Type *BaseTy = getBaseElementTypeUnsafe();
2229  assert(BaseTy && "NULL element type");
2230 
2231  // Return false for incomplete types after skipping any incomplete array
2232  // types which are expressly allowed by the standard and thus our API.
2233  if (BaseTy->isIncompleteType())
2234  return false;
2235 
2236  // As an extension, Clang treats vector types as Scalar types.
2237  if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true;
2238  if (const RecordType *RT = BaseTy->getAs<RecordType>()) {
2239  if (const CXXRecordDecl *ClassDecl =
2240  dyn_cast<CXXRecordDecl>(RT->getDecl()))
2241  if (!ClassDecl->isStandardLayout())
2242  return false;
2243 
2244  // Default to 'true' for non-C++ class types.
2245  // FIXME: This is a bit dubious, but plain C structs should trivially meet
2246  // all the requirements of standard layout classes.
2247  return true;
2248  }
2249 
2250  // No other types can match.
2251  return false;
2252 }
2253 
2254 // This is effectively the intersection of isTrivialType and
2255 // isStandardLayoutType. We implement it directly to avoid redundant
2256 // conversions from a type to a CXXRecordDecl.
2257 bool QualType::isCXX11PODType(const ASTContext &Context) const {
2258  const Type *ty = getTypePtr();
2259  if (ty->isDependentType())
2260  return false;
2261 
2263  return false;
2264 
2265  // C++11 [basic.types]p9:
2266  // Scalar types, POD classes, arrays of such types, and cv-qualified
2267  // versions of these types are collectively called trivial types.
2268  const Type *BaseTy = ty->getBaseElementTypeUnsafe();
2269  assert(BaseTy && "NULL element type");
2270 
2271  // Return false for incomplete types after skipping any incomplete array
2272  // types which are expressly allowed by the standard and thus our API.
2273  if (BaseTy->isIncompleteType())
2274  return false;
2275 
2276  // As an extension, Clang treats vector types as Scalar types.
2277  if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true;
2278  if (const RecordType *RT = BaseTy->getAs<RecordType>()) {
2279  if (const CXXRecordDecl *ClassDecl =
2280  dyn_cast<CXXRecordDecl>(RT->getDecl())) {
2281  // C++11 [class]p10:
2282  // A POD struct is a non-union class that is both a trivial class [...]
2283  if (!ClassDecl->isTrivial()) return false;
2284 
2285  // C++11 [class]p10:
2286  // A POD struct is a non-union class that is both a trivial class and
2287  // a standard-layout class [...]
2288  if (!ClassDecl->isStandardLayout()) return false;
2289 
2290  // C++11 [class]p10:
2291  // A POD struct is a non-union class that is both a trivial class and
2292  // a standard-layout class, and has no non-static data members of type
2293  // non-POD struct, non-POD union (or array of such types). [...]
2294  //
2295  // We don't directly query the recursive aspect as the requirements for
2296  // both standard-layout classes and trivial classes apply recursively
2297  // already.
2298  }
2299 
2300  return true;
2301  }
2302 
2303  // No other types can match.
2304  return false;
2305 }
2306 
2307 bool Type::isAlignValT() const {
2308  if (auto *ET = getAs<EnumType>()) {
2309  auto *II = ET->getDecl()->getIdentifier();
2310  if (II && II->isStr("align_val_t") && ET->getDecl()->isInStdNamespace())
2311  return true;
2312  }
2313  return false;
2314 }
2315 
2316 bool Type::isStdByteType() const {
2317  if (auto *ET = getAs<EnumType>()) {
2318  auto *II = ET->getDecl()->getIdentifier();
2319  if (II && II->isStr("byte") && ET->getDecl()->isInStdNamespace())
2320  return true;
2321  }
2322  return false;
2323 }
2324 
2326  if (const BuiltinType *BT = getAs<BuiltinType>())
2327  switch (BT->getKind()) {
2328  case BuiltinType::Bool:
2329  case BuiltinType::Char_S:
2330  case BuiltinType::Char_U:
2331  case BuiltinType::SChar:
2332  case BuiltinType::UChar:
2333  case BuiltinType::Short:
2334  case BuiltinType::UShort:
2335  case BuiltinType::WChar_S:
2336  case BuiltinType::WChar_U:
2337  case BuiltinType::Char16:
2338  case BuiltinType::Char32:
2339  return true;
2340  default:
2341  return false;
2342  }
2343 
2344  // Enumerated types are promotable to their compatible integer types
2345  // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2).
2346  if (const EnumType *ET = getAs<EnumType>()){
2347  if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull()
2348  || ET->getDecl()->isScoped())
2349  return false;
2350 
2351  return true;
2352  }
2353 
2354  return false;
2355 }
2356 
2358  // Note that this intentionally does not use the canonical type.
2359  switch (getTypeClass()) {
2360  case Builtin:
2361  case Record:
2362  case Enum:
2363  case Typedef:
2364  case Complex:
2365  case TypeOfExpr:
2366  case TypeOf:
2367  case TemplateTypeParm:
2368  case SubstTemplateTypeParm:
2369  case TemplateSpecialization:
2370  case Elaborated:
2371  case DependentName:
2372  case DependentTemplateSpecialization:
2373  case ObjCInterface:
2374  case ObjCObject:
2375  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
2376  return true;
2377  default:
2378  return false;
2379  }
2380 }
2381 
2384  switch (TypeSpec) {
2385  default: return ETK_None;
2386  case TST_typename: return ETK_Typename;
2387  case TST_class: return ETK_Class;
2388  case TST_struct: return ETK_Struct;
2389  case TST_interface: return ETK_Interface;
2390  case TST_union: return ETK_Union;
2391  case TST_enum: return ETK_Enum;
2392  }
2393 }
2394 
2397  switch(TypeSpec) {
2398  case TST_class: return TTK_Class;
2399  case TST_struct: return TTK_Struct;
2400  case TST_interface: return TTK_Interface;
2401  case TST_union: return TTK_Union;
2402  case TST_enum: return TTK_Enum;
2403  }
2404 
2405  llvm_unreachable("Type specifier is not a tag type kind.");
2406 }
2407 
2410  switch (Kind) {
2411  case TTK_Class: return ETK_Class;
2412  case TTK_Struct: return ETK_Struct;
2413  case TTK_Interface: return ETK_Interface;
2414  case TTK_Union: return ETK_Union;
2415  case TTK_Enum: return ETK_Enum;
2416  }
2417  llvm_unreachable("Unknown tag type kind.");
2418 }
2419 
2422  switch (Keyword) {
2423  case ETK_Class: return TTK_Class;
2424  case ETK_Struct: return TTK_Struct;
2425  case ETK_Interface: return TTK_Interface;
2426  case ETK_Union: return TTK_Union;
2427  case ETK_Enum: return TTK_Enum;
2428  case ETK_None: // Fall through.
2429  case ETK_Typename:
2430  llvm_unreachable("Elaborated type keyword is not a tag type kind.");
2431  }
2432  llvm_unreachable("Unknown elaborated type keyword.");
2433 }
2434 
2435 bool
2437  switch (Keyword) {
2438  case ETK_None:
2439  case ETK_Typename:
2440  return false;
2441  case ETK_Class:
2442  case ETK_Struct:
2443  case ETK_Interface:
2444  case ETK_Union:
2445  case ETK_Enum:
2446  return true;
2447  }
2448  llvm_unreachable("Unknown elaborated type keyword.");
2449 }
2450 
2452  switch (Keyword) {
2453  case ETK_None: return "";
2454  case ETK_Typename: return "typename";
2455  case ETK_Class: return "class";
2456  case ETK_Struct: return "struct";
2457  case ETK_Interface: return "__interface";
2458  case ETK_Union: return "union";
2459  case ETK_Enum: return "enum";
2460  }
2461 
2462  llvm_unreachable("Unknown elaborated type keyword.");
2463 }
2464 
2465 DependentTemplateSpecializationType::DependentTemplateSpecializationType(
2466  ElaboratedTypeKeyword Keyword,
2469  QualType Canon)
2470  : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true, true,
2471  /*VariablyModified=*/false,
2472  NNS && NNS->containsUnexpandedParameterPack()),
2473  NNS(NNS), Name(Name), NumArgs(Args.size()) {
2474  assert((!NNS || NNS->isDependent()) &&
2475  "DependentTemplateSpecializatonType requires dependent qualifier");
2476  TemplateArgument *ArgBuffer = getArgBuffer();
2477  for (const TemplateArgument &Arg : Args) {
2478  if (Arg.containsUnexpandedParameterPack())
2480 
2481  new (ArgBuffer++) TemplateArgument(Arg);
2482  }
2483 }
2484 
2485 void
2487  const ASTContext &Context,
2488  ElaboratedTypeKeyword Keyword,
2489  NestedNameSpecifier *Qualifier,
2490  const IdentifierInfo *Name,
2492  ID.AddInteger(Keyword);
2493  ID.AddPointer(Qualifier);
2494  ID.AddPointer(Name);
2495  for (const TemplateArgument &Arg : Args)
2496  Arg.Profile(ID, Context);
2497 }
2498 
2500  ElaboratedTypeKeyword Keyword;
2501  if (const ElaboratedType *Elab = dyn_cast<ElaboratedType>(this))
2502  Keyword = Elab->getKeyword();
2503  else if (const DependentNameType *DepName = dyn_cast<DependentNameType>(this))
2504  Keyword = DepName->getKeyword();
2505  else if (const DependentTemplateSpecializationType *DepTST =
2506  dyn_cast<DependentTemplateSpecializationType>(this))
2507  Keyword = DepTST->getKeyword();
2508  else
2509  return false;
2510 
2511  return TypeWithKeyword::KeywordIsTagTypeKind(Keyword);
2512 }
2513 
2514 const char *Type::getTypeClassName() const {
2515  switch (TypeBits.TC) {
2516 #define ABSTRACT_TYPE(Derived, Base)
2517 #define TYPE(Derived, Base) case Derived: return #Derived;
2518 #include "clang/AST/TypeNodes.def"
2519  }
2520 
2521  llvm_unreachable("Invalid type class.");
2522 }
2523 
2524 StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
2525  switch (getKind()) {
2526  case Void:
2527  return "void";
2528  case Bool:
2529  return Policy.Bool ? "bool" : "_Bool";
2530  case Char_S:
2531  return "char";
2532  case Char_U:
2533  return "char";
2534  case SChar:
2535  return "signed char";
2536  case Short:
2537  return "short";
2538  case Int:
2539  return "int";
2540  case Long:
2541  return "long";
2542  case LongLong:
2543  return "long long";
2544  case Int128:
2545  return "__int128";
2546  case UChar:
2547  return "unsigned char";
2548  case UShort:
2549  return "unsigned short";
2550  case UInt:
2551  return "unsigned int";
2552  case ULong:
2553  return "unsigned long";
2554  case ULongLong:
2555  return "unsigned long long";
2556  case UInt128:
2557  return "unsigned __int128";
2558  case Half:
2559  return Policy.Half ? "half" : "__fp16";
2560  case Float:
2561  return "float";
2562  case Double:
2563  return "double";
2564  case LongDouble:
2565  return "long double";
2566  case Float128:
2567  return "__float128";
2568  case WChar_S:
2569  case WChar_U:
2570  return Policy.MSWChar ? "__wchar_t" : "wchar_t";
2571  case Char16:
2572  return "char16_t";
2573  case Char32:
2574  return "char32_t";
2575  case NullPtr:
2576  return "nullptr_t";
2577  case Overload:
2578  return "<overloaded function type>";
2579  case BoundMember:
2580  return "<bound member function type>";
2581  case PseudoObject:
2582  return "<pseudo-object type>";
2583  case Dependent:
2584  return "<dependent type>";
2585  case UnknownAny:
2586  return "<unknown type>";
2587  case ARCUnbridgedCast:
2588  return "<ARC unbridged cast type>";
2589  case BuiltinFn:
2590  return "<builtin fn type>";
2591  case ObjCId:
2592  return "id";
2593  case ObjCClass:
2594  return "Class";
2595  case ObjCSel:
2596  return "SEL";
2597 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2598  case Id: \
2599  return "__" #Access " " #ImgType "_t";
2600 #include "clang/Basic/OpenCLImageTypes.def"
2601  case OCLSampler:
2602  return "sampler_t";
2603  case OCLEvent:
2604  return "event_t";
2605  case OCLClkEvent:
2606  return "clk_event_t";
2607  case OCLQueue:
2608  return "queue_t";
2609  case OCLReserveID:
2610  return "reserve_id_t";
2611  case OMPArraySection:
2612  return "<OpenMP array section type>";
2613  }
2614 
2615  llvm_unreachable("Invalid builtin type.");
2616 }
2617 
2619  if (const ReferenceType *RefType = getTypePtr()->getAs<ReferenceType>())
2620  return RefType->getPointeeType();
2621 
2622  // C++0x [basic.lval]:
2623  // Class prvalues can have cv-qualified types; non-class prvalues always
2624  // have cv-unqualified types.
2625  //
2626  // See also C99 6.3.2.1p2.
2627  if (!Context.getLangOpts().CPlusPlus ||
2629  return getUnqualifiedType();
2630 
2631  return *this;
2632 }
2633 
2635  switch (CC) {
2636  case CC_C: return "cdecl";
2637  case CC_X86StdCall: return "stdcall";
2638  case CC_X86FastCall: return "fastcall";
2639  case CC_X86ThisCall: return "thiscall";
2640  case CC_X86Pascal: return "pascal";
2641  case CC_X86VectorCall: return "vectorcall";
2642  case CC_Win64: return "ms_abi";
2643  case CC_X86_64SysV: return "sysv_abi";
2644  case CC_X86RegCall : return "regcall";
2645  case CC_AAPCS: return "aapcs";
2646  case CC_AAPCS_VFP: return "aapcs-vfp";
2647  case CC_IntelOclBicc: return "intel_ocl_bicc";
2648  case CC_SpirFunction: return "spir_function";
2649  case CC_OpenCLKernel: return "opencl_kernel";
2650  case CC_Swift: return "swiftcall";
2651  case CC_PreserveMost: return "preserve_most";
2652  case CC_PreserveAll: return "preserve_all";
2653  }
2654 
2655  llvm_unreachable("Invalid calling convention.");
2656 }
2657 
2658 FunctionProtoType::FunctionProtoType(QualType result, ArrayRef<QualType> params,
2659  QualType canonical,
2660  const ExtProtoInfo &epi)
2661  : FunctionType(FunctionProto, result, canonical,
2662  result->isDependentType(),
2663  result->isInstantiationDependentType(),
2664  result->isVariablyModifiedType(),
2665  result->containsUnexpandedParameterPack(), epi.ExtInfo),
2666  NumParams(params.size()),
2667  NumExceptions(epi.ExceptionSpec.Exceptions.size()),
2668  ExceptionSpecType(epi.ExceptionSpec.Type),
2669  HasExtParameterInfos(epi.ExtParameterInfos != nullptr),
2670  Variadic(epi.Variadic), HasTrailingReturn(epi.HasTrailingReturn) {
2671  assert(NumParams == params.size() && "function has too many parameters");
2672 
2673  FunctionTypeBits.TypeQuals = epi.TypeQuals;
2674  FunctionTypeBits.RefQualifier = epi.RefQualifier;
2675 
2676  // Fill in the trailing argument array.
2677  QualType *argSlot = reinterpret_cast<QualType*>(this+1);
2678  for (unsigned i = 0; i != NumParams; ++i) {
2679  if (params[i]->isDependentType())
2680  setDependent();
2681  else if (params[i]->isInstantiationDependentType())
2683 
2684  if (params[i]->containsUnexpandedParameterPack())
2686 
2687  argSlot[i] = params[i];
2688  }
2689 
2690  if (getExceptionSpecType() == EST_Dynamic) {
2691  // Fill in the exception array.
2692  QualType *exnSlot = argSlot + NumParams;
2693  unsigned I = 0;
2694  for (QualType ExceptionType : epi.ExceptionSpec.Exceptions) {
2695  // Note that, before C++17, a dependent exception specification does
2696  // *not* make a type dependent; it's not even part of the C++ type
2697  // system.
2698  if (ExceptionType->isInstantiationDependentType())
2700 
2701  if (ExceptionType->containsUnexpandedParameterPack())
2703 
2704  exnSlot[I++] = ExceptionType;
2705  }
2706  } else if (getExceptionSpecType() == EST_ComputedNoexcept) {
2707  // Store the noexcept expression and context.
2708  Expr **noexSlot = reinterpret_cast<Expr **>(argSlot + NumParams);
2709  *noexSlot = epi.ExceptionSpec.NoexceptExpr;
2710 
2711  if (epi.ExceptionSpec.NoexceptExpr) {
2712  if (epi.ExceptionSpec.NoexceptExpr->isValueDependent() ||
2713  epi.ExceptionSpec.NoexceptExpr->isInstantiationDependent())
2715 
2716  if (epi.ExceptionSpec.NoexceptExpr->containsUnexpandedParameterPack())
2718  }
2719  } else if (getExceptionSpecType() == EST_Uninstantiated) {
2720  // Store the function decl from which we will resolve our
2721  // exception specification.
2722  FunctionDecl **slot =
2723  reinterpret_cast<FunctionDecl **>(argSlot + NumParams);
2724  slot[0] = epi.ExceptionSpec.SourceDecl;
2725  slot[1] = epi.ExceptionSpec.SourceTemplate;
2726  // This exception specification doesn't make the type dependent, because
2727  // it's not instantiated as part of instantiating the type.
2728  } else if (getExceptionSpecType() == EST_Unevaluated) {
2729  // Store the function decl from which we will resolve our
2730  // exception specification.
2731  FunctionDecl **slot =
2732  reinterpret_cast<FunctionDecl **>(argSlot + NumParams);
2733  slot[0] = epi.ExceptionSpec.SourceDecl;
2734  }
2735 
2736  // If this is a canonical type, and its exception specification is dependent,
2737  // then it's a dependent type. This only happens in C++17 onwards.
2738  if (isCanonicalUnqualified()) {
2739  if (getExceptionSpecType() == EST_Dynamic ||
2740  getExceptionSpecType() == EST_ComputedNoexcept) {
2741  assert(hasDependentExceptionSpec() && "type should not be canonical");
2742  setDependent();
2743  }
2744  } else if (getCanonicalTypeInternal()->isDependentType()) {
2745  // Ask our canonical type whether our exception specification was dependent.
2746  setDependent();
2747  }
2748 
2749  if (epi.ExtParameterInfos) {
2750  ExtParameterInfo *extParamInfos =
2751  const_cast<ExtParameterInfo *>(getExtParameterInfosBuffer());
2752  for (unsigned i = 0; i != NumParams; ++i)
2753  extParamInfos[i] = epi.ExtParameterInfos[i];
2754  }
2755 }
2756 
2758  if (Expr *NE = getNoexceptExpr())
2759  return NE->isValueDependent();
2760  for (QualType ET : exceptions())
2761  // A pack expansion with a non-dependent pattern is still dependent,
2762  // because we don't know whether the pattern is in the exception spec
2763  // or not (that depends on whether the pack has 0 expansions).
2764  if (ET->isDependentType() || ET->getAs<PackExpansionType>())
2765  return true;
2766  return false;
2767 }
2768 
2770  if (Expr *NE = getNoexceptExpr())
2771  return NE->isInstantiationDependent();
2772  for (QualType ET : exceptions())
2773  if (ET->isInstantiationDependentType())
2774  return true;
2775  return false;
2776 }
2777 
2781  if (est == EST_BasicNoexcept)
2782  return NR_Nothrow;
2783 
2784  if (est != EST_ComputedNoexcept)
2785  return NR_NoNoexcept;
2786 
2787  Expr *noexceptExpr = getNoexceptExpr();
2788  if (!noexceptExpr)
2789  return NR_BadNoexcept;
2790  if (noexceptExpr->isValueDependent())
2791  return NR_Dependent;
2792 
2793  llvm::APSInt value;
2794  bool isICE = noexceptExpr->isIntegerConstantExpr(value, ctx, nullptr,
2795  /*evaluated*/false);
2796  (void)isICE;
2797  assert(isICE && "AST should not contain bad noexcept expressions.");
2798 
2799  return value.getBoolValue() ? NR_Nothrow : NR_Throw;
2800 }
2801 
2804  assert(EST != EST_Unevaluated && EST != EST_Uninstantiated);
2805  if (EST == EST_DynamicNone || EST == EST_BasicNoexcept)
2806  return CT_Cannot;
2807 
2808  if (EST == EST_Dynamic) {
2809  // A dynamic exception specification is throwing unless every exception
2810  // type is an (unexpanded) pack expansion type.
2811  for (unsigned I = 0, N = NumExceptions; I != N; ++I)
2812  if (!getExceptionType(I)->getAs<PackExpansionType>())
2813  return CT_Can;
2814  return CT_Dependent;
2815  }
2816 
2817  if (EST != EST_ComputedNoexcept)
2818  return CT_Can;
2819 
2820  NoexceptResult NR = getNoexceptSpec(Ctx);
2821  if (NR == NR_Dependent)
2822  return CT_Dependent;
2823  return NR == NR_Nothrow ? CT_Cannot : CT_Can;
2824 }
2825 
2827  for (unsigned ArgIdx = getNumParams(); ArgIdx; --ArgIdx)
2828  if (isa<PackExpansionType>(getParamType(ArgIdx - 1)))
2829  return true;
2830 
2831  return false;
2832 }
2833 
2834 void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result,
2835  const QualType *ArgTys, unsigned NumParams,
2836  const ExtProtoInfo &epi,
2837  const ASTContext &Context, bool Canonical) {
2838 
2839  // We have to be careful not to get ambiguous profile encodings.
2840  // Note that valid type pointers are never ambiguous with anything else.
2841  //
2842  // The encoding grammar begins:
2843  // type type* bool int bool
2844  // If that final bool is true, then there is a section for the EH spec:
2845  // bool type*
2846  // This is followed by an optional "consumed argument" section of the
2847  // same length as the first type sequence:
2848  // bool*
2849  // Finally, we have the ext info and trailing return type flag:
2850  // int bool
2851  //
2852  // There is no ambiguity between the consumed arguments and an empty EH
2853  // spec because of the leading 'bool' which unambiguously indicates
2854  // whether the following bool is the EH spec or part of the arguments.
2855 
2856  ID.AddPointer(Result.getAsOpaquePtr());
2857  for (unsigned i = 0; i != NumParams; ++i)
2858  ID.AddPointer(ArgTys[i].getAsOpaquePtr());
2859  // This method is relatively performance sensitive, so as a performance
2860  // shortcut, use one AddInteger call instead of four for the next four
2861  // fields.
2862  assert(!(unsigned(epi.Variadic) & ~1) &&
2863  !(unsigned(epi.TypeQuals) & ~255) &&
2864  !(unsigned(epi.RefQualifier) & ~3) &&
2865  !(unsigned(epi.ExceptionSpec.Type) & ~15) &&
2866  "Values larger than expected.");
2867  ID.AddInteger(unsigned(epi.Variadic) +
2868  (epi.TypeQuals << 1) +
2869  (epi.RefQualifier << 9) +
2870  (epi.ExceptionSpec.Type << 11));
2871  if (epi.ExceptionSpec.Type == EST_Dynamic) {
2872  for (QualType Ex : epi.ExceptionSpec.Exceptions)
2873  ID.AddPointer(Ex.getAsOpaquePtr());
2874  } else if (epi.ExceptionSpec.Type == EST_ComputedNoexcept &&
2875  epi.ExceptionSpec.NoexceptExpr) {
2876  epi.ExceptionSpec.NoexceptExpr->Profile(ID, Context, Canonical);
2877  } else if (epi.ExceptionSpec.Type == EST_Uninstantiated ||
2878  epi.ExceptionSpec.Type == EST_Unevaluated) {
2879  ID.AddPointer(epi.ExceptionSpec.SourceDecl->getCanonicalDecl());
2880  }
2881  if (epi.ExtParameterInfos) {
2882  for (unsigned i = 0; i != NumParams; ++i)
2883  ID.AddInteger(epi.ExtParameterInfos[i].getOpaqueValue());
2884  }
2885  epi.ExtInfo.Profile(ID);
2886  ID.AddBoolean(epi.HasTrailingReturn);
2887 }
2888 
2889 void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID,
2890  const ASTContext &Ctx) {
2891  Profile(ID, getReturnType(), param_type_begin(), NumParams, getExtProtoInfo(),
2892  Ctx, isCanonicalUnqualified());
2893 }
2894 
2896  return getDecl()->getUnderlyingType();
2897 }
2898 
2900  : Type(TypeOfExpr, can, E->isTypeDependent(),
2901  E->isInstantiationDependent(),
2902  E->getType()->isVariablyModifiedType(),
2903  E->containsUnexpandedParameterPack()),
2904  TOExpr(E) {
2905 }
2906 
2908  return !TOExpr->isTypeDependent();
2909 }
2910 
2912  if (isSugared())
2913  return getUnderlyingExpr()->getType();
2914 
2915  return QualType(this, 0);
2916 }
2917 
2918 void DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID,
2919  const ASTContext &Context, Expr *E) {
2920  E->Profile(ID, Context, true);
2921 }
2922 
2924  // C++11 [temp.type]p2: "If an expression e involves a template parameter,
2925  // decltype(e) denotes a unique dependent type." Hence a decltype type is
2926  // type-dependent even if its expression is only instantiation-dependent.
2927  : Type(Decltype, can, E->isInstantiationDependent(),
2928  E->isInstantiationDependent(),
2929  E->getType()->isVariablyModifiedType(),
2930  E->containsUnexpandedParameterPack()),
2931  E(E),
2932  UnderlyingType(underlyingType) {
2933 }
2934 
2936 
2938  if (isSugared())
2939  return getUnderlyingType();
2940 
2941  return QualType(this, 0);
2942 }
2943 
2945  : DecltypeType(E, Context.DependentTy), Context(Context) { }
2946 
2947 void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID,
2948  const ASTContext &Context, Expr *E) {
2949  E->Profile(ID, Context, true);
2950 }
2951 
2953  QualType UnderlyingType,
2954  UTTKind UKind,
2955  QualType CanonicalType)
2956  : Type(UnaryTransform, CanonicalType, BaseType->isDependentType(),
2957  BaseType->isInstantiationDependentType(),
2958  BaseType->isVariablyModifiedType(),
2959  BaseType->containsUnexpandedParameterPack())
2960  , BaseType(BaseType), UnderlyingType(UnderlyingType), UKind(UKind)
2961 {}
2962 
2964  QualType BaseType,
2965  UTTKind UKind)
2966  : UnaryTransformType(BaseType, C.DependentTy, UKind, QualType())
2967 {}
2968 
2969 
2971  : Type(TC, can, D->isDependentType(),
2972  /*InstantiationDependent=*/D->isDependentType(),
2973  /*VariablyModified=*/false,
2974  /*ContainsUnexpandedParameterPack=*/false),
2975  decl(const_cast<TagDecl*>(D)) {}
2976 
2978  for (auto I : decl->redecls()) {
2979  if (I->isCompleteDefinition() || I->isBeingDefined())
2980  return I;
2981  }
2982  // If there's no definition (not even in progress), return what we have.
2983  return decl;
2984 }
2985 
2987  return getInterestingTagDecl(decl);
2988 }
2989 
2991  return getDecl()->isBeingDefined();
2992 }
2993 
2995  switch (getAttrKind()) {
2996  // These are type qualifiers in the traditional C sense: they annotate
2997  // something about a specific value/variable of a type. (They aren't
2998  // always part of the canonical type, though.)
3006  return true;
3007 
3008  // These aren't qualifiers; they rewrite the modified type to be a
3009  // semantically different type.
3036  return false;
3037  }
3038  llvm_unreachable("bad attributed type kind");
3039 }
3040 
3042  switch (getAttrKind()) {
3043  default: return false;
3044  case attr_ptr32:
3045  case attr_ptr64:
3046  case attr_sptr:
3047  case attr_uptr:
3048  return true;
3049  }
3050  llvm_unreachable("invalid attr kind");
3051 }
3052 
3054  switch (getAttrKind()) {
3055  case attr_ptr32:
3056  case attr_ptr64:
3057  case attr_sptr:
3058  case attr_uptr:
3059  case attr_address_space:
3060  case attr_regparm:
3061  case attr_vector_size:
3062  case attr_neon_vector_type:
3064  case attr_objc_gc:
3065  case attr_objc_ownership:
3067  case attr_noreturn:
3068  case attr_nonnull:
3070  case attr_nullable:
3071  case attr_null_unspecified:
3072  case attr_objc_kindof:
3073  return false;
3074 
3075  case attr_pcs:
3076  case attr_pcs_vfp:
3077  case attr_cdecl:
3078  case attr_fastcall:
3079  case attr_stdcall:
3080  case attr_thiscall:
3081  case attr_regcall:
3082  case attr_swiftcall:
3083  case attr_vectorcall:
3084  case attr_pascal:
3085  case attr_ms_abi:
3086  case attr_sysv_abi:
3087  case attr_inteloclbicc:
3088  case attr_preserve_most:
3089  case attr_preserve_all:
3090  return true;
3091  }
3092  llvm_unreachable("invalid attr kind");
3093 }
3094 
3096  return cast<CXXRecordDecl>(getInterestingTagDecl(Decl));
3097 }
3098 
3100  return isCanonicalUnqualified() ? nullptr : getDecl()->getIdentifier();
3101 }
3102 
3103 SubstTemplateTypeParmPackType::
3104 SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param,
3105  QualType Canon,
3106  const TemplateArgument &ArgPack)
3107  : Type(SubstTemplateTypeParmPack, Canon, true, true, false, true),
3108  Replaced(Param),
3109  Arguments(ArgPack.pack_begin()), NumArguments(ArgPack.pack_size())
3110 {
3111 }
3112 
3114  return TemplateArgument(llvm::makeArrayRef(Arguments, NumArguments));
3115 }
3116 
3117 void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID) {
3119 }
3120 
3121 void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID,
3122  const TemplateTypeParmType *Replaced,
3123  const TemplateArgument &ArgPack) {
3124  ID.AddPointer(Replaced);
3125  ID.AddInteger(ArgPack.pack_size());
3126  for (const auto &P : ArgPack.pack_elements())
3127  ID.AddPointer(P.getAsType().getAsOpaquePtr());
3128 }
3129 
3132  bool &InstantiationDependent) {
3134  InstantiationDependent);
3135 }
3136 
3139  bool &InstantiationDependent) {
3140  for (const TemplateArgumentLoc &ArgLoc : Args) {
3141  if (ArgLoc.getArgument().isDependent()) {
3142  InstantiationDependent = true;
3143  return true;
3144  }
3145 
3146  if (ArgLoc.getArgument().isInstantiationDependent())
3147  InstantiationDependent = true;
3148  }
3149  return false;
3150 }
3151 
3152 TemplateSpecializationType::
3153 TemplateSpecializationType(TemplateName T,
3155  QualType Canon, QualType AliasedType)
3156  : Type(TemplateSpecialization,
3157  Canon.isNull()? QualType(this, 0) : Canon,
3158  Canon.isNull()? true : Canon->isDependentType(),
3159  Canon.isNull()? true : Canon->isInstantiationDependentType(),
3160  false,
3161  T.containsUnexpandedParameterPack()),
3162  Template(T), NumArgs(Args.size()), TypeAlias(!AliasedType.isNull()) {
3163  assert(!T.getAsDependentTemplateName() &&
3164  "Use DependentTemplateSpecializationType for dependent template-name");
3165  assert((T.getKind() == TemplateName::Template ||
3168  "Unexpected template name for TemplateSpecializationType");
3169 
3170  TemplateArgument *TemplateArgs
3171  = reinterpret_cast<TemplateArgument *>(this + 1);
3172  for (const TemplateArgument &Arg : Args) {
3173  // Update instantiation-dependent and variably-modified bits.
3174  // If the canonical type exists and is non-dependent, the template
3175  // specialization type can be non-dependent even if one of the type
3176  // arguments is. Given:
3177  // template<typename T> using U = int;
3178  // U<T> is always non-dependent, irrespective of the type T.
3179  // However, U<Ts> contains an unexpanded parameter pack, even though
3180  // its expansion (and thus its desugared type) doesn't.
3181  if (Arg.isInstantiationDependent())
3183  if (Arg.getKind() == TemplateArgument::Type &&
3184  Arg.getAsType()->isVariablyModifiedType())
3186  if (Arg.containsUnexpandedParameterPack())
3188  new (TemplateArgs++) TemplateArgument(Arg);
3189  }
3190 
3191  // Store the aliased type if this is a type alias template specialization.
3192  if (TypeAlias) {
3193  TemplateArgument *Begin = reinterpret_cast<TemplateArgument *>(this + 1);
3194  *reinterpret_cast<QualType*>(Begin + getNumArgs()) = AliasedType;
3195  }
3196 }
3197 
3198 void
3199 TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
3200  TemplateName T,
3202  const ASTContext &Context) {
3203  T.Profile(ID);
3204  for (const TemplateArgument &Arg : Args)
3205  Arg.Profile(ID, Context);
3206 }
3207 
3208 QualType
3209 QualifierCollector::apply(const ASTContext &Context, QualType QT) const {
3210  if (!hasNonFastQualifiers())
3212 
3213  return Context.getQualifiedType(QT, *this);
3214 }
3215 
3216 QualType
3217 QualifierCollector::apply(const ASTContext &Context, const Type *T) const {
3218  if (!hasNonFastQualifiers())
3219  return QualType(T, getFastQualifiers());
3220 
3221  return Context.getQualifiedType(T, *this);
3222 }
3223 
3224 void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID,
3225  QualType BaseType,
3226  ArrayRef<QualType> typeArgs,
3227  ArrayRef<ObjCProtocolDecl *> protocols,
3228  bool isKindOf) {
3229  ID.AddPointer(BaseType.getAsOpaquePtr());
3230  ID.AddInteger(typeArgs.size());
3231  for (auto typeArg : typeArgs)
3232  ID.AddPointer(typeArg.getAsOpaquePtr());
3233  ID.AddInteger(protocols.size());
3234  for (auto proto : protocols)
3235  ID.AddPointer(proto);
3236  ID.AddBoolean(isKindOf);
3237 }
3238 
3239 void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) {
3241  llvm::makeArrayRef(qual_begin(), getNumProtocols()),
3243 }
3244 
3245 void ObjCTypeParamType::Profile(llvm::FoldingSetNodeID &ID,
3246  const ObjCTypeParamDecl *OTPDecl,
3247  ArrayRef<ObjCProtocolDecl *> protocols) {
3248  ID.AddPointer(OTPDecl);
3249  ID.AddInteger(protocols.size());
3250  for (auto proto : protocols)
3251  ID.AddPointer(proto);
3252 }
3253 
3254 void ObjCTypeParamType::Profile(llvm::FoldingSetNodeID &ID) {
3255  Profile(ID, getDecl(),
3256  llvm::makeArrayRef(qual_begin(), getNumProtocols()));
3257 }
3258 
3259 namespace {
3260 
3261 /// \brief The cached properties of a type.
3262 class CachedProperties {
3263  Linkage L;
3264  bool local;
3265 
3266 public:
3267  CachedProperties(Linkage L, bool local) : L(L), local(local) {}
3268 
3269  Linkage getLinkage() const { return L; }
3270  bool hasLocalOrUnnamedType() const { return local; }
3271 
3272  friend CachedProperties merge(CachedProperties L, CachedProperties R) {
3273  Linkage MergedLinkage = minLinkage(L.L, R.L);
3274  return CachedProperties(MergedLinkage,
3275  L.hasLocalOrUnnamedType() | R.hasLocalOrUnnamedType());
3276  }
3277 };
3278 }
3279 
3280 static CachedProperties computeCachedProperties(const Type *T);
3281 
3282 namespace clang {
3283 /// The type-property cache. This is templated so as to be
3284 /// instantiated at an internal type to prevent unnecessary symbol
3285 /// leakage.
3286 template <class Private> class TypePropertyCache {
3287 public:
3288  static CachedProperties get(QualType T) {
3289  return get(T.getTypePtr());
3290  }
3291 
3292  static CachedProperties get(const Type *T) {
3293  ensure(T);
3294  return CachedProperties(T->TypeBits.getLinkage(),
3295  T->TypeBits.hasLocalOrUnnamedType());
3296  }
3297 
3298  static void ensure(const Type *T) {
3299  // If the cache is valid, we're okay.
3300  if (T->TypeBits.isCacheValid()) return;
3301 
3302  // If this type is non-canonical, ask its canonical type for the
3303  // relevant information.
3304  if (!T->isCanonicalUnqualified()) {
3305  const Type *CT = T->getCanonicalTypeInternal().getTypePtr();
3306  ensure(CT);
3307  T->TypeBits.CacheValid = true;
3308  T->TypeBits.CachedLinkage = CT->TypeBits.CachedLinkage;
3309  T->TypeBits.CachedLocalOrUnnamed = CT->TypeBits.CachedLocalOrUnnamed;
3310  return;
3311  }
3312 
3313  // Compute the cached properties and then set the cache.
3314  CachedProperties Result = computeCachedProperties(T);
3315  T->TypeBits.CacheValid = true;
3316  T->TypeBits.CachedLinkage = Result.getLinkage();
3317  T->TypeBits.CachedLocalOrUnnamed = Result.hasLocalOrUnnamedType();
3318  }
3319 };
3320 }
3321 
3322 // Instantiate the friend template at a private class. In a
3323 // reasonable implementation, these symbols will be internal.
3324 // It is terrible that this is the best way to accomplish this.
3325 namespace { class Private {}; }
3327 
3328 static CachedProperties computeCachedProperties(const Type *T) {
3329  switch (T->getTypeClass()) {
3330 #define TYPE(Class,Base)
3331 #define NON_CANONICAL_TYPE(Class,Base) case Type::Class:
3332 #include "clang/AST/TypeNodes.def"
3333  llvm_unreachable("didn't expect a non-canonical type here");
3334 
3335 #define TYPE(Class,Base)
3336 #define DEPENDENT_TYPE(Class,Base) case Type::Class:
3337 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class:
3338 #include "clang/AST/TypeNodes.def"
3339  // Treat instantiation-dependent types as external.
3340  assert(T->isInstantiationDependentType());
3341  return CachedProperties(ExternalLinkage, false);
3342 
3343  case Type::Auto:
3344  case Type::DeducedTemplateSpecialization:
3345  // Give non-deduced 'auto' types external linkage. We should only see them
3346  // here in error recovery.
3347  return CachedProperties(ExternalLinkage, false);
3348 
3349  case Type::Builtin:
3350  // C++ [basic.link]p8:
3351  // A type is said to have linkage if and only if:
3352  // - it is a fundamental type (3.9.1); or
3353  return CachedProperties(ExternalLinkage, false);
3354 
3355  case Type::Record:
3356  case Type::Enum: {
3357  const TagDecl *Tag = cast<TagType>(T)->getDecl();
3358 
3359  // C++ [basic.link]p8:
3360  // - it is a class or enumeration type that is named (or has a name
3361  // for linkage purposes (7.1.3)) and the name has linkage; or
3362  // - it is a specialization of a class template (14); or
3363  Linkage L = Tag->getLinkageInternal();
3364  bool IsLocalOrUnnamed =
3365  Tag->getDeclContext()->isFunctionOrMethod() ||
3366  !Tag->hasNameForLinkage();
3367  return CachedProperties(L, IsLocalOrUnnamed);
3368  }
3369 
3370  // C++ [basic.link]p8:
3371  // - it is a compound type (3.9.2) other than a class or enumeration,
3372  // compounded exclusively from types that have linkage; or
3373  case Type::Complex:
3374  return Cache::get(cast<ComplexType>(T)->getElementType());
3375  case Type::Pointer:
3376  return Cache::get(cast<PointerType>(T)->getPointeeType());
3377  case Type::BlockPointer:
3378  return Cache::get(cast<BlockPointerType>(T)->getPointeeType());
3379  case Type::LValueReference:
3380  case Type::RValueReference:
3381  return Cache::get(cast<ReferenceType>(T)->getPointeeType());
3382  case Type::MemberPointer: {
3383  const MemberPointerType *MPT = cast<MemberPointerType>(T);
3384  return merge(Cache::get(MPT->getClass()),
3385  Cache::get(MPT->getPointeeType()));
3386  }
3387  case Type::ConstantArray:
3388  case Type::IncompleteArray:
3389  case Type::VariableArray:
3390  return Cache::get(cast<ArrayType>(T)->getElementType());
3391  case Type::Vector:
3392  case Type::ExtVector:
3393  return Cache::get(cast<VectorType>(T)->getElementType());
3394  case Type::FunctionNoProto:
3395  return Cache::get(cast<FunctionType>(T)->getReturnType());
3396  case Type::FunctionProto: {
3397  const FunctionProtoType *FPT = cast<FunctionProtoType>(T);
3398  CachedProperties result = Cache::get(FPT->getReturnType());
3399  for (const auto &ai : FPT->param_types())
3400  result = merge(result, Cache::get(ai));
3401  return result;
3402  }
3403  case Type::ObjCInterface: {
3404  Linkage L = cast<ObjCInterfaceType>(T)->getDecl()->getLinkageInternal();
3405  return CachedProperties(L, false);
3406  }
3407  case Type::ObjCObject:
3408  return Cache::get(cast<ObjCObjectType>(T)->getBaseType());
3409  case Type::ObjCObjectPointer:
3410  return Cache::get(cast<ObjCObjectPointerType>(T)->getPointeeType());
3411  case Type::Atomic:
3412  return Cache::get(cast<AtomicType>(T)->getValueType());
3413  case Type::Pipe:
3414  return Cache::get(cast<PipeType>(T)->getElementType());
3415  }
3416 
3417  llvm_unreachable("unhandled type class");
3418 }
3419 
3420 /// \brief Determine the linkage of this type.
3422  Cache::ensure(this);
3423  return TypeBits.getLinkage();
3424 }
3425 
3427  Cache::ensure(this);
3428  return TypeBits.hasLocalOrUnnamedType();
3429 }
3430 
3432 
3434  switch (T->getTypeClass()) {
3435 #define TYPE(Class,Base)
3436 #define NON_CANONICAL_TYPE(Class,Base) case Type::Class:
3437 #include "clang/AST/TypeNodes.def"
3438  llvm_unreachable("didn't expect a non-canonical type here");
3439 
3440 #define TYPE(Class,Base)
3441 #define DEPENDENT_TYPE(Class,Base) case Type::Class:
3442 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class:
3443 #include "clang/AST/TypeNodes.def"
3444  // Treat instantiation-dependent types as external.
3445  assert(T->isInstantiationDependentType());
3446  return LinkageInfo::external();
3447 
3448  case Type::Builtin:
3449  return LinkageInfo::external();
3450 
3451  case Type::Auto:
3452  case Type::DeducedTemplateSpecialization:
3453  return LinkageInfo::external();
3454 
3455  case Type::Record:
3456  case Type::Enum:
3457  return cast<TagType>(T)->getDecl()->getLinkageAndVisibility();
3458 
3459  case Type::Complex:
3460  return computeLinkageInfo(cast<ComplexType>(T)->getElementType());
3461  case Type::Pointer:
3462  return computeLinkageInfo(cast<PointerType>(T)->getPointeeType());
3463  case Type::BlockPointer:
3464  return computeLinkageInfo(cast<BlockPointerType>(T)->getPointeeType());
3465  case Type::LValueReference:
3466  case Type::RValueReference:
3467  return computeLinkageInfo(cast<ReferenceType>(T)->getPointeeType());
3468  case Type::MemberPointer: {
3469  const MemberPointerType *MPT = cast<MemberPointerType>(T);
3472  return LV;
3473  }
3474  case Type::ConstantArray:
3475  case Type::IncompleteArray:
3476  case Type::VariableArray:
3477  return computeLinkageInfo(cast<ArrayType>(T)->getElementType());
3478  case Type::Vector:
3479  case Type::ExtVector:
3480  return computeLinkageInfo(cast<VectorType>(T)->getElementType());
3481  case Type::FunctionNoProto:
3482  return computeLinkageInfo(cast<FunctionType>(T)->getReturnType());
3483  case Type::FunctionProto: {
3484  const FunctionProtoType *FPT = cast<FunctionProtoType>(T);
3486  for (const auto &ai : FPT->param_types())
3487  LV.merge(computeLinkageInfo(ai));
3488  return LV;
3489  }
3490  case Type::ObjCInterface:
3491  return cast<ObjCInterfaceType>(T)->getDecl()->getLinkageAndVisibility();
3492  case Type::ObjCObject:
3493  return computeLinkageInfo(cast<ObjCObjectType>(T)->getBaseType());
3494  case Type::ObjCObjectPointer:
3495  return computeLinkageInfo(cast<ObjCObjectPointerType>(T)->getPointeeType());
3496  case Type::Atomic:
3497  return computeLinkageInfo(cast<AtomicType>(T)->getValueType());
3498  case Type::Pipe:
3499  return computeLinkageInfo(cast<PipeType>(T)->getElementType());
3500  }
3501 
3502  llvm_unreachable("unhandled type class");
3503 }
3504 
3506  return computeLinkageInfo(T.getTypePtr());
3507 }
3508 
3509 bool Type::isLinkageValid() const {
3510  if (!TypeBits.isCacheValid())
3511  return true;
3512 
3514  TypeBits.getLinkage();
3515 }
3516 
3518  if (!isCanonicalUnqualified())
3520 
3521  LinkageInfo LV = computeLinkageInfo(this);
3522  assert(LV.getLinkage() == getLinkage());
3523  return LV;
3524 }
3525 
3527  QualType type(this, 0);
3528  do {
3529  // Check whether this is an attributed type with nullability
3530  // information.
3531  if (auto attributed = dyn_cast<AttributedType>(type.getTypePtr())) {
3532  if (auto nullability = attributed->getImmediateNullability())
3533  return nullability;
3534  }
3535 
3536  // Desugar the type. If desugaring does nothing, we're done.
3537  QualType desugared = type.getSingleStepDesugaredType(context);
3538  if (desugared.getTypePtr() == type.getTypePtr())
3539  return None;
3540 
3541  type = desugared;
3542  } while (true);
3543 }
3544 
3545 bool Type::canHaveNullability(bool ResultIfUnknown) const {
3547 
3548  switch (type->getTypeClass()) {
3549  // We'll only see canonical types here.
3550 #define NON_CANONICAL_TYPE(Class, Parent) \
3551  case Type::Class: \
3552  llvm_unreachable("non-canonical type");
3553 #define TYPE(Class, Parent)
3554 #include "clang/AST/TypeNodes.def"
3555 
3556  // Pointer types.
3557  case Type::Pointer:
3558  case Type::BlockPointer:
3559  case Type::MemberPointer:
3560  case Type::ObjCObjectPointer:
3561  return true;
3562 
3563  // Dependent types that could instantiate to pointer types.
3564  case Type::UnresolvedUsing:
3565  case Type::TypeOfExpr:
3566  case Type::TypeOf:
3567  case Type::Decltype:
3568  case Type::UnaryTransform:
3569  case Type::TemplateTypeParm:
3570  case Type::SubstTemplateTypeParmPack:
3571  case Type::DependentName:
3572  case Type::DependentTemplateSpecialization:
3573  case Type::Auto:
3574  return ResultIfUnknown;
3575 
3576  // Dependent template specializations can instantiate to pointer
3577  // types unless they're known to be specializations of a class
3578  // template.
3579  case Type::TemplateSpecialization:
3580  if (TemplateDecl *templateDecl
3581  = cast<TemplateSpecializationType>(type.getTypePtr())
3582  ->getTemplateName().getAsTemplateDecl()) {
3583  if (isa<ClassTemplateDecl>(templateDecl))
3584  return false;
3585  }
3586  return ResultIfUnknown;
3587 
3588  case Type::Builtin:
3589  switch (cast<BuiltinType>(type.getTypePtr())->getKind()) {
3590  // Signed, unsigned, and floating-point types cannot have nullability.
3591 #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
3592 #define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
3593 #define FLOATING_TYPE(Id, SingletonId) case BuiltinType::Id:
3594 #define BUILTIN_TYPE(Id, SingletonId)
3595 #include "clang/AST/BuiltinTypes.def"
3596  return false;
3597 
3598  // Dependent types that could instantiate to a pointer type.
3599  case BuiltinType::Dependent:
3600  case BuiltinType::Overload:
3601  case BuiltinType::BoundMember:
3602  case BuiltinType::PseudoObject:
3603  case BuiltinType::UnknownAny:
3604  case BuiltinType::ARCUnbridgedCast:
3605  return ResultIfUnknown;
3606 
3607  case BuiltinType::Void:
3608  case BuiltinType::ObjCId:
3609  case BuiltinType::ObjCClass:
3610  case BuiltinType::ObjCSel:
3611 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3612  case BuiltinType::Id:
3613 #include "clang/Basic/OpenCLImageTypes.def"
3614  case BuiltinType::OCLSampler:
3615  case BuiltinType::OCLEvent:
3616  case BuiltinType::OCLClkEvent:
3617  case BuiltinType::OCLQueue:
3618  case BuiltinType::OCLReserveID:
3619  case BuiltinType::BuiltinFn:
3620  case BuiltinType::NullPtr:
3621  case BuiltinType::OMPArraySection:
3622  return false;
3623  }
3624  llvm_unreachable("unknown builtin type");
3625 
3626  // Non-pointer types.
3627  case Type::Complex:
3628  case Type::LValueReference:
3629  case Type::RValueReference:
3630  case Type::ConstantArray:
3631  case Type::IncompleteArray:
3632  case Type::VariableArray:
3633  case Type::DependentSizedArray:
3634  case Type::DependentSizedExtVector:
3635  case Type::Vector:
3636  case Type::ExtVector:
3637  case Type::FunctionProto:
3638  case Type::FunctionNoProto:
3639  case Type::Record:
3640  case Type::DeducedTemplateSpecialization:
3641  case Type::Enum:
3642  case Type::InjectedClassName:
3643  case Type::PackExpansion:
3644  case Type::ObjCObject:
3645  case Type::ObjCInterface:
3646  case Type::Atomic:
3647  case Type::Pipe:
3648  return false;
3649  }
3650  llvm_unreachable("bad type kind!");
3651 }
3652 
3655  return NullabilityKind::NonNull;
3660  return None;
3661 }
3662 
3664  if (auto attributed = dyn_cast<AttributedType>(T.getTypePtr())) {
3665  if (auto nullability = attributed->getImmediateNullability()) {
3666  T = attributed->getModifiedType();
3667  return nullability;
3668  }
3669  }
3670 
3671  return None;
3672 }
3673 
3675  const ObjCObjectPointerType *objcPtr = getAs<ObjCObjectPointerType>();
3676  if (!objcPtr)
3677  return false;
3678 
3679  if (objcPtr->isObjCIdType()) {
3680  // id is always okay.
3681  return true;
3682  }
3683 
3684  // Blocks are NSObjects.
3685  if (ObjCInterfaceDecl *iface = objcPtr->getInterfaceDecl()) {
3686  if (iface->getIdentifier() != ctx.getNSObjectName())
3687  return false;
3688 
3689  // Continue to check qualifiers, below.
3690  } else if (objcPtr->isObjCQualifiedIdType()) {
3691  // Continue to check qualifiers, below.
3692  } else {
3693  return false;
3694  }
3695 
3696  // Check protocol qualifiers.
3697  for (ObjCProtocolDecl *proto : objcPtr->quals()) {
3698  // Blocks conform to NSObject and NSCopying.
3699  if (proto->getIdentifier() != ctx.getNSObjectName() &&
3700  proto->getIdentifier() != ctx.getNSCopyingName())
3701  return false;
3702  }
3703 
3704  return true;
3705 }
3706 
3710  return Qualifiers::OCL_Strong;
3711 }
3712 
3714  assert(isObjCLifetimeType() &&
3715  "cannot query implicit lifetime for non-inferrable type");
3716 
3717  const Type *canon = getCanonicalTypeInternal().getTypePtr();
3718 
3719  // Walk down to the base type. We don't care about qualifiers for this.
3720  while (const ArrayType *array = dyn_cast<ArrayType>(canon))
3721  canon = array->getElementType().getTypePtr();
3722 
3723  if (const ObjCObjectPointerType *opt
3724  = dyn_cast<ObjCObjectPointerType>(canon)) {
3725  // Class and Class<Protocol> don't require retention.
3726  if (opt->getObjectType()->isObjCClass())
3727  return true;
3728  }
3729 
3730  return false;
3731 }
3732 
3734  const Type *cur = this;
3735  while (true) {
3736  if (const TypedefType *typedefType = dyn_cast<TypedefType>(cur))
3737  return typedefType->getDecl()->hasAttr<ObjCNSObjectAttr>();
3738 
3739  // Single-step desugar until we run out of sugar.
3741  if (next.getTypePtr() == cur) return false;
3742  cur = next.getTypePtr();
3743  }
3744 }
3745 
3747  if (const TypedefType *typedefType = dyn_cast<TypedefType>(this))
3748  return typedefType->getDecl()->hasAttr<ObjCIndependentClassAttr>();
3749  return false;
3750 }
3752  return isObjCObjectPointerType() ||
3753  isBlockPointerType() ||
3755 }
3757  if (isObjCLifetimeType())
3758  return true;
3759  if (const PointerType *OPT = getAs<PointerType>())
3760  return OPT->getPointeeType()->isObjCIndirectLifetimeType();
3761  if (const ReferenceType *Ref = getAs<ReferenceType>())
3762  return Ref->getPointeeType()->isObjCIndirectLifetimeType();
3763  if (const MemberPointerType *MemPtr = getAs<MemberPointerType>())
3764  return MemPtr->getPointeeType()->isObjCIndirectLifetimeType();
3765  return false;
3766 }
3767 
3768 /// Returns true if objects of this type have lifetime semantics under
3769 /// ARC.
3771  const Type *type = this;
3772  while (const ArrayType *array = type->getAsArrayTypeUnsafe())
3773  type = array->getElementType().getTypePtr();
3774  return type->isObjCRetainableType();
3775 }
3776 
3777 /// \brief Determine whether the given type T is a "bridgable" Objective-C type,
3778 /// which is either an Objective-C object pointer type or an
3781 }
3782 
3783 /// \brief Determine whether the given type T is a "bridgeable" C type.
3785  const PointerType *Pointer = getAs<PointerType>();
3786  if (!Pointer)
3787  return false;
3788 
3789  QualType Pointee = Pointer->getPointeeType();
3790  return Pointee->isVoidType() || Pointee->isRecordType();
3791 }
3792 
3794  if (!isVariablyModifiedType()) return false;
3795 
3796  if (const PointerType *ptr = getAs<PointerType>())
3797  return ptr->getPointeeType()->hasSizedVLAType();
3798  if (const ReferenceType *ref = getAs<ReferenceType>())
3799  return ref->getPointeeType()->hasSizedVLAType();
3800  if (const ArrayType *arr = getAsArrayTypeUnsafe()) {
3801  if (isa<VariableArrayType>(arr) &&
3802  cast<VariableArrayType>(arr)->getSizeExpr())
3803  return true;
3804 
3805  return arr->getElementType()->hasSizedVLAType();
3806  }
3807 
3808  return false;
3809 }
3810 
3811 QualType::DestructionKind QualType::isDestructedTypeImpl(QualType type) {
3812  switch (type.getObjCLifetime()) {
3813  case Qualifiers::OCL_None:
3816  break;
3817 
3819  return DK_objc_strong_lifetime;
3820  case Qualifiers::OCL_Weak:
3821  return DK_objc_weak_lifetime;
3822  }
3823 
3824  /// Currently, the only destruction kind we recognize is C++ objects
3825  /// with non-trivial destructors.
3826  const CXXRecordDecl *record =
3828  if (record && record->hasDefinition() && !record->hasTrivialDestructor())
3829  return DK_cxx_destructor;
3830 
3831  return DK_none;
3832 }
3833 
3836 }
Kind getKind() const
Definition: Type.h:2105
unsigned getNumElements() const
Definition: Type.h:2822
bool hasObjCGCAttr() const
Definition: Type.h:287
unsigned getAddressSpace() const
Return the address space of this type.
Definition: Type.h:5605
const ComplexType * getAsComplexIntegerType() const
Definition: Type.cpp:407
bool isUnspecialized() const
Determine whether this object type is "unspecialized", meaning that it has no type arguments...
Definition: Type.h:5065
DecltypeType(Expr *E, QualType underlyingType, QualType can=QualType())
Definition: Type.cpp:2923
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
Definition: Type.cpp:2451
bool hasDefinition() const
Determine whether this class has been defined.
Definition: DeclObjC.h:1457
Defines the clang::ASTContext interface.
QualType getExceptionType(unsigned i) const
Definition: Type.h:3402
Represents a type that was referred to using an elaborated type keyword, e.g., struct S...
Definition: Type.h:4576
QualType getUnderlyingType() const
Definition: Type.h:3676
const Type * Ty
The locally-unqualified type.
Definition: Type.h:561
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
Definition: Type.h:4405
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1618
External linkage, which indicates that the entity can be referred to from other translation units...
Definition: Linkage.h:61
The "enum" keyword introduces the elaborated-type-specifier.
Definition: Type.h:4513
DependentUnaryTransformType(const ASTContext &C, QualType BaseType, UTTKind UKind)
Definition: Type.cpp:2963
void setDependent(bool D=true)
Definition: Type.h:1541
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2224
A (possibly-)qualified type.
Definition: Type.h:616
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
Definition: Type.cpp:2005
SourceRange getBracketsRange() const
Definition: Type.h:2669
void computeSuperClassTypeSlow() const
Definition: Type.cpp:1396
bool isCharType() const
Definition: Type.cpp:1694
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition: Type.h:1581
bool hasFloatingRepresentation() const
Determine whether this type has a floating-point representation of some sort, e.g., it is a floating-point type or a vector thereof.
Definition: Type.cpp:1830
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
Definition: DeclCXX.h:1350
QualType getAdjustedType(QualType Orig, QualType New) const
Return the uniqued reference to a type adjusted from the original type to a new type.
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type...
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
Definition: Decl.h:232
bool isKindOfTypeAsWritten() const
Whether this is a "__kindof" type as written.
Definition: Type.h:5082
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:1803
unsigned getFastQualifiers() const
Definition: Type.h:367
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type...
Definition: Type.cpp:2618
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:1804
Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const
Return the implicit lifetime for this type, which must not be dependent.
Definition: Type.cpp:3707
void setInstantiationDependent(bool D=true)
Definition: Type.h:1546
Stmt - This represents one statement.
Definition: Stmt.h:60
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition: Decl.h:3288
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition: Type.cpp:1724
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:2923
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type...
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
bool hasAutoForTrailingReturnType() const
Determine whether this type was written with a leading 'auto' corresponding to a trailing return type...
Definition: Type.cpp:1632
unsigned MSWChar
When true, print the built-in wchar_t type as __wchar_t.
C Language Family Type Representation.
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:4642
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:179
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.cpp:3117
CXXRecordDecl * getDecl() const
Definition: Type.cpp:3095
bool hasInstantiationDependentExceptionSpec() const
Return whether this function has an instantiation-dependent exception spec.
Definition: Type.cpp:2769
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:330
bool isRecordType() const
Definition: Type.h:5769
QualType getUnderlyingType() const
Definition: Decl.h:2727
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:81
bool isChar16Type() const
Definition: Type.cpp:1710
ObjCObjectTypeBitfields ObjCObjectTypeBits
Definition: Type.h:1507
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
Definition: Type.cpp:2154
Defines the C++ template declaration subclasses.
StringRef P
bool isVoidPointerType() const
Definition: Type.cpp:384
Represents a C++11 auto or C++14 decltype(auto) type.
Definition: Type.h:4206
QualType substObjCTypeArgs(ASTContext &ctx, ArrayRef< QualType > typeArgs, ObjCSubstitutionContext context) const
Substitute type arguments for the Objective-C type parameters used in the subject type...
Definition: Type.cpp:1074
bool isEnumeralType() const
Definition: Type.h:5772
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
Definition: Type.cpp:2889
TypePropertyCache< Private > Cache
Definition: Type.cpp:3326
bool hasDefinition() const
Definition: DeclCXX.h:702
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type...
static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag)
Converts a TagTypeKind into an elaborated type keyword.
Definition: Type.cpp:2409
QualType getPointeeType() const
Definition: Type.h:2461
The base class of the type hierarchy.
Definition: Type.h:1303
bool isElaboratedTypeSpecifier() const
Determine wither this type is a C++ elaborated-type-specifier.
Definition: Type.cpp:2499
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2497
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:5260
DependentDecltypeType(const ASTContext &Context, Expr *E)
Definition: Type.cpp:2944
bool isBlockPointerType() const
Definition: Type.h:5718
const ObjCObjectPointerType * getAsObjCQualifiedClassType() const
Definition: Type.cpp:1508
bool isSpelledAsLValue() const
Definition: Type.h:2377
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:201
bool hasUnsignedIntegerRepresentation() const
Determine whether this type has an unsigned integer representation of some sort, e.g., it is an unsigned integer type or a vector.
Definition: Type.cpp:1814
const llvm::APInt & getSize() const
Definition: Type.h:2568
void * getAsOpaquePtr() const
Definition: Type.h:664
static CachedProperties computeCachedProperties(const Type *T)
Definition: Type.cpp:3328
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
QualType substObjCMemberType(QualType objectType, const DeclContext *dc, ObjCSubstitutionContext context) const
Substitute type arguments from an object type for the Objective-C type parameters used in the subject...
Definition: Type.cpp:1264
The noexcept specifier has a bad expression.
Definition: Type.h:3394
ObjCLifetime getObjCLifetime() const
Definition: Type.h:309
The "union" keyword.
Definition: Type.h:4494
Extra information about a function prototype.
Definition: Type.h:3234
The "__interface" keyword.
Definition: Type.h:4492
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:1924
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:4028
QualType getOriginalType() const
Definition: Type.h:2288
bool isRealType() const
Definition: Type.cpp:1843
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
bool canHaveNullability(bool ResultIfUnknown=true) const
Determine whether the given type can have a nullability specifier applied to it, i.e., if it is any kind of pointer type.
Definition: Type.cpp:3545
unsigned size() const
Determine the number of type parameters in this list.
Definition: DeclObjC.h:653
bool isSpecialized() const
Determine whether this object type is "specialized", meaning that it has type arguments.
Definition: Type.cpp:579
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1575
bool isObjCRetainableType() const
Definition: Type.cpp:3751
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:4062
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
Definition: Linkage.h:25
unsigned getNumArgs() const
Retrieve the number of template arguments.
Definition: Type.h:4390
bool isUnionType() const
Definition: Type.cpp:390
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs, typeofs, etc., as well as any qualifiers.
Definition: Type.cpp:340
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
bool isVoidType() const
Definition: Type.h:5906
The collection of all-type qualifiers we support.
Definition: Type.h:118
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2739
bool isTemplateVariadic() const
Determines whether this function prototype contains a parameter pack at the end.
Definition: Type.cpp:2826
unsigned getNumParams() const
Definition: Type.h:3338
bool isCXX11PODType(const ASTContext &Context) const
Return true if this is a POD type according to the more relaxed rules of the C++11 standard...
Definition: Type.cpp:2257
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3354
QualType getElementType() const
Definition: Type.h:2773
One of these records is kept for each identifier that is lexed.
unsigned getIndexTypeCVRQualifiers() const
Definition: Type.h:2538
bool isScalarType() const
Definition: Type.h:5941
QualType apply(const ASTContext &Context, QualType QT) const
Apply the collected qualifiers to the given type.
Definition: Type.cpp:3209
TagDecl * getAsTagDecl() const
Retrieves the TagDecl that this type refers to, either because the type is a TagType or because it is...
Definition: Type.cpp:1552
bool hasAttr() const
Definition: DeclBase.h:521
Represents a class type in Objective C.
Definition: Type.h:4969
Expr * getSizeExpr() const
Definition: Type.h:2664
IdentifierInfo * getIdentifier() const
Definition: Type.cpp:3099
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Definition: Type.h:1813
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:128
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:3343
bool isObjCARCImplicitlyUnretainedType() const
Determines if this type, which must satisfy isObjCLifetimeType(), is implicitly __unsafe_unretained r...
Definition: Type.cpp:3713
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.cpp:2907
static bool anyDependentTemplateArguments(ArrayRef< TemplateArgumentLoc > Args, bool &InstantiationDependent)
Determine whether any of the given template arguments are dependent.
Definition: Type.cpp:3138
bool isReferenceType() const
Definition: Type.h:5721
bool isStructureOrClassType() const
Definition: Type.cpp:377
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size...
bool isCompleteDefinition() const
isCompleteDefinition - Return true if this decl has its body fully specified.
Definition: Decl.h:2960
bool isClass() const
Definition: Decl.h:3027
An operation on a type.
Definition: TypeVisitor.h:65
NoexceptResult
Result type of getNoexceptSpec().
Definition: Type.h:3392
NameKind getKind() const
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
Definition: ASTMatchers.h:281
bool isBeingDefined() const
Determines whether this type is in the process of being defined.
Definition: Type.cpp:2990
bool isChar32Type() const
Definition: Type.cpp:1716
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that that type refers to...
Definition: Type.cpp:1533
const RecordType * getAsUnionType() const
NOTE: getAs*ArrayType are methods on ASTContext.
Definition: Type.cpp:449
Linkage getLinkage() const
Definition: Visibility.h:82
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.cpp:2935
QualType desugar() const
Definition: Type.cpp:2895
Values of this type can be null.
bool isIntegralOrUnscopedEnumerationType() const
Determine whether this type is an integral or unscoped enumeration type.
Definition: Type.cpp:1677
bool hasNonFastQualifiers() const
Return true if the set contains any qualifiers which require an ExtQuals node to be allocated...
Definition: Type.h:386
TemplateArgument getArgumentPack() const
Definition: Type.cpp:3113
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2424
param_type_range param_types() const
Definition: Type.h:3465
QualType getParenType(QualType NamedType) const
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:643
const LangOptions & getLangOpts() const
Definition: ASTContext.h:659
A convenient class for passing around template argument information.
Definition: TemplateBase.h:524
LinkageInfo getLinkageAndVisibility() const
Determine the linkage and visibility of this type.
Definition: Type.cpp:3517
QualType getBaseType() const
Gets the base type of this object type.
Definition: Type.h:5030
QualType getReturnType() const
Definition: Type.h:3065
The "struct" keyword introduces the elaborated-type-specifier.
Definition: Type.h:4505
static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec)
Converts a type specifier (DeclSpec::TST) into an elaborated type keyword.
Definition: Type.cpp:2383
Whether values of this type can be null is (explicitly) unspecified.
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
Definition: Type.cpp:3770
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
Expr * getNoexceptExpr() const
Definition: Type.h:3406
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
Definition: Expr.h:148
RecordDecl * getDecl() const
Definition: Type.h:3793
ObjCInterfaceDecl * getInterface() const
Gets the interface declaration for this object type, if the base type really is an interface...
Definition: Type.h:5199
bool isUnsignedIntegerType() const
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
Definition: Type.cpp:1784
const ObjCObjectType * getAsObjCInterfaceType() const
Definition: Type.cpp:1518
Values of this type can never be null.
static unsigned getNumAddressingBits(const ASTContext &Context, QualType ElementType, const llvm::APInt &NumElements)
Determine the number of bits required to address a member of.
Definition: Type.cpp:76
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
static TagDecl * getInterestingTagDecl(TagDecl *decl)
Definition: Type.cpp:2977
TypeClass getTypeClass() const
Definition: Type.h:1555
unsigned Half
When true, print the half-precision floating-point type as 'half' instead of '__fp16'.
bool isStructureType() const
Definition: Type.cpp:362
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:1985
bool isObjCIndependentClassType() const
Definition: Type.cpp:3746
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
Definition: Type.cpp:1930
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
bool isTrivialType(const ASTContext &Context) const
Return true if this is a trivial type per (C++0x [basic.types]p9)
Definition: Type.cpp:2061
Represents an ObjC class declaration.
Definition: DeclObjC.h:1108
bool empty() const
Definition: Type.h:395
detail::InMemoryDirectory::const_iterator I
QualType getCanonicalTypeInternal() const
Definition: Type.h:2045
bool isTriviallyCopyableType(const ASTContext &Context) const
Return true if this is a trivially copyable type (C++0x [basic.types]p9)
Definition: Type.cpp:2110
TagType(TypeClass TC, const TagDecl *D, QualType can)
Definition: Type.cpp:2970
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:2759
This object can be modified without requiring retains or releases.
Definition: Type.h:139
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Definition: Type.h:4138
bool isLinkageValid() const
True if the computed linkage is valid.
Definition: Type.cpp:3509
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type...
Definition: Type.h:6091
EnumDecl * getDecl() const
Definition: Type.h:3816
Represents a K&R-style 'int foo()' function, which has no information available about its arguments...
Definition: Type.h:3095
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
Definition: Type.h:5402
static void ensure(const Type *T)
Definition: Type.cpp:3298
ExtInfo getExtInfo() const
Definition: Type.h:3074
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type...
Definition: Type.h:6114
QualType getObjCObjectType(QualType Base, ObjCProtocolDecl *const *Protocols, unsigned NumProtocols) const
Legacy interface: cannot provide type arguments or __kindof.
CXXRecordDecl * getMostRecentDecl()
Definition: DeclCXX.h:686
Optional< ArrayRef< QualType > > getObjCSubstitutions(const DeclContext *dc) const
Retrieve the set of substitutions required when accessing a member of the Objective-C receiver type t...
Definition: Type.cpp:1303
QualType getParamType(unsigned i) const
Definition: Type.h:3339
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3129
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:3371
static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword)
Definition: Type.cpp:2436
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition: Type.h:1028
param_type_iterator param_type_begin() const
Definition: Type.h:3468
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition: Type.h:2503
ASTContext * Context
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on a template...
Definition: Expr.h:190
QualType getAtomicType(QualType T) const
Return the uniqued reference to the atomic type for the specified type.
QualType desugar() const
Remove a single level of sugar.
Definition: Type.cpp:2937
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:414
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl...
bool hasSizedVLAType() const
Whether this type involves a variable-length array type with a definite size.
Definition: Type.cpp:3793
bool isRealFloatingType() const
Floating point categories.
Definition: Type.cpp:1837
bool isObjCInertUnsafeUnretainedType() const
Was this type written with the special inert-in-MRC __unsafe_unretained qualifier?
Definition: Type.cpp:518
bool isKindOfType() const
Whether this is a "__kindof" type.
Definition: Type.h:5309
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
Definition: Type.cpp:1760
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:5497
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
Definition: TargetCXXABI.h:154
QualType getSuperClassType() const
Retrieve the type of the superclass of this object type.
Definition: Type.h:5093
QualType getPointeeType() const
Definition: Type.h:2341
Expr - This represents one expression.
Definition: Expr.h:105
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition: Type.h:4516
bool isAnyComplexType() const
Definition: Type.h:5775
bool isStruct() const
Definition: Decl.h:3025
QualType getLocallyUnqualifiedSingleStepDesugaredType() const
Pull a single level of sugar off of this locally-unqualified type.
Definition: Type.cpp:223
ASTContext & getParentASTContext() const
Definition: DeclBase.h:1323
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:4503
bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const
Definition: Type.cpp:2148
ObjCObjectType(QualType Canonical, QualType Base, ArrayRef< QualType > typeArgs, ArrayRef< ObjCProtocolDecl * > protocols, bool isKindOf)
Definition: Type.cpp:546
static LinkageInfo computeLinkageInfo(QualType T)
Definition: Type.cpp:3505
ObjCSubstitutionContext
The kind of type we are substituting Objective-C type arguments into.
Definition: Type.h:589
Expr * getUnderlyingExpr() const
Definition: Type.h:3609
bool isVariableArrayType() const
Definition: Type.h:5760
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:4606
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:3347
DeclContext * getDeclContext()
Definition: DeclBase.h:416
bool isFloatingType() const
Definition: Type.cpp:1821
SourceLocation Begin
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3699
static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec)
Converts a type specifier (DeclSpec::TST) into a tag type kind.
Definition: Type.cpp:2396
Represents a C++ template name within the type system.
Definition: TemplateName.h:176
Represents the type decltype(expr) (C++11).
Definition: Type.h:3667
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
Definition: Type.h:910
There is no noexcept specifier.
Definition: Type.h:3393
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:559
Kind getAttrKind() const
Definition: Type.h:3906
static Optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
Definition: Type.cpp:3663
const ObjCObjectPointerType * stripObjCKindOfTypeAndQuals(const ASTContext &ctx) const
Strip off the Objective-C "kindof" type and (with it) any protocol qualifiers.
Definition: Type.cpp:652
QualType stripObjCKindOfType(const ASTContext &ctx) const
Strip Objective-C "__kindof" types from the given type.
Definition: Type.cpp:1273
A unary type transform, which is a type constructed from another.
Definition: Type.h:3708
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:1797
bool hasTrailingReturn() const
Definition: Type.h:3452
bool isFunctionOrMethod() const
Definition: DeclBase.h:1343
Qualifiers Quals
The local qualifiers.
Definition: Type.h:564
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
Definition: Type.h:5298
#define TRIVIAL_TYPE_CLASS(Class)
Definition: Type.cpp:687
ScalarTypeKind
Definition: Type.h:1781
QualType withFastQualifiers(unsigned TQs) const
Definition: Type.h:825
A helper class for Type nodes having an ElaboratedTypeKeyword.
Definition: Type.h:4525
const IdentifierInfo * getBaseTypeIdentifier() const
Retrieves a pointer to the name of the base type.
Definition: Type.cpp:46
Represents a GCC generic vector type.
Definition: Type.h:2797
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2407
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
Definition: Type.h:4166
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition: Decl.cpp:1076
QualType getElementType() const
Definition: Type.h:2821
bool isStrictSupersetOf(Qualifiers Other) const
Determine whether this set of qualifiers is a strict superset of another set of qualifiers, not considering qualifier compatibility.
Definition: Type.cpp:31
The result type of a method or function.
bool isComplexIntegerType() const
Definition: Type.cpp:402
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type...
Definition: Decl.h:3046
IdentifierInfo * getNSObjectName()
Retrieve the identifier 'NSObject'.
Definition: ASTContext.h:1567
bool isUnsignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is unsigned or an enumeration types whose underlying ...
Definition: Type.cpp:1800
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
Definition: Type.h:4083
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:232
static LinkageInfo external()
Definition: Visibility.h:66
bool hasObjCLifetime() const
Definition: Type.h:308
QualType stripObjCKindOfTypeAndQuals(const ASTContext &ctx) const
Strip off the Objective-C "kindof" type and (with it) any protocol qualifiers.
Definition: Type.cpp:632
IdentifierInfo * getNSCopyingName()
Retrieve the identifier 'NSCopying'.
Definition: ASTContext.h:1576
bool hasUnnamedOrLocalType() const
Whether this type is or contains a local or unnamed type.
Definition: Type.cpp:3426
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Definition: Type.h:4077
unsigned Bool
Whether we can use 'bool' rather than '_Bool' (even if the language doesn't actually have 'bool'...
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Definition: Type.cpp:3834
A template template parameter pack that has been substituted for a template template argument pack...
Definition: TemplateName.h:205
CanThrowResult
Possible results from evaluation of a noexcept expression.
There is no lifetime qualification on this type.
Definition: Type.h:135
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: Redeclarable.h:289
#define false
Definition: stdbool.h:33
The "struct" keyword.
Definition: Type.h:4490
Assigning into this object requires the old value to be released and the new value to be retained...
Definition: Type.h:146
Kind
QualType getAtomicUnqualifiedType() const
Remove all qualifiers including _Atomic.
Definition: Type.cpp:1297
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:3220
bool isAlignValT() const
Definition: Type.cpp:2307
bool isInterface() const
Definition: Decl.h:3026
Encodes a location in the source.
bool hasIntegerRepresentation() const
Determine whether this type has an integer representation of some sort, e.g., it is an integer type o...
Definition: Type.cpp:1637
Sugar for parentheses used when specifying types.
Definition: Type.h:2193
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Definition: Type.h:3810
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5489
bool isQualifier() const
Does this attribute behave like a type qualifier?
Definition: Type.cpp:2994
bool isConstant(const ASTContext &Ctx) const
Definition: Type.h:753
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:5165
bool isComplexType() const
isComplexType() does not include complex integers (a GCC extension).
Definition: Type.cpp:396
const std::string ID
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2816
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6.7.5p3.
Definition: Type.cpp:1920
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:346
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical) const
Produce a unique representation of the given statement.
VectorKind getVectorKind() const
Definition: Type.h:2830
bool qual_empty() const
Definition: Type.h:5349
bool isObjCClassOrClassKindOfType() const
Whether the type is Objective-C 'Class' or a __kindof type of an Class type, e.g., __kindof Class <NSCopying>.
Definition: Type.cpp:495
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
QualType getIncompleteArrayType(QualType EltTy, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return a unique reference to the type for an incomplete array of the specified element type...
The noexcept specifier evaluates to true.
Definition: Type.h:3397
bool isCXX98PODType(const ASTContext &Context) const
Return true if this is a POD type according to the rules of the C++98 standard, regardless of the cur...
Definition: Type.cpp:2013
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
Definition: Type.cpp:1663
bool isObjCBoxableRecordType() const
Definition: Type.cpp:367
const Type * getArrayElementTypeNoTypeQual() const
If this is an array type, return the element type of the array, potentially with type qualifiers miss...
Definition: Type.cpp:190
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2189
bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx, SourceLocation *Loc=nullptr, bool isEvaluated=true) const
isIntegerConstantExpr - Return true if this expression is a valid integer constant expression...
void Profile(llvm::FoldingSetNodeID &ID)
Definition: TemplateName.h:294
SplitQualType getSplitDesugaredType() const
Definition: Type.h:914
bool hasDependentExceptionSpec() const
Return whether this function has a dependent exception spec.
Definition: Type.cpp:2757
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition: Type.h:6000
bool isSpecializedAsWritten() const
Determine whether this object type was written with type arguments.
Definition: Type.h:5059
TypedefNameDecl * getDecl() const
Definition: Type.h:3593
bool isObjCQualifiedClassType() const
True if this is equivalent to 'Class.
Definition: Type.h:5304
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
Definition: Expr.h:166
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:6105
NoexceptResult getNoexceptSpec(const ASTContext &Ctx) const
Get the meaning of the noexcept spec on this function, if any.
Definition: Type.cpp:2779
CanThrowResult canThrow(const ASTContext &Ctx) const
Determine whether this function type has a non-throwing exception specification.
Definition: Type.cpp:2802
QualType getAttributedType(AttributedType::Kind attrKind, QualType modifiedType, QualType equivalentType)
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent) const
C++11 deduced auto type.
bool isVectorType() const
Definition: Type.h:5778
bool isPromotableIntegerType() const
More type predicates useful for type checking/promotion.
Definition: Type.cpp:2325
Assigning into this object requires a lifetime extension.
Definition: Type.h:152
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition: Type.cpp:2421
void setVariablyModified(bool VM=true)
Definition: Type.h:1548
ObjCTypeParamDecl * getDecl() const
Definition: Type.h:4938
TypeOfExprType(Expr *E, QualType can=QualType())
Definition: Type.cpp:2899
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type...
Definition: Type.cpp:1627
Represents a pointer type decayed from an array or function type.
Definition: Type.h:2308
QualType getPointeeType() const
Definition: Type.h:2238
Represents a pack expansion of types.
Definition: Type.h:4787
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments of this object type as they were written.
Definition: Type.h:5076
Defines various enumerations that describe declaration and type specifiers.
ArrayRef< QualType > getTypeArgs() const
Retrieve the type arguments of this object type (semantically).
Definition: Type.cpp:597
const char * getTypeClassName() const
Definition: Type.cpp:2514
static unsigned getMaxSizeBits(const ASTContext &Context)
Determine the maximum number of active bits that an array's size can require, which limits the maximu...
Definition: Type.cpp:111
Linkage minLinkage(Linkage L1, Linkage L2)
Compute the minimum linkage given two linkages.
Definition: Linkage.h:116
QualType getType() const
Definition: Expr.h:127
bool isStdByteType() const
Definition: Type.cpp:2316
Represents a template argument.
Definition: TemplateBase.h:40
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons...
Definition: Type.h:2272
TagTypeKind
The kind of a tag type.
Definition: Type.h:4488
CanQualType ObjCBuiltinIdTy
Definition: ASTContext.h:982
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
not evaluated yet, for special member function
A qualifier set is used to build a set of qualifiers.
Definition: Type.h:5455
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1215
bool isAggregateType() const
Determines whether the type is a C++ aggregate type or C aggregate or union type. ...
Definition: Type.cpp:1906
void setContainsUnexpandedParameterPack(bool PP=true)
Definition: Type.h:1550
StringRef Name
Definition: USRFinder.cpp:123
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:378
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchers.h:2126
bool isKindOfType() const
Whether this ia a "__kindof" type (semantically).
Definition: Type.cpp:615
QualType IgnoreParens() const
Returns the specified type after dropping any outer-level parentheses.
Definition: Type.h:929
bool isCallingConv() const
Definition: Type.cpp:3053
const ObjCInterfaceType * getInterfaceType() const
If this pointer points to an Objective C @interface type, gets the type for that interface.
Definition: Type.cpp:1466
bool isStandardLayoutType() const
Test if this type is a standard-layout type.
Definition: Type.cpp:2220
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.cpp:3239
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:537
The "union" keyword introduces the elaborated-type-specifier.
Definition: Type.h:4509
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
Definition: Type.h:5462
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:2783
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.cpp:3254
The "class" keyword introduces the elaborated-type-specifier.
Definition: Type.h:4511
static const T * getAsSugar(const Type *Cur)
This will check for a T (which should be a Type which can act as sugar, such as a TypedefType) by rem...
Definition: Type.cpp:307
EnumDecl - Represents an enum.
Definition: Decl.h:3102
detail::InMemoryDirectory::const_iterator E
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2442
unsigned getNumProtocols() const
Return the number of qualifying protocols in this type, or 0 if there are none.
Definition: Type.h:4882
QualType getModifiedType() const
Definition: Type.h:3910
UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind, QualType CanonicalTy)
Definition: Type.cpp:2952
void addConsistentQualifiers(Qualifiers qs)
Add the qualifiers from the given set to this set, given that they don't conflict.
Definition: Type.h:433
const RecordType * getAsStructureType() const
Definition: Type.cpp:430
bool isWideCharType() const
Definition: Type.cpp:1703
Represents a pointer to an Objective C object.
Definition: Type.h:5220
Pointer to a block type.
Definition: Type.h:2327
FunctionTypeBitfields FunctionTypeBits
Definition: Type.h:1506
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:3784
Complex values, per C99 6.2.5p11.
Definition: Type.h:2164
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:428
llvm::Optional< NullabilityKind > getImmediateNullability() const
Definition: Type.cpp:3653
bool isObjCNSObjectType() const
Definition: Type.cpp:3733
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:6042
QualType getCanonicalType() const
Definition: Type.h:5528
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameters of this class.
Definition: DeclObjC.cpp:285
bool isSpecifierType() const
Returns true if this type can be represented by some set of type specifiers.
Definition: Type.cpp:2357
ObjCInterfaceDecl * getInterfaceDecl() const
If this pointer points to an Objective @interface type, gets the declaration for that interface...
Definition: Type.h:5275
const ObjCObjectType * getAsObjCQualifiedInterfaceType() const
Definition: Type.cpp:1484
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
Definition: ASTContext.h:1281
VectorTypeBitfields VectorTypeBits
Definition: Type.h:1510
ExtVectorType - Extended vector type.
Definition: Type.h:2858
QualType getInnerType() const
Definition: Type.h:2207
The noexcept specifier evaluates to false.
Definition: Type.h:3396
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2360
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1548
unsigned getAddressSpace() const
Definition: Type.h:335
The template argument is a type.
Definition: TemplateBase.h:48
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:552
The "class" keyword.
Definition: Type.h:4496
GC getObjCGCAttr() const
Definition: Type.h:288
char __ovld __cnfn max(char x, char y)
Returns y if x < y, otherwise it returns x.
bool isMSTypeSpec() const
Definition: Type.cpp:3041
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:3222
void merge(LinkageInfo other)
Merge both linkage and visibility.
Definition: Visibility.h:131
Linkage getLinkage() const
Determine the linkage of this type.
Definition: Type.cpp:3421
The type-property cache.
Definition: Type.cpp:3286
bool hasNonTrivialObjCLifetime() const
Definition: Type.h:1032
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
const Type * getClass() const
Definition: Type.h:2475
TypeBitfields TypeBits
Definition: Type.h:1501
Reading or writing from this object requires a barrier call.
Definition: Type.h:149
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:3838
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
bool hasAddressSpace() const
Definition: Type.h:334
bool isBlockCompatibleObjCPointerType(ASTContext &ctx) const
Definition: Type.cpp:3674
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:336
bool isObjCClassType() const
True if this is equivalent to the 'Class' type, i.e.
Definition: Type.h:5287
QualType getVariableArrayType(QualType EltTy, Expr *NumElts, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a variable array of the specified element type...
bool isCARCBridgableType() const
Determine whether the given type T is a "bridgeable" C type.
Definition: Type.cpp:3784
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:5569
Represents a C++ struct/union/class.
Definition: DeclCXX.h:267
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:861
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4695
bool isObjCObjectPointerType() const
Definition: Type.h:5784
Represents a C array with an unspecified size.
Definition: Type.h:2603
The parameter type of a method or function.
ArraySizeModifier getSizeModifier() const
Definition: Type.h:2532
The "enum" keyword.
Definition: Type.h:4498
qual_range quals() const
Definition: Type.h:5342
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3634
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorType::VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition: DeclObjC.h:615
This class is used for builtin types like 'int'.
Definition: Type.h:2084
bool isArrayType() const
Definition: Type.h:5751
Defines the clang::TargetInfo interface.
QualType getPointeeTypeAsWritten() const
Definition: Type.h:2380
TagDecl * getDecl() const
Definition: Type.cpp:2986
bool isObjCIndirectLifetimeType() const
Definition: Type.cpp:3756
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:897
QualType applyObjCProtocolQualifiers(QualType type, ArrayRef< ObjCProtocolDecl * > protocols, bool &hasError, bool allowOnPointerType=false) const
Apply Objective-C protocol qualifiers to the given type.
void initialize(ArrayRef< ObjCProtocolDecl * > protocols)
Definition: Type.h:4861
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:4297
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type...
QualType getElementType() const
Definition: Type.h:2531
static StringRef getNameForCallConv(CallingConv CC)
Definition: Type.cpp:2634
#define true
Definition: stdbool.h:32
bool isObjCARCBridgableType() const
Determine whether the given type T is a "bridgable" Objective-C type, which is either an Objective-C ...
Definition: Type.cpp:3779
bool isInterfaceType() const
Definition: Type.cpp:372
QualType desugar() const
Remove a single level of sugar.
Definition: Type.cpp:2911
A trivial tuple used to represent a source range.
VectorType(QualType vecType, unsigned nElements, QualType canonType, VectorKind vecKind)
Definition: Type.cpp:171
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
StringRef getName(const PrintingPolicy &Policy) const
Definition: Type.cpp:2524
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:2648
bool isObjCIdOrObjectKindOfType(const ASTContext &ctx, const ObjCObjectType *&bound) const
Whether the type is Objective-C 'id' or a __kindof type of an object type, e.g., __kindof NSView * or...
Definition: Type.cpp:469
bool isArithmeticType() const
Definition: Type.cpp:1852
bool isClassType() const
Definition: Type.cpp:357
No keyword precedes the qualified type name.
Definition: Type.h:4518
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], or an enum decl which has a signed representation.
Definition: Type.cpp:1744
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition: Type.h:5548
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g., it is an signed integer type or a vector.
Definition: Type.cpp:1774
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:683
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:4749
const ObjCObjectPointerType * getAsObjCInterfacePointerType() const
Definition: Type.cpp:1525
QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced, QualType Replacement) const
Retrieve a substitution-result type.
bool isObjCIdType() const
True if this is equivalent to the 'id' type, i.e.
Definition: Type.h:5281
The noexcept specifier is dependent.
Definition: Type.h:3395
Optional< NullabilityKind > getNullability(const ASTContext &context) const
Determine the nullability of the given type.
Definition: Type.cpp:3526
QualType getSingleStepDesugaredType(const ASTContext &Context) const
Return the specified type with one level of "sugar" removed from the type.
Definition: Type.h:923
QualType getSuperClassType() const
Retrieve the type of the superclass of this object pointer type.
Definition: Type.cpp:1475
The "__interface" keyword introduces the elaborated-type-specifier.
Definition: Type.h:4507
ArrayRef< QualType > exceptions() const
Definition: Type.h:3477
bool isBeingDefined() const
isBeingDefined - Return true if this decl is currently being defined.
Definition: Decl.h:2971
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:2553
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:3254
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
const ObjCObjectType * getSuperClassType() const
Retrieve the superclass type.
Definition: DeclObjC.h:1487
bool isObjCQualifiedInterfaceType() const
Definition: Type.cpp:1494
ScalarTypeKind getScalarTypeKind() const
Given that this is a scalar type, classify it.
Definition: Type.cpp:1867
A single template declaration.
Definition: TemplateName.h:190
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:5928
const ObjCObjectPointerType * getAsObjCQualifiedIdType() const
Definition: Type.cpp:1498
bool isPointerType() const
Definition: Type.h:5712