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