clang  10.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  SUGARED_TYPE_CLASS(MacroQualified)
977 
978  QualType VisitAdjustedType(const AdjustedType *T) {
979  QualType originalType = recurse(T->getOriginalType());
980  if (originalType.isNull())
981  return {};
982 
983  QualType adjustedType = recurse(T->getAdjustedType());
984  if (adjustedType.isNull())
985  return {};
986 
987  if (originalType.getAsOpaquePtr()
988  == T->getOriginalType().getAsOpaquePtr() &&
989  adjustedType.getAsOpaquePtr() == T->getAdjustedType().getAsOpaquePtr())
990  return QualType(T, 0);
991 
992  return Ctx.getAdjustedType(originalType, adjustedType);
993  }
994 
995  QualType VisitDecayedType(const DecayedType *T) {
996  QualType originalType = recurse(T->getOriginalType());
997  if (originalType.isNull())
998  return {};
999 
1000  if (originalType.getAsOpaquePtr()
1001  == T->getOriginalType().getAsOpaquePtr())
1002  return QualType(T, 0);
1003 
1004  return Ctx.getDecayedType(originalType);
1005  }
1006 
1007  SUGARED_TYPE_CLASS(TypeOfExpr)
1008  SUGARED_TYPE_CLASS(TypeOf)
1009  SUGARED_TYPE_CLASS(Decltype)
1010  SUGARED_TYPE_CLASS(UnaryTransform)
1011  TRIVIAL_TYPE_CLASS(Record)
1012  TRIVIAL_TYPE_CLASS(Enum)
1013 
1014  // FIXME: Non-trivial to implement, but important for C++
1015  SUGARED_TYPE_CLASS(Elaborated)
1016 
1017  QualType VisitAttributedType(const AttributedType *T) {
1018  QualType modifiedType = recurse(T->getModifiedType());
1019  if (modifiedType.isNull())
1020  return {};
1021 
1022  QualType equivalentType = recurse(T->getEquivalentType());
1023  if (equivalentType.isNull())
1024  return {};
1025 
1026  if (modifiedType.getAsOpaquePtr()
1027  == T->getModifiedType().getAsOpaquePtr() &&
1028  equivalentType.getAsOpaquePtr()
1030  return QualType(T, 0);
1031 
1032  return Ctx.getAttributedType(T->getAttrKind(), modifiedType,
1033  equivalentType);
1034  }
1035 
1036  QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
1037  QualType replacementType = recurse(T->getReplacementType());
1038  if (replacementType.isNull())
1039  return {};
1040 
1041  if (replacementType.getAsOpaquePtr()
1043  return QualType(T, 0);
1044 
1045  return Ctx.getSubstTemplateTypeParmType(T->getReplacedParameter(),
1046  replacementType);
1047  }
1048 
1049  // FIXME: Non-trivial to implement, but important for C++
1050  SUGARED_TYPE_CLASS(TemplateSpecialization)
1051 
1052  QualType VisitAutoType(const AutoType *T) {
1053  if (!T->isDeduced())
1054  return QualType(T, 0);
1055 
1056  QualType deducedType = recurse(T->getDeducedType());
1057  if (deducedType.isNull())
1058  return {};
1059 
1060  if (deducedType.getAsOpaquePtr()
1061  == T->getDeducedType().getAsOpaquePtr())
1062  return QualType(T, 0);
1063 
1064  return Ctx.getAutoType(deducedType, T->getKeyword(),
1065  T->isDependentType());
1066  }
1067 
1068  // FIXME: Non-trivial to implement, but important for C++
1069  SUGARED_TYPE_CLASS(PackExpansion)
1070 
1071  QualType VisitObjCObjectType(const ObjCObjectType *T) {
1072  QualType baseType = recurse(T->getBaseType());
1073  if (baseType.isNull())
1074  return {};
1075 
1076  // Transform type arguments.
1077  bool typeArgChanged = false;
1078  SmallVector<QualType, 4> typeArgs;
1079  for (auto typeArg : T->getTypeArgsAsWritten()) {
1080  QualType newTypeArg = recurse(typeArg);
1081  if (newTypeArg.isNull())
1082  return {};
1083 
1084  if (newTypeArg.getAsOpaquePtr() != typeArg.getAsOpaquePtr())
1085  typeArgChanged = true;
1086 
1087  typeArgs.push_back(newTypeArg);
1088  }
1089 
1090  if (baseType.getAsOpaquePtr() == T->getBaseType().getAsOpaquePtr() &&
1091  !typeArgChanged)
1092  return QualType(T, 0);
1093 
1094  return Ctx.getObjCObjectType(baseType, typeArgs,
1095  llvm::makeArrayRef(T->qual_begin(),
1096  T->getNumProtocols()),
1097  T->isKindOfTypeAsWritten());
1098  }
1099 
1100  TRIVIAL_TYPE_CLASS(ObjCInterface)
1101 
1102  QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1103  QualType pointeeType = recurse(T->getPointeeType());
1104  if (pointeeType.isNull())
1105  return {};
1106 
1107  if (pointeeType.getAsOpaquePtr()
1108  == T->getPointeeType().getAsOpaquePtr())
1109  return QualType(T, 0);
1110 
1111  return Ctx.getObjCObjectPointerType(pointeeType);
1112  }
1113 
1114  QualType VisitAtomicType(const AtomicType *T) {
1115  QualType valueType = recurse(T->getValueType());
1116  if (valueType.isNull())
1117  return {};
1118 
1119  if (valueType.getAsOpaquePtr()
1120  == T->getValueType().getAsOpaquePtr())
1121  return QualType(T, 0);
1122 
1123  return Ctx.getAtomicType(valueType);
1124  }
1125 
1126 #undef TRIVIAL_TYPE_CLASS
1127 #undef SUGARED_TYPE_CLASS
1128 };
1129 
1130 struct SubstObjCTypeArgsVisitor
1131  : public SimpleTransformVisitor<SubstObjCTypeArgsVisitor> {
1132  using BaseType = SimpleTransformVisitor<SubstObjCTypeArgsVisitor>;
1133 
1134  ArrayRef<QualType> TypeArgs;
1135  ObjCSubstitutionContext SubstContext;
1136 
1137  SubstObjCTypeArgsVisitor(ASTContext &ctx, ArrayRef<QualType> typeArgs,
1138  ObjCSubstitutionContext context)
1139  : BaseType(ctx), TypeArgs(typeArgs), SubstContext(context) {}
1140 
1141  QualType VisitObjCTypeParamType(const ObjCTypeParamType *OTPTy) {
1142  // Replace an Objective-C type parameter reference with the corresponding
1143  // type argument.
1144  ObjCTypeParamDecl *typeParam = OTPTy->getDecl();
1145  // If we have type arguments, use them.
1146  if (!TypeArgs.empty()) {
1147  QualType argType = TypeArgs[typeParam->getIndex()];
1148  if (OTPTy->qual_empty())
1149  return argType;
1150 
1151  // Apply protocol lists if exists.
1152  bool hasError;
1154  protocolsVec.append(OTPTy->qual_begin(), OTPTy->qual_end());
1155  ArrayRef<ObjCProtocolDecl *> protocolsToApply = protocolsVec;
1156  return Ctx.applyObjCProtocolQualifiers(
1157  argType, protocolsToApply, hasError, true/*allowOnPointerType*/);
1158  }
1159 
1160  switch (SubstContext) {
1164  // Substitute the bound.
1165  return typeParam->getUnderlyingType();
1166 
1169  // Substitute the __kindof form of the underlying type.
1170  const auto *objPtr =
1172 
1173  // __kindof types, id, and Class don't need an additional
1174  // __kindof.
1175  if (objPtr->isKindOfType() || objPtr->isObjCIdOrClassType())
1176  return typeParam->getUnderlyingType();
1177 
1178  // Add __kindof.
1179  const auto *obj = objPtr->getObjectType();
1180  QualType resultTy = Ctx.getObjCObjectType(
1181  obj->getBaseType(), obj->getTypeArgsAsWritten(), obj->getProtocols(),
1182  /*isKindOf=*/true);
1183 
1184  // Rebuild object pointer type.
1185  return Ctx.getObjCObjectPointerType(resultTy);
1186  }
1187  }
1188  llvm_unreachable("Unexpected ObjCSubstitutionContext!");
1189  }
1190 
1191  QualType VisitFunctionType(const FunctionType *funcType) {
1192  // If we have a function type, update the substitution context
1193  // appropriately.
1194 
1195  //Substitute result type.
1196  QualType returnType = funcType->getReturnType().substObjCTypeArgs(
1197  Ctx, TypeArgs, ObjCSubstitutionContext::Result);
1198  if (returnType.isNull())
1199  return {};
1200 
1201  // Handle non-prototyped functions, which only substitute into the result
1202  // type.
1203  if (isa<FunctionNoProtoType>(funcType)) {
1204  // If the return type was unchanged, do nothing.
1205  if (returnType.getAsOpaquePtr() ==
1206  funcType->getReturnType().getAsOpaquePtr())
1207  return BaseType::VisitFunctionType(funcType);
1208 
1209  // Otherwise, build a new type.
1210  return Ctx.getFunctionNoProtoType(returnType, funcType->getExtInfo());
1211  }
1212 
1213  const auto *funcProtoType = cast<FunctionProtoType>(funcType);
1214 
1215  // Transform parameter types.
1216  SmallVector<QualType, 4> paramTypes;
1217  bool paramChanged = false;
1218  for (auto paramType : funcProtoType->getParamTypes()) {
1219  QualType newParamType = paramType.substObjCTypeArgs(
1220  Ctx, TypeArgs, ObjCSubstitutionContext::Parameter);
1221  if (newParamType.isNull())
1222  return {};
1223 
1224  if (newParamType.getAsOpaquePtr() != paramType.getAsOpaquePtr())
1225  paramChanged = true;
1226 
1227  paramTypes.push_back(newParamType);
1228  }
1229 
1230  // Transform extended info.
1231  FunctionProtoType::ExtProtoInfo info = funcProtoType->getExtProtoInfo();
1232  bool exceptionChanged = false;
1233  if (info.ExceptionSpec.Type == EST_Dynamic) {
1234  SmallVector<QualType, 4> exceptionTypes;
1235  for (auto exceptionType : info.ExceptionSpec.Exceptions) {
1236  QualType newExceptionType = exceptionType.substObjCTypeArgs(
1237  Ctx, TypeArgs, ObjCSubstitutionContext::Ordinary);
1238  if (newExceptionType.isNull())
1239  return {};
1240 
1241  if (newExceptionType.getAsOpaquePtr() != exceptionType.getAsOpaquePtr())
1242  exceptionChanged = true;
1243 
1244  exceptionTypes.push_back(newExceptionType);
1245  }
1246 
1247  if (exceptionChanged) {
1248  info.ExceptionSpec.Exceptions =
1249  llvm::makeArrayRef(exceptionTypes).copy(Ctx);
1250  }
1251  }
1252 
1253  if (returnType.getAsOpaquePtr() ==
1254  funcProtoType->getReturnType().getAsOpaquePtr() &&
1255  !paramChanged && !exceptionChanged)
1256  return BaseType::VisitFunctionType(funcType);
1257 
1258  return Ctx.getFunctionType(returnType, paramTypes, info);
1259  }
1260 
1261  QualType VisitObjCObjectType(const ObjCObjectType *objcObjectType) {
1262  // Substitute into the type arguments of a specialized Objective-C object
1263  // type.
1264  if (objcObjectType->isSpecializedAsWritten()) {
1265  SmallVector<QualType, 4> newTypeArgs;
1266  bool anyChanged = false;
1267  for (auto typeArg : objcObjectType->getTypeArgsAsWritten()) {
1268  QualType newTypeArg = typeArg.substObjCTypeArgs(
1269  Ctx, TypeArgs, ObjCSubstitutionContext::Ordinary);
1270  if (newTypeArg.isNull())
1271  return {};
1272 
1273  if (newTypeArg.getAsOpaquePtr() != typeArg.getAsOpaquePtr()) {
1274  // If we're substituting based on an unspecialized context type,
1275  // produce an unspecialized type.
1276  ArrayRef<ObjCProtocolDecl *> protocols(
1277  objcObjectType->qual_begin(), objcObjectType->getNumProtocols());
1278  if (TypeArgs.empty() &&
1279  SubstContext != ObjCSubstitutionContext::Superclass) {
1280  return Ctx.getObjCObjectType(
1281  objcObjectType->getBaseType(), {}, protocols,
1282  objcObjectType->isKindOfTypeAsWritten());
1283  }
1284 
1285  anyChanged = true;
1286  }
1287 
1288  newTypeArgs.push_back(newTypeArg);
1289  }
1290 
1291  if (anyChanged) {
1292  ArrayRef<ObjCProtocolDecl *> protocols(
1293  objcObjectType->qual_begin(), objcObjectType->getNumProtocols());
1294  return Ctx.getObjCObjectType(objcObjectType->getBaseType(), newTypeArgs,
1295  protocols,
1296  objcObjectType->isKindOfTypeAsWritten());
1297  }
1298  }
1299 
1300  return BaseType::VisitObjCObjectType(objcObjectType);
1301  }
1302 
1303  QualType VisitAttributedType(const AttributedType *attrType) {
1304  QualType newType = BaseType::VisitAttributedType(attrType);
1305  if (newType.isNull())
1306  return {};
1307 
1308  const auto *newAttrType = dyn_cast<AttributedType>(newType.getTypePtr());
1309  if (!newAttrType || newAttrType->getAttrKind() != attr::ObjCKindOf)
1310  return newType;
1311 
1312  // Find out if it's an Objective-C object or object pointer type;
1313  QualType newEquivType = newAttrType->getEquivalentType();
1314  const ObjCObjectPointerType *ptrType =
1315  newEquivType->getAs<ObjCObjectPointerType>();
1316  const ObjCObjectType *objType = ptrType
1317  ? ptrType->getObjectType()
1318  : newEquivType->getAs<ObjCObjectType>();
1319  if (!objType)
1320  return newType;
1321 
1322  // Rebuild the "equivalent" type, which pushes __kindof down into
1323  // the object type.
1324  newEquivType = Ctx.getObjCObjectType(
1325  objType->getBaseType(), objType->getTypeArgsAsWritten(),
1326  objType->getProtocols(),
1327  // There is no need to apply kindof on an unqualified id type.
1328  /*isKindOf=*/objType->isObjCUnqualifiedId() ? false : true);
1329 
1330  // If we started with an object pointer type, rebuild it.
1331  if (ptrType)
1332  newEquivType = Ctx.getObjCObjectPointerType(newEquivType);
1333 
1334  // Rebuild the attributed type.
1335  return Ctx.getAttributedType(newAttrType->getAttrKind(),
1336  newAttrType->getModifiedType(), newEquivType);
1337  }
1338 };
1339 
1340 struct StripObjCKindOfTypeVisitor
1341  : public SimpleTransformVisitor<StripObjCKindOfTypeVisitor> {
1342  using BaseType = SimpleTransformVisitor<StripObjCKindOfTypeVisitor>;
1343 
1344  explicit StripObjCKindOfTypeVisitor(ASTContext &ctx) : BaseType(ctx) {}
1345 
1346  QualType VisitObjCObjectType(const ObjCObjectType *objType) {
1347  if (!objType->isKindOfType())
1348  return BaseType::VisitObjCObjectType(objType);
1349 
1350  QualType baseType = objType->getBaseType().stripObjCKindOfType(Ctx);
1351  return Ctx.getObjCObjectType(baseType, objType->getTypeArgsAsWritten(),
1352  objType->getProtocols(),
1353  /*isKindOf=*/false);
1354  }
1355 };
1356 
1357 } // namespace
1358 
1359 /// Substitute the given type arguments for Objective-C type
1360 /// parameters within the given type, recursively.
1362  ArrayRef<QualType> typeArgs,
1363  ObjCSubstitutionContext context) const {
1364  SubstObjCTypeArgsVisitor visitor(ctx, typeArgs, context);
1365  return visitor.recurse(*this);
1366 }
1367 
1369  const DeclContext *dc,
1370  ObjCSubstitutionContext context) const {
1371  if (auto subs = objectType->getObjCSubstitutions(dc))
1372  return substObjCTypeArgs(dc->getParentASTContext(), *subs, context);
1373 
1374  return *this;
1375 }
1376 
1378  // FIXME: Because ASTContext::getAttributedType() is non-const.
1379  auto &ctx = const_cast<ASTContext &>(constCtx);
1380  StripObjCKindOfTypeVisitor visitor(ctx);
1381  return visitor.recurse(*this);
1382 }
1383 
1385  if (const auto AT = getTypePtr()->getAs<AtomicType>())
1386  return AT->getValueType().getUnqualifiedType();
1387  return getUnqualifiedType();
1388 }
1389 
1391  const DeclContext *dc) const {
1392  // Look through method scopes.
1393  if (const auto method = dyn_cast<ObjCMethodDecl>(dc))
1394  dc = method->getDeclContext();
1395 
1396  // Find the class or category in which the type we're substituting
1397  // was declared.
1398  const auto *dcClassDecl = dyn_cast<ObjCInterfaceDecl>(dc);
1399  const ObjCCategoryDecl *dcCategoryDecl = nullptr;
1400  ObjCTypeParamList *dcTypeParams = nullptr;
1401  if (dcClassDecl) {
1402  // If the class does not have any type parameters, there's no
1403  // substitution to do.
1404  dcTypeParams = dcClassDecl->getTypeParamList();
1405  if (!dcTypeParams)
1406  return None;
1407  } else {
1408  // If we are in neither a class nor a category, there's no
1409  // substitution to perform.
1410  dcCategoryDecl = dyn_cast<ObjCCategoryDecl>(dc);
1411  if (!dcCategoryDecl)
1412  return None;
1413 
1414  // If the category does not have any type parameters, there's no
1415  // substitution to do.
1416  dcTypeParams = dcCategoryDecl->getTypeParamList();
1417  if (!dcTypeParams)
1418  return None;
1419 
1420  dcClassDecl = dcCategoryDecl->getClassInterface();
1421  if (!dcClassDecl)
1422  return None;
1423  }
1424  assert(dcTypeParams && "No substitutions to perform");
1425  assert(dcClassDecl && "No class context");
1426 
1427  // Find the underlying object type.
1428  const ObjCObjectType *objectType;
1429  if (const auto *objectPointerType = getAs<ObjCObjectPointerType>()) {
1430  objectType = objectPointerType->getObjectType();
1431  } else if (getAs<BlockPointerType>()) {
1432  ASTContext &ctx = dc->getParentASTContext();
1433  objectType = ctx.getObjCObjectType(ctx.ObjCBuiltinIdTy, {}, {})
1434  ->castAs<ObjCObjectType>();
1435  } else {
1436  objectType = getAs<ObjCObjectType>();
1437  }
1438 
1439  /// Extract the class from the receiver object type.
1440  ObjCInterfaceDecl *curClassDecl = objectType ? objectType->getInterface()
1441  : nullptr;
1442  if (!curClassDecl) {
1443  // If we don't have a context type (e.g., this is "id" or some
1444  // variant thereof), substitute the bounds.
1445  return llvm::ArrayRef<QualType>();
1446  }
1447 
1448  // Follow the superclass chain until we've mapped the receiver type
1449  // to the same class as the context.
1450  while (curClassDecl != dcClassDecl) {
1451  // Map to the superclass type.
1452  QualType superType = objectType->getSuperClassType();
1453  if (superType.isNull()) {
1454  objectType = nullptr;
1455  break;
1456  }
1457 
1458  objectType = superType->castAs<ObjCObjectType>();
1459  curClassDecl = objectType->getInterface();
1460  }
1461 
1462  // If we don't have a receiver type, or the receiver type does not
1463  // have type arguments, substitute in the defaults.
1464  if (!objectType || objectType->isUnspecialized()) {
1465  return llvm::ArrayRef<QualType>();
1466  }
1467 
1468  // The receiver type has the type arguments we want.
1469  return objectType->getTypeArgs();
1470 }
1471 
1473  if (auto *IfaceT = getAsObjCInterfaceType()) {
1474  if (auto *ID = IfaceT->getInterface()) {
1475  if (ID->getTypeParamList())
1476  return true;
1477  }
1478  }
1479 
1480  return false;
1481 }
1482 
1484  // Retrieve the class declaration for this type. If there isn't one
1485  // (e.g., this is some variant of "id" or "Class"), then there is no
1486  // superclass type.
1487  ObjCInterfaceDecl *classDecl = getInterface();
1488  if (!classDecl) {
1489  CachedSuperClassType.setInt(true);
1490  return;
1491  }
1492 
1493  // Extract the superclass type.
1494  const ObjCObjectType *superClassObjTy = classDecl->getSuperClassType();
1495  if (!superClassObjTy) {
1496  CachedSuperClassType.setInt(true);
1497  return;
1498  }
1499 
1500  ObjCInterfaceDecl *superClassDecl = superClassObjTy->getInterface();
1501  if (!superClassDecl) {
1502  CachedSuperClassType.setInt(true);
1503  return;
1504  }
1505 
1506  // If the superclass doesn't have type parameters, then there is no
1507  // substitution to perform.
1508  QualType superClassType(superClassObjTy, 0);
1509  ObjCTypeParamList *superClassTypeParams = superClassDecl->getTypeParamList();
1510  if (!superClassTypeParams) {
1511  CachedSuperClassType.setPointerAndInt(
1512  superClassType->castAs<ObjCObjectType>(), true);
1513  return;
1514  }
1515 
1516  // If the superclass reference is unspecialized, return it.
1517  if (superClassObjTy->isUnspecialized()) {
1518  CachedSuperClassType.setPointerAndInt(superClassObjTy, true);
1519  return;
1520  }
1521 
1522  // If the subclass is not parameterized, there aren't any type
1523  // parameters in the superclass reference to substitute.
1524  ObjCTypeParamList *typeParams = classDecl->getTypeParamList();
1525  if (!typeParams) {
1526  CachedSuperClassType.setPointerAndInt(
1527  superClassType->castAs<ObjCObjectType>(), true);
1528  return;
1529  }
1530 
1531  // If the subclass type isn't specialized, return the unspecialized
1532  // superclass.
1533  if (isUnspecialized()) {
1534  QualType unspecializedSuper
1535  = classDecl->getASTContext().getObjCInterfaceType(
1536  superClassObjTy->getInterface());
1537  CachedSuperClassType.setPointerAndInt(
1538  unspecializedSuper->castAs<ObjCObjectType>(),
1539  true);
1540  return;
1541  }
1542 
1543  // Substitute the provided type arguments into the superclass type.
1544  ArrayRef<QualType> typeArgs = getTypeArgs();
1545  assert(typeArgs.size() == typeParams->size());
1546  CachedSuperClassType.setPointerAndInt(
1547  superClassType.substObjCTypeArgs(classDecl->getASTContext(), typeArgs,
1549  ->castAs<ObjCObjectType>(),
1550  true);
1551 }
1552 
1554  if (auto interfaceDecl = getObjectType()->getInterface()) {
1555  return interfaceDecl->getASTContext().getObjCInterfaceType(interfaceDecl)
1557  }
1558 
1559  return nullptr;
1560 }
1561 
1563  QualType superObjectType = getObjectType()->getSuperClassType();
1564  if (superObjectType.isNull())
1565  return superObjectType;
1566 
1567  ASTContext &ctx = getInterfaceDecl()->getASTContext();
1568  return ctx.getObjCObjectPointerType(superObjectType);
1569 }
1570 
1572  // There is no sugar for ObjCObjectType's, just return the canonical
1573  // type pointer if it is the right class. There is no typedef information to
1574  // return and these cannot be Address-space qualified.
1575  if (const auto *T = getAs<ObjCObjectType>())
1576  if (T->getNumProtocols() && T->getInterface())
1577  return T;
1578  return nullptr;
1579 }
1580 
1582  return getAsObjCQualifiedInterfaceType() != nullptr;
1583 }
1584 
1586  // There is no sugar for ObjCQualifiedIdType's, just return the canonical
1587  // type pointer if it is the right class.
1588  if (const auto *OPT = getAs<ObjCObjectPointerType>()) {
1589  if (OPT->isObjCQualifiedIdType())
1590  return OPT;
1591  }
1592  return nullptr;
1593 }
1594 
1596  // There is no sugar for ObjCQualifiedClassType's, just return the canonical
1597  // type pointer if it is the right class.
1598  if (const auto *OPT = getAs<ObjCObjectPointerType>()) {
1599  if (OPT->isObjCQualifiedClassType())
1600  return OPT;
1601  }
1602  return nullptr;
1603 }
1604 
1606  if (const auto *OT = getAs<ObjCObjectType>()) {
1607  if (OT->getInterface())
1608  return OT;
1609  }
1610  return nullptr;
1611 }
1612 
1614  if (const auto *OPT = getAs<ObjCObjectPointerType>()) {
1615  if (OPT->getInterfaceType())
1616  return OPT;
1617  }
1618  return nullptr;
1619 }
1620 
1622  QualType PointeeType;
1623  if (const auto *PT = getAs<PointerType>())
1624  PointeeType = PT->getPointeeType();
1625  else if (const auto *RT = getAs<ReferenceType>())
1626  PointeeType = RT->getPointeeType();
1627  else
1628  return nullptr;
1629 
1630  if (const auto *RT = PointeeType->getAs<RecordType>())
1631  return dyn_cast<CXXRecordDecl>(RT->getDecl());
1632 
1633  return nullptr;
1634 }
1635 
1637  return dyn_cast_or_null<CXXRecordDecl>(getAsTagDecl());
1638 }
1639 
1641  return dyn_cast_or_null<RecordDecl>(getAsTagDecl());
1642 }
1643 
1645  if (const auto *TT = getAs<TagType>())
1646  return TT->getDecl();
1647  if (const auto *Injected = getAs<InjectedClassNameType>())
1648  return Injected->getDecl();
1649 
1650  return nullptr;
1651 }
1652 
1653 bool Type::hasAttr(attr::Kind AK) const {
1654  const Type *Cur = this;
1655  while (const auto *AT = Cur->getAs<AttributedType>()) {
1656  if (AT->getAttrKind() == AK)
1657  return true;
1658  Cur = AT->getEquivalentType().getTypePtr();
1659  }
1660  return false;
1661 }
1662 
1663 namespace {
1664 
1665  class GetContainedDeducedTypeVisitor :
1666  public TypeVisitor<GetContainedDeducedTypeVisitor, Type*> {
1667  bool Syntactic;
1668 
1669  public:
1670  GetContainedDeducedTypeVisitor(bool Syntactic = false)
1671  : Syntactic(Syntactic) {}
1672 
1674 
1675  Type *Visit(QualType T) {
1676  if (T.isNull())
1677  return nullptr;
1678  return Visit(T.getTypePtr());
1679  }
1680 
1681  // The deduced type itself.
1682  Type *VisitDeducedType(const DeducedType *AT) {
1683  return const_cast<DeducedType*>(AT);
1684  }
1685 
1686  // Only these types can contain the desired 'auto' type.
1687 
1688  Type *VisitElaboratedType(const ElaboratedType *T) {
1689  return Visit(T->getNamedType());
1690  }
1691 
1692  Type *VisitPointerType(const PointerType *T) {
1693  return Visit(T->getPointeeType());
1694  }
1695 
1696  Type *VisitBlockPointerType(const BlockPointerType *T) {
1697  return Visit(T->getPointeeType());
1698  }
1699 
1700  Type *VisitReferenceType(const ReferenceType *T) {
1701  return Visit(T->getPointeeTypeAsWritten());
1702  }
1703 
1704  Type *VisitMemberPointerType(const MemberPointerType *T) {
1705  return Visit(T->getPointeeType());
1706  }
1707 
1708  Type *VisitArrayType(const ArrayType *T) {
1709  return Visit(T->getElementType());
1710  }
1711 
1712  Type *VisitDependentSizedExtVectorType(
1713  const DependentSizedExtVectorType *T) {
1714  return Visit(T->getElementType());
1715  }
1716 
1717  Type *VisitVectorType(const VectorType *T) {
1718  return Visit(T->getElementType());
1719  }
1720 
1721  Type *VisitFunctionProtoType(const FunctionProtoType *T) {
1722  if (Syntactic && T->hasTrailingReturn())
1723  return const_cast<FunctionProtoType*>(T);
1724  return VisitFunctionType(T);
1725  }
1726 
1727  Type *VisitFunctionType(const FunctionType *T) {
1728  return Visit(T->getReturnType());
1729  }
1730 
1731  Type *VisitParenType(const ParenType *T) {
1732  return Visit(T->getInnerType());
1733  }
1734 
1735  Type *VisitAttributedType(const AttributedType *T) {
1736  return Visit(T->getModifiedType());
1737  }
1738 
1739  Type *VisitMacroQualifiedType(const MacroQualifiedType *T) {
1740  return Visit(T->getUnderlyingType());
1741  }
1742 
1743  Type *VisitAdjustedType(const AdjustedType *T) {
1744  return Visit(T->getOriginalType());
1745  }
1746 
1747  Type *VisitPackExpansionType(const PackExpansionType *T) {
1748  return Visit(T->getPattern());
1749  }
1750  };
1751 
1752 } // namespace
1753 
1755  return cast_or_null<DeducedType>(
1756  GetContainedDeducedTypeVisitor().Visit(this));
1757 }
1758 
1760  return dyn_cast_or_null<FunctionType>(
1761  GetContainedDeducedTypeVisitor(true).Visit(this));
1762 }
1763 
1765  if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
1766  return VT->getElementType()->isIntegerType();
1767  else
1768  return isIntegerType();
1769 }
1770 
1771 /// Determine whether this type is an integral type.
1772 ///
1773 /// This routine determines whether the given type is an integral type per
1774 /// C++ [basic.fundamental]p7. Although the C standard does not define the
1775 /// term "integral type", it has a similar term "integer type", and in C++
1776 /// the two terms are equivalent. However, C's "integer type" includes
1777 /// enumeration types, while C++'s "integer type" does not. The \c ASTContext
1778 /// parameter is used to determine whether we should be following the C or
1779 /// C++ rules when determining whether this type is an integral/integer type.
1780 ///
1781 /// For cases where C permits "an integer type" and C++ permits "an integral
1782 /// type", use this routine.
1783 ///
1784 /// For cases where C permits "an integer type" and C++ permits "an integral
1785 /// or enumeration type", use \c isIntegralOrEnumerationType() instead.
1786 ///
1787 /// \param Ctx The context in which this type occurs.
1788 ///
1789 /// \returns true if the type is considered an integral type, false otherwise.
1790 bool Type::isIntegralType(const ASTContext &Ctx) const {
1791  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1792  return BT->getKind() >= BuiltinType::Bool &&
1793  BT->getKind() <= BuiltinType::Int128;
1794 
1795  // Complete enum types are integral in C.
1796  if (!Ctx.getLangOpts().CPlusPlus)
1797  if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
1798  return ET->getDecl()->isComplete();
1799 
1800  return false;
1801 }
1802 
1804  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1805  return BT->getKind() >= BuiltinType::Bool &&
1806  BT->getKind() <= BuiltinType::Int128;
1807 
1808  // Check for a complete enum type; incomplete enum types are not properly an
1809  // enumeration type in the sense required here.
1810  // C++0x: However, if the underlying type of the enum is fixed, it is
1811  // considered complete.
1812  if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
1813  return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped();
1814 
1815  return false;
1816 }
1817 
1818 bool Type::isCharType() const {
1819  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1820  return BT->getKind() == BuiltinType::Char_U ||
1821  BT->getKind() == BuiltinType::UChar ||
1822  BT->getKind() == BuiltinType::Char_S ||
1823  BT->getKind() == BuiltinType::SChar;
1824  return false;
1825 }
1826 
1827 bool Type::isWideCharType() const {
1828  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1829  return BT->getKind() == BuiltinType::WChar_S ||
1830  BT->getKind() == BuiltinType::WChar_U;
1831  return false;
1832 }
1833 
1834 bool Type::isChar8Type() const {
1835  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
1836  return BT->getKind() == BuiltinType::Char8;
1837  return false;
1838 }
1839 
1840 bool Type::isChar16Type() const {
1841  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1842  return BT->getKind() == BuiltinType::Char16;
1843  return false;
1844 }
1845 
1846 bool Type::isChar32Type() const {
1847  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1848  return BT->getKind() == BuiltinType::Char32;
1849  return false;
1850 }
1851 
1852 /// Determine whether this type is any of the built-in character
1853 /// types.
1855  const auto *BT = dyn_cast<BuiltinType>(CanonicalType);
1856  if (!BT) return false;
1857  switch (BT->getKind()) {
1858  default: return false;
1859  case BuiltinType::Char_U:
1860  case BuiltinType::UChar:
1861  case BuiltinType::WChar_U:
1862  case BuiltinType::Char8:
1863  case BuiltinType::Char16:
1864  case BuiltinType::Char32:
1865  case BuiltinType::Char_S:
1866  case BuiltinType::SChar:
1867  case BuiltinType::WChar_S:
1868  return true;
1869  }
1870 }
1871 
1872 /// isSignedIntegerType - Return true if this is an integer type that is
1873 /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
1874 /// an enum decl which has a signed representation
1876  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
1877  return BT->getKind() >= BuiltinType::Char_S &&
1878  BT->getKind() <= BuiltinType::Int128;
1879  }
1880 
1881  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
1882  // Incomplete enum types are not treated as integer types.
1883  // FIXME: In C++, enum types are never integer types.
1884  if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
1885  return ET->getDecl()->getIntegerType()->isSignedIntegerType();
1886  }
1887 
1888  return false;
1889 }
1890 
1892  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
1893  return BT->getKind() >= BuiltinType::Char_S &&
1894  BT->getKind() <= BuiltinType::Int128;
1895  }
1896 
1897  if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
1898  if (ET->getDecl()->isComplete())
1899  return ET->getDecl()->getIntegerType()->isSignedIntegerType();
1900  }
1901 
1902  return false;
1903 }
1904 
1906  if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
1907  return VT->getElementType()->isSignedIntegerOrEnumerationType();
1908  else
1910 }
1911 
1912 /// isUnsignedIntegerType - Return true if this is an integer type that is
1913 /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
1914 /// decl which has an unsigned representation
1916  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
1917  return BT->getKind() >= BuiltinType::Bool &&
1918  BT->getKind() <= BuiltinType::UInt128;
1919  }
1920 
1921  if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
1922  // Incomplete enum types are not treated as integer types.
1923  // FIXME: In C++, enum types are never integer types.
1924  if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
1925  return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
1926  }
1927 
1928  return false;
1929 }
1930 
1932  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
1933  return BT->getKind() >= BuiltinType::Bool &&
1934  BT->getKind() <= BuiltinType::UInt128;
1935  }
1936 
1937  if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
1938  if (ET->getDecl()->isComplete())
1939  return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
1940  }
1941 
1942  return false;
1943 }
1944 
1946  if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
1947  return VT->getElementType()->isUnsignedIntegerOrEnumerationType();
1948  else
1950 }
1951 
1952 bool Type::isFloatingType() const {
1953  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1954  return BT->getKind() >= BuiltinType::Half &&
1955  BT->getKind() <= BuiltinType::Float128;
1956  if (const auto *CT = dyn_cast<ComplexType>(CanonicalType))
1957  return CT->getElementType()->isFloatingType();
1958  return false;
1959 }
1960 
1962  if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
1963  return VT->getElementType()->isFloatingType();
1964  else
1965  return isFloatingType();
1966 }
1967 
1969  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1970  return BT->isFloatingPoint();
1971  return false;
1972 }
1973 
1974 bool Type::isRealType() const {
1975  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1976  return BT->getKind() >= BuiltinType::Bool &&
1977  BT->getKind() <= BuiltinType::Float128;
1978  if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
1979  return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped();
1980  return false;
1981 }
1982 
1984  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1985  return BT->getKind() >= BuiltinType::Bool &&
1986  BT->getKind() <= BuiltinType::Float128;
1987  if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
1988  // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
1989  // If a body isn't seen by the time we get here, return false.
1990  //
1991  // C++0x: Enumerations are not arithmetic types. For now, just return
1992  // false for scoped enumerations since that will disable any
1993  // unwanted implicit conversions.
1994  return !ET->getDecl()->isScoped() && ET->getDecl()->isComplete();
1995  return isa<ComplexType>(CanonicalType);
1996 }
1997 
1999  assert(isScalarType());
2000 
2001  const Type *T = CanonicalType.getTypePtr();
2002  if (const auto *BT = dyn_cast<BuiltinType>(T)) {
2003  if (BT->getKind() == BuiltinType::Bool) return STK_Bool;
2004  if (BT->getKind() == BuiltinType::NullPtr) return STK_CPointer;
2005  if (BT->isInteger()) return STK_Integral;
2006  if (BT->isFloatingPoint()) return STK_Floating;
2007  if (BT->isFixedPointType()) return STK_FixedPoint;
2008  llvm_unreachable("unknown scalar builtin type");
2009  } else if (isa<PointerType>(T)) {
2010  return STK_CPointer;
2011  } else if (isa<BlockPointerType>(T)) {
2012  return STK_BlockPointer;
2013  } else if (isa<ObjCObjectPointerType>(T)) {
2014  return STK_ObjCObjectPointer;
2015  } else if (isa<MemberPointerType>(T)) {
2016  return STK_MemberPointer;
2017  } else if (isa<EnumType>(T)) {
2018  assert(cast<EnumType>(T)->getDecl()->isComplete());
2019  return STK_Integral;
2020  } else if (const auto *CT = dyn_cast<ComplexType>(T)) {
2021  if (CT->getElementType()->isRealFloatingType())
2022  return STK_FloatingComplex;
2023  return STK_IntegralComplex;
2024  }
2025 
2026  llvm_unreachable("unknown scalar type");
2027 }
2028 
2029 /// Determines whether the type is a C++ aggregate type or C
2030 /// aggregate or union type.
2031 ///
2032 /// An aggregate type is an array or a class type (struct, union, or
2033 /// class) that has no user-declared constructors, no private or
2034 /// protected non-static data members, no base classes, and no virtual
2035 /// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type
2036 /// subsumes the notion of C aggregates (C99 6.2.5p21) because it also
2037 /// includes union types.
2039  if (const auto *Record = dyn_cast<RecordType>(CanonicalType)) {
2040  if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl()))
2041  return ClassDecl->isAggregate();
2042 
2043  return true;
2044  }
2045 
2046  return isa<ArrayType>(CanonicalType);
2047 }
2048 
2049 /// isConstantSizeType - Return true if this is not a variable sized type,
2050 /// according to the rules of C99 6.7.5p3. It is not legal to call this on
2051 /// incomplete types or dependent types.
2053  assert(!isIncompleteType() && "This doesn't make sense for incomplete types");
2054  assert(!isDependentType() && "This doesn't make sense for dependent types");
2055  // The VAT must have a size, as it is known to be complete.
2056  return !isa<VariableArrayType>(CanonicalType);
2057 }
2058 
2059 /// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1)
2060 /// - a type that can describe objects, but which lacks information needed to
2061 /// determine its size.
2063  if (Def)
2064  *Def = nullptr;
2065 
2066  switch (CanonicalType->getTypeClass()) {
2067  default: return false;
2068  case Builtin:
2069  // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never
2070  // be completed.
2071  return isVoidType();
2072  case Enum: {
2073  EnumDecl *EnumD = cast<EnumType>(CanonicalType)->getDecl();
2074  if (Def)
2075  *Def = EnumD;
2076  return !EnumD->isComplete();
2077  }
2078  case Record: {
2079  // A tagged type (struct/union/enum/class) is incomplete if the decl is a
2080  // forward declaration, but not a full definition (C99 6.2.5p22).
2081  RecordDecl *Rec = cast<RecordType>(CanonicalType)->getDecl();
2082  if (Def)
2083  *Def = Rec;
2084  return !Rec->isCompleteDefinition();
2085  }
2086  case ConstantArray:
2087  // An array is incomplete if its element type is incomplete
2088  // (C++ [dcl.array]p1).
2089  // We don't handle variable arrays (they're not allowed in C++) or
2090  // dependent-sized arrays (dependent types are never treated as incomplete).
2091  return cast<ArrayType>(CanonicalType)->getElementType()
2092  ->isIncompleteType(Def);
2093  case IncompleteArray:
2094  // An array of unknown size is an incomplete type (C99 6.2.5p22).
2095  return true;
2096  case MemberPointer: {
2097  // Member pointers in the MS ABI have special behavior in
2098  // RequireCompleteType: they attach a MSInheritanceAttr to the CXXRecordDecl
2099  // to indicate which inheritance model to use.
2100  auto *MPTy = cast<MemberPointerType>(CanonicalType);
2101  const Type *ClassTy = MPTy->getClass();
2102  // Member pointers with dependent class types don't get special treatment.
2103  if (ClassTy->isDependentType())
2104  return false;
2105  const CXXRecordDecl *RD = ClassTy->getAsCXXRecordDecl();
2106  ASTContext &Context = RD->getASTContext();
2107  // Member pointers not in the MS ABI don't get special treatment.
2108  if (!Context.getTargetInfo().getCXXABI().isMicrosoft())
2109  return false;
2110  // The inheritance attribute might only be present on the most recent
2111  // CXXRecordDecl, use that one.
2112  RD = RD->getMostRecentNonInjectedDecl();
2113  // Nothing interesting to do if the inheritance attribute is already set.
2114  if (RD->hasAttr<MSInheritanceAttr>())
2115  return false;
2116  return true;
2117  }
2118  case ObjCObject:
2119  return cast<ObjCObjectType>(CanonicalType)->getBaseType()
2120  ->isIncompleteType(Def);
2121  case ObjCInterface: {
2122  // ObjC interfaces are incomplete if they are @class, not @interface.
2123  ObjCInterfaceDecl *Interface
2124  = cast<ObjCInterfaceType>(CanonicalType)->getDecl();
2125  if (Def)
2126  *Def = Interface;
2127  return !Interface->hasDefinition();
2128  }
2129  }
2130 }
2131 
2132 bool QualType::isPODType(const ASTContext &Context) const {
2133  // C++11 has a more relaxed definition of POD.
2134  if (Context.getLangOpts().CPlusPlus11)
2135  return isCXX11PODType(Context);
2136 
2137  return isCXX98PODType(Context);
2138 }
2139 
2140 bool QualType::isCXX98PODType(const ASTContext &Context) const {
2141  // The compiler shouldn't query this for incomplete types, but the user might.
2142  // We return false for that case. Except for incomplete arrays of PODs, which
2143  // are PODs according to the standard.
2144  if (isNull())
2145  return false;
2146 
2147  if ((*this)->isIncompleteArrayType())
2148  return Context.getBaseElementType(*this).isCXX98PODType(Context);
2149 
2150  if ((*this)->isIncompleteType())
2151  return false;
2152 
2153  if (hasNonTrivialObjCLifetime())
2154  return false;
2155 
2156  QualType CanonicalType = getTypePtr()->CanonicalType;
2157  switch (CanonicalType->getTypeClass()) {
2158  // Everything not explicitly mentioned is not POD.
2159  default: return false;
2160  case Type::VariableArray:
2161  case Type::ConstantArray:
2162  // IncompleteArray is handled above.
2163  return Context.getBaseElementType(*this).isCXX98PODType(Context);
2164 
2165  case Type::ObjCObjectPointer:
2166  case Type::BlockPointer:
2167  case Type::Builtin:
2168  case Type::Complex:
2169  case Type::Pointer:
2170  case Type::MemberPointer:
2171  case Type::Vector:
2172  case Type::ExtVector:
2173  return true;
2174 
2175  case Type::Enum:
2176  return true;
2177 
2178  case Type::Record:
2179  if (const auto *ClassDecl =
2180  dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl()))
2181  return ClassDecl->isPOD();
2182 
2183  // C struct/union is POD.
2184  return true;
2185  }
2186 }
2187 
2188 bool QualType::isTrivialType(const ASTContext &Context) const {
2189  // The compiler shouldn't query this for incomplete types, but the user might.
2190  // We return false for that case. Except for incomplete arrays of PODs, which
2191  // are PODs according to the standard.
2192  if (isNull())
2193  return false;
2194 
2195  if ((*this)->isArrayType())
2196  return Context.getBaseElementType(*this).isTrivialType(Context);
2197 
2198  // Return false for incomplete types after skipping any incomplete array
2199  // types which are expressly allowed by the standard and thus our API.
2200  if ((*this)->isIncompleteType())
2201  return false;
2202 
2203  if (hasNonTrivialObjCLifetime())
2204  return false;
2205 
2206  QualType CanonicalType = getTypePtr()->CanonicalType;
2207  if (CanonicalType->isDependentType())
2208  return false;
2209 
2210  // C++0x [basic.types]p9:
2211  // Scalar types, trivial class types, arrays of such types, and
2212  // cv-qualified versions of these types are collectively called trivial
2213  // types.
2214 
2215  // As an extension, Clang treats vector types as Scalar types.
2216  if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
2217  return true;
2218  if (const auto *RT = CanonicalType->getAs<RecordType>()) {
2219  if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
2220  // C++11 [class]p6:
2221  // A trivial class is a class that has a default constructor,
2222  // has no non-trivial default constructors, and is trivially
2223  // copyable.
2224  return ClassDecl->hasDefaultConstructor() &&
2225  !ClassDecl->hasNonTrivialDefaultConstructor() &&
2226  ClassDecl->isTriviallyCopyable();
2227  }
2228 
2229  return true;
2230  }
2231 
2232  // No other types can match.
2233  return false;
2234 }
2235 
2236 bool QualType::isTriviallyCopyableType(const ASTContext &Context) const {
2237  if ((*this)->isArrayType())
2238  return Context.getBaseElementType(*this).isTriviallyCopyableType(Context);
2239 
2240  if (hasNonTrivialObjCLifetime())
2241  return false;
2242 
2243  // C++11 [basic.types]p9 - See Core 2094
2244  // Scalar types, trivially copyable class types, arrays of such types, and
2245  // cv-qualified versions of these types are collectively
2246  // called trivially copyable types.
2247 
2248  QualType CanonicalType = getCanonicalType();
2249  if (CanonicalType->isDependentType())
2250  return false;
2251 
2252  // Return false for incomplete types after skipping any incomplete array types
2253  // which are expressly allowed by the standard and thus our API.
2254  if (CanonicalType->isIncompleteType())
2255  return false;
2256 
2257  // As an extension, Clang treats vector types as Scalar types.
2258  if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
2259  return true;
2260 
2261  if (const auto *RT = CanonicalType->getAs<RecordType>()) {
2262  if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
2263  if (!ClassDecl->isTriviallyCopyable()) return false;
2264  }
2265 
2266  return true;
2267  }
2268 
2269  // No other types can match.
2270  return false;
2271 }
2272 
2274  return !Context.getLangOpts().ObjCAutoRefCount &&
2275  Context.getLangOpts().ObjCWeak &&
2276  getObjCLifetime() != Qualifiers::OCL_Weak;
2277 }
2278 
2279 namespace {
2280 // Helper class that determines whether this is a type that is non-trivial to
2281 // primitive copy or move, or is a struct type that has a field of such type.
2282 template <bool IsMove>
2283 struct IsNonTrivialCopyMoveVisitor
2284  : CopiedTypeVisitor<IsNonTrivialCopyMoveVisitor<IsMove>, IsMove, bool> {
2285  using Super =
2287  IsNonTrivialCopyMoveVisitor(const ASTContext &C) : Ctx(C) {}
2288  void preVisit(QualType::PrimitiveCopyKind PCK, QualType QT) {}
2289 
2290  bool visitWithKind(QualType::PrimitiveCopyKind PCK, QualType QT) {
2291  if (const auto *AT = this->Ctx.getAsArrayType(QT))
2292  return this->asDerived().visit(Ctx.getBaseElementType(AT));
2293  return Super::visitWithKind(PCK, QT);
2294  }
2295 
2296  bool visitARCStrong(QualType QT) { return true; }
2297  bool visitARCWeak(QualType QT) { return true; }
2298  bool visitTrivial(QualType QT) { return false; }
2299  // Volatile fields are considered trivial.
2300  bool visitVolatileTrivial(QualType QT) { return false; }
2301 
2302  bool visitStruct(QualType QT) {
2303  const RecordDecl *RD = QT->castAs<RecordType>()->getDecl();
2304  // We don't want to apply the C restriction in C++ because C++
2305  // (1) can apply the restriction at a finer grain by banning copying or
2306  // destroying the union, and
2307  // (2) allows users to override these restrictions by declaring explicit
2308  // constructors/etc, which we're not proposing to add to C.
2309  if (isa<CXXRecordDecl>(RD))
2310  return false;
2311  for (const FieldDecl *FD : RD->fields())
2312  if (this->asDerived().visit(FD->getType()))
2313  return true;
2314  return false;
2315  }
2316 
2317  const ASTContext &Ctx;
2318 };
2319 
2320 } // namespace
2321 
2323  if (isNonTrivialToPrimitiveDefaultInitialize())
2324  return true;
2325  DestructionKind DK = isDestructedType();
2326  if (DK != DK_none && DK != DK_cxx_destructor)
2327  return true;
2328  if (IsNonTrivialCopyMoveVisitor<false>(Ctx).visit(*this))
2329  return true;
2330  if (IsNonTrivialCopyMoveVisitor<true>(Ctx).visit(*this))
2331  return true;
2332  return false;
2333 }
2334 
2337  if (const auto *RT =
2338  getTypePtr()->getBaseElementTypeUnsafe()->getAs<RecordType>())
2339  if (RT->getDecl()->isNonTrivialToPrimitiveDefaultInitialize())
2340  return PDIK_Struct;
2341 
2342  switch (getQualifiers().getObjCLifetime()) {
2344  return PDIK_ARCStrong;
2345  case Qualifiers::OCL_Weak:
2346  return PDIK_ARCWeak;
2347  default:
2348  return PDIK_Trivial;
2349  }
2350 }
2351 
2353  if (const auto *RT =
2354  getTypePtr()->getBaseElementTypeUnsafe()->getAs<RecordType>())
2355  if (RT->getDecl()->isNonTrivialToPrimitiveCopy())
2356  return PCK_Struct;
2357 
2358  Qualifiers Qs = getQualifiers();
2359  switch (Qs.getObjCLifetime()) {
2361  return PCK_ARCStrong;
2362  case Qualifiers::OCL_Weak:
2363  return PCK_ARCWeak;
2364  default:
2365  return Qs.hasVolatile() ? PCK_VolatileTrivial : PCK_Trivial;
2366  }
2367 }
2368 
2371  return isNonTrivialToPrimitiveCopy();
2372 }
2373 
2374 bool Type::isLiteralType(const ASTContext &Ctx) const {
2375  if (isDependentType())
2376  return false;
2377 
2378  // C++1y [basic.types]p10:
2379  // A type is a literal type if it is:
2380  // -- cv void; or
2381  if (Ctx.getLangOpts().CPlusPlus14 && isVoidType())
2382  return true;
2383 
2384  // C++11 [basic.types]p10:
2385  // A type is a literal type if it is:
2386  // [...]
2387  // -- an array of literal type other than an array of runtime bound; or
2388  if (isVariableArrayType())
2389  return false;
2390  const Type *BaseTy = getBaseElementTypeUnsafe();
2391  assert(BaseTy && "NULL element type");
2392 
2393  // Return false for incomplete types after skipping any incomplete array
2394  // types; those are expressly allowed by the standard and thus our API.
2395  if (BaseTy->isIncompleteType())
2396  return false;
2397 
2398  // C++11 [basic.types]p10:
2399  // A type is a literal type if it is:
2400  // -- a scalar type; or
2401  // As an extension, Clang treats vector types and complex types as
2402  // literal types.
2403  if (BaseTy->isScalarType() || BaseTy->isVectorType() ||
2404  BaseTy->isAnyComplexType())
2405  return true;
2406  // -- a reference type; or
2407  if (BaseTy->isReferenceType())
2408  return true;
2409  // -- a class type that has all of the following properties:
2410  if (const auto *RT = BaseTy->getAs<RecordType>()) {
2411  // -- a trivial destructor,
2412  // -- every constructor call and full-expression in the
2413  // brace-or-equal-initializers for non-static data members (if any)
2414  // is a constant expression,
2415  // -- it is an aggregate type or has at least one constexpr
2416  // constructor or constructor template that is not a copy or move
2417  // constructor, and
2418  // -- all non-static data members and base classes of literal types
2419  //
2420  // We resolve DR1361 by ignoring the second bullet.
2421  if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl()))
2422  return ClassDecl->isLiteral();
2423 
2424  return true;
2425  }
2426 
2427  // We treat _Atomic T as a literal type if T is a literal type.
2428  if (const auto *AT = BaseTy->getAs<AtomicType>())
2429  return AT->getValueType()->isLiteralType(Ctx);
2430 
2431  // If this type hasn't been deduced yet, then conservatively assume that
2432  // it'll work out to be a literal type.
2433  if (isa<AutoType>(BaseTy->getCanonicalTypeInternal()))
2434  return true;
2435 
2436  return false;
2437 }
2438 
2440  if (isDependentType())
2441  return false;
2442 
2443  // C++0x [basic.types]p9:
2444  // Scalar types, standard-layout class types, arrays of such types, and
2445  // cv-qualified versions of these types are collectively called
2446  // standard-layout types.
2447  const Type *BaseTy = getBaseElementTypeUnsafe();
2448  assert(BaseTy && "NULL element type");
2449 
2450  // Return false for incomplete types after skipping any incomplete array
2451  // types which are expressly allowed by the standard and thus our API.
2452  if (BaseTy->isIncompleteType())
2453  return false;
2454 
2455  // As an extension, Clang treats vector types as Scalar types.
2456  if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true;
2457  if (const auto *RT = BaseTy->getAs<RecordType>()) {
2458  if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl()))
2459  if (!ClassDecl->isStandardLayout())
2460  return false;
2461 
2462  // Default to 'true' for non-C++ class types.
2463  // FIXME: This is a bit dubious, but plain C structs should trivially meet
2464  // all the requirements of standard layout classes.
2465  return true;
2466  }
2467 
2468  // No other types can match.
2469  return false;
2470 }
2471 
2472 // This is effectively the intersection of isTrivialType and
2473 // isStandardLayoutType. We implement it directly to avoid redundant
2474 // conversions from a type to a CXXRecordDecl.
2475 bool QualType::isCXX11PODType(const ASTContext &Context) const {
2476  const Type *ty = getTypePtr();
2477  if (ty->isDependentType())
2478  return false;
2479 
2480  if (hasNonTrivialObjCLifetime())
2481  return false;
2482 
2483  // C++11 [basic.types]p9:
2484  // Scalar types, POD classes, arrays of such types, and cv-qualified
2485  // versions of these types are collectively called trivial types.
2486  const Type *BaseTy = ty->getBaseElementTypeUnsafe();
2487  assert(BaseTy && "NULL element type");
2488 
2489  // Return false for incomplete types after skipping any incomplete array
2490  // types which are expressly allowed by the standard and thus our API.
2491  if (BaseTy->isIncompleteType())
2492  return false;
2493 
2494  // As an extension, Clang treats vector types as Scalar types.
2495  if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true;
2496  if (const auto *RT = BaseTy->getAs<RecordType>()) {
2497  if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
2498  // C++11 [class]p10:
2499  // A POD struct is a non-union class that is both a trivial class [...]
2500  if (!ClassDecl->isTrivial()) return false;
2501 
2502  // C++11 [class]p10:
2503  // A POD struct is a non-union class that is both a trivial class and
2504  // a standard-layout class [...]
2505  if (!ClassDecl->isStandardLayout()) return false;
2506 
2507  // C++11 [class]p10:
2508  // A POD struct is a non-union class that is both a trivial class and
2509  // a standard-layout class, and has no non-static data members of type
2510  // non-POD struct, non-POD union (or array of such types). [...]
2511  //
2512  // We don't directly query the recursive aspect as the requirements for
2513  // both standard-layout classes and trivial classes apply recursively
2514  // already.
2515  }
2516 
2517  return true;
2518  }
2519 
2520  // No other types can match.
2521  return false;
2522 }
2523 
2524 bool Type::isAlignValT() const {
2525  if (const auto *ET = getAs<EnumType>()) {
2526  IdentifierInfo *II = ET->getDecl()->getIdentifier();
2527  if (II && II->isStr("align_val_t") && ET->getDecl()->isInStdNamespace())
2528  return true;
2529  }
2530  return false;
2531 }
2532 
2533 bool Type::isStdByteType() const {
2534  if (const auto *ET = getAs<EnumType>()) {
2535  IdentifierInfo *II = ET->getDecl()->getIdentifier();
2536  if (II && II->isStr("byte") && ET->getDecl()->isInStdNamespace())
2537  return true;
2538  }
2539  return false;
2540 }
2541 
2543  if (const auto *BT = getAs<BuiltinType>())
2544  switch (BT->getKind()) {
2545  case BuiltinType::Bool:
2546  case BuiltinType::Char_S:
2547  case BuiltinType::Char_U:
2548  case BuiltinType::SChar:
2549  case BuiltinType::UChar:
2550  case BuiltinType::Short:
2551  case BuiltinType::UShort:
2552  case BuiltinType::WChar_S:
2553  case BuiltinType::WChar_U:
2554  case BuiltinType::Char8:
2555  case BuiltinType::Char16:
2556  case BuiltinType::Char32:
2557  return true;
2558  default:
2559  return false;
2560  }
2561 
2562  // Enumerated types are promotable to their compatible integer types
2563  // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2).
2564  if (const auto *ET = getAs<EnumType>()){
2565  if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull()
2566  || ET->getDecl()->isScoped())
2567  return false;
2568 
2569  return true;
2570  }
2571 
2572  return false;
2573 }
2574 
2576  // Note that this intentionally does not use the canonical type.
2577  switch (getTypeClass()) {
2578  case Builtin:
2579  case Record:
2580  case Enum:
2581  case Typedef:
2582  case Complex:
2583  case TypeOfExpr:
2584  case TypeOf:
2585  case TemplateTypeParm:
2586  case SubstTemplateTypeParm:
2587  case TemplateSpecialization:
2588  case Elaborated:
2589  case DependentName:
2590  case DependentTemplateSpecialization:
2591  case ObjCInterface:
2592  case ObjCObject:
2593  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
2594  return true;
2595  default:
2596  return false;
2597  }
2598 }
2599 
2602  switch (TypeSpec) {
2603  default: return ETK_None;
2604  case TST_typename: return ETK_Typename;
2605  case TST_class: return ETK_Class;
2606  case TST_struct: return ETK_Struct;
2607  case TST_interface: return ETK_Interface;
2608  case TST_union: return ETK_Union;
2609  case TST_enum: return ETK_Enum;
2610  }
2611 }
2612 
2615  switch(TypeSpec) {
2616  case TST_class: return TTK_Class;
2617  case TST_struct: return TTK_Struct;
2618  case TST_interface: return TTK_Interface;
2619  case TST_union: return TTK_Union;
2620  case TST_enum: return TTK_Enum;
2621  }
2622 
2623  llvm_unreachable("Type specifier is not a tag type kind.");
2624 }
2625 
2628  switch (Kind) {
2629  case TTK_Class: return ETK_Class;
2630  case TTK_Struct: return ETK_Struct;
2631  case TTK_Interface: return ETK_Interface;
2632  case TTK_Union: return ETK_Union;
2633  case TTK_Enum: return ETK_Enum;
2634  }
2635  llvm_unreachable("Unknown tag type kind.");
2636 }
2637 
2640  switch (Keyword) {
2641  case ETK_Class: return TTK_Class;
2642  case ETK_Struct: return TTK_Struct;
2643  case ETK_Interface: return TTK_Interface;
2644  case ETK_Union: return TTK_Union;
2645  case ETK_Enum: return TTK_Enum;
2646  case ETK_None: // Fall through.
2647  case ETK_Typename:
2648  llvm_unreachable("Elaborated type keyword is not a tag type kind.");
2649  }
2650  llvm_unreachable("Unknown elaborated type keyword.");
2651 }
2652 
2653 bool
2655  switch (Keyword) {
2656  case ETK_None:
2657  case ETK_Typename:
2658  return false;
2659  case ETK_Class:
2660  case ETK_Struct:
2661  case ETK_Interface:
2662  case ETK_Union:
2663  case ETK_Enum:
2664  return true;
2665  }
2666  llvm_unreachable("Unknown elaborated type keyword.");
2667 }
2668 
2670  switch (Keyword) {
2671  case ETK_None: return {};
2672  case ETK_Typename: return "typename";
2673  case ETK_Class: return "class";
2674  case ETK_Struct: return "struct";
2675  case ETK_Interface: return "__interface";
2676  case ETK_Union: return "union";
2677  case ETK_Enum: return "enum";
2678  }
2679 
2680  llvm_unreachable("Unknown elaborated type keyword.");
2681 }
2682 
2683 DependentTemplateSpecializationType::DependentTemplateSpecializationType(
2684  ElaboratedTypeKeyword Keyword,
2685  NestedNameSpecifier *NNS, const IdentifierInfo *Name,
2687  QualType Canon)
2688  : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true, true,
2689  /*VariablyModified=*/false,
2690  NNS && NNS->containsUnexpandedParameterPack()),
2691  NNS(NNS), Name(Name) {
2692  DependentTemplateSpecializationTypeBits.NumArgs = Args.size();
2693  assert((!NNS || NNS->isDependent()) &&
2694  "DependentTemplateSpecializatonType requires dependent qualifier");
2695  TemplateArgument *ArgBuffer = getArgBuffer();
2696  for (const TemplateArgument &Arg : Args) {
2697  if (Arg.containsUnexpandedParameterPack())
2699 
2700  new (ArgBuffer++) TemplateArgument(Arg);
2701  }
2702 }
2703 
2704 void
2706  const ASTContext &Context,
2707  ElaboratedTypeKeyword Keyword,
2708  NestedNameSpecifier *Qualifier,
2709  const IdentifierInfo *Name,
2711  ID.AddInteger(Keyword);
2712  ID.AddPointer(Qualifier);
2713  ID.AddPointer(Name);
2714  for (const TemplateArgument &Arg : Args)
2715  Arg.Profile(ID, Context);
2716 }
2717 
2719  ElaboratedTypeKeyword Keyword;
2720  if (const auto *Elab = dyn_cast<ElaboratedType>(this))
2721  Keyword = Elab->getKeyword();
2722  else if (const auto *DepName = dyn_cast<DependentNameType>(this))
2723  Keyword = DepName->getKeyword();
2724  else if (const auto *DepTST =
2725  dyn_cast<DependentTemplateSpecializationType>(this))
2726  Keyword = DepTST->getKeyword();
2727  else
2728  return false;
2729 
2730  return TypeWithKeyword::KeywordIsTagTypeKind(Keyword);
2731 }
2732 
2733 const char *Type::getTypeClassName() const {
2734  switch (TypeBits.TC) {
2735 #define ABSTRACT_TYPE(Derived, Base)
2736 #define TYPE(Derived, Base) case Derived: return #Derived;
2737 #include "clang/AST/TypeNodes.def"
2738  }
2739 
2740  llvm_unreachable("Invalid type class.");
2741 }
2742 
2743 StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
2744  switch (getKind()) {
2745  case Void:
2746  return "void";
2747  case Bool:
2748  return Policy.Bool ? "bool" : "_Bool";
2749  case Char_S:
2750  return "char";
2751  case Char_U:
2752  return "char";
2753  case SChar:
2754  return "signed char";
2755  case Short:
2756  return "short";
2757  case Int:
2758  return "int";
2759  case Long:
2760  return "long";
2761  case LongLong:
2762  return "long long";
2763  case Int128:
2764  return "__int128";
2765  case UChar:
2766  return "unsigned char";
2767  case UShort:
2768  return "unsigned short";
2769  case UInt:
2770  return "unsigned int";
2771  case ULong:
2772  return "unsigned long";
2773  case ULongLong:
2774  return "unsigned long long";
2775  case UInt128:
2776  return "unsigned __int128";
2777  case Half:
2778  return Policy.Half ? "half" : "__fp16";
2779  case Float:
2780  return "float";
2781  case Double:
2782  return "double";
2783  case LongDouble:
2784  return "long double";
2785  case ShortAccum:
2786  return "short _Accum";
2787  case Accum:
2788  return "_Accum";
2789  case LongAccum:
2790  return "long _Accum";
2791  case UShortAccum:
2792  return "unsigned short _Accum";
2793  case UAccum:
2794  return "unsigned _Accum";
2795  case ULongAccum:
2796  return "unsigned long _Accum";
2797  case BuiltinType::ShortFract:
2798  return "short _Fract";
2799  case BuiltinType::Fract:
2800  return "_Fract";
2801  case BuiltinType::LongFract:
2802  return "long _Fract";
2803  case BuiltinType::UShortFract:
2804  return "unsigned short _Fract";
2805  case BuiltinType::UFract:
2806  return "unsigned _Fract";
2807  case BuiltinType::ULongFract:
2808  return "unsigned long _Fract";
2809  case BuiltinType::SatShortAccum:
2810  return "_Sat short _Accum";
2811  case BuiltinType::SatAccum:
2812  return "_Sat _Accum";
2813  case BuiltinType::SatLongAccum:
2814  return "_Sat long _Accum";
2815  case BuiltinType::SatUShortAccum:
2816  return "_Sat unsigned short _Accum";
2817  case BuiltinType::SatUAccum:
2818  return "_Sat unsigned _Accum";
2819  case BuiltinType::SatULongAccum:
2820  return "_Sat unsigned long _Accum";
2821  case BuiltinType::SatShortFract:
2822  return "_Sat short _Fract";
2823  case BuiltinType::SatFract:
2824  return "_Sat _Fract";
2825  case BuiltinType::SatLongFract:
2826  return "_Sat long _Fract";
2827  case BuiltinType::SatUShortFract:
2828  return "_Sat unsigned short _Fract";
2829  case BuiltinType::SatUFract:
2830  return "_Sat unsigned _Fract";
2831  case BuiltinType::SatULongFract:
2832  return "_Sat unsigned long _Fract";
2833  case Float16:
2834  return "_Float16";
2835  case Float128:
2836  return "__float128";
2837  case WChar_S:
2838  case WChar_U:
2839  return Policy.MSWChar ? "__wchar_t" : "wchar_t";
2840  case Char8:
2841  return "char8_t";
2842  case Char16:
2843  return "char16_t";
2844  case Char32:
2845  return "char32_t";
2846  case NullPtr:
2847  return "nullptr_t";
2848  case Overload:
2849  return "<overloaded function type>";
2850  case BoundMember:
2851  return "<bound member function type>";
2852  case PseudoObject:
2853  return "<pseudo-object type>";
2854  case Dependent:
2855  return "<dependent type>";
2856  case UnknownAny:
2857  return "<unknown type>";
2858  case ARCUnbridgedCast:
2859  return "<ARC unbridged cast type>";
2860  case BuiltinFn:
2861  return "<builtin fn type>";
2862  case ObjCId:
2863  return "id";
2864  case ObjCClass:
2865  return "Class";
2866  case ObjCSel:
2867  return "SEL";
2868 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2869  case Id: \
2870  return "__" #Access " " #ImgType "_t";
2871 #include "clang/Basic/OpenCLImageTypes.def"
2872  case OCLSampler:
2873  return "sampler_t";
2874  case OCLEvent:
2875  return "event_t";
2876  case OCLClkEvent:
2877  return "clk_event_t";
2878  case OCLQueue:
2879  return "queue_t";
2880  case OCLReserveID:
2881  return "reserve_id_t";
2882  case OMPArraySection:
2883  return "<OpenMP array section type>";
2884 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
2885  case Id: \
2886  return #ExtType;
2887 #include "clang/Basic/OpenCLExtensionTypes.def"
2888 #define SVE_TYPE(Name, Id, SingletonId) \
2889  case Id: \
2890  return Name;
2891 #include "clang/Basic/AArch64SVEACLETypes.def"
2892  }
2893 
2894  llvm_unreachable("Invalid builtin type.");
2895 }
2896 
2898  if (const auto *RefType = getTypePtr()->getAs<ReferenceType>())
2899  return RefType->getPointeeType();
2900 
2901  // C++0x [basic.lval]:
2902  // Class prvalues can have cv-qualified types; non-class prvalues always
2903  // have cv-unqualified types.
2904  //
2905  // See also C99 6.3.2.1p2.
2906  if (!Context.getLangOpts().CPlusPlus ||
2907  (!getTypePtr()->isDependentType() && !getTypePtr()->isRecordType()))
2908  return getUnqualifiedType();
2909 
2910  return *this;
2911 }
2912 
2914  switch (CC) {
2915  case CC_C: return "cdecl";
2916  case CC_X86StdCall: return "stdcall";
2917  case CC_X86FastCall: return "fastcall";
2918  case CC_X86ThisCall: return "thiscall";
2919  case CC_X86Pascal: return "pascal";
2920  case CC_X86VectorCall: return "vectorcall";
2921  case CC_Win64: return "ms_abi";
2922  case CC_X86_64SysV: return "sysv_abi";
2923  case CC_X86RegCall : return "regcall";
2924  case CC_AAPCS: return "aapcs";
2925  case CC_AAPCS_VFP: return "aapcs-vfp";
2926  case CC_AArch64VectorCall: return "aarch64_vector_pcs";
2927  case CC_IntelOclBicc: return "intel_ocl_bicc";
2928  case CC_SpirFunction: return "spir_function";
2929  case CC_OpenCLKernel: return "opencl_kernel";
2930  case CC_Swift: return "swiftcall";
2931  case CC_PreserveMost: return "preserve_most";
2932  case CC_PreserveAll: return "preserve_all";
2933  }
2934 
2935  llvm_unreachable("Invalid calling convention.");
2936 }
2937 
2938 FunctionProtoType::FunctionProtoType(QualType result, ArrayRef<QualType> params,
2939  QualType canonical,
2940  const ExtProtoInfo &epi)
2941  : FunctionType(FunctionProto, result, canonical, result->isDependentType(),
2942  result->isInstantiationDependentType(),
2943  result->isVariablyModifiedType(),
2944  result->containsUnexpandedParameterPack(), epi.ExtInfo) {
2945  FunctionTypeBits.FastTypeQuals = epi.TypeQuals.getFastQualifiers();
2946  FunctionTypeBits.RefQualifier = epi.RefQualifier;
2947  FunctionTypeBits.NumParams = params.size();
2948  assert(getNumParams() == params.size() && "NumParams overflow!");
2949  FunctionTypeBits.ExceptionSpecType = epi.ExceptionSpec.Type;
2950  FunctionTypeBits.HasExtParameterInfos = !!epi.ExtParameterInfos;
2951  FunctionTypeBits.Variadic = epi.Variadic;
2952  FunctionTypeBits.HasTrailingReturn = epi.HasTrailingReturn;
2953 
2954  // Fill in the extra trailing bitfields if present.
2955  if (hasExtraBitfields(epi.ExceptionSpec.Type)) {
2956  auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
2957  ExtraBits.NumExceptionType = epi.ExceptionSpec.Exceptions.size();
2958  }
2959 
2960  // Fill in the trailing argument array.
2961  auto *argSlot = getTrailingObjects<QualType>();
2962  for (unsigned i = 0; i != getNumParams(); ++i) {
2963  if (params[i]->isDependentType())
2964  setDependent();
2965  else if (params[i]->isInstantiationDependentType())
2967 
2968  if (params[i]->containsUnexpandedParameterPack())
2970 
2971  argSlot[i] = params[i];
2972  }
2973 
2974  // Fill in the exception type array if present.
2975  if (getExceptionSpecType() == EST_Dynamic) {
2976  assert(hasExtraBitfields() && "missing trailing extra bitfields!");
2977  auto *exnSlot =
2978  reinterpret_cast<QualType *>(getTrailingObjects<ExceptionType>());
2979  unsigned I = 0;
2980  for (QualType ExceptionType : epi.ExceptionSpec.Exceptions) {
2981  // Note that, before C++17, a dependent exception specification does
2982  // *not* make a type dependent; it's not even part of the C++ type
2983  // system.
2984  if (ExceptionType->isInstantiationDependentType())
2986 
2987  if (ExceptionType->containsUnexpandedParameterPack())
2989 
2990  exnSlot[I++] = ExceptionType;
2991  }
2992  }
2993  // Fill in the Expr * in the exception specification if present.
2994  else if (isComputedNoexcept(getExceptionSpecType())) {
2995  assert(epi.ExceptionSpec.NoexceptExpr && "computed noexcept with no expr");
2996  assert((getExceptionSpecType() == EST_DependentNoexcept) ==
2997  epi.ExceptionSpec.NoexceptExpr->isValueDependent());
2998 
2999  // Store the noexcept expression and context.
3000  *getTrailingObjects<Expr *>() = epi.ExceptionSpec.NoexceptExpr;
3001 
3002  if (epi.ExceptionSpec.NoexceptExpr->isValueDependent() ||
3003  epi.ExceptionSpec.NoexceptExpr->isInstantiationDependent())
3005 
3006  if (epi.ExceptionSpec.NoexceptExpr->containsUnexpandedParameterPack())
3008  }
3009  // Fill in the FunctionDecl * in the exception specification if present.
3010  else if (getExceptionSpecType() == EST_Uninstantiated) {
3011  // Store the function decl from which we will resolve our
3012  // exception specification.
3013  auto **slot = getTrailingObjects<FunctionDecl *>();
3014  slot[0] = epi.ExceptionSpec.SourceDecl;
3015  slot[1] = epi.ExceptionSpec.SourceTemplate;
3016  // This exception specification doesn't make the type dependent, because
3017  // it's not instantiated as part of instantiating the type.
3018  } else if (getExceptionSpecType() == EST_Unevaluated) {
3019  // Store the function decl from which we will resolve our
3020  // exception specification.
3021  auto **slot = getTrailingObjects<FunctionDecl *>();
3022  slot[0] = epi.ExceptionSpec.SourceDecl;
3023  }
3024 
3025  // If this is a canonical type, and its exception specification is dependent,
3026  // then it's a dependent type. This only happens in C++17 onwards.
3027  if (isCanonicalUnqualified()) {
3028  if (getExceptionSpecType() == EST_Dynamic ||
3029  getExceptionSpecType() == EST_DependentNoexcept) {
3030  assert(hasDependentExceptionSpec() && "type should not be canonical");
3031  setDependent();
3032  }
3033  } else if (getCanonicalTypeInternal()->isDependentType()) {
3034  // Ask our canonical type whether our exception specification was dependent.
3035  setDependent();
3036  }
3037 
3038  // Fill in the extra parameter info if present.
3039  if (epi.ExtParameterInfos) {
3040  auto *extParamInfos = getTrailingObjects<ExtParameterInfo>();
3041  for (unsigned i = 0; i != getNumParams(); ++i)
3042  extParamInfos[i] = epi.ExtParameterInfos[i];
3043  }
3044 
3045  if (epi.TypeQuals.hasNonFastQualifiers()) {
3046  FunctionTypeBits.HasExtQuals = 1;
3047  *getTrailingObjects<Qualifiers>() = epi.TypeQuals;
3048  } else {
3049  FunctionTypeBits.HasExtQuals = 0;
3050  }
3051 }
3052 
3054  if (Expr *NE = getNoexceptExpr())
3055  return NE->isValueDependent();
3056  for (QualType ET : exceptions())
3057  // A pack expansion with a non-dependent pattern is still dependent,
3058  // because we don't know whether the pattern is in the exception spec
3059  // or not (that depends on whether the pack has 0 expansions).
3060  if (ET->isDependentType() || ET->getAs<PackExpansionType>())
3061  return true;
3062  return false;
3063 }
3064 
3066  if (Expr *NE = getNoexceptExpr())
3067  return NE->isInstantiationDependent();
3068  for (QualType ET : exceptions())
3069  if (ET->isInstantiationDependentType())
3070  return true;
3071  return false;
3072 }
3073 
3075  switch (getExceptionSpecType()) {
3076  case EST_Unparsed:
3077  case EST_Unevaluated:
3078  case EST_Uninstantiated:
3079  llvm_unreachable("should not call this with unresolved exception specs");
3080 
3081  case EST_DynamicNone:
3082  case EST_BasicNoexcept:
3083  case EST_NoexceptTrue:
3084  case EST_NoThrow:
3085  return CT_Cannot;
3086 
3087  case EST_None:
3088  case EST_MSAny:
3089  case EST_NoexceptFalse:
3090  return CT_Can;
3091 
3092  case EST_Dynamic:
3093  // A dynamic exception specification is throwing unless every exception
3094  // type is an (unexpanded) pack expansion type.
3095  for (unsigned I = 0; I != getNumExceptions(); ++I)
3096  if (!getExceptionType(I)->getAs<PackExpansionType>())
3097  return CT_Can;
3098  return CT_Dependent;
3099 
3100  case EST_DependentNoexcept:
3101  return CT_Dependent;
3102  }
3103 
3104  llvm_unreachable("unexpected exception specification kind");
3105 }
3106 
3108  for (unsigned ArgIdx = getNumParams(); ArgIdx; --ArgIdx)
3109  if (isa<PackExpansionType>(getParamType(ArgIdx - 1)))
3110  return true;
3111 
3112  return false;
3113 }
3114 
3115 void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result,
3116  const QualType *ArgTys, unsigned NumParams,
3117  const ExtProtoInfo &epi,
3118  const ASTContext &Context, bool Canonical) {
3119  // We have to be careful not to get ambiguous profile encodings.
3120  // Note that valid type pointers are never ambiguous with anything else.
3121  //
3122  // The encoding grammar begins:
3123  // type type* bool int bool
3124  // If that final bool is true, then there is a section for the EH spec:
3125  // bool type*
3126  // This is followed by an optional "consumed argument" section of the
3127  // same length as the first type sequence:
3128  // bool*
3129  // Finally, we have the ext info and trailing return type flag:
3130  // int bool
3131  //
3132  // There is no ambiguity between the consumed arguments and an empty EH
3133  // spec because of the leading 'bool' which unambiguously indicates
3134  // whether the following bool is the EH spec or part of the arguments.
3135 
3136  ID.AddPointer(Result.getAsOpaquePtr());
3137  for (unsigned i = 0; i != NumParams; ++i)
3138  ID.AddPointer(ArgTys[i].getAsOpaquePtr());
3139  // This method is relatively performance sensitive, so as a performance
3140  // shortcut, use one AddInteger call instead of four for the next four
3141  // fields.
3142  assert(!(unsigned(epi.Variadic) & ~1) &&
3143  !(unsigned(epi.RefQualifier) & ~3) &&
3144  !(unsigned(epi.ExceptionSpec.Type) & ~15) &&
3145  "Values larger than expected.");
3146  ID.AddInteger(unsigned(epi.Variadic) +
3147  (epi.RefQualifier << 1) +
3148  (epi.ExceptionSpec.Type << 3));
3149  ID.Add(epi.TypeQuals);
3150  if (epi.ExceptionSpec.Type == EST_Dynamic) {
3151  for (QualType Ex : epi.ExceptionSpec.Exceptions)
3152  ID.AddPointer(Ex.getAsOpaquePtr());
3153  } else if (isComputedNoexcept(epi.ExceptionSpec.Type)) {
3154  epi.ExceptionSpec.NoexceptExpr->Profile(ID, Context, Canonical);
3155  } else if (epi.ExceptionSpec.Type == EST_Uninstantiated ||
3157  ID.AddPointer(epi.ExceptionSpec.SourceDecl->getCanonicalDecl());
3158  }
3159  if (epi.ExtParameterInfos) {
3160  for (unsigned i = 0; i != NumParams; ++i)
3161  ID.AddInteger(epi.ExtParameterInfos[i].getOpaqueValue());
3162  }
3163  epi.ExtInfo.Profile(ID);
3164  ID.AddBoolean(epi.HasTrailingReturn);
3165 }
3166 
3167 void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID,
3168  const ASTContext &Ctx) {
3169  Profile(ID, getReturnType(), param_type_begin(), getNumParams(),
3170  getExtProtoInfo(), Ctx, isCanonicalUnqualified());
3171 }
3172 
3174  return getDecl()->getUnderlyingType();
3175 }
3176 
3178 
3180  // Step over MacroQualifiedTypes from the same macro to find the type
3181  // ultimately qualified by the macro qualifier.
3182  QualType Inner = cast<AttributedType>(getUnderlyingType())->getModifiedType();
3183  while (auto *InnerMQT = dyn_cast<MacroQualifiedType>(Inner)) {
3184  if (InnerMQT->getMacroIdentifier() != getMacroIdentifier())
3185  break;
3186  Inner = InnerMQT->getModifiedType();
3187  }
3188  return Inner;
3189 }
3190 
3192  : Type(TypeOfExpr, can, E->isTypeDependent(),
3193  E->isInstantiationDependent(),
3194  E->getType()->isVariablyModifiedType(),
3196  TOExpr(E) {}
3197 
3199  return !TOExpr->isTypeDependent();
3200 }
3201 
3203  if (isSugared())
3204  return getUnderlyingExpr()->getType();
3205 
3206  return QualType(this, 0);
3207 }
3208 
3209 void DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID,
3210  const ASTContext &Context, Expr *E) {
3211  E->Profile(ID, Context, true);
3212 }
3213 
3215  // C++11 [temp.type]p2: "If an expression e involves a template parameter,
3216  // decltype(e) denotes a unique dependent type." Hence a decltype type is
3217  // type-dependent even if its expression is only instantiation-dependent.
3218  : Type(Decltype, can, E->isInstantiationDependent(),
3219  E->isInstantiationDependent(),
3220  E->getType()->isVariablyModifiedType(),
3222  E(E), UnderlyingType(underlyingType) {}
3223 
3225 
3227  if (isSugared())
3228  return getUnderlyingType();
3229 
3230  return QualType(this, 0);
3231 }
3232 
3234  : DecltypeType(E, Context.DependentTy), Context(Context) {}
3235 
3236 void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID,
3237  const ASTContext &Context, Expr *E) {
3238  E->Profile(ID, Context, true);
3239 }
3240 
3242  QualType UnderlyingType,
3243  UTTKind UKind,
3244  QualType CanonicalType)
3245  : Type(UnaryTransform, CanonicalType, BaseType->isDependentType(),
3246  BaseType->isInstantiationDependentType(),
3247  BaseType->isVariablyModifiedType(),
3248  BaseType->containsUnexpandedParameterPack()),
3249  BaseType(BaseType), UnderlyingType(UnderlyingType), UKind(UKind) {}
3250 
3252  QualType BaseType,
3253  UTTKind UKind)
3254  : UnaryTransformType(BaseType, C.DependentTy, UKind, QualType()) {}
3255 
3257  : Type(TC, can, D->isDependentType(),
3258  /*InstantiationDependent=*/D->isDependentType(),
3259  /*VariablyModified=*/false,
3260  /*ContainsUnexpandedParameterPack=*/false),
3261  decl(const_cast<TagDecl*>(D)) {}
3262 
3264  for (auto I : decl->redecls()) {
3265  if (I->isCompleteDefinition() || I->isBeingDefined())
3266  return I;
3267  }
3268  // If there's no definition (not even in progress), return what we have.
3269  return decl;
3270 }
3271 
3273  return getInterestingTagDecl(decl);
3274 }
3275 
3277  return getDecl()->isBeingDefined();
3278 }
3279 
3281  std::vector<const RecordType*> RecordTypeList;
3282  RecordTypeList.push_back(this);
3283  unsigned NextToCheckIndex = 0;
3284 
3285  while (RecordTypeList.size() > NextToCheckIndex) {
3286  for (FieldDecl *FD :
3287  RecordTypeList[NextToCheckIndex]->getDecl()->fields()) {
3288  QualType FieldTy = FD->getType();
3289  if (FieldTy.isConstQualified())
3290  return true;
3291  FieldTy = FieldTy.getCanonicalType();
3292  if (const auto *FieldRecTy = FieldTy->getAs<RecordType>()) {
3293  if (llvm::find(RecordTypeList, FieldRecTy) == RecordTypeList.end())
3294  RecordTypeList.push_back(FieldRecTy);
3295  }
3296  }
3297  ++NextToCheckIndex;
3298  }
3299  return false;
3300 }
3301 
3303  // FIXME: Generate this with TableGen.
3304  switch (getAttrKind()) {
3305  // These are type qualifiers in the traditional C sense: they annotate
3306  // something about a specific value/variable of a type. (They aren't
3307  // always part of the canonical type, though.)
3308  case attr::ObjCGC:
3309  case attr::ObjCOwnership:
3310  case attr::ObjCInertUnsafeUnretained:
3311  case attr::TypeNonNull:
3312  case attr::TypeNullable:
3313  case attr::TypeNullUnspecified:
3314  case attr::LifetimeBound:
3315  case attr::AddressSpace:
3316  return true;
3317 
3318  // All other type attributes aren't qualifiers; they rewrite the modified
3319  // type to be a semantically different type.
3320  default:
3321  return false;
3322  }
3323 }
3324 
3326  // FIXME: Generate this with TableGen?
3327  switch (getAttrKind()) {
3328  default: return false;
3329  case attr::Ptr32:
3330  case attr::Ptr64:
3331  case attr::SPtr:
3332  case attr::UPtr:
3333  return true;
3334  }
3335  llvm_unreachable("invalid attr kind");
3336 }
3337 
3339  // FIXME: Generate this with TableGen.
3340  switch (getAttrKind()) {
3341  default: return false;
3342  case attr::Pcs:
3343  case attr::CDecl:
3344  case attr::FastCall:
3345  case attr::StdCall:
3346  case attr::ThisCall:
3347  case attr::RegCall:
3348  case attr::SwiftCall:
3349  case attr::VectorCall:
3350  case attr::AArch64VectorPcs:
3351  case attr::Pascal:
3352  case attr::MSABI:
3353  case attr::SysVABI:
3354  case attr::IntelOclBicc:
3355  case attr::PreserveMost:
3356  case attr::PreserveAll:
3357  return true;
3358  }
3359  llvm_unreachable("invalid attr kind");
3360 }
3361 
3363  return cast<CXXRecordDecl>(getInterestingTagDecl(Decl));
3364 }
3365 
3367  return isCanonicalUnqualified() ? nullptr : getDecl()->getIdentifier();
3368 }
3369 
3370 SubstTemplateTypeParmPackType::
3371 SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param,
3372  QualType Canon,
3373  const TemplateArgument &ArgPack)
3374  : Type(SubstTemplateTypeParmPack, Canon, true, true, false, true),
3375  Replaced(Param), Arguments(ArgPack.pack_begin()) {
3376  SubstTemplateTypeParmPackTypeBits.NumArgs = ArgPack.pack_size();
3377 }
3378 
3380  return TemplateArgument(llvm::makeArrayRef(Arguments, getNumArgs()));
3381 }
3382 
3383 void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID) {
3384  Profile(ID, getReplacedParameter(), getArgumentPack());
3385 }
3386 
3387 void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID,
3388  const TemplateTypeParmType *Replaced,
3389  const TemplateArgument &ArgPack) {
3390  ID.AddPointer(Replaced);
3391  ID.AddInteger(ArgPack.pack_size());
3392  for (const auto &P : ArgPack.pack_elements())
3393  ID.AddPointer(P.getAsType().getAsOpaquePtr());
3394 }
3395 
3398  bool &InstantiationDependent) {
3399  return anyDependentTemplateArguments(Args.arguments(),
3400  InstantiationDependent);
3401 }
3402 
3405  bool &InstantiationDependent) {
3406  for (const TemplateArgumentLoc &ArgLoc : Args) {
3407  if (ArgLoc.getArgument().isDependent()) {
3408  InstantiationDependent = true;
3409  return true;
3410  }
3411 
3412  if (ArgLoc.getArgument().isInstantiationDependent())
3413  InstantiationDependent = true;
3414  }
3415  return false;
3416 }
3417 
3418 TemplateSpecializationType::
3419 TemplateSpecializationType(TemplateName T,
3421  QualType Canon, QualType AliasedType)
3422  : Type(TemplateSpecialization,
3423  Canon.isNull()? QualType(this, 0) : Canon,
3424  Canon.isNull()? true : Canon->isDependentType(),
3425  Canon.isNull()? true : Canon->isInstantiationDependentType(),
3426  false,
3427  T.containsUnexpandedParameterPack()), Template(T) {
3428  TemplateSpecializationTypeBits.NumArgs = Args.size();
3429  TemplateSpecializationTypeBits.TypeAlias = !AliasedType.isNull();
3430 
3431  assert(!T.getAsDependentTemplateName() &&
3432  "Use DependentTemplateSpecializationType for dependent template-name");
3433  assert((T.getKind() == TemplateName::Template ||
3436  "Unexpected template name for TemplateSpecializationType");
3437 
3438  auto *TemplateArgs = reinterpret_cast<TemplateArgument *>(this + 1);
3439  for (const TemplateArgument &Arg : Args) {
3440  // Update instantiation-dependent and variably-modified bits.
3441  // If the canonical type exists and is non-dependent, the template
3442  // specialization type can be non-dependent even if one of the type
3443  // arguments is. Given:
3444  // template<typename T> using U = int;
3445  // U<T> is always non-dependent, irrespective of the type T.
3446  // However, U<Ts> contains an unexpanded parameter pack, even though
3447  // its expansion (and thus its desugared type) doesn't.
3448  if (Arg.isInstantiationDependent())
3450  if (Arg.getKind() == TemplateArgument::Type &&
3451  Arg.getAsType()->isVariablyModifiedType())
3453  if (Arg.containsUnexpandedParameterPack())
3455  new (TemplateArgs++) TemplateArgument(Arg);
3456  }
3457 
3458  // Store the aliased type if this is a type alias template specialization.
3459  if (isTypeAlias()) {
3460  auto *Begin = reinterpret_cast<TemplateArgument *>(this + 1);
3461  *reinterpret_cast<QualType*>(Begin + getNumArgs()) = AliasedType;
3462  }
3463 }
3464 
3465 void
3466 TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
3467  TemplateName T,
3469  const ASTContext &Context) {
3470  T.Profile(ID);
3471  for (const TemplateArgument &Arg : Args)
3472  Arg.Profile(ID, Context);
3473 }
3474 
3475 QualType
3476 QualifierCollector::apply(const ASTContext &Context, QualType QT) const {
3477  if (!hasNonFastQualifiers())
3478  return QT.withFastQualifiers(getFastQualifiers());
3479 
3480  return Context.getQualifiedType(QT, *this);
3481 }
3482 
3483 QualType
3484 QualifierCollector::apply(const ASTContext &Context, const Type *T) const {
3485  if (!hasNonFastQualifiers())
3486  return QualType(T, getFastQualifiers());
3487 
3488  return Context.getQualifiedType(T, *this);
3489 }
3490 
3491 void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID,
3492  QualType BaseType,
3493  ArrayRef<QualType> typeArgs,
3494  ArrayRef<ObjCProtocolDecl *> protocols,
3495  bool isKindOf) {
3496  ID.AddPointer(BaseType.getAsOpaquePtr());
3497  ID.AddInteger(typeArgs.size());
3498  for (auto typeArg : typeArgs)
3499  ID.AddPointer(typeArg.getAsOpaquePtr());
3500  ID.AddInteger(protocols.size());
3501  for (auto proto : protocols)
3502  ID.AddPointer(proto);
3503  ID.AddBoolean(isKindOf);
3504 }
3505 
3506 void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) {
3507  Profile(ID, getBaseType(), getTypeArgsAsWritten(),
3508  llvm::makeArrayRef(qual_begin(), getNumProtocols()),
3509  isKindOfTypeAsWritten());
3510 }
3511 
3512 void ObjCTypeParamType::Profile(llvm::FoldingSetNodeID &ID,
3513  const ObjCTypeParamDecl *OTPDecl,
3514  ArrayRef<ObjCProtocolDecl *> protocols) {
3515  ID.AddPointer(OTPDecl);
3516  ID.AddInteger(protocols.size());
3517  for (auto proto : protocols)
3518  ID.AddPointer(proto);
3519 }
3520 
3521 void ObjCTypeParamType::Profile(llvm::FoldingSetNodeID &ID) {
3522  Profile(ID, getDecl(),
3523  llvm::makeArrayRef(qual_begin(), getNumProtocols()));
3524 }
3525 
3526 namespace {
3527 
3528 /// The cached properties of a type.
3529 class CachedProperties {
3530  Linkage L;
3531  bool local;
3532 
3533 public:
3534  CachedProperties(Linkage L, bool local) : L(L), local(local) {}
3535 
3536  Linkage getLinkage() const { return L; }
3537  bool hasLocalOrUnnamedType() const { return local; }
3538 
3539  friend CachedProperties merge(CachedProperties L, CachedProperties R) {
3540  Linkage MergedLinkage = minLinkage(L.L, R.L);
3541  return CachedProperties(MergedLinkage,
3542  L.hasLocalOrUnnamedType() | R.hasLocalOrUnnamedType());
3543  }
3544 };
3545 
3546 } // namespace
3547 
3548 static CachedProperties computeCachedProperties(const Type *T);
3549 
3550 namespace clang {
3551 
3552 /// The type-property cache. This is templated so as to be
3553 /// instantiated at an internal type to prevent unnecessary symbol
3554 /// leakage.
3555 template <class Private> class TypePropertyCache {
3556 public:
3557  static CachedProperties get(QualType T) {
3558  return get(T.getTypePtr());
3559  }
3560 
3561  static CachedProperties get(const Type *T) {
3562  ensure(T);
3563  return CachedProperties(T->TypeBits.getLinkage(),
3564  T->TypeBits.hasLocalOrUnnamedType());
3565  }
3566 
3567  static void ensure(const Type *T) {
3568  // If the cache is valid, we're okay.
3569  if (T->TypeBits.isCacheValid()) return;
3570 
3571  // If this type is non-canonical, ask its canonical type for the
3572  // relevant information.
3573  if (!T->isCanonicalUnqualified()) {
3574  const Type *CT = T->getCanonicalTypeInternal().getTypePtr();
3575  ensure(CT);
3576  T->TypeBits.CacheValid = true;
3577  T->TypeBits.CachedLinkage = CT->TypeBits.CachedLinkage;
3578  T->TypeBits.CachedLocalOrUnnamed = CT->TypeBits.CachedLocalOrUnnamed;
3579  return;
3580  }
3581 
3582  // Compute the cached properties and then set the cache.
3583  CachedProperties Result = computeCachedProperties(T);
3584  T->TypeBits.CacheValid = true;
3585  T->TypeBits.CachedLinkage = Result.getLinkage();
3586  T->TypeBits.CachedLocalOrUnnamed = Result.hasLocalOrUnnamedType();
3587  }
3588 };
3589 
3590 } // namespace clang
3591 
3592 // Instantiate the friend template at a private class. In a
3593 // reasonable implementation, these symbols will be internal.
3594 // It is terrible that this is the best way to accomplish this.
3595 namespace {
3596 
3597 class Private {};
3598 
3599 } // namespace
3600 
3602 
3603 static CachedProperties computeCachedProperties(const Type *T) {
3604  switch (T->getTypeClass()) {
3605 #define TYPE(Class,Base)
3606 #define NON_CANONICAL_TYPE(Class,Base) case Type::Class:
3607 #include "clang/AST/TypeNodes.def"
3608  llvm_unreachable("didn't expect a non-canonical type here");
3609 
3610 #define TYPE(Class,Base)
3611 #define DEPENDENT_TYPE(Class,Base) case Type::Class:
3612 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class:
3613 #include "clang/AST/TypeNodes.def"
3614  // Treat instantiation-dependent types as external.
3615  assert(T->isInstantiationDependentType());
3616  return CachedProperties(ExternalLinkage, false);
3617 
3618  case Type::Auto:
3619  case Type::DeducedTemplateSpecialization:
3620  // Give non-deduced 'auto' types external linkage. We should only see them
3621  // here in error recovery.
3622  return CachedProperties(ExternalLinkage, false);
3623 
3624  case Type::Builtin:
3625  // C++ [basic.link]p8:
3626  // A type is said to have linkage if and only if:
3627  // - it is a fundamental type (3.9.1); or
3628  return CachedProperties(ExternalLinkage, false);
3629 
3630  case Type::Record:
3631  case Type::Enum: {
3632  const TagDecl *Tag = cast<TagType>(T)->getDecl();
3633 
3634  // C++ [basic.link]p8:
3635  // - it is a class or enumeration type that is named (or has a name
3636  // for linkage purposes (7.1.3)) and the name has linkage; or
3637  // - it is a specialization of a class template (14); or
3638  Linkage L = Tag->getLinkageInternal();
3639  bool IsLocalOrUnnamed =
3640  Tag->getDeclContext()->isFunctionOrMethod() ||
3641  !Tag->hasNameForLinkage();
3642  return CachedProperties(L, IsLocalOrUnnamed);
3643  }
3644 
3645  // C++ [basic.link]p8:
3646  // - it is a compound type (3.9.2) other than a class or enumeration,
3647  // compounded exclusively from types that have linkage; or
3648  case Type::Complex:
3649  return Cache::get(cast<ComplexType>(T)->getElementType());
3650  case Type::Pointer:
3651  return Cache::get(cast<PointerType>(T)->getPointeeType());
3652  case Type::BlockPointer:
3653  return Cache::get(cast<BlockPointerType>(T)->getPointeeType());
3654  case Type::LValueReference:
3655  case Type::RValueReference:
3656  return Cache::get(cast<ReferenceType>(T)->getPointeeType());
3657  case Type::MemberPointer: {
3658  const auto *MPT = cast<MemberPointerType>(T);
3659  return merge(Cache::get(MPT->getClass()),
3660  Cache::get(MPT->getPointeeType()));
3661  }
3662  case Type::ConstantArray:
3663  case Type::IncompleteArray:
3664  case Type::VariableArray:
3665  return Cache::get(cast<ArrayType>(T)->getElementType());
3666  case Type::Vector:
3667  case Type::ExtVector:
3668  return Cache::get(cast<VectorType>(T)->getElementType());
3669  case Type::FunctionNoProto:
3670  return Cache::get(cast<FunctionType>(T)->getReturnType());
3671  case Type::FunctionProto: {
3672  const auto *FPT = cast<FunctionProtoType>(T);
3673  CachedProperties result = Cache::get(FPT->getReturnType());
3674  for (const auto &ai : FPT->param_types())
3675  result = merge(result, Cache::get(ai));
3676  return result;
3677  }
3678  case Type::ObjCInterface: {
3679  Linkage L = cast<ObjCInterfaceType>(T)->getDecl()->getLinkageInternal();
3680  return CachedProperties(L, false);
3681  }
3682  case Type::ObjCObject:
3683  return Cache::get(cast<ObjCObjectType>(T)->getBaseType());
3684  case Type::ObjCObjectPointer:
3685  return Cache::get(cast<ObjCObjectPointerType>(T)->getPointeeType());
3686  case Type::Atomic:
3687  return Cache::get(cast<AtomicType>(T)->getValueType());
3688  case Type::Pipe:
3689  return Cache::get(cast<PipeType>(T)->getElementType());
3690  }
3691 
3692  llvm_unreachable("unhandled type class");
3693 }
3694 
3695 /// Determine the linkage of this type.
3697  Cache::ensure(this);
3698  return TypeBits.getLinkage();
3699 }
3700 
3702  Cache::ensure(this);
3703  return TypeBits.hasLocalOrUnnamedType();
3704 }
3705 
3707  switch (T->getTypeClass()) {
3708 #define TYPE(Class,Base)
3709 #define NON_CANONICAL_TYPE(Class,Base) case Type::Class:
3710 #include "clang/AST/TypeNodes.def"
3711  llvm_unreachable("didn't expect a non-canonical type here");
3712 
3713 #define TYPE(Class,Base)
3714 #define DEPENDENT_TYPE(Class,Base) case Type::Class:
3715 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class:
3716 #include "clang/AST/TypeNodes.def"
3717  // Treat instantiation-dependent types as external.
3718  assert(T->isInstantiationDependentType());
3719  return LinkageInfo::external();
3720 
3721  case Type::Builtin:
3722  return LinkageInfo::external();
3723 
3724  case Type::Auto:
3725  case Type::DeducedTemplateSpecialization:
3726  return LinkageInfo::external();
3727 
3728  case Type::Record:
3729  case Type::Enum:
3730  return getDeclLinkageAndVisibility(cast<TagType>(T)->getDecl());
3731 
3732  case Type::Complex:
3733  return computeTypeLinkageInfo(cast<ComplexType>(T)->getElementType());
3734  case Type::Pointer:
3735  return computeTypeLinkageInfo(cast<PointerType>(T)->getPointeeType());
3736  case Type::BlockPointer:
3737  return computeTypeLinkageInfo(cast<BlockPointerType>(T)->getPointeeType());
3738  case Type::LValueReference:
3739  case Type::RValueReference:
3740  return computeTypeLinkageInfo(cast<ReferenceType>(T)->getPointeeType());
3741  case Type::MemberPointer: {
3742  const auto *MPT = cast<MemberPointerType>(T);
3743  LinkageInfo LV = computeTypeLinkageInfo(MPT->getClass());
3744  LV.merge(computeTypeLinkageInfo(MPT->getPointeeType()));
3745  return LV;
3746  }
3747  case Type::ConstantArray:
3748  case Type::IncompleteArray:
3749  case Type::VariableArray:
3750  return computeTypeLinkageInfo(cast<ArrayType>(T)->getElementType());
3751  case Type::Vector:
3752  case Type::ExtVector:
3753  return computeTypeLinkageInfo(cast<VectorType>(T)->getElementType());
3754  case Type::FunctionNoProto:
3755  return computeTypeLinkageInfo(cast<FunctionType>(T)->getReturnType());
3756  case Type::FunctionProto: {
3757  const auto *FPT = cast<FunctionProtoType>(T);
3758  LinkageInfo LV = computeTypeLinkageInfo(FPT->getReturnType());
3759  for (const auto &ai : FPT->param_types())
3760  LV.merge(computeTypeLinkageInfo(ai));
3761  return LV;
3762  }
3763  case Type::ObjCInterface:
3764  return getDeclLinkageAndVisibility(cast<ObjCInterfaceType>(T)->getDecl());
3765  case Type::ObjCObject:
3766  return computeTypeLinkageInfo(cast<ObjCObjectType>(T)->getBaseType());
3767  case Type::ObjCObjectPointer:
3768  return computeTypeLinkageInfo(
3769  cast<ObjCObjectPointerType>(T)->getPointeeType());
3770  case Type::Atomic:
3771  return computeTypeLinkageInfo(cast<AtomicType>(T)->getValueType());
3772  case Type::Pipe:
3773  return computeTypeLinkageInfo(cast<PipeType>(T)->getElementType());
3774  }
3775 
3776  llvm_unreachable("unhandled type class");
3777 }
3778 
3779 bool Type::isLinkageValid() const {
3780  if (!TypeBits.isCacheValid())
3781  return true;
3782 
3783  Linkage L = LinkageComputer{}
3785  .getLinkage();
3786  return L == TypeBits.getLinkage();
3787 }
3788 
3790  if (!T->isCanonicalUnqualified())
3791  return computeTypeLinkageInfo(T->getCanonicalTypeInternal());
3792 
3793  LinkageInfo LV = computeTypeLinkageInfo(T);
3794  assert(LV.getLinkage() == T->getLinkage());
3795  return LV;
3796 }
3797 
3800 }
3801 
3803 Type::getNullability(const ASTContext &Context) const {
3804  QualType Type(this, 0);
3805  while (const auto *AT = Type->getAs<AttributedType>()) {
3806  // Check whether this is an attributed type with nullability
3807  // information.
3808  if (auto Nullability = AT->getImmediateNullability())
3809  return Nullability;
3810 
3811  Type = AT->getEquivalentType();
3812  }
3813  return None;
3814 }
3815 
3816 bool Type::canHaveNullability(bool ResultIfUnknown) const {
3818 
3819  switch (type->getTypeClass()) {
3820  // We'll only see canonical types here.
3821 #define NON_CANONICAL_TYPE(Class, Parent) \
3822  case Type::Class: \
3823  llvm_unreachable("non-canonical type");
3824 #define TYPE(Class, Parent)
3825 #include "clang/AST/TypeNodes.def"
3826 
3827  // Pointer types.
3828  case Type::Pointer:
3829  case Type::BlockPointer:
3830  case Type::MemberPointer:
3831  case Type::ObjCObjectPointer:
3832  return true;
3833 
3834  // Dependent types that could instantiate to pointer types.
3835  case Type::UnresolvedUsing:
3836  case Type::TypeOfExpr:
3837  case Type::TypeOf:
3838  case Type::Decltype:
3839  case Type::UnaryTransform:
3840  case Type::TemplateTypeParm:
3841  case Type::SubstTemplateTypeParmPack:
3842  case Type::DependentName:
3843  case Type::DependentTemplateSpecialization:
3844  case Type::Auto:
3845  return ResultIfUnknown;
3846 
3847  // Dependent template specializations can instantiate to pointer
3848  // types unless they're known to be specializations of a class
3849  // template.
3850  case Type::TemplateSpecialization:
3851  if (TemplateDecl *templateDecl
3852  = cast<TemplateSpecializationType>(type.getTypePtr())
3853  ->getTemplateName().getAsTemplateDecl()) {
3854  if (isa<ClassTemplateDecl>(templateDecl))
3855  return false;
3856  }
3857  return ResultIfUnknown;
3858 
3859  case Type::Builtin:
3860  switch (cast<BuiltinType>(type.getTypePtr())->getKind()) {
3861  // Signed, unsigned, and floating-point types cannot have nullability.
3862 #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
3863 #define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
3864 #define FLOATING_TYPE(Id, SingletonId) case BuiltinType::Id:
3865 #define BUILTIN_TYPE(Id, SingletonId)
3866 #include "clang/AST/BuiltinTypes.def"
3867  return false;
3868 
3869  // Dependent types that could instantiate to a pointer type.
3870  case BuiltinType::Dependent:
3871  case BuiltinType::Overload:
3872  case BuiltinType::BoundMember:
3873  case BuiltinType::PseudoObject:
3874  case BuiltinType::UnknownAny:
3875  case BuiltinType::ARCUnbridgedCast:
3876  return ResultIfUnknown;
3877 
3878  case BuiltinType::Void:
3879  case BuiltinType::ObjCId:
3880  case BuiltinType::ObjCClass:
3881  case BuiltinType::ObjCSel:
3882 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3883  case BuiltinType::Id:
3884 #include "clang/Basic/OpenCLImageTypes.def"
3885 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3886  case BuiltinType::Id:
3887 #include "clang/Basic/OpenCLExtensionTypes.def"
3888  case BuiltinType::OCLSampler:
3889  case BuiltinType::OCLEvent:
3890  case BuiltinType::OCLClkEvent:
3891  case BuiltinType::OCLQueue:
3892  case BuiltinType::OCLReserveID:
3893 #define SVE_TYPE(Name, Id, SingletonId) \
3894  case BuiltinType::Id:
3895 #include "clang/Basic/AArch64SVEACLETypes.def"
3896  case BuiltinType::BuiltinFn:
3897  case BuiltinType::NullPtr:
3898  case BuiltinType::OMPArraySection:
3899  return false;
3900  }
3901  llvm_unreachable("unknown builtin type");
3902 
3903  // Non-pointer types.
3904  case Type::Complex:
3905  case Type::LValueReference:
3906  case Type::RValueReference:
3907  case Type::ConstantArray:
3908  case Type::IncompleteArray:
3909  case Type::VariableArray:
3910  case Type::DependentSizedArray:
3911  case Type::DependentVector:
3912  case Type::DependentSizedExtVector:
3913  case Type::Vector:
3914  case Type::ExtVector:
3915  case Type::DependentAddressSpace:
3916  case Type::FunctionProto:
3917  case Type::FunctionNoProto:
3918  case Type::Record:
3919  case Type::DeducedTemplateSpecialization:
3920  case Type::Enum:
3921  case Type::InjectedClassName:
3922  case Type::PackExpansion:
3923  case Type::ObjCObject:
3924  case Type::ObjCInterface:
3925  case Type::Atomic:
3926  case Type::Pipe:
3927  return false;
3928  }
3929  llvm_unreachable("bad type kind!");
3930 }
3931 
3934  if (getAttrKind() == attr::TypeNonNull)
3935  return NullabilityKind::NonNull;
3936  if (getAttrKind() == attr::TypeNullable)
3938  if (getAttrKind() == attr::TypeNullUnspecified)
3940  return None;
3941 }
3942 
3944  QualType AttrTy = T;
3945  if (auto MacroTy = dyn_cast<MacroQualifiedType>(T))
3946  AttrTy = MacroTy->getUnderlyingType();
3947 
3948  if (auto attributed = dyn_cast<AttributedType>(AttrTy)) {
3949  if (auto nullability = attributed->getImmediateNullability()) {
3950  T = attributed->getModifiedType();
3951  return nullability;
3952  }
3953  }
3954 
3955  return None;
3956 }
3957 
3959  const auto *objcPtr = getAs<ObjCObjectPointerType>();
3960  if (!objcPtr)
3961  return false;
3962 
3963  if (objcPtr->isObjCIdType()) {
3964  // id is always okay.
3965  return true;
3966  }
3967 
3968  // Blocks are NSObjects.
3969  if (ObjCInterfaceDecl *iface = objcPtr->getInterfaceDecl()) {
3970  if (iface->getIdentifier() != ctx.getNSObjectName())
3971  return false;
3972 
3973  // Continue to check qualifiers, below.
3974  } else if (objcPtr->isObjCQualifiedIdType()) {
3975  // Continue to check qualifiers, below.
3976  } else {
3977  return false;
3978  }
3979 
3980  // Check protocol qualifiers.
3981  for (ObjCProtocolDecl *proto : objcPtr->quals()) {
3982  // Blocks conform to NSObject and NSCopying.
3983  if (proto->getIdentifier() != ctx.getNSObjectName() &&
3984  proto->getIdentifier() != ctx.getNSCopyingName())
3985  return false;
3986  }
3987 
3988  return true;
3989 }
3990 
3994  return Qualifiers::OCL_Strong;
3995 }
3996 
3998  assert(isObjCLifetimeType() &&
3999  "cannot query implicit lifetime for non-inferrable type");
4000 
4001  const Type *canon = getCanonicalTypeInternal().getTypePtr();
4002 
4003  // Walk down to the base type. We don't care about qualifiers for this.
4004  while (const auto *array = dyn_cast<ArrayType>(canon))
4005  canon = array->getElementType().getTypePtr();
4006 
4007  if (const auto *opt = dyn_cast<ObjCObjectPointerType>(canon)) {
4008  // Class and Class<Protocol> don't require retention.
4009  if (opt->getObjectType()->isObjCClass())
4010  return true;
4011  }
4012 
4013  return false;
4014 }
4015 
4017  const Type *cur = this;
4018  while (true) {
4019  if (const auto *typedefType = dyn_cast<TypedefType>(cur))
4020  return typedefType->getDecl()->hasAttr<ObjCNSObjectAttr>();
4021 
4022  // Single-step desugar until we run out of sugar.
4024  if (next.getTypePtr() == cur) return false;
4025  cur = next.getTypePtr();
4026  }
4027 }
4028 
4030  if (const auto *typedefType = dyn_cast<TypedefType>(this))
4031  return typedefType->getDecl()->hasAttr<ObjCIndependentClassAttr>();
4032  return false;
4033 }
4034 
4036  return isObjCObjectPointerType() ||
4037  isBlockPointerType() ||
4039 }
4040 
4042  if (isObjCLifetimeType())
4043  return true;
4044  if (const auto *OPT = getAs<PointerType>())
4045  return OPT->getPointeeType()->isObjCIndirectLifetimeType();
4046  if (const auto *Ref = getAs<ReferenceType>())
4047  return Ref->getPointeeType()->isObjCIndirectLifetimeType();
4048  if (const auto *MemPtr = getAs<MemberPointerType>())
4049  return MemPtr->getPointeeType()->isObjCIndirectLifetimeType();
4050  return false;
4051 }
4052 
4053 /// Returns true if objects of this type have lifetime semantics under
4054 /// ARC.
4056  const Type *type = this;
4057  while (const ArrayType *array = type->getAsArrayTypeUnsafe())
4058  type = array->getElementType().getTypePtr();
4059  return type->isObjCRetainableType();
4060 }
4061 
4062 /// Determine whether the given type T is a "bridgable" Objective-C type,
4063 /// which is either an Objective-C object pointer type or an
4066 }
4067 
4068 /// Determine whether the given type T is a "bridgeable" C type.
4070  const auto *Pointer = getAs<PointerType>();
4071  if (!Pointer)
4072  return false;
4073 
4074  QualType Pointee = Pointer->getPointeeType();
4075  return Pointee->isVoidType() || Pointee->isRecordType();
4076 }
4077 
4079  if (!isVariablyModifiedType()) return false;
4080 
4081  if (const auto *ptr = getAs<PointerType>())
4082  return ptr->getPointeeType()->hasSizedVLAType();
4083  if (const auto *ref = getAs<ReferenceType>())
4084  return ref->getPointeeType()->hasSizedVLAType();
4085  if (const ArrayType *arr = getAsArrayTypeUnsafe()) {
4086  if (isa<VariableArrayType>(arr) &&
4087  cast<VariableArrayType>(arr)->getSizeExpr())
4088  return true;
4089 
4090  return arr->getElementType()->hasSizedVLAType();
4091  }
4092 
4093  return false;
4094 }
4095 
4096 QualType::DestructionKind QualType::isDestructedTypeImpl(QualType type) {
4097  switch (type.getObjCLifetime()) {
4098  case Qualifiers::OCL_None:
4101  break;
4102 
4104  return DK_objc_strong_lifetime;
4105  case Qualifiers::OCL_Weak:
4106  return DK_objc_weak_lifetime;
4107  }
4108 
4109  if (const auto *RT =
4111  const RecordDecl *RD = RT->getDecl();
4112  if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
4113  /// Check if this is a C++ object with a non-trivial destructor.
4114  if (CXXRD->hasDefinition() && !CXXRD->hasTrivialDestructor())
4115  return DK_cxx_destructor;
4116  } else {
4117  /// Check if this is a C struct that is non-trivial to destroy or an array
4118  /// that contains such a struct.
4120  return DK_nontrivial_c_struct;
4121  }
4122  }
4123 
4124  return DK_none;
4125 }
4126 
4128  return getClass()->getAsCXXRecordDecl()->getMostRecentNonInjectedDecl();
4129 }
4130 
4132  llvm::APSInt Val, unsigned Scale) {
4133  FixedPointSemantics FXSema(Val.getBitWidth(), Scale, Val.isSigned(),
4134  /*IsSaturated=*/false,
4135  /*HasUnsignedPadding=*/false);
4136  APFixedPoint(Val, FXSema).toString(Str);
4137 }
DecltypeType(Expr *E, QualType underlyingType, QualType can=QualType())
Definition: Type.cpp:3214
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
Definition: Type.cpp:2669
const ObjCInterfaceType * getInterfaceType() const
If this pointer points to an Objective C @interface type, gets the type for that interface.
Definition: Type.cpp:1553
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Definition: Type.h:5434
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:2273
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:4791
Represents a type that was referred to using an elaborated type keyword, e.g., struct S...
Definition: Type.h:5187
const Type * Ty
The locally-unqualified type.
Definition: Type.h:584
bool isStruct() const
Definition: Decl.h:3282
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:4990
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:1653
bool isKindOfTypeAsWritten() const
Whether this is a "__kindof" type as written.
Definition: Type.h:5713
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:5122
DependentUnaryTransformType(const ASTContext &C, QualType BaseType, UTTKind UKind)
Definition: Type.cpp:3251
void setDependent(bool D=true)
Definition: Type.h:1800
no exception specification
bool isTemplateVariadic() const
Determines whether this function prototype contains a parameter pack at the end.
Definition: Type.cpp:3107
StringRef getName(const PrintingPolicy &Policy) const
Definition: Type.cpp:2743
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2557
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments of this object type as they were written.
Definition: Type.h:5707
QualType getPointeeType() const
Definition: Type.h:2570
A (possibly-)qualified type.
Definition: Type.h:643
bool isBlockPointerType() const
Definition: Type.h:6362
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:1361
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
Definition: Type.cpp:2132
bool isArrayType() const
Definition: Type.h:6410
bool isUnsignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is unsigned or an enumeration types whose underlying ...
Definition: Type.cpp:1931
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:943
PrimitiveDefaultInitializeKind isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C struct types.
Definition: Type.cpp:2336
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:3595
bool isArithmeticType() const
Definition: Type.cpp:1983
void setInstantiationDependent(bool D=true)
Definition: Type.h:1806
Stmt - This represents one statement.
Definition: Stmt.h:66
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3375
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:2718
unsigned MSWChar
When true, print the built-in wchar_t type as __wchar_t.
bool isRealFloatingType() const
Floating point categories.
Definition: Type.cpp:1968
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:4064
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.cpp:3383
bool isRecordType() const
Definition: Type.h:6434
QualType getUnderlyingType() const
Definition: Type.h:4217
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:1929
const ObjCObjectType * getAsObjCInterfaceType() const
Definition: Type.cpp:1605
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
TagDecl * getDecl() const
Definition: Type.cpp:3272
ObjCObjectTypeBitfields ObjCObjectTypeBits
Definition: Type.h:1724
const RecordType * getAsStructureType() const
Definition: Type.cpp:521
SubstTemplateTypeParmPackTypeBitfields SubstTemplateTypeParmPackTypeBits
Definition: Type.h:1729
Defines the C++ template declaration subclasses.
StringRef P
Represents a C++11 auto or C++14 decltype(auto) type.
Definition: Type.h:4805
QualType desugar() const
Remove a single level of sugar.
Definition: Type.cpp:3226
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
Definition: Type.cpp:3167
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:2627
The base class of the type hierarchy.
Definition: Type.h:1418
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2832
bool isObjCBoxableRecordType() const
Definition: Type.cpp:449
const ObjCObjectPointerType * getAsObjCInterfacePointerType() const
Definition: Type.cpp:1613
DependentDecltypeType(const ASTContext &Context, Expr *E)
Definition: Type.cpp:3233
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:693
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
Definition: Type.h:6041
bool isCARCBridgableType() const
Determine whether the given type T is a "bridgeable" C type.
Definition: Type.cpp:4069
bool isUnspecialized() const
Determine whether this object type is "unspecialized", meaning that it has no type arguments...
Definition: Type.h:5696
Linkage getLinkage() const
Determine the linkage of this type.
Definition: Type.cpp:3696
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:219
QualType getElementType() const
Definition: Type.h:2867
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3202
const RecordType * getAsUnionType() const
NOTE: getAs*ArrayType are methods on ASTContext.
Definition: Type.cpp:540
QualType withFastQualifiers(unsigned TQs) const
Definition: Type.h:858
static CachedProperties computeCachedProperties(const Type *T)
Definition: Type.cpp:3603
bool isTrivialType(const ASTContext &Context) const
Return true if this is a trivial type per (C++0x [basic.types]p9)
Definition: Type.cpp:2188
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:1915
bool isInterface() const
Definition: Decl.h:3283
bool isStructureType() const
Definition: Type.cpp:443
ArrayRef< ObjCProtocolDecl * > getProtocols() const
Retrieve all of the protocol qualifiers.
Definition: Type.h:5515
bool isEnumeralType() const
Definition: Type.h:6438
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6821
The "union" keyword.
Definition: Type.h:5097
Extra information about a function prototype.
Definition: Type.h:3787
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type...
Definition: Type.h:6895
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:5094
bool isChar32Type() const
Definition: Type.cpp:1846
bool isCallingConv() const
Definition: Type.cpp:3338
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:37
LinkageInfo computeTypeLinkageInfo(const Type *T)
Definition: Type.cpp:3706
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:4659
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:2439
The collection of all-type qualifiers we support.
Definition: Type.h:137
bool isVariableArrayType() const
Definition: Type.h:6422
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.cpp:3224
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:1961
bool isClass() const
Definition: Decl.h:3284
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3085
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:3816
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:3626
QualType getOriginalType() const
Definition: Type.h:2621
bool isWideCharType() const
Definition: Type.cpp:1827
FunctionType::ExtInfo ExtInfo
Definition: Type.h:3788
bool isComplete() const
Returns true if this can be considered a complete type.
Definition: Decl.h:3567
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:1060
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:962
Represents a class type in Objective C.
Definition: Type.h:5596
bool isObjCIndependentClassType() const
Definition: Type.cpp:4029
QualType getPointeeType() const
Definition: Type.h:2674
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:2533
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:3916
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
Definition: Type.cpp:4055
static bool anyDependentTemplateArguments(ArrayRef< TemplateArgumentLoc > Args, bool &InstantiationDependent)
Determine whether any of the given template arguments are dependent.
Definition: Type.cpp:3404
bool isCharType() const
Definition: Type.cpp:1818
bool isSpelledAsLValue() const
Definition: Type.h:2709
field_range fields() const
Definition: Decl.h:3817
Represents a member of a struct/union/class.
Definition: Decl.h:2607
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition: Type.h:1850
Defines the ExceptionSpecificationType enumeration and various utility functions. ...
An operation on a type.
Definition: TypeVisitor.h:64
const ObjCObjectPointerType * getAsObjCQualifiedIdType() const
Definition: Type.cpp:1585
bool isReferenceType() const
Definition: Type.h:6366
qual_iterator qual_begin() const
Definition: Type.h:5497
__DEVICE__ int max(int __a, int __b)
unsigned char getOpaqueValue() const
Definition: Type.h:3450
const AstTypeMatcher< TypedefType > typedefType
Matches typedef types.
unsigned getIndex() const
Retrieve the index into its type parameter list.
Definition: DeclObjC.h:614
QualType getModifiedType() const
Return this attributed type&#39;s modified type with no qualifiers attached to it.
Definition: Type.cpp:3179
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:3130
Type(TypeClass tc, QualType canon, bool Dependent, bool InstantiationDependent, bool VariablyModified, bool ContainsUnexpandedParameterPack)
Definition: Type.h:1781
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2758
bool isMSTypeSpec() const
Definition: Type.cpp:3325
const ObjCObjectType * getAsObjCQualifiedInterfaceType() const
Definition: Type.cpp:1571
qual_iterator qual_end() const
Definition: Type.h:5498
QualType desugar() const
Definition: Type.cpp:3177
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:2475
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:2236
bool hasAddressSpace() const
Definition: Type.h:352
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:6872
The "struct" keyword introduces the elaborated-type-specifier.
Definition: Type.h:5110
static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec)
Converts a type specifier (DeclSpec::TST) into an elaborated type keyword.
Definition: Type.cpp:2601
Whether values of this type can be null is (explicitly) unspecified.
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation...
Definition: Type.h:4198
const ObjCObjectPointerType * getAsObjCQualifiedClassType() const
Definition: Type.cpp:1595
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1844
LangAS getAddressSpace() const
Definition: Type.h:353
const Type * getClass() const
Definition: Type.h:2810
CXXRecordDecl * getDecl() const
Definition: Type.cpp:3362
Values of this type can never be null.
Expr * getSizeExpr() const
Definition: Type.h:3011
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6130
LinkageInfo getTypeLinkageAndVisibility(const Type *T)
Definition: Type.cpp:3789
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:3263
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type...
Definition: Decl.h:3303
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:3958
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:176
bool isScalarType() const
Definition: Type.h:6702
void * getAsOpaquePtr() const
Definition: Type.h:688
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:5831
PrimitiveDefaultInitializeKind
Definition: Type.h:1078
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: Type.h:3773
SplitQualType getSplitDesugaredType() const
Definition: Type.h:947
QualType getPointeeTypeAsWritten() const
Definition: Type.h:2712
TagType(TypeClass TC, const TagDecl *D, QualType can)
Definition: Type.cpp:3256
unsigned getNumProtocols() const
Return the number of qualifying protocols in this type, or 0 if there are none.
Definition: Type.h:5504
QualType getElementType() const
Definition: Type.h:3164
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:1945
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3148
This object can be modified without requiring retains or releases.
Definition: Type.h:158
CXXRecordDecl * getMostRecentNonInjectedDecl()
Definition: DeclCXX.h:756
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:1803
Represents a K&R-style &#39;int foo()&#39; function, which has no information available about its arguments...
Definition: Type.h:3670
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:5690
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:2322
bool hasAttr() const
Definition: DeclBase.h:542
QualType getBaseType() const
Gets the base type of this object type.
Definition: Type.h:5659
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition: Type.cpp:1640
static void ensure(const Type *T)
Definition: Type.cpp:3567
bool acceptsObjCTypeParams() const
Determines if this is an ObjC interface type that may accept type parameters.
Definition: Type.cpp:1472
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:2542
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1636
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3707
const ObjCObjectType * getSuperClassType() const
Retrieve the superclass type.
Definition: DeclObjC.h:1564
static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword)
Definition: Type.cpp:2654
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:1670
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition: Type.h:2838
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:178
ObjCTypeParamDecl * getDecl() const
Definition: Type.h:5565
DependentTemplateSpecializationTypeBitfields DependentTemplateSpecializationTypeBits
Definition: Type.h:1732
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:2370
QualType getElementType() const
Definition: Type.h:2510
IdentifierInfo * getIdentifier() const
Definition: Type.cpp:3366
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:5126
bool isObjCARCImplicitlyUnretainedType() const
Determines if this type, which must satisfy isObjCLifetimeType(), is implicitly __unsafe_unretained r...
Definition: Type.cpp:3997
QualType desugar() const
Definition: Type.h:3231
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:1621
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:6886
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:5108
bool isObjCRetainableType() const
Definition: Type.cpp:4035
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
ObjCSubstitutionContext
The kind of type we are substituting Objective-C type arguments into.
Definition: Type.h:612
bool isChar16Type() const
Definition: Type.cpp:1840
const char * getTypeClassName() const
Definition: Type.cpp:2733
Linkage getLinkage() const
Definition: Visibility.h:83
ObjCLifetime getObjCLifetime() const
Definition: Type.h:327
DeclContext * getDeclContext()
Definition: DeclBase.h:438
bool isAnyComplexType() const
Definition: Type.h:6442
SourceLocation Begin
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4336
static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec)
Converts a type specifier (DeclSpec::TST) into a tag type kind.
Definition: Type.cpp:2614
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:1998
Represents a C++ template name within the type system.
Definition: TemplateName.h:187
Represents the type decltype(expr) (C++11).
Definition: Type.h:4302
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:582
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:1875
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3292
QualType desugar() const
Remove a single level of sugar.
Definition: Type.cpp:3202
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
QualType getType() const
Definition: Expr.h:137
bool isFunctionOrMethod() const
Definition: DeclBase.h:1824
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:3943
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:1644
A unary type transform, which is a type constructed from another.
Definition: Type.h:4345
Qualifiers Quals
The local qualifiers.
Definition: Type.h:587
bool isSpecifierType() const
Returns true if this type can be represented by some set of type specifiers.
Definition: Type.cpp:2575
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:1368
#define TRIVIAL_TYPE_CLASS(Class)
Definition: Type.cpp:758
ScalarTypeKind
Definition: Type.h:2075
bool hasInstantiationDependentExceptionSpec() const
Return whether this function has an instantiation-dependent exception spec.
Definition: Type.cpp:3065
A helper class for Type nodes having an ElaboratedTypeKeyword.
Definition: Type.h:5136
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:1373
Represents a GCC generic vector type.
Definition: Type.h:3188
ArraySizeModifier getSizeModifier() const
Definition: Type.h:2869
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2740
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
Definition: Type.h:4765
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition: Type.h:6761
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:708
bool hasAutoForTrailingReturnType() const
Determine whether this type was written with a leading &#39;auto&#39; corresponding to a trailing return type...
Definition: Type.cpp:1759
bool isChar8Type() const
Definition: Type.cpp:1834
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:264
static LinkageInfo external()
Definition: Visibility.h:67
Expr * getUnderlyingExpr() const
Definition: Type.h:4241
bool isNonTrivialToPrimitiveDestroy() const
Definition: Decl.h:3741
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:6189
IdentifierInfo * getNSCopyingName()
Retrieve the identifier &#39;NSCopying&#39;.
Definition: ASTContext.h:1679
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition: Type.h:4034
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:6138
RecordDecl * getDecl() const
Definition: Type.h:4436
void toString(llvm::SmallVectorImpl< char > &Str) const
Definition: FixedPoint.cpp:176
noexcept(expression), evals to &#39;false&#39;
bool isAlignValT() const
Definition: Type.cpp:2524
LinkageInfo getLinkageAndVisibility() const
Determine the linkage and visibility of this type.
Definition: Type.cpp:3798
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:224
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:17
The "struct" keyword.
Definition: Type.h:5091
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:6169
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:3763
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on a template...
Definition: Expr.h:200
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:3920
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:3794
Encodes a location in the source.
Sugar for parentheses used when specifying types.
Definition: Type.h:2527
QualType getAdjustedType() const
Definition: Type.h:2622
QualType getReturnType() const
Definition: Type.h:3633
bool isLinkageValid() const
True if the computed linkage is valid.
Definition: Type.cpp:3779
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Definition: Type.h:4452
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:6246
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:5796
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Definition: Type.h:2109
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:2374
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3097
TemplateArgument getArgumentPack() const
Definition: Type.cpp:3379
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:376
QualType getElementType() const
Definition: Type.h:3223
static QualType getUnderlyingType(const SubRegion *R)
void FixedPointValueToString(SmallVectorImpl< char > &Str, llvm::APSInt Val, unsigned Scale)
Definition: Type.cpp:4131
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:1790
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:5483
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:1891
QualType getEquivalentType() const
Definition: Type.h:4507
void Profile(llvm::FoldingSetNodeID &ID)
Definition: TemplateName.h:323
QualType getInnerType() const
Definition: Type.h:2540
bool isObjCObjectPointerType() const
Definition: Type.h:6458
AutoTypeKeyword getKeyword() const
Definition: Type.h:4820
TypeClass getTypeClass() const
Definition: Type.h:1824
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition: Type.cpp:1854
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:2352
QualType getSuperClassType() const
Retrieve the type of the superclass of this object type.
Definition: Type.h:5724
EnumDecl * getDecl() const
Definition: Type.h:4459
bool isVectorType() const
Definition: Type.h:6446
__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:3280
Assigning into this object requires a lifetime extension.
Definition: Type.h:171
TemplateSpecializationTypeBitfields TemplateSpecializationTypeBits
Definition: Type.h:1730
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition: Type.cpp:2639
void setVariablyModified(bool VM=true)
Definition: Type.h:1809
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
TypeOfExprType(Expr *E, QualType can=QualType())
Definition: Type.cpp:3191
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:2099
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition: Decl.cpp:1085
Represents a pointer type decayed from an array or function type.
Definition: Type.h:2642
Represents a pack expansion of types.
Definition: Type.h:5413
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:1974
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:4127
Represents a template argument.
Definition: TemplateBase.h:50
bool isDeduced() const
Definition: Type.h:4794
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:2605
TagTypeKind
The kind of a tag type.
Definition: Type.h:5089
Optional< types::ID > Type
CanQualType ObjCBuiltinIdTy
Definition: ASTContext.h:1034
GC getObjCGCAttr() const
Definition: Type.h:301
Dataflow Directional Tag Classes.
bool isObjCQualifiedInterfaceType() const
Definition: Type.cpp:1581
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type...
Definition: Type.cpp:1754
ExtInfo getExtInfo() const
Definition: Type.h:3644
not evaluated yet, for special member function
A qualifier set is used to build a set of qualifiers.
Definition: Type.h:6097
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1271
void setContainsUnexpandedParameterPack(bool PP=true)
Definition: Type.h:1811
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:403
bool hasUnnamedOrLocalType() const
Whether this type is or contains a local or unnamed type.
Definition: Type.cpp:3701
static CachedProperties get(QualType T)
Definition: Type.cpp:3557
bool hasDependentExceptionSpec() const
Return whether this function has a dependent exception spec.
Definition: Type.cpp:3053
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:2140
QualType getUnderlyingType() const
Definition: Decl.h:3004
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:1377
QualType getUnderlyingType() const
Definition: Type.h:4313
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:3506
VectorKind getVectorKind() const
Definition: Type.h:3233
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:558
The "union" keyword introduces the elaborated-type-specifier.
Definition: Type.h:5116
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
Definition: Type.h:6104
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:3174
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.cpp:3521
bool isObjCIndirectLifetimeType() const
Definition: Type.cpp:4041
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:5893
The "class" keyword introduces the elaborated-type-specifier.
Definition: Type.h:5119
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:3359
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2776
bool hasObjCLifetime() const
Definition: Type.h:326
bool isAggregateType() const
Determines whether the type is a C++ aggregate type or C aggregate or union type. ...
Definition: Type.cpp:2038
bool isQualifier() const
Does this attribute behave like a type qualifier?
Definition: Type.cpp:3302
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:3476
UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind, QualType CanonicalTy)
Definition: Type.cpp:3241
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:4674
void addConsistentQualifiers(Qualifiers qs)
Add the qualifiers from the given set to this set, given that they don&#39;t conflict.
Definition: Type.h:453
QualType getModifiedType() const
Definition: Type.h:4506
Represents a pointer to an Objective C object.
Definition: Type.h:5852
Pointer to a block type.
Definition: Type.h:2659
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.cpp:3198
FunctionTypeBitfields FunctionTypeBits
Definition: Type.h:1723
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4426
Complex values, per C99 6.2.5p11.
Definition: Type.h:2497
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:449
unsigned getIndexTypeCVRQualifiers() const
Definition: Type.h:2877
bool empty() const
Definition: Type.h:415
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:2052
QualType getCanonicalTypeInternal() const
Definition: Type.h:2372
QualType getAtomicUnqualifiedType() const
Remove all qualifiers including _Atomic.
Definition: Type.cpp:1384
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:6647
CanThrowResult canThrow() const
Determine whether this function type has a non-throwing exception specification.
Definition: Type.cpp:3074
const llvm::APInt & getSize() const
Definition: Type.h:2910
Kind getAttrKind() const
Definition: Type.h:4502
VectorTypeBitfields VectorTypeBits
Definition: Type.h:1728
ExtVectorType - Extended vector type.
Definition: Type.h:3307
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2693
SourceRange getBracketsRange() const
Definition: Type.h:3017
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:1390
Optional< NullabilityKind > getNullability(const ASTContext &context) const
Determine the nullability of the given type.
Definition: Type.cpp:3803
The "class" keyword.
Definition: Type.h:5100
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type...
Definition: Type.cpp:2897
bool isBeingDefined() const
Determines whether this type is in the process of being defined.
Definition: Type.cpp:3276
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:2070
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:3766
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:2062
bool hasObjCGCAttr() const
Definition: Type.h:300
The type-property cache.
Definition: Type.cpp:3555
bool isClassType() const
Definition: Type.cpp:437
TypedefNameDecl * getDecl() const
Definition: Type.h:4188
TypeBitfields TypeBits
Definition: Type.h:1718
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:3769
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:4481
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:5522
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:1905
Represents a C++ struct/union/class.
Definition: DeclCXX.h:300
bool isVoidType() const
Definition: Type.h:6613
Represents a C array with an unspecified size.
Definition: Type.h:2946
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:1764
The parameter type of a method or function.
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:5227
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
Definition: Type.h:4680
The "enum" keyword.
Definition: Type.h:5103
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates)...
Definition: Expr.h:223
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4266
Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const
Return the implicit lifetime for this type, which must not be dependent.
Definition: Type.cpp:3991
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:2408
Defines the clang::TargetInfo interface.
bool isComplexIntegerType() const
Definition: Type.cpp:487
ASTContext & getParentASTContext() const
Definition: DeclBase.h:1801
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
Definition: TargetCXXABI.h:153
bool hasVolatile() const
Definition: Type.h:259
NameKind getKind() const
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:944
unsigned getNumElements() const
Definition: Type.h:3224
QualType getSuperClassType() const
Retrieve the type of the superclass of this object pointer type.
Definition: Type.cpp:1562
void initialize(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema)
Microsoft __declspec(nothrow) extension.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2093
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:4899
bool isPointerType() const
Definition: Type.h:6354
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
static StringRef getNameForCallConv(CallingConv CC)
Definition: Type.cpp:2913
#define true
Definition: stdbool.h:16
bool isFloatingType() const
Definition: Type.cpp:1952
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:3062
void computeSuperClassTypeSlow() const
Definition: Type.cpp:1483
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:3603
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:2991
No keyword precedes the qualified type name.
Definition: Type.h:5129
bool isConstant(const ASTContext &Ctx) const
Definition: Type.h:778
bool isInterfaceType() const
Definition: Type.cpp:455
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:5375
QualType desugar() const
Definition: Type.cpp:3173
const LangOptions & getLangOpts() const
Definition: ASTContext.h:710
unsigned size() const
Determine the number of type parameters in this list.
Definition: DeclObjC.h:676
llvm::Optional< NullabilityKind > getImmediateNullability() const
Definition: Type.cpp:3933
The "__interface" keyword introduces the elaborated-type-specifier.
Definition: Type.h:5113
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:2892
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:3793
bool isObjCNSObjectType() const
Definition: Type.cpp:4016
bool hasSizedVLAType() const
Whether this type involves a variable-length array type with a definite size.
Definition: Type.cpp:4078
QualType getPointeeType() const
Definition: Type.h:2796
A single template declaration.
Definition: TemplateName.h:200
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3222
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:1063
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:5868