clang 19.0.0git
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"
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"
22#include "clang/AST/DeclObjC.h"
25#include "clang/AST/Expr.h"
35#include "clang/Basic/LLVM.h"
37#include "clang/Basic/Linkage.h"
42#include "llvm/ADT/APInt.h"
43#include "llvm/ADT/APSInt.h"
44#include "llvm/ADT/ArrayRef.h"
45#include "llvm/ADT/FoldingSet.h"
46#include "llvm/ADT/SmallVector.h"
47#include "llvm/Support/Casting.h"
48#include "llvm/Support/ErrorHandling.h"
49#include "llvm/Support/MathExtras.h"
50#include "llvm/TargetParser/RISCVTargetParser.h"
51#include <algorithm>
52#include <cassert>
53#include <cstdint>
54#include <cstring>
55#include <optional>
56#include <type_traits>
57
58using namespace clang;
59
61 return (*this != Other) &&
62 // CVR qualifiers superset
63 (((Mask & CVRMask) | (Other.Mask & CVRMask)) == (Mask & CVRMask)) &&
64 // ObjC GC qualifiers superset
65 ((getObjCGCAttr() == Other.getObjCGCAttr()) ||
66 (hasObjCGCAttr() && !Other.hasObjCGCAttr())) &&
67 // Address space superset.
68 ((getAddressSpace() == Other.getAddressSpace()) ||
69 (hasAddressSpace()&& !Other.hasAddressSpace())) &&
70 // Lifetime qualifier superset.
71 ((getObjCLifetime() == Other.getObjCLifetime()) ||
72 (hasObjCLifetime() && !Other.hasObjCLifetime()));
73}
74
76 const Type* ty = getTypePtr();
77 NamedDecl *ND = nullptr;
78 if (ty->isPointerType() || ty->isReferenceType())
80 else if (ty->isRecordType())
81 ND = ty->castAs<RecordType>()->getDecl();
82 else if (ty->isEnumeralType())
83 ND = ty->castAs<EnumType>()->getDecl();
84 else if (ty->getTypeClass() == Type::Typedef)
85 ND = ty->castAs<TypedefType>()->getDecl();
86 else if (ty->isArrayType())
87 return ty->castAsArrayTypeUnsafe()->
88 getElementType().getBaseTypeIdentifier();
89
90 if (ND)
91 return ND->getIdentifier();
92 return nullptr;
93}
94
96 const auto *ClassDecl = getTypePtr()->getPointeeCXXRecordDecl();
97 return ClassDecl && ClassDecl->mayBeDynamicClass();
98}
99
101 const auto *ClassDecl = getTypePtr()->getPointeeCXXRecordDecl();
102 return !ClassDecl || ClassDecl->mayBeNonDynamicClass();
103}
104
105bool QualType::isConstant(QualType T, const ASTContext &Ctx) {
106 if (T.isConstQualified())
107 return true;
108
109 if (const ArrayType *AT = Ctx.getAsArrayType(T))
110 return AT->getElementType().isConstant(Ctx);
111
113}
114
115std::optional<QualType::NonConstantStorageReason>
116QualType::isNonConstantStorage(const ASTContext &Ctx, bool ExcludeCtor,
117 bool ExcludeDtor) {
118 if (!isConstant(Ctx) && !(*this)->isReferenceType())
120 if (!Ctx.getLangOpts().CPlusPlus)
121 return std::nullopt;
122 if (const CXXRecordDecl *Record =
124 if (!ExcludeCtor)
126 if (Record->hasMutableFields())
128 if (!Record->hasTrivialDestructor() && !ExcludeDtor)
130 }
131 return std::nullopt;
132}
133
134// C++ [temp.dep.type]p1:
135// A type is dependent if it is...
136// - an array type constructed from any dependent type or whose
137// size is specified by a constant expression that is
138// value-dependent,
140 ArraySizeModifier sm, unsigned tq, const Expr *sz)
141 // Note, we need to check for DependentSizedArrayType explicitly here
142 // because we use a DependentSizedArrayType with no size expression as the
143 // type of a dependent array of unknown bound with a dependent braced
144 // initializer:
145 //
146 // template<int ...N> int arr[] = {N...};
147 : Type(tc, can,
148 et->getDependence() |
149 (sz ? toTypeDependence(
150 turnValueToTypeDependence(sz->getDependence()))
151 : TypeDependence::None) |
152 (tc == VariableArray ? TypeDependence::VariablyModified
153 : TypeDependence::None) |
154 (tc == DependentSizedArray
155 ? TypeDependence::DependentInstantiation
156 : TypeDependence::None)),
157 ElementType(et) {
158 ArrayTypeBits.IndexTypeQuals = tq;
159 ArrayTypeBits.SizeModifier = llvm::to_underlying(sm);
160}
161
163 QualType ElementType,
164 const llvm::APInt &NumElements) {
165 uint64_t ElementSize = Context.getTypeSizeInChars(ElementType).getQuantity();
166
167 // Fast path the common cases so we can avoid the conservative computation
168 // below, which in common cases allocates "large" APSInt values, which are
169 // slow.
170
171 // If the element size is a power of 2, we can directly compute the additional
172 // number of addressing bits beyond those required for the element count.
173 if (llvm::isPowerOf2_64(ElementSize)) {
174 return NumElements.getActiveBits() + llvm::Log2_64(ElementSize);
175 }
176
177 // If both the element count and element size fit in 32-bits, we can do the
178 // computation directly in 64-bits.
179 if ((ElementSize >> 32) == 0 && NumElements.getBitWidth() <= 64 &&
180 (NumElements.getZExtValue() >> 32) == 0) {
181 uint64_t TotalSize = NumElements.getZExtValue() * ElementSize;
182 return llvm::bit_width(TotalSize);
183 }
184
185 // Otherwise, use APSInt to handle arbitrary sized values.
186 llvm::APSInt SizeExtended(NumElements, true);
187 unsigned SizeTypeBits = Context.getTypeSize(Context.getSizeType());
188 SizeExtended = SizeExtended.extend(std::max(SizeTypeBits,
189 SizeExtended.getBitWidth()) * 2);
190
191 llvm::APSInt TotalSize(llvm::APInt(SizeExtended.getBitWidth(), ElementSize));
192 TotalSize *= SizeExtended;
193
194 return TotalSize.getActiveBits();
195}
196
197unsigned
199 return getNumAddressingBits(Context, getElementType(), getSize());
200}
201
203 unsigned Bits = Context.getTypeSize(Context.getSizeType());
204
205 // Limit the number of bits in size_t so that maximal bit size fits 64 bit
206 // integer (see PR8256). We can do this as currently there is no hardware
207 // that supports full 64-bit virtual space.
208 if (Bits > 61)
209 Bits = 61;
210
211 return Bits;
212}
213
214void ConstantArrayType::Profile(llvm::FoldingSetNodeID &ID,
215 const ASTContext &Context, QualType ET,
216 const llvm::APInt &ArraySize,
217 const Expr *SizeExpr, ArraySizeModifier SizeMod,
218 unsigned TypeQuals) {
219 ID.AddPointer(ET.getAsOpaquePtr());
220 ID.AddInteger(ArraySize.getZExtValue());
221 ID.AddInteger(llvm::to_underlying(SizeMod));
222 ID.AddInteger(TypeQuals);
223 ID.AddBoolean(SizeExpr != nullptr);
224 if (SizeExpr)
225 SizeExpr->Profile(ID, Context, true);
226}
227
228DependentSizedArrayType::DependentSizedArrayType(QualType et, QualType can,
229 Expr *e, ArraySizeModifier sm,
230 unsigned tq,
231 SourceRange brackets)
232 : ArrayType(DependentSizedArray, et, can, sm, tq, e), SizeExpr((Stmt *)e),
233 Brackets(brackets) {}
234
235void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID,
236 const ASTContext &Context,
237 QualType ET,
238 ArraySizeModifier SizeMod,
239 unsigned TypeQuals,
240 Expr *E) {
241 ID.AddPointer(ET.getAsOpaquePtr());
242 ID.AddInteger(llvm::to_underlying(SizeMod));
243 ID.AddInteger(TypeQuals);
244 E->Profile(ID, Context, true);
245}
246
247DependentVectorType::DependentVectorType(QualType ElementType,
248 QualType CanonType, Expr *SizeExpr,
249 SourceLocation Loc, VectorKind VecKind)
250 : Type(DependentVector, CanonType,
251 TypeDependence::DependentInstantiation |
252 ElementType->getDependence() |
253 (SizeExpr ? toTypeDependence(SizeExpr->getDependence())
254 : TypeDependence::None)),
255 ElementType(ElementType), SizeExpr(SizeExpr), Loc(Loc) {
256 VectorTypeBits.VecKind = llvm::to_underlying(VecKind);
257}
258
259void DependentVectorType::Profile(llvm::FoldingSetNodeID &ID,
260 const ASTContext &Context,
261 QualType ElementType, const Expr *SizeExpr,
262 VectorKind VecKind) {
263 ID.AddPointer(ElementType.getAsOpaquePtr());
264 ID.AddInteger(llvm::to_underlying(VecKind));
265 SizeExpr->Profile(ID, Context, true);
266}
267
268DependentSizedExtVectorType::DependentSizedExtVectorType(QualType ElementType,
269 QualType can,
270 Expr *SizeExpr,
271 SourceLocation loc)
272 : Type(DependentSizedExtVector, can,
273 TypeDependence::DependentInstantiation |
274 ElementType->getDependence() |
275 (SizeExpr ? toTypeDependence(SizeExpr->getDependence())
276 : TypeDependence::None)),
277 SizeExpr(SizeExpr), ElementType(ElementType), loc(loc) {}
278
279void
280DependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID,
281 const ASTContext &Context,
282 QualType ElementType, Expr *SizeExpr) {
283 ID.AddPointer(ElementType.getAsOpaquePtr());
284 SizeExpr->Profile(ID, Context, true);
285}
286
287DependentAddressSpaceType::DependentAddressSpaceType(QualType PointeeType,
288 QualType can,
289 Expr *AddrSpaceExpr,
290 SourceLocation loc)
291 : Type(DependentAddressSpace, can,
292 TypeDependence::DependentInstantiation |
293 PointeeType->getDependence() |
294 (AddrSpaceExpr ? toTypeDependence(AddrSpaceExpr->getDependence())
295 : TypeDependence::None)),
296 AddrSpaceExpr(AddrSpaceExpr), PointeeType(PointeeType), loc(loc) {}
297
298void DependentAddressSpaceType::Profile(llvm::FoldingSetNodeID &ID,
299 const ASTContext &Context,
300 QualType PointeeType,
301 Expr *AddrSpaceExpr) {
302 ID.AddPointer(PointeeType.getAsOpaquePtr());
303 AddrSpaceExpr->Profile(ID, Context, true);
304}
305
307 const Expr *RowExpr, const Expr *ColumnExpr)
308 : Type(tc, canonType,
309 (RowExpr ? (matrixType->getDependence() | TypeDependence::Dependent |
310 TypeDependence::Instantiation |
311 (matrixType->isVariablyModifiedType()
312 ? TypeDependence::VariablyModified
313 : TypeDependence::None) |
314 (matrixType->containsUnexpandedParameterPack() ||
315 (RowExpr &&
316 RowExpr->containsUnexpandedParameterPack()) ||
317 (ColumnExpr &&
318 ColumnExpr->containsUnexpandedParameterPack())
319 ? TypeDependence::UnexpandedPack
321 : matrixType->getDependence())),
322 ElementType(matrixType) {}
323
325 unsigned nColumns, QualType canonType)
326 : ConstantMatrixType(ConstantMatrix, matrixType, nRows, nColumns,
327 canonType) {}
328
330 unsigned nRows, unsigned nColumns,
331 QualType canonType)
332 : MatrixType(tc, matrixType, canonType), NumRows(nRows),
333 NumColumns(nColumns) {}
334
335DependentSizedMatrixType::DependentSizedMatrixType(QualType ElementType,
336 QualType CanonicalType,
337 Expr *RowExpr,
338 Expr *ColumnExpr,
339 SourceLocation loc)
340 : MatrixType(DependentSizedMatrix, ElementType, CanonicalType, RowExpr,
341 ColumnExpr),
342 RowExpr(RowExpr), ColumnExpr(ColumnExpr), loc(loc) {}
343
344void DependentSizedMatrixType::Profile(llvm::FoldingSetNodeID &ID,
345 const ASTContext &CTX,
346 QualType ElementType, Expr *RowExpr,
347 Expr *ColumnExpr) {
348 ID.AddPointer(ElementType.getAsOpaquePtr());
349 RowExpr->Profile(ID, CTX, true);
350 ColumnExpr->Profile(ID, CTX, true);
351}
352
353VectorType::VectorType(QualType vecType, unsigned nElements, QualType canonType,
354 VectorKind vecKind)
355 : VectorType(Vector, vecType, nElements, canonType, vecKind) {}
356
357VectorType::VectorType(TypeClass tc, QualType vecType, unsigned nElements,
358 QualType canonType, VectorKind vecKind)
359 : Type(tc, canonType, vecType->getDependence()), ElementType(vecType) {
360 VectorTypeBits.VecKind = llvm::to_underlying(vecKind);
361 VectorTypeBits.NumElements = nElements;
362}
363
364BitIntType::BitIntType(bool IsUnsigned, unsigned NumBits)
365 : Type(BitInt, QualType{}, TypeDependence::None), IsUnsigned(IsUnsigned),
366 NumBits(NumBits) {}
367
368DependentBitIntType::DependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr)
369 : Type(DependentBitInt, QualType{},
370 toTypeDependence(NumBitsExpr->getDependence())),
371 ExprAndUnsigned(NumBitsExpr, IsUnsigned) {}
372
374 return ExprAndUnsigned.getInt();
375}
376
378 return ExprAndUnsigned.getPointer();
379}
380
381void DependentBitIntType::Profile(llvm::FoldingSetNodeID &ID,
382 const ASTContext &Context, bool IsUnsigned,
383 Expr *NumBitsExpr) {
384 ID.AddBoolean(IsUnsigned);
385 NumBitsExpr->Profile(ID, Context, true);
386}
387
388/// getArrayElementTypeNoTypeQual - If this is an array type, return the
389/// element type of the array, potentially with type qualifiers missing.
390/// This method should never be used when type qualifiers are meaningful.
392 // If this is directly an array type, return it.
393 if (const auto *ATy = dyn_cast<ArrayType>(this))
394 return ATy->getElementType().getTypePtr();
395
396 // If the canonical form of this type isn't the right kind, reject it.
397 if (!isa<ArrayType>(CanonicalType))
398 return nullptr;
399
400 // If this is a typedef for an array type, strip the typedef off without
401 // losing all typedef information.
402 return cast<ArrayType>(getUnqualifiedDesugaredType())
403 ->getElementType().getTypePtr();
404}
405
406/// getDesugaredType - Return the specified type with any "sugar" removed from
407/// the type. This takes off typedefs, typeof's etc. If the outer level of
408/// the type is already concrete, it returns it unmodified. This is similar
409/// to getting the canonical type, but it doesn't remove *all* typedefs. For
410/// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
411/// concrete.
414 return Context.getQualifiedType(split.Ty, split.Quals);
415}
416
417QualType QualType::getSingleStepDesugaredTypeImpl(QualType type,
418 const ASTContext &Context) {
419 SplitQualType split = type.split();
421 return Context.getQualifiedType(desugar, split.Quals);
422}
423
424// Check that no type class is polymorphic. LLVM style RTTI should be used
425// instead. If absolutely needed an exception can still be added here by
426// defining the appropriate macro (but please don't do this).
427#define TYPE(CLASS, BASE) \
428 static_assert(!std::is_polymorphic<CLASS##Type>::value, \
429 #CLASS "Type should not be polymorphic!");
430#include "clang/AST/TypeNodes.inc"
431
432// Check that no type class has a non-trival destructor. Types are
433// allocated with the BumpPtrAllocator from ASTContext and therefore
434// their destructor is not executed.
435//
436// FIXME: ConstantArrayType is not trivially destructible because of its
437// APInt member. It should be replaced in favor of ASTContext allocation.
438#define TYPE(CLASS, BASE) \
439 static_assert(std::is_trivially_destructible<CLASS##Type>::value || \
440 std::is_same<CLASS##Type, ConstantArrayType>::value, \
441 #CLASS "Type should be trivially destructible!");
442#include "clang/AST/TypeNodes.inc"
443
445 switch (getTypeClass()) {
446#define ABSTRACT_TYPE(Class, Parent)
447#define TYPE(Class, Parent) \
448 case Type::Class: { \
449 const auto *ty = cast<Class##Type>(this); \
450 if (!ty->isSugared()) return QualType(ty, 0); \
451 return ty->desugar(); \
452 }
453#include "clang/AST/TypeNodes.inc"
454 }
455 llvm_unreachable("bad type kind!");
456}
457
460
461 QualType Cur = T;
462 while (true) {
463 const Type *CurTy = Qs.strip(Cur);
464 switch (CurTy->getTypeClass()) {
465#define ABSTRACT_TYPE(Class, Parent)
466#define TYPE(Class, Parent) \
467 case Type::Class: { \
468 const auto *Ty = cast<Class##Type>(CurTy); \
469 if (!Ty->isSugared()) \
470 return SplitQualType(Ty, Qs); \
471 Cur = Ty->desugar(); \
472 break; \
473 }
474#include "clang/AST/TypeNodes.inc"
475 }
476 }
477}
478
479SplitQualType QualType::getSplitUnqualifiedTypeImpl(QualType type) {
480 SplitQualType split = type.split();
481
482 // All the qualifiers we've seen so far.
483 Qualifiers quals = split.Quals;
484
485 // The last type node we saw with any nodes inside it.
486 const Type *lastTypeWithQuals = split.Ty;
487
488 while (true) {
489 QualType next;
490
491 // Do a single-step desugar, aborting the loop if the type isn't
492 // sugared.
493 switch (split.Ty->getTypeClass()) {
494#define ABSTRACT_TYPE(Class, Parent)
495#define TYPE(Class, Parent) \
496 case Type::Class: { \
497 const auto *ty = cast<Class##Type>(split.Ty); \
498 if (!ty->isSugared()) goto done; \
499 next = ty->desugar(); \
500 break; \
501 }
502#include "clang/AST/TypeNodes.inc"
503 }
504
505 // Otherwise, split the underlying type. If that yields qualifiers,
506 // update the information.
507 split = next.split();
508 if (!split.Quals.empty()) {
509 lastTypeWithQuals = split.Ty;
511 }
512 }
513
514 done:
515 return SplitQualType(lastTypeWithQuals, quals);
516}
517
519 // FIXME: this seems inherently un-qualifiers-safe.
520 while (const auto *PT = T->getAs<ParenType>())
521 T = PT->getInnerType();
522 return T;
523}
524
525/// This will check for a T (which should be a Type which can act as
526/// sugar, such as a TypedefType) by removing any existing sugar until it
527/// reaches a T or a non-sugared type.
528template<typename T> static const T *getAsSugar(const Type *Cur) {
529 while (true) {
530 if (const auto *Sugar = dyn_cast<T>(Cur))
531 return Sugar;
532 switch (Cur->getTypeClass()) {
533#define ABSTRACT_TYPE(Class, Parent)
534#define TYPE(Class, Parent) \
535 case Type::Class: { \
536 const auto *Ty = cast<Class##Type>(Cur); \
537 if (!Ty->isSugared()) return 0; \
538 Cur = Ty->desugar().getTypePtr(); \
539 break; \
540 }
541#include "clang/AST/TypeNodes.inc"
542 }
543 }
544}
545
546template <> const TypedefType *Type::getAs() const {
547 return getAsSugar<TypedefType>(this);
548}
549
550template <> const UsingType *Type::getAs() const {
551 return getAsSugar<UsingType>(this);
552}
553
554template <> const TemplateSpecializationType *Type::getAs() const {
555 return getAsSugar<TemplateSpecializationType>(this);
556}
557
558template <> const AttributedType *Type::getAs() const {
559 return getAsSugar<AttributedType>(this);
560}
561
562/// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic
563/// sugar off the given type. This should produce an object of the
564/// same dynamic type as the canonical type.
566 const Type *Cur = this;
567
568 while (true) {
569 switch (Cur->getTypeClass()) {
570#define ABSTRACT_TYPE(Class, Parent)
571#define TYPE(Class, Parent) \
572 case Class: { \
573 const auto *Ty = cast<Class##Type>(Cur); \
574 if (!Ty->isSugared()) return Cur; \
575 Cur = Ty->desugar().getTypePtr(); \
576 break; \
577 }
578#include "clang/AST/TypeNodes.inc"
579 }
580 }
581}
582
583bool Type::isClassType() const {
584 if (const auto *RT = getAs<RecordType>())
585 return RT->getDecl()->isClass();
586 return false;
587}
588
590 if (const auto *RT = getAs<RecordType>())
591 return RT->getDecl()->isStruct();
592 return false;
593}
594
596 if (const auto *RT = getAs<RecordType>())
597 return RT->getDecl()->hasAttr<ObjCBoxableAttr>();
598 return false;
599}
600
602 if (const auto *RT = getAs<RecordType>())
603 return RT->getDecl()->isInterface();
604 return false;
605}
606
608 if (const auto *RT = getAs<RecordType>()) {
609 RecordDecl *RD = RT->getDecl();
610 return RD->isStruct() || RD->isClass() || RD->isInterface();
611 }
612 return false;
613}
614
616 if (const auto *PT = getAs<PointerType>())
617 return PT->getPointeeType()->isVoidType();
618 return false;
619}
620
621bool Type::isUnionType() const {
622 if (const auto *RT = getAs<RecordType>())
623 return RT->getDecl()->isUnion();
624 return false;
625}
626
628 if (const auto *CT = dyn_cast<ComplexType>(CanonicalType))
629 return CT->getElementType()->isFloatingType();
630 return false;
631}
632
634 // Check for GCC complex integer extension.
636}
637
639 if (const auto *ET = getAs<EnumType>())
640 return ET->getDecl()->isScoped();
641 return false;
642}
643
645 if (const auto *Complex = getAs<ComplexType>())
646 if (Complex->getElementType()->isIntegerType())
647 return Complex;
648 return nullptr;
649}
650
652 if (const auto *PT = getAs<PointerType>())
653 return PT->getPointeeType();
654 if (const auto *OPT = getAs<ObjCObjectPointerType>())
655 return OPT->getPointeeType();
656 if (const auto *BPT = getAs<BlockPointerType>())
657 return BPT->getPointeeType();
658 if (const auto *RT = getAs<ReferenceType>())
659 return RT->getPointeeType();
660 if (const auto *MPT = getAs<MemberPointerType>())
661 return MPT->getPointeeType();
662 if (const auto *DT = getAs<DecayedType>())
663 return DT->getPointeeType();
664 return {};
665}
666
668 // If this is directly a structure type, return it.
669 if (const auto *RT = dyn_cast<RecordType>(this)) {
670 if (RT->getDecl()->isStruct())
671 return RT;
672 }
673
674 // If the canonical form of this type isn't the right kind, reject it.
675 if (const auto *RT = dyn_cast<RecordType>(CanonicalType)) {
676 if (!RT->getDecl()->isStruct())
677 return nullptr;
678
679 // If this is a typedef for a structure type, strip the typedef off without
680 // losing all typedef information.
681 return cast<RecordType>(getUnqualifiedDesugaredType());
682 }
683 return nullptr;
684}
685
687 // If this is directly a union type, return it.
688 if (const auto *RT = dyn_cast<RecordType>(this)) {
689 if (RT->getDecl()->isUnion())
690 return RT;
691 }
692
693 // If the canonical form of this type isn't the right kind, reject it.
694 if (const auto *RT = dyn_cast<RecordType>(CanonicalType)) {
695 if (!RT->getDecl()->isUnion())
696 return nullptr;
697
698 // If this is a typedef for a union type, strip the typedef off without
699 // losing all typedef information.
700 return cast<RecordType>(getUnqualifiedDesugaredType());
701 }
702
703 return nullptr;
704}
705
707 const ObjCObjectType *&bound) const {
708 bound = nullptr;
709
710 const auto *OPT = getAs<ObjCObjectPointerType>();
711 if (!OPT)
712 return false;
713
714 // Easy case: id.
715 if (OPT->isObjCIdType())
716 return true;
717
718 // If it's not a __kindof type, reject it now.
719 if (!OPT->isKindOfType())
720 return false;
721
722 // If it's Class or qualified Class, it's not an object type.
723 if (OPT->isObjCClassType() || OPT->isObjCQualifiedClassType())
724 return false;
725
726 // Figure out the type bound for the __kindof type.
727 bound = OPT->getObjectType()->stripObjCKindOfTypeAndQuals(ctx)
729 return true;
730}
731
733 const auto *OPT = getAs<ObjCObjectPointerType>();
734 if (!OPT)
735 return false;
736
737 // Easy case: Class.
738 if (OPT->isObjCClassType())
739 return true;
740
741 // If it's not a __kindof type, reject it now.
742 if (!OPT->isKindOfType())
743 return false;
744
745 // If it's Class or qualified Class, it's a class __kindof type.
746 return OPT->isObjCClassType() || OPT->isObjCQualifiedClassType();
747}
748
749ObjCTypeParamType::ObjCTypeParamType(const ObjCTypeParamDecl *D, QualType can,
751 : Type(ObjCTypeParam, can, toSemanticDependence(can->getDependence())),
752 OTPDecl(const_cast<ObjCTypeParamDecl *>(D)) {
753 initialize(protocols);
754}
755
757 ArrayRef<QualType> typeArgs,
759 bool isKindOf)
760 : Type(ObjCObject, Canonical, Base->getDependence()), BaseType(Base) {
761 ObjCObjectTypeBits.IsKindOf = isKindOf;
762
763 ObjCObjectTypeBits.NumTypeArgs = typeArgs.size();
764 assert(getTypeArgsAsWritten().size() == typeArgs.size() &&
765 "bitfield overflow in type argument count");
766 if (!typeArgs.empty())
767 memcpy(getTypeArgStorage(), typeArgs.data(),
768 typeArgs.size() * sizeof(QualType));
769
770 for (auto typeArg : typeArgs) {
771 addDependence(typeArg->getDependence() & ~TypeDependence::VariablyModified);
772 }
773 // Initialize the protocol qualifiers. The protocol storage is known
774 // after we set number of type arguments.
775 initialize(protocols);
776}
777
779 // If we have type arguments written here, the type is specialized.
780 if (ObjCObjectTypeBits.NumTypeArgs > 0)
781 return true;
782
783 // Otherwise, check whether the base type is specialized.
784 if (const auto objcObject = getBaseType()->getAs<ObjCObjectType>()) {
785 // Terminate when we reach an interface type.
786 if (isa<ObjCInterfaceType>(objcObject))
787 return false;
788
789 return objcObject->isSpecialized();
790 }
791
792 // Not specialized.
793 return false;
794}
795
797 // We have type arguments written on this type.
799 return getTypeArgsAsWritten();
800
801 // Look at the base type, which might have type arguments.
802 if (const auto objcObject = getBaseType()->getAs<ObjCObjectType>()) {
803 // Terminate when we reach an interface type.
804 if (isa<ObjCInterfaceType>(objcObject))
805 return {};
806
807 return objcObject->getTypeArgs();
808 }
809
810 // No type arguments.
811 return {};
812}
813
816 return true;
817
818 // Look at the base type, which might have type arguments.
819 if (const auto objcObject = getBaseType()->getAs<ObjCObjectType>()) {
820 // Terminate when we reach an interface type.
821 if (isa<ObjCInterfaceType>(objcObject))
822 return false;
823
824 return objcObject->isKindOfType();
825 }
826
827 // Not a "__kindof" type.
828 return false;
829}
830
832 const ASTContext &ctx) const {
833 if (!isKindOfType() && qual_empty())
834 return QualType(this, 0);
835
836 // Recursively strip __kindof.
837 SplitQualType splitBaseType = getBaseType().split();
838 QualType baseType(splitBaseType.Ty, 0);
839 if (const auto *baseObj = splitBaseType.Ty->getAs<ObjCObjectType>())
840 baseType = baseObj->stripObjCKindOfTypeAndQuals(ctx);
841
842 return ctx.getObjCObjectType(ctx.getQualifiedType(baseType,
843 splitBaseType.Quals),
845 /*protocols=*/{},
846 /*isKindOf=*/false);
847}
848
851 if (ObjCInterfaceDecl *Def = Canon->getDefinition())
852 return Def;
853 return Canon;
854}
855
857 const ASTContext &ctx) const {
858 if (!isKindOfType() && qual_empty())
859 return this;
860
863}
864
865namespace {
866
867/// Visitor used to perform a simple type transformation that does not change
868/// the semantics of the type.
869template <typename Derived>
870struct SimpleTransformVisitor : public TypeVisitor<Derived, QualType> {
871 ASTContext &Ctx;
872
873 QualType recurse(QualType type) {
874 // Split out the qualifiers from the type.
875 SplitQualType splitType = type.split();
876
877 // Visit the type itself.
878 QualType result = static_cast<Derived *>(this)->Visit(splitType.Ty);
879 if (result.isNull())
880 return result;
881
882 // Reconstruct the transformed type by applying the local qualifiers
883 // from the split type.
884 return Ctx.getQualifiedType(result, splitType.Quals);
885 }
886
887public:
888 explicit SimpleTransformVisitor(ASTContext &ctx) : Ctx(ctx) {}
889
890 // None of the clients of this transformation can occur where
891 // there are dependent types, so skip dependent types.
892#define TYPE(Class, Base)
893#define DEPENDENT_TYPE(Class, Base) \
894 QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); }
895#include "clang/AST/TypeNodes.inc"
896
897#define TRIVIAL_TYPE_CLASS(Class) \
898 QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); }
899#define SUGARED_TYPE_CLASS(Class) \
900 QualType Visit##Class##Type(const Class##Type *T) { \
901 if (!T->isSugared()) \
902 return QualType(T, 0); \
903 QualType desugaredType = recurse(T->desugar()); \
904 if (desugaredType.isNull()) \
905 return {}; \
906 if (desugaredType.getAsOpaquePtr() == T->desugar().getAsOpaquePtr()) \
907 return QualType(T, 0); \
908 return desugaredType; \
909 }
910
911 TRIVIAL_TYPE_CLASS(Builtin)
912
913 QualType VisitComplexType(const ComplexType *T) {
914 QualType elementType = recurse(T->getElementType());
915 if (elementType.isNull())
916 return {};
917
918 if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
919 return QualType(T, 0);
920
921 return Ctx.getComplexType(elementType);
922 }
923
924 QualType VisitPointerType(const PointerType *T) {
925 QualType pointeeType = recurse(T->getPointeeType());
926 if (pointeeType.isNull())
927 return {};
928
929 if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
930 return QualType(T, 0);
931
932 return Ctx.getPointerType(pointeeType);
933 }
934
935 QualType VisitBlockPointerType(const BlockPointerType *T) {
936 QualType pointeeType = recurse(T->getPointeeType());
937 if (pointeeType.isNull())
938 return {};
939
940 if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
941 return QualType(T, 0);
942
943 return Ctx.getBlockPointerType(pointeeType);
944 }
945
946 QualType VisitLValueReferenceType(const LValueReferenceType *T) {
947 QualType pointeeType = recurse(T->getPointeeTypeAsWritten());
948 if (pointeeType.isNull())
949 return {};
950
951 if (pointeeType.getAsOpaquePtr()
953 return QualType(T, 0);
954
955 return Ctx.getLValueReferenceType(pointeeType, T->isSpelledAsLValue());
956 }
957
958 QualType VisitRValueReferenceType(const RValueReferenceType *T) {
959 QualType pointeeType = recurse(T->getPointeeTypeAsWritten());
960 if (pointeeType.isNull())
961 return {};
962
963 if (pointeeType.getAsOpaquePtr()
965 return QualType(T, 0);
966
967 return Ctx.getRValueReferenceType(pointeeType);
968 }
969
970 QualType VisitMemberPointerType(const MemberPointerType *T) {
971 QualType pointeeType = recurse(T->getPointeeType());
972 if (pointeeType.isNull())
973 return {};
974
975 if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
976 return QualType(T, 0);
977
978 return Ctx.getMemberPointerType(pointeeType, T->getClass());
979 }
980
981 QualType VisitConstantArrayType(const ConstantArrayType *T) {
982 QualType elementType = recurse(T->getElementType());
983 if (elementType.isNull())
984 return {};
985
986 if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
987 return QualType(T, 0);
988
989 return Ctx.getConstantArrayType(elementType, T->getSize(), T->getSizeExpr(),
990 T->getSizeModifier(),
992 }
993
994 QualType VisitVariableArrayType(const VariableArrayType *T) {
995 QualType elementType = recurse(T->getElementType());
996 if (elementType.isNull())
997 return {};
998
999 if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
1000 return QualType(T, 0);
1001
1002 return Ctx.getVariableArrayType(elementType, T->getSizeExpr(),
1003 T->getSizeModifier(),
1005 T->getBracketsRange());
1006 }
1007
1008 QualType VisitIncompleteArrayType(const IncompleteArrayType *T) {
1009 QualType elementType = recurse(T->getElementType());
1010 if (elementType.isNull())
1011 return {};
1012
1013 if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
1014 return QualType(T, 0);
1015
1016 return Ctx.getIncompleteArrayType(elementType, T->getSizeModifier(),
1018 }
1019
1020 QualType VisitVectorType(const VectorType *T) {
1021 QualType elementType = recurse(T->getElementType());
1022 if (elementType.isNull())
1023 return {};
1024
1025 if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
1026 return QualType(T, 0);
1027
1028 return Ctx.getVectorType(elementType, T->getNumElements(),
1029 T->getVectorKind());
1030 }
1031
1032 QualType VisitExtVectorType(const ExtVectorType *T) {
1033 QualType elementType = recurse(T->getElementType());
1034 if (elementType.isNull())
1035 return {};
1036
1037 if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
1038 return QualType(T, 0);
1039
1040 return Ctx.getExtVectorType(elementType, T->getNumElements());
1041 }
1042
1043 QualType VisitConstantMatrixType(const ConstantMatrixType *T) {
1044 QualType elementType = recurse(T->getElementType());
1045 if (elementType.isNull())
1046 return {};
1047 if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
1048 return QualType(T, 0);
1049
1050 return Ctx.getConstantMatrixType(elementType, T->getNumRows(),
1051 T->getNumColumns());
1052 }
1053
1054 QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1055 QualType returnType = recurse(T->getReturnType());
1056 if (returnType.isNull())
1057 return {};
1058
1059 if (returnType.getAsOpaquePtr() == T->getReturnType().getAsOpaquePtr())
1060 return QualType(T, 0);
1061
1062 return Ctx.getFunctionNoProtoType(returnType, T->getExtInfo());
1063 }
1064
1065 QualType VisitFunctionProtoType(const FunctionProtoType *T) {
1066 QualType returnType = recurse(T->getReturnType());
1067 if (returnType.isNull())
1068 return {};
1069
1070 // Transform parameter types.
1071 SmallVector<QualType, 4> paramTypes;
1072 bool paramChanged = false;
1073 for (auto paramType : T->getParamTypes()) {
1074 QualType newParamType = recurse(paramType);
1075 if (newParamType.isNull())
1076 return {};
1077
1078 if (newParamType.getAsOpaquePtr() != paramType.getAsOpaquePtr())
1079 paramChanged = true;
1080
1081 paramTypes.push_back(newParamType);
1082 }
1083
1084 // Transform extended info.
1086 bool exceptionChanged = false;
1087 if (info.ExceptionSpec.Type == EST_Dynamic) {
1088 SmallVector<QualType, 4> exceptionTypes;
1089 for (auto exceptionType : info.ExceptionSpec.Exceptions) {
1090 QualType newExceptionType = recurse(exceptionType);
1091 if (newExceptionType.isNull())
1092 return {};
1093
1094 if (newExceptionType.getAsOpaquePtr() != exceptionType.getAsOpaquePtr())
1095 exceptionChanged = true;
1096
1097 exceptionTypes.push_back(newExceptionType);
1098 }
1099
1100 if (exceptionChanged) {
1102 llvm::ArrayRef(exceptionTypes).copy(Ctx);
1103 }
1104 }
1105
1106 if (returnType.getAsOpaquePtr() == T->getReturnType().getAsOpaquePtr() &&
1107 !paramChanged && !exceptionChanged)
1108 return QualType(T, 0);
1109
1110 return Ctx.getFunctionType(returnType, paramTypes, info);
1111 }
1112
1113 QualType VisitParenType(const ParenType *T) {
1114 QualType innerType = recurse(T->getInnerType());
1115 if (innerType.isNull())
1116 return {};
1117
1118 if (innerType.getAsOpaquePtr() == T->getInnerType().getAsOpaquePtr())
1119 return QualType(T, 0);
1120
1121 return Ctx.getParenType(innerType);
1122 }
1123
1124 SUGARED_TYPE_CLASS(Typedef)
1125 SUGARED_TYPE_CLASS(ObjCTypeParam)
1126 SUGARED_TYPE_CLASS(MacroQualified)
1127
1128 QualType VisitAdjustedType(const AdjustedType *T) {
1129 QualType originalType = recurse(T->getOriginalType());
1130 if (originalType.isNull())
1131 return {};
1132
1133 QualType adjustedType = recurse(T->getAdjustedType());
1134 if (adjustedType.isNull())
1135 return {};
1136
1137 if (originalType.getAsOpaquePtr()
1138 == T->getOriginalType().getAsOpaquePtr() &&
1139 adjustedType.getAsOpaquePtr() == T->getAdjustedType().getAsOpaquePtr())
1140 return QualType(T, 0);
1141
1142 return Ctx.getAdjustedType(originalType, adjustedType);
1143 }
1144
1145 QualType VisitDecayedType(const DecayedType *T) {
1146 QualType originalType = recurse(T->getOriginalType());
1147 if (originalType.isNull())
1148 return {};
1149
1150 if (originalType.getAsOpaquePtr()
1152 return QualType(T, 0);
1153
1154 return Ctx.getDecayedType(originalType);
1155 }
1156
1157 SUGARED_TYPE_CLASS(TypeOfExpr)
1158 SUGARED_TYPE_CLASS(TypeOf)
1159 SUGARED_TYPE_CLASS(Decltype)
1160 SUGARED_TYPE_CLASS(UnaryTransform)
1163
1164 // FIXME: Non-trivial to implement, but important for C++
1165 SUGARED_TYPE_CLASS(Elaborated)
1166
1167 QualType VisitAttributedType(const AttributedType *T) {
1168 QualType modifiedType = recurse(T->getModifiedType());
1169 if (modifiedType.isNull())
1170 return {};
1171
1172 QualType equivalentType = recurse(T->getEquivalentType());
1173 if (equivalentType.isNull())
1174 return {};
1175
1176 if (modifiedType.getAsOpaquePtr()
1177 == T->getModifiedType().getAsOpaquePtr() &&
1178 equivalentType.getAsOpaquePtr()
1180 return QualType(T, 0);
1181
1182 return Ctx.getAttributedType(T->getAttrKind(), modifiedType,
1183 equivalentType);
1184 }
1185
1186 QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
1187 QualType replacementType = recurse(T->getReplacementType());
1188 if (replacementType.isNull())
1189 return {};
1190
1191 if (replacementType.getAsOpaquePtr()
1193 return QualType(T, 0);
1194
1195 return Ctx.getSubstTemplateTypeParmType(replacementType,
1196 T->getAssociatedDecl(),
1197 T->getIndex(), T->getPackIndex());
1198 }
1199
1200 // FIXME: Non-trivial to implement, but important for C++
1201 SUGARED_TYPE_CLASS(TemplateSpecialization)
1202
1203 QualType VisitAutoType(const AutoType *T) {
1204 if (!T->isDeduced())
1205 return QualType(T, 0);
1206
1207 QualType deducedType = recurse(T->getDeducedType());
1208 if (deducedType.isNull())
1209 return {};
1210
1211 if (deducedType.getAsOpaquePtr()
1213 return QualType(T, 0);
1214
1215 return Ctx.getAutoType(deducedType, T->getKeyword(),
1216 T->isDependentType(), /*IsPack=*/false,
1219 }
1220
1221 QualType VisitObjCObjectType(const ObjCObjectType *T) {
1222 QualType baseType = recurse(T->getBaseType());
1223 if (baseType.isNull())
1224 return {};
1225
1226 // Transform type arguments.
1227 bool typeArgChanged = false;
1228 SmallVector<QualType, 4> typeArgs;
1229 for (auto typeArg : T->getTypeArgsAsWritten()) {
1230 QualType newTypeArg = recurse(typeArg);
1231 if (newTypeArg.isNull())
1232 return {};
1233
1234 if (newTypeArg.getAsOpaquePtr() != typeArg.getAsOpaquePtr())
1235 typeArgChanged = true;
1236
1237 typeArgs.push_back(newTypeArg);
1238 }
1239
1240 if (baseType.getAsOpaquePtr() == T->getBaseType().getAsOpaquePtr() &&
1241 !typeArgChanged)
1242 return QualType(T, 0);
1243
1244 return Ctx.getObjCObjectType(
1245 baseType, typeArgs,
1248 }
1249
1250 TRIVIAL_TYPE_CLASS(ObjCInterface)
1251
1252 QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1253 QualType pointeeType = recurse(T->getPointeeType());
1254 if (pointeeType.isNull())
1255 return {};
1256
1257 if (pointeeType.getAsOpaquePtr()
1259 return QualType(T, 0);
1260
1261 return Ctx.getObjCObjectPointerType(pointeeType);
1262 }
1263
1264 QualType VisitAtomicType(const AtomicType *T) {
1265 QualType valueType = recurse(T->getValueType());
1266 if (valueType.isNull())
1267 return {};
1268
1269 if (valueType.getAsOpaquePtr()
1270 == T->getValueType().getAsOpaquePtr())
1271 return QualType(T, 0);
1272
1273 return Ctx.getAtomicType(valueType);
1274 }
1275
1276#undef TRIVIAL_TYPE_CLASS
1277#undef SUGARED_TYPE_CLASS
1278};
1279
1280struct SubstObjCTypeArgsVisitor
1281 : public SimpleTransformVisitor<SubstObjCTypeArgsVisitor> {
1282 using BaseType = SimpleTransformVisitor<SubstObjCTypeArgsVisitor>;
1283
1284 ArrayRef<QualType> TypeArgs;
1285 ObjCSubstitutionContext SubstContext;
1286
1287 SubstObjCTypeArgsVisitor(ASTContext &ctx, ArrayRef<QualType> typeArgs,
1289 : BaseType(ctx), TypeArgs(typeArgs), SubstContext(context) {}
1290
1291 QualType VisitObjCTypeParamType(const ObjCTypeParamType *OTPTy) {
1292 // Replace an Objective-C type parameter reference with the corresponding
1293 // type argument.
1294 ObjCTypeParamDecl *typeParam = OTPTy->getDecl();
1295 // If we have type arguments, use them.
1296 if (!TypeArgs.empty()) {
1297 QualType argType = TypeArgs[typeParam->getIndex()];
1298 if (OTPTy->qual_empty())
1299 return argType;
1300
1301 // Apply protocol lists if exists.
1302 bool hasError;
1304 protocolsVec.append(OTPTy->qual_begin(), OTPTy->qual_end());
1305 ArrayRef<ObjCProtocolDecl *> protocolsToApply = protocolsVec;
1306 return Ctx.applyObjCProtocolQualifiers(
1307 argType, protocolsToApply, hasError, true/*allowOnPointerType*/);
1308 }
1309
1310 switch (SubstContext) {
1311 case ObjCSubstitutionContext::Ordinary:
1312 case ObjCSubstitutionContext::Parameter:
1313 case ObjCSubstitutionContext::Superclass:
1314 // Substitute the bound.
1315 return typeParam->getUnderlyingType();
1316
1317 case ObjCSubstitutionContext::Result:
1318 case ObjCSubstitutionContext::Property: {
1319 // Substitute the __kindof form of the underlying type.
1320 const auto *objPtr =
1322
1323 // __kindof types, id, and Class don't need an additional
1324 // __kindof.
1325 if (objPtr->isKindOfType() || objPtr->isObjCIdOrClassType())
1326 return typeParam->getUnderlyingType();
1327
1328 // Add __kindof.
1329 const auto *obj = objPtr->getObjectType();
1330 QualType resultTy = Ctx.getObjCObjectType(
1331 obj->getBaseType(), obj->getTypeArgsAsWritten(), obj->getProtocols(),
1332 /*isKindOf=*/true);
1333
1334 // Rebuild object pointer type.
1335 return Ctx.getObjCObjectPointerType(resultTy);
1336 }
1337 }
1338 llvm_unreachable("Unexpected ObjCSubstitutionContext!");
1339 }
1340
1341 QualType VisitFunctionType(const FunctionType *funcType) {
1342 // If we have a function type, update the substitution context
1343 // appropriately.
1344
1345 //Substitute result type.
1346 QualType returnType = funcType->getReturnType().substObjCTypeArgs(
1347 Ctx, TypeArgs, ObjCSubstitutionContext::Result);
1348 if (returnType.isNull())
1349 return {};
1350
1351 // Handle non-prototyped functions, which only substitute into the result
1352 // type.
1353 if (isa<FunctionNoProtoType>(funcType)) {
1354 // If the return type was unchanged, do nothing.
1355 if (returnType.getAsOpaquePtr() ==
1356 funcType->getReturnType().getAsOpaquePtr())
1357 return BaseType::VisitFunctionType(funcType);
1358
1359 // Otherwise, build a new type.
1360 return Ctx.getFunctionNoProtoType(returnType, funcType->getExtInfo());
1361 }
1362
1363 const auto *funcProtoType = cast<FunctionProtoType>(funcType);
1364
1365 // Transform parameter types.
1366 SmallVector<QualType, 4> paramTypes;
1367 bool paramChanged = false;
1368 for (auto paramType : funcProtoType->getParamTypes()) {
1369 QualType newParamType = paramType.substObjCTypeArgs(
1370 Ctx, TypeArgs, ObjCSubstitutionContext::Parameter);
1371 if (newParamType.isNull())
1372 return {};
1373
1374 if (newParamType.getAsOpaquePtr() != paramType.getAsOpaquePtr())
1375 paramChanged = true;
1376
1377 paramTypes.push_back(newParamType);
1378 }
1379
1380 // Transform extended info.
1381 FunctionProtoType::ExtProtoInfo info = funcProtoType->getExtProtoInfo();
1382 bool exceptionChanged = false;
1383 if (info.ExceptionSpec.Type == EST_Dynamic) {
1384 SmallVector<QualType, 4> exceptionTypes;
1385 for (auto exceptionType : info.ExceptionSpec.Exceptions) {
1386 QualType newExceptionType = exceptionType.substObjCTypeArgs(
1387 Ctx, TypeArgs, ObjCSubstitutionContext::Ordinary);
1388 if (newExceptionType.isNull())
1389 return {};
1390
1391 if (newExceptionType.getAsOpaquePtr() != exceptionType.getAsOpaquePtr())
1392 exceptionChanged = true;
1393
1394 exceptionTypes.push_back(newExceptionType);
1395 }
1396
1397 if (exceptionChanged) {
1399 llvm::ArrayRef(exceptionTypes).copy(Ctx);
1400 }
1401 }
1402
1403 if (returnType.getAsOpaquePtr() ==
1404 funcProtoType->getReturnType().getAsOpaquePtr() &&
1405 !paramChanged && !exceptionChanged)
1406 return BaseType::VisitFunctionType(funcType);
1407
1408 return Ctx.getFunctionType(returnType, paramTypes, info);
1409 }
1410
1411 QualType VisitObjCObjectType(const ObjCObjectType *objcObjectType) {
1412 // Substitute into the type arguments of a specialized Objective-C object
1413 // type.
1414 if (objcObjectType->isSpecializedAsWritten()) {
1415 SmallVector<QualType, 4> newTypeArgs;
1416 bool anyChanged = false;
1417 for (auto typeArg : objcObjectType->getTypeArgsAsWritten()) {
1418 QualType newTypeArg = typeArg.substObjCTypeArgs(
1419 Ctx, TypeArgs, ObjCSubstitutionContext::Ordinary);
1420 if (newTypeArg.isNull())
1421 return {};
1422
1423 if (newTypeArg.getAsOpaquePtr() != typeArg.getAsOpaquePtr()) {
1424 // If we're substituting based on an unspecialized context type,
1425 // produce an unspecialized type.
1427 objcObjectType->qual_begin(), objcObjectType->getNumProtocols());
1428 if (TypeArgs.empty() &&
1429 SubstContext != ObjCSubstitutionContext::Superclass) {
1430 return Ctx.getObjCObjectType(
1431 objcObjectType->getBaseType(), {}, protocols,
1432 objcObjectType->isKindOfTypeAsWritten());
1433 }
1434
1435 anyChanged = true;
1436 }
1437
1438 newTypeArgs.push_back(newTypeArg);
1439 }
1440
1441 if (anyChanged) {
1443 objcObjectType->qual_begin(), objcObjectType->getNumProtocols());
1444 return Ctx.getObjCObjectType(objcObjectType->getBaseType(), newTypeArgs,
1445 protocols,
1446 objcObjectType->isKindOfTypeAsWritten());
1447 }
1448 }
1449
1450 return BaseType::VisitObjCObjectType(objcObjectType);
1451 }
1452
1453 QualType VisitAttributedType(const AttributedType *attrType) {
1454 QualType newType = BaseType::VisitAttributedType(attrType);
1455 if (newType.isNull())
1456 return {};
1457
1458 const auto *newAttrType = dyn_cast<AttributedType>(newType.getTypePtr());
1459 if (!newAttrType || newAttrType->getAttrKind() != attr::ObjCKindOf)
1460 return newType;
1461
1462 // Find out if it's an Objective-C object or object pointer type;
1463 QualType newEquivType = newAttrType->getEquivalentType();
1464 const ObjCObjectPointerType *ptrType =
1465 newEquivType->getAs<ObjCObjectPointerType>();
1466 const ObjCObjectType *objType = ptrType
1467 ? ptrType->getObjectType()
1468 : newEquivType->getAs<ObjCObjectType>();
1469 if (!objType)
1470 return newType;
1471
1472 // Rebuild the "equivalent" type, which pushes __kindof down into
1473 // the object type.
1474 newEquivType = Ctx.getObjCObjectType(
1475 objType->getBaseType(), objType->getTypeArgsAsWritten(),
1476 objType->getProtocols(),
1477 // There is no need to apply kindof on an unqualified id type.
1478 /*isKindOf=*/objType->isObjCUnqualifiedId() ? false : true);
1479
1480 // If we started with an object pointer type, rebuild it.
1481 if (ptrType)
1482 newEquivType = Ctx.getObjCObjectPointerType(newEquivType);
1483
1484 // Rebuild the attributed type.
1485 return Ctx.getAttributedType(newAttrType->getAttrKind(),
1486 newAttrType->getModifiedType(), newEquivType);
1487 }
1488};
1489
1490struct StripObjCKindOfTypeVisitor
1491 : public SimpleTransformVisitor<StripObjCKindOfTypeVisitor> {
1492 using BaseType = SimpleTransformVisitor<StripObjCKindOfTypeVisitor>;
1493
1494 explicit StripObjCKindOfTypeVisitor(ASTContext &ctx) : BaseType(ctx) {}
1495
1496 QualType VisitObjCObjectType(const ObjCObjectType *objType) {
1497 if (!objType->isKindOfType())
1498 return BaseType::VisitObjCObjectType(objType);
1499
1500 QualType baseType = objType->getBaseType().stripObjCKindOfType(Ctx);
1501 return Ctx.getObjCObjectType(baseType, objType->getTypeArgsAsWritten(),
1502 objType->getProtocols(),
1503 /*isKindOf=*/false);
1504 }
1505};
1506
1507} // namespace
1508
1510 const BuiltinType *BT = getTypePtr()->getAs<BuiltinType>();
1511 if (!BT) {
1512 const VectorType *VT = getTypePtr()->getAs<VectorType>();
1513 if (VT) {
1514 QualType ElementType = VT->getElementType();
1515 return ElementType.UseExcessPrecision(Ctx);
1516 }
1517 } else {
1518 switch (BT->getKind()) {
1519 case BuiltinType::Kind::Float16: {
1520 const TargetInfo &TI = Ctx.getTargetInfo();
1521 if (TI.hasFloat16Type() && !TI.hasLegalHalfType() &&
1522 Ctx.getLangOpts().getFloat16ExcessPrecision() !=
1523 Ctx.getLangOpts().ExcessPrecisionKind::FPP_None)
1524 return true;
1525 break;
1526 }
1527 case BuiltinType::Kind::BFloat16: {
1528 const TargetInfo &TI = Ctx.getTargetInfo();
1529 if (TI.hasBFloat16Type() && !TI.hasFullBFloat16Type() &&
1530 Ctx.getLangOpts().getBFloat16ExcessPrecision() !=
1531 Ctx.getLangOpts().ExcessPrecisionKind::FPP_None)
1532 return true;
1533 break;
1534 }
1535 default:
1536 return false;
1537 }
1538 }
1539 return false;
1540}
1541
1542/// Substitute the given type arguments for Objective-C type
1543/// parameters within the given type, recursively.
1545 ArrayRef<QualType> typeArgs,
1546 ObjCSubstitutionContext context) const {
1547 SubstObjCTypeArgsVisitor visitor(ctx, typeArgs, context);
1548 return visitor.recurse(*this);
1549}
1550
1552 const DeclContext *dc,
1553 ObjCSubstitutionContext context) const {
1554 if (auto subs = objectType->getObjCSubstitutions(dc))
1555 return substObjCTypeArgs(dc->getParentASTContext(), *subs, context);
1556
1557 return *this;
1558}
1559
1561 // FIXME: Because ASTContext::getAttributedType() is non-const.
1562 auto &ctx = const_cast<ASTContext &>(constCtx);
1563 StripObjCKindOfTypeVisitor visitor(ctx);
1564 return visitor.recurse(*this);
1565}
1566
1568 if (const auto AT = getTypePtr()->getAs<AtomicType>())
1569 return AT->getValueType().getUnqualifiedType();
1570 return getUnqualifiedType();
1571}
1572
1573std::optional<ArrayRef<QualType>>
1575 // Look through method scopes.
1576 if (const auto method = dyn_cast<ObjCMethodDecl>(dc))
1577 dc = method->getDeclContext();
1578
1579 // Find the class or category in which the type we're substituting
1580 // was declared.
1581 const auto *dcClassDecl = dyn_cast<ObjCInterfaceDecl>(dc);
1582 const ObjCCategoryDecl *dcCategoryDecl = nullptr;
1583 ObjCTypeParamList *dcTypeParams = nullptr;
1584 if (dcClassDecl) {
1585 // If the class does not have any type parameters, there's no
1586 // substitution to do.
1587 dcTypeParams = dcClassDecl->getTypeParamList();
1588 if (!dcTypeParams)
1589 return std::nullopt;
1590 } else {
1591 // If we are in neither a class nor a category, there's no
1592 // substitution to perform.
1593 dcCategoryDecl = dyn_cast<ObjCCategoryDecl>(dc);
1594 if (!dcCategoryDecl)
1595 return std::nullopt;
1596
1597 // If the category does not have any type parameters, there's no
1598 // substitution to do.
1599 dcTypeParams = dcCategoryDecl->getTypeParamList();
1600 if (!dcTypeParams)
1601 return std::nullopt;
1602
1603 dcClassDecl = dcCategoryDecl->getClassInterface();
1604 if (!dcClassDecl)
1605 return std::nullopt;
1606 }
1607 assert(dcTypeParams && "No substitutions to perform");
1608 assert(dcClassDecl && "No class context");
1609
1610 // Find the underlying object type.
1611 const ObjCObjectType *objectType;
1612 if (const auto *objectPointerType = getAs<ObjCObjectPointerType>()) {
1613 objectType = objectPointerType->getObjectType();
1614 } else if (getAs<BlockPointerType>()) {
1615 ASTContext &ctx = dc->getParentASTContext();
1616 objectType = ctx.getObjCObjectType(ctx.ObjCBuiltinIdTy, {}, {})
1618 } else {
1619 objectType = getAs<ObjCObjectType>();
1620 }
1621
1622 /// Extract the class from the receiver object type.
1623 ObjCInterfaceDecl *curClassDecl = objectType ? objectType->getInterface()
1624 : nullptr;
1625 if (!curClassDecl) {
1626 // If we don't have a context type (e.g., this is "id" or some
1627 // variant thereof), substitute the bounds.
1628 return llvm::ArrayRef<QualType>();
1629 }
1630
1631 // Follow the superclass chain until we've mapped the receiver type
1632 // to the same class as the context.
1633 while (curClassDecl != dcClassDecl) {
1634 // Map to the superclass type.
1635 QualType superType = objectType->getSuperClassType();
1636 if (superType.isNull()) {
1637 objectType = nullptr;
1638 break;
1639 }
1640
1641 objectType = superType->castAs<ObjCObjectType>();
1642 curClassDecl = objectType->getInterface();
1643 }
1644
1645 // If we don't have a receiver type, or the receiver type does not
1646 // have type arguments, substitute in the defaults.
1647 if (!objectType || objectType->isUnspecialized()) {
1648 return llvm::ArrayRef<QualType>();
1649 }
1650
1651 // The receiver type has the type arguments we want.
1652 return objectType->getTypeArgs();
1653}
1654
1656 if (auto *IfaceT = getAsObjCInterfaceType()) {
1657 if (auto *ID = IfaceT->getInterface()) {
1658 if (ID->getTypeParamList())
1659 return true;
1660 }
1661 }
1662
1663 return false;
1664}
1665
1667 // Retrieve the class declaration for this type. If there isn't one
1668 // (e.g., this is some variant of "id" or "Class"), then there is no
1669 // superclass type.
1670 ObjCInterfaceDecl *classDecl = getInterface();
1671 if (!classDecl) {
1672 CachedSuperClassType.setInt(true);
1673 return;
1674 }
1675
1676 // Extract the superclass type.
1677 const ObjCObjectType *superClassObjTy = classDecl->getSuperClassType();
1678 if (!superClassObjTy) {
1679 CachedSuperClassType.setInt(true);
1680 return;
1681 }
1682
1683 ObjCInterfaceDecl *superClassDecl = superClassObjTy->getInterface();
1684 if (!superClassDecl) {
1685 CachedSuperClassType.setInt(true);
1686 return;
1687 }
1688
1689 // If the superclass doesn't have type parameters, then there is no
1690 // substitution to perform.
1691 QualType superClassType(superClassObjTy, 0);
1692 ObjCTypeParamList *superClassTypeParams = superClassDecl->getTypeParamList();
1693 if (!superClassTypeParams) {
1694 CachedSuperClassType.setPointerAndInt(
1695 superClassType->castAs<ObjCObjectType>(), true);
1696 return;
1697 }
1698
1699 // If the superclass reference is unspecialized, return it.
1700 if (superClassObjTy->isUnspecialized()) {
1701 CachedSuperClassType.setPointerAndInt(superClassObjTy, true);
1702 return;
1703 }
1704
1705 // If the subclass is not parameterized, there aren't any type
1706 // parameters in the superclass reference to substitute.
1707 ObjCTypeParamList *typeParams = classDecl->getTypeParamList();
1708 if (!typeParams) {
1709 CachedSuperClassType.setPointerAndInt(
1710 superClassType->castAs<ObjCObjectType>(), true);
1711 return;
1712 }
1713
1714 // If the subclass type isn't specialized, return the unspecialized
1715 // superclass.
1716 if (isUnspecialized()) {
1717 QualType unspecializedSuper
1718 = classDecl->getASTContext().getObjCInterfaceType(
1719 superClassObjTy->getInterface());
1720 CachedSuperClassType.setPointerAndInt(
1721 unspecializedSuper->castAs<ObjCObjectType>(),
1722 true);
1723 return;
1724 }
1725
1726 // Substitute the provided type arguments into the superclass type.
1727 ArrayRef<QualType> typeArgs = getTypeArgs();
1728 assert(typeArgs.size() == typeParams->size());
1729 CachedSuperClassType.setPointerAndInt(
1730 superClassType.substObjCTypeArgs(classDecl->getASTContext(), typeArgs,
1733 true);
1734}
1735
1737 if (auto interfaceDecl = getObjectType()->getInterface()) {
1738 return interfaceDecl->getASTContext().getObjCInterfaceType(interfaceDecl)
1740 }
1741
1742 return nullptr;
1743}
1744
1746 QualType superObjectType = getObjectType()->getSuperClassType();
1747 if (superObjectType.isNull())
1748 return superObjectType;
1749
1751 return ctx.getObjCObjectPointerType(superObjectType);
1752}
1753
1755 // There is no sugar for ObjCObjectType's, just return the canonical
1756 // type pointer if it is the right class. There is no typedef information to
1757 // return and these cannot be Address-space qualified.
1758 if (const auto *T = getAs<ObjCObjectType>())
1759 if (T->getNumProtocols() && T->getInterface())
1760 return T;
1761 return nullptr;
1762}
1763
1765 return getAsObjCQualifiedInterfaceType() != nullptr;
1766}
1767
1769 // There is no sugar for ObjCQualifiedIdType's, just return the canonical
1770 // type pointer if it is the right class.
1771 if (const auto *OPT = getAs<ObjCObjectPointerType>()) {
1772 if (OPT->isObjCQualifiedIdType())
1773 return OPT;
1774 }
1775 return nullptr;
1776}
1777
1779 // There is no sugar for ObjCQualifiedClassType's, just return the canonical
1780 // type pointer if it is the right class.
1781 if (const auto *OPT = getAs<ObjCObjectPointerType>()) {
1782 if (OPT->isObjCQualifiedClassType())
1783 return OPT;
1784 }
1785 return nullptr;
1786}
1787
1789 if (const auto *OT = getAs<ObjCObjectType>()) {
1790 if (OT->getInterface())
1791 return OT;
1792 }
1793 return nullptr;
1794}
1795
1797 if (const auto *OPT = getAs<ObjCObjectPointerType>()) {
1798 if (OPT->getInterfaceType())
1799 return OPT;
1800 }
1801 return nullptr;
1802}
1803
1805 QualType PointeeType;
1806 if (const auto *PT = getAs<PointerType>())
1807 PointeeType = PT->getPointeeType();
1808 else if (const auto *RT = getAs<ReferenceType>())
1809 PointeeType = RT->getPointeeType();
1810 else
1811 return nullptr;
1812
1813 if (const auto *RT = PointeeType->getAs<RecordType>())
1814 return dyn_cast<CXXRecordDecl>(RT->getDecl());
1815
1816 return nullptr;
1817}
1818
1820 return dyn_cast_or_null<CXXRecordDecl>(getAsTagDecl());
1821}
1822
1824 return dyn_cast_or_null<RecordDecl>(getAsTagDecl());
1825}
1826
1828 if (const auto *TT = getAs<TagType>())
1829 return TT->getDecl();
1830 if (const auto *Injected = getAs<InjectedClassNameType>())
1831 return Injected->getDecl();
1832
1833 return nullptr;
1834}
1835
1837 const Type *Cur = this;
1838 while (const auto *AT = Cur->getAs<AttributedType>()) {
1839 if (AT->getAttrKind() == AK)
1840 return true;
1841 Cur = AT->getEquivalentType().getTypePtr();
1842 }
1843 return false;
1844}
1845
1846namespace {
1847
1848 class GetContainedDeducedTypeVisitor :
1849 public TypeVisitor<GetContainedDeducedTypeVisitor, Type*> {
1850 bool Syntactic;
1851
1852 public:
1853 GetContainedDeducedTypeVisitor(bool Syntactic = false)
1854 : Syntactic(Syntactic) {}
1855
1856 using TypeVisitor<GetContainedDeducedTypeVisitor, Type*>::Visit;
1857
1858 Type *Visit(QualType T) {
1859 if (T.isNull())
1860 return nullptr;
1861 return Visit(T.getTypePtr());
1862 }
1863
1864 // The deduced type itself.
1865 Type *VisitDeducedType(const DeducedType *AT) {
1866 return const_cast<DeducedType*>(AT);
1867 }
1868
1869 // Only these types can contain the desired 'auto' type.
1870 Type *VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
1871 return Visit(T->getReplacementType());
1872 }
1873
1874 Type *VisitElaboratedType(const ElaboratedType *T) {
1875 return Visit(T->getNamedType());
1876 }
1877
1878 Type *VisitPointerType(const PointerType *T) {
1879 return Visit(T->getPointeeType());
1880 }
1881
1882 Type *VisitBlockPointerType(const BlockPointerType *T) {
1883 return Visit(T->getPointeeType());
1884 }
1885
1886 Type *VisitReferenceType(const ReferenceType *T) {
1887 return Visit(T->getPointeeTypeAsWritten());
1888 }
1889
1890 Type *VisitMemberPointerType(const MemberPointerType *T) {
1891 return Visit(T->getPointeeType());
1892 }
1893
1894 Type *VisitArrayType(const ArrayType *T) {
1895 return Visit(T->getElementType());
1896 }
1897
1898 Type *VisitDependentSizedExtVectorType(
1899 const DependentSizedExtVectorType *T) {
1900 return Visit(T->getElementType());
1901 }
1902
1903 Type *VisitVectorType(const VectorType *T) {
1904 return Visit(T->getElementType());
1905 }
1906
1907 Type *VisitDependentSizedMatrixType(const DependentSizedMatrixType *T) {
1908 return Visit(T->getElementType());
1909 }
1910
1911 Type *VisitConstantMatrixType(const ConstantMatrixType *T) {
1912 return Visit(T->getElementType());
1913 }
1914
1915 Type *VisitFunctionProtoType(const FunctionProtoType *T) {
1916 if (Syntactic && T->hasTrailingReturn())
1917 return const_cast<FunctionProtoType*>(T);
1918 return VisitFunctionType(T);
1919 }
1920
1921 Type *VisitFunctionType(const FunctionType *T) {
1922 return Visit(T->getReturnType());
1923 }
1924
1925 Type *VisitParenType(const ParenType *T) {
1926 return Visit(T->getInnerType());
1927 }
1928
1929 Type *VisitAttributedType(const AttributedType *T) {
1930 return Visit(T->getModifiedType());
1931 }
1932
1933 Type *VisitMacroQualifiedType(const MacroQualifiedType *T) {
1934 return Visit(T->getUnderlyingType());
1935 }
1936
1937 Type *VisitAdjustedType(const AdjustedType *T) {
1938 return Visit(T->getOriginalType());
1939 }
1940
1941 Type *VisitPackExpansionType(const PackExpansionType *T) {
1942 return Visit(T->getPattern());
1943 }
1944 };
1945
1946} // namespace
1947
1949 return cast_or_null<DeducedType>(
1950 GetContainedDeducedTypeVisitor().Visit(this));
1951}
1952
1954 return isa_and_nonnull<FunctionType>(
1955 GetContainedDeducedTypeVisitor(true).Visit(this));
1956}
1957
1959 if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
1960 return VT->getElementType()->isIntegerType();
1961 if (CanonicalType->isSveVLSBuiltinType()) {
1962 const auto *VT = cast<BuiltinType>(CanonicalType);
1963 return VT->getKind() == BuiltinType::SveBool ||
1964 (VT->getKind() >= BuiltinType::SveInt8 &&
1965 VT->getKind() <= BuiltinType::SveUint64);
1966 }
1967 if (CanonicalType->isRVVVLSBuiltinType()) {
1968 const auto *VT = cast<BuiltinType>(CanonicalType);
1969 return (VT->getKind() >= BuiltinType::RvvInt8mf8 &&
1970 VT->getKind() <= BuiltinType::RvvUint64m8);
1971 }
1972
1973 return isIntegerType();
1974}
1975
1976/// Determine whether this type is an integral type.
1977///
1978/// This routine determines whether the given type is an integral type per
1979/// C++ [basic.fundamental]p7. Although the C standard does not define the
1980/// term "integral type", it has a similar term "integer type", and in C++
1981/// the two terms are equivalent. However, C's "integer type" includes
1982/// enumeration types, while C++'s "integer type" does not. The \c ASTContext
1983/// parameter is used to determine whether we should be following the C or
1984/// C++ rules when determining whether this type is an integral/integer type.
1985///
1986/// For cases where C permits "an integer type" and C++ permits "an integral
1987/// type", use this routine.
1988///
1989/// For cases where C permits "an integer type" and C++ permits "an integral
1990/// or enumeration type", use \c isIntegralOrEnumerationType() instead.
1991///
1992/// \param Ctx The context in which this type occurs.
1993///
1994/// \returns true if the type is considered an integral type, false otherwise.
1995bool Type::isIntegralType(const ASTContext &Ctx) const {
1996 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1997 return BT->getKind() >= BuiltinType::Bool &&
1998 BT->getKind() <= BuiltinType::Int128;
1999
2000 // Complete enum types are integral in C.
2001 if (!Ctx.getLangOpts().CPlusPlus)
2002 if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
2003 return ET->getDecl()->isComplete();
2004
2005 return isBitIntType();
2006}
2007
2009 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2010 return BT->getKind() >= BuiltinType::Bool &&
2011 BT->getKind() <= BuiltinType::Int128;
2012
2013 if (isBitIntType())
2014 return true;
2015
2017}
2018
2020 if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
2021 return !ET->getDecl()->isScoped();
2022
2023 return false;
2024}
2025
2026bool Type::isCharType() const {
2027 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2028 return BT->getKind() == BuiltinType::Char_U ||
2029 BT->getKind() == BuiltinType::UChar ||
2030 BT->getKind() == BuiltinType::Char_S ||
2031 BT->getKind() == BuiltinType::SChar;
2032 return false;
2033}
2034
2036 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2037 return BT->getKind() == BuiltinType::WChar_S ||
2038 BT->getKind() == BuiltinType::WChar_U;
2039 return false;
2040}
2041
2042bool Type::isChar8Type() const {
2043 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
2044 return BT->getKind() == BuiltinType::Char8;
2045 return false;
2046}
2047
2049 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2050 return BT->getKind() == BuiltinType::Char16;
2051 return false;
2052}
2053
2055 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2056 return BT->getKind() == BuiltinType::Char32;
2057 return false;
2058}
2059
2060/// Determine whether this type is any of the built-in character
2061/// types.
2063 const auto *BT = dyn_cast<BuiltinType>(CanonicalType);
2064 if (!BT) return false;
2065 switch (BT->getKind()) {
2066 default: return false;
2067 case BuiltinType::Char_U:
2068 case BuiltinType::UChar:
2069 case BuiltinType::WChar_U:
2070 case BuiltinType::Char8:
2071 case BuiltinType::Char16:
2072 case BuiltinType::Char32:
2073 case BuiltinType::Char_S:
2074 case BuiltinType::SChar:
2075 case BuiltinType::WChar_S:
2076 return true;
2077 }
2078}
2079
2080/// isSignedIntegerType - Return true if this is an integer type that is
2081/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
2082/// an enum decl which has a signed representation
2084 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2085 return BT->getKind() >= BuiltinType::Char_S &&
2086 BT->getKind() <= BuiltinType::Int128;
2087 }
2088
2089 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
2090 // Incomplete enum types are not treated as integer types.
2091 // FIXME: In C++, enum types are never integer types.
2092 if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
2093 return ET->getDecl()->getIntegerType()->isSignedIntegerType();
2094 }
2095
2096 if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2097 return IT->isSigned();
2098 if (const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2099 return IT->isSigned();
2100
2101 return false;
2102}
2103
2105 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2106 return BT->getKind() >= BuiltinType::Char_S &&
2107 BT->getKind() <= BuiltinType::Int128;
2108 }
2109
2110 if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2111 if (ET->getDecl()->isComplete())
2112 return ET->getDecl()->getIntegerType()->isSignedIntegerType();
2113 }
2114
2115 if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2116 return IT->isSigned();
2117 if (const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2118 return IT->isSigned();
2119
2120 return false;
2121}
2122
2124 if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
2125 return VT->getElementType()->isSignedIntegerOrEnumerationType();
2126 else
2128}
2129
2130/// isUnsignedIntegerType - Return true if this is an integer type that is
2131/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
2132/// decl which has an unsigned representation
2134 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2135 return BT->getKind() >= BuiltinType::Bool &&
2136 BT->getKind() <= BuiltinType::UInt128;
2137 }
2138
2139 if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2140 // Incomplete enum types are not treated as integer types.
2141 // FIXME: In C++, enum types are never integer types.
2142 if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
2143 return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
2144 }
2145
2146 if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2147 return IT->isUnsigned();
2148 if (const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2149 return IT->isUnsigned();
2150
2151 return false;
2152}
2153
2155 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2156 return BT->getKind() >= BuiltinType::Bool &&
2157 BT->getKind() <= BuiltinType::UInt128;
2158 }
2159
2160 if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2161 if (ET->getDecl()->isComplete())
2162 return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
2163 }
2164
2165 if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2166 return IT->isUnsigned();
2167 if (const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2168 return IT->isUnsigned();
2169
2170 return false;
2171}
2172
2174 if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
2175 return VT->getElementType()->isUnsignedIntegerOrEnumerationType();
2176 if (const auto *VT = dyn_cast<MatrixType>(CanonicalType))
2177 return VT->getElementType()->isUnsignedIntegerOrEnumerationType();
2178 if (CanonicalType->isSveVLSBuiltinType()) {
2179 const auto *VT = cast<BuiltinType>(CanonicalType);
2180 return VT->getKind() >= BuiltinType::SveUint8 &&
2181 VT->getKind() <= BuiltinType::SveUint64;
2182 }
2184}
2185
2187 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2188 return BT->getKind() >= BuiltinType::Half &&
2189 BT->getKind() <= BuiltinType::Ibm128;
2190 if (const auto *CT = dyn_cast<ComplexType>(CanonicalType))
2191 return CT->getElementType()->isFloatingType();
2192 return false;
2193}
2194
2196 if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
2197 return VT->getElementType()->isFloatingType();
2198 if (const auto *MT = dyn_cast<MatrixType>(CanonicalType))
2199 return MT->getElementType()->isFloatingType();
2200 return isFloatingType();
2201}
2202
2204 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2205 return BT->isFloatingPoint();
2206 return false;
2207}
2208
2209bool Type::isRealType() const {
2210 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2211 return BT->getKind() >= BuiltinType::Bool &&
2212 BT->getKind() <= BuiltinType::Ibm128;
2213 if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
2214 return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped();
2215 return isBitIntType();
2216}
2217
2219 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2220 return BT->getKind() >= BuiltinType::Bool &&
2221 BT->getKind() <= BuiltinType::Ibm128;
2222 if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
2223 // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
2224 // If a body isn't seen by the time we get here, return false.
2225 //
2226 // C++0x: Enumerations are not arithmetic types. For now, just return
2227 // false for scoped enumerations since that will disable any
2228 // unwanted implicit conversions.
2229 return !ET->getDecl()->isScoped() && ET->getDecl()->isComplete();
2230 return isa<ComplexType>(CanonicalType) || isBitIntType();
2231}
2232
2234 assert(isScalarType());
2235
2236 const Type *T = CanonicalType.getTypePtr();
2237 if (const auto *BT = dyn_cast<BuiltinType>(T)) {
2238 if (BT->getKind() == BuiltinType::Bool) return STK_Bool;
2239 if (BT->getKind() == BuiltinType::NullPtr) return STK_CPointer;
2240 if (BT->isInteger()) return STK_Integral;
2241 if (BT->isFloatingPoint()) return STK_Floating;
2242 if (BT->isFixedPointType()) return STK_FixedPoint;
2243 llvm_unreachable("unknown scalar builtin type");
2244 } else if (isa<PointerType>(T)) {
2245 return STK_CPointer;
2246 } else if (isa<BlockPointerType>(T)) {
2247 return STK_BlockPointer;
2248 } else if (isa<ObjCObjectPointerType>(T)) {
2249 return STK_ObjCObjectPointer;
2250 } else if (isa<MemberPointerType>(T)) {
2251 return STK_MemberPointer;
2252 } else if (isa<EnumType>(T)) {
2253 assert(cast<EnumType>(T)->getDecl()->isComplete());
2254 return STK_Integral;
2255 } else if (const auto *CT = dyn_cast<ComplexType>(T)) {
2256 if (CT->getElementType()->isRealFloatingType())
2257 return STK_FloatingComplex;
2258 return STK_IntegralComplex;
2259 } else if (isBitIntType()) {
2260 return STK_Integral;
2261 }
2262
2263 llvm_unreachable("unknown scalar type");
2264}
2265
2266/// Determines whether the type is a C++ aggregate type or C
2267/// aggregate or union type.
2268///
2269/// An aggregate type is an array or a class type (struct, union, or
2270/// class) that has no user-declared constructors, no private or
2271/// protected non-static data members, no base classes, and no virtual
2272/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type
2273/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also
2274/// includes union types.
2276 if (const auto *Record = dyn_cast<RecordType>(CanonicalType)) {
2277 if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl()))
2278 return ClassDecl->isAggregate();
2279
2280 return true;
2281 }
2282
2283 return isa<ArrayType>(CanonicalType);
2284}
2285
2286/// isConstantSizeType - Return true if this is not a variable sized type,
2287/// according to the rules of C99 6.7.5p3. It is not legal to call this on
2288/// incomplete types or dependent types.
2290 assert(!isIncompleteType() && "This doesn't make sense for incomplete types");
2291 assert(!isDependentType() && "This doesn't make sense for dependent types");
2292 // The VAT must have a size, as it is known to be complete.
2293 return !isa<VariableArrayType>(CanonicalType);
2294}
2295
2296/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1)
2297/// - a type that can describe objects, but which lacks information needed to
2298/// determine its size.
2300 if (Def)
2301 *Def = nullptr;
2302
2303 switch (CanonicalType->getTypeClass()) {
2304 default: return false;
2305 case Builtin:
2306 // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never
2307 // be completed.
2308 return isVoidType();
2309 case Enum: {
2310 EnumDecl *EnumD = cast<EnumType>(CanonicalType)->getDecl();
2311 if (Def)
2312 *Def = EnumD;
2313 return !EnumD->isComplete();
2314 }
2315 case Record: {
2316 // A tagged type (struct/union/enum/class) is incomplete if the decl is a
2317 // forward declaration, but not a full definition (C99 6.2.5p22).
2318 RecordDecl *Rec = cast<RecordType>(CanonicalType)->getDecl();
2319 if (Def)
2320 *Def = Rec;
2321 return !Rec->isCompleteDefinition();
2322 }
2323 case ConstantArray:
2324 case VariableArray:
2325 // An array is incomplete if its element type is incomplete
2326 // (C++ [dcl.array]p1).
2327 // We don't handle dependent-sized arrays (dependent types are never treated
2328 // as incomplete).
2329 return cast<ArrayType>(CanonicalType)->getElementType()
2330 ->isIncompleteType(Def);
2331 case IncompleteArray:
2332 // An array of unknown size is an incomplete type (C99 6.2.5p22).
2333 return true;
2334 case MemberPointer: {
2335 // Member pointers in the MS ABI have special behavior in
2336 // RequireCompleteType: they attach a MSInheritanceAttr to the CXXRecordDecl
2337 // to indicate which inheritance model to use.
2338 auto *MPTy = cast<MemberPointerType>(CanonicalType);
2339 const Type *ClassTy = MPTy->getClass();
2340 // Member pointers with dependent class types don't get special treatment.
2341 if (ClassTy->isDependentType())
2342 return false;
2343 const CXXRecordDecl *RD = ClassTy->getAsCXXRecordDecl();
2344 ASTContext &Context = RD->getASTContext();
2345 // Member pointers not in the MS ABI don't get special treatment.
2346 if (!Context.getTargetInfo().getCXXABI().isMicrosoft())
2347 return false;
2348 // The inheritance attribute might only be present on the most recent
2349 // CXXRecordDecl, use that one.
2351 // Nothing interesting to do if the inheritance attribute is already set.
2352 if (RD->hasAttr<MSInheritanceAttr>())
2353 return false;
2354 return true;
2355 }
2356 case ObjCObject:
2357 return cast<ObjCObjectType>(CanonicalType)->getBaseType()
2358 ->isIncompleteType(Def);
2359 case ObjCInterface: {
2360 // ObjC interfaces are incomplete if they are @class, not @interface.
2362 = cast<ObjCInterfaceType>(CanonicalType)->getDecl();
2363 if (Def)
2364 *Def = Interface;
2365 return !Interface->hasDefinition();
2366 }
2367 }
2368}
2369
2372 return true;
2373
2374 if (const BuiltinType *BT = getAs<BuiltinType>()) {
2375 switch (BT->getKind()) {
2376 // WebAssembly reference types
2377#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2378#include "clang/Basic/WebAssemblyReferenceTypes.def"
2379 return true;
2380 default:
2381 return false;
2382 }
2383 }
2384 return false;
2385}
2386
2388 if (const auto *BT = getAs<BuiltinType>())
2389 return BT->getKind() == BuiltinType::WasmExternRef;
2390 return false;
2391}
2392
2394 if (const auto *ATy = dyn_cast<ArrayType>(this))
2395 return ATy->getElementType().isWebAssemblyReferenceType();
2396
2397 if (const auto *PTy = dyn_cast<PointerType>(this))
2398 return PTy->getPointeeType().isWebAssemblyReferenceType();
2399
2400 return false;
2401}
2402
2404
2407}
2408
2410 if (const BuiltinType *BT = getAs<BuiltinType>()) {
2411 switch (BT->getKind()) {
2412 // SVE Types
2413#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2414#include "clang/Basic/AArch64SVEACLETypes.def"
2415 return true;
2416 default:
2417 return false;
2418 }
2419 }
2420 return false;
2421}
2422
2424 if (const BuiltinType *BT = getAs<BuiltinType>()) {
2425 switch (BT->getKind()) {
2426#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2427#include "clang/Basic/RISCVVTypes.def"
2428 return true;
2429 default:
2430 return false;
2431 }
2432 }
2433 return false;
2434}
2435
2437 if (const BuiltinType *BT = getAs<BuiltinType>()) {
2438 switch (BT->getKind()) {
2439 case BuiltinType::SveInt8:
2440 case BuiltinType::SveInt16:
2441 case BuiltinType::SveInt32:
2442 case BuiltinType::SveInt64:
2443 case BuiltinType::SveUint8:
2444 case BuiltinType::SveUint16:
2445 case BuiltinType::SveUint32:
2446 case BuiltinType::SveUint64:
2447 case BuiltinType::SveFloat16:
2448 case BuiltinType::SveFloat32:
2449 case BuiltinType::SveFloat64:
2450 case BuiltinType::SveBFloat16:
2451 case BuiltinType::SveBool:
2452 case BuiltinType::SveBoolx2:
2453 case BuiltinType::SveBoolx4:
2454 return true;
2455 default:
2456 return false;
2457 }
2458 }
2459 return false;
2460}
2461
2463 assert(isSveVLSBuiltinType() && "unsupported type!");
2464
2465 const BuiltinType *BTy = castAs<BuiltinType>();
2466 if (BTy->getKind() == BuiltinType::SveBool)
2467 // Represent predicates as i8 rather than i1 to avoid any layout issues.
2468 // The type is bitcasted to a scalable predicate type when casting between
2469 // scalable and fixed-length vectors.
2470 return Ctx.UnsignedCharTy;
2471 else
2472 return Ctx.getBuiltinVectorTypeInfo(BTy).ElementType;
2473}
2474
2476 if (const BuiltinType *BT = getAs<BuiltinType>()) {
2477 switch (BT->getKind()) {
2478#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, \
2479 IsFP, IsBF) \
2480 case BuiltinType::Id: \
2481 return NF == 1;
2482#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls) \
2483 case BuiltinType::Id: \
2484 return true;
2485#include "clang/Basic/RISCVVTypes.def"
2486 default:
2487 return false;
2488 }
2489 }
2490 return false;
2491}
2492
2494 assert(isRVVVLSBuiltinType() && "unsupported type!");
2495
2496 const BuiltinType *BTy = castAs<BuiltinType>();
2497
2498 switch (BTy->getKind()) {
2499#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls) \
2500 case BuiltinType::Id: \
2501 return Ctx.UnsignedCharTy;
2502 default:
2503 return Ctx.getBuiltinVectorTypeInfo(BTy).ElementType;
2504#include "clang/Basic/RISCVVTypes.def"
2505 }
2506
2507 llvm_unreachable("Unhandled type");
2508}
2509
2510bool QualType::isPODType(const ASTContext &Context) const {
2511 // C++11 has a more relaxed definition of POD.
2512 if (Context.getLangOpts().CPlusPlus11)
2513 return isCXX11PODType(Context);
2514
2515 return isCXX98PODType(Context);
2516}
2517
2518bool QualType::isCXX98PODType(const ASTContext &Context) const {
2519 // The compiler shouldn't query this for incomplete types, but the user might.
2520 // We return false for that case. Except for incomplete arrays of PODs, which
2521 // are PODs according to the standard.
2522 if (isNull())
2523 return false;
2524
2525 if ((*this)->isIncompleteArrayType())
2526 return Context.getBaseElementType(*this).isCXX98PODType(Context);
2527
2528 if ((*this)->isIncompleteType())
2529 return false;
2530
2532 return false;
2533
2534 QualType CanonicalType = getTypePtr()->CanonicalType;
2535 switch (CanonicalType->getTypeClass()) {
2536 // Everything not explicitly mentioned is not POD.
2537 default: return false;
2538 case Type::VariableArray:
2539 case Type::ConstantArray:
2540 // IncompleteArray is handled above.
2541 return Context.getBaseElementType(*this).isCXX98PODType(Context);
2542
2543 case Type::ObjCObjectPointer:
2544 case Type::BlockPointer:
2545 case Type::Builtin:
2546 case Type::Complex:
2547 case Type::Pointer:
2548 case Type::MemberPointer:
2549 case Type::Vector:
2550 case Type::ExtVector:
2551 case Type::BitInt:
2552 return true;
2553
2554 case Type::Enum:
2555 return true;
2556
2557 case Type::Record:
2558 if (const auto *ClassDecl =
2559 dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl()))
2560 return ClassDecl->isPOD();
2561
2562 // C struct/union is POD.
2563 return true;
2564 }
2565}
2566
2567bool QualType::isTrivialType(const ASTContext &Context) const {
2568 // The compiler shouldn't query this for incomplete types, but the user might.
2569 // We return false for that case. Except for incomplete arrays of PODs, which
2570 // are PODs according to the standard.
2571 if (isNull())
2572 return false;
2573
2574 if ((*this)->isArrayType())
2575 return Context.getBaseElementType(*this).isTrivialType(Context);
2576
2577 if ((*this)->isSizelessBuiltinType())
2578 return true;
2579
2580 // Return false for incomplete types after skipping any incomplete array
2581 // types which are expressly allowed by the standard and thus our API.
2582 if ((*this)->isIncompleteType())
2583 return false;
2584
2586 return false;
2587
2588 QualType CanonicalType = getTypePtr()->CanonicalType;
2589 if (CanonicalType->isDependentType())
2590 return false;
2591
2592 // C++0x [basic.types]p9:
2593 // Scalar types, trivial class types, arrays of such types, and
2594 // cv-qualified versions of these types are collectively called trivial
2595 // types.
2596
2597 // As an extension, Clang treats vector types as Scalar types.
2598 if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
2599 return true;
2600 if (const auto *RT = CanonicalType->getAs<RecordType>()) {
2601 if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
2602 // C++20 [class]p6:
2603 // A trivial class is a class that is trivially copyable, and
2604 // has one or more eligible default constructors such that each is
2605 // trivial.
2606 // FIXME: We should merge this definition of triviality into
2607 // CXXRecordDecl::isTrivial. Currently it computes the wrong thing.
2608 return ClassDecl->hasTrivialDefaultConstructor() &&
2609 !ClassDecl->hasNonTrivialDefaultConstructor() &&
2610 ClassDecl->isTriviallyCopyable();
2611 }
2612
2613 return true;
2614 }
2615
2616 // No other types can match.
2617 return false;
2618}
2619
2621 const ASTContext &Context,
2622 bool IsCopyConstructible) {
2623 if (type->isArrayType())
2625 Context, IsCopyConstructible);
2626
2627 if (type.hasNonTrivialObjCLifetime())
2628 return false;
2629
2630 // C++11 [basic.types]p9 - See Core 2094
2631 // Scalar types, trivially copyable class types, arrays of such types, and
2632 // cv-qualified versions of these types are collectively
2633 // called trivially copy constructible types.
2634
2635 QualType CanonicalType = type.getCanonicalType();
2636 if (CanonicalType->isDependentType())
2637 return false;
2638
2639 if (CanonicalType->isSizelessBuiltinType())
2640 return true;
2641
2642 // Return false for incomplete types after skipping any incomplete array types
2643 // which are expressly allowed by the standard and thus our API.
2644 if (CanonicalType->isIncompleteType())
2645 return false;
2646
2647 // As an extension, Clang treats vector types as Scalar types.
2648 if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
2649 return true;
2650
2651 if (const auto *RT = CanonicalType->getAs<RecordType>()) {
2652 if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
2653 if (IsCopyConstructible) {
2654 return ClassDecl->isTriviallyCopyConstructible();
2655 } else {
2656 return ClassDecl->isTriviallyCopyable();
2657 }
2658 }
2659 return true;
2660 }
2661 // No other types can match.
2662 return false;
2663}
2664
2666 return isTriviallyCopyableTypeImpl(*this, Context,
2667 /*IsCopyConstructible=*/false);
2668}
2669
2671 const ASTContext &Context) const {
2672 return isTriviallyCopyableTypeImpl(*this, Context,
2673 /*IsCopyConstructible=*/true);
2674}
2675
2677 QualType BaseElementType = Context.getBaseElementType(*this);
2678
2679 if (BaseElementType->isIncompleteType()) {
2680 return false;
2681 } else if (!BaseElementType->isObjectType()) {
2682 return false;
2683 } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
2684 return RD->canPassInRegisters();
2685 } else if (BaseElementType.isTriviallyCopyableType(Context)) {
2686 return true;
2687 } else {
2689 case PCK_Trivial:
2690 return !isDestructedType();
2691 case PCK_ARCStrong:
2692 return true;
2693 default:
2694 return false;
2695 }
2696 }
2697}
2698
2699static bool
2701 if (Decl->isUnion())
2702 return false;
2703 if (Decl->isLambda())
2704 return Decl->isCapturelessLambda();
2705
2706 auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
2707 return Function->getOverloadedOperator() ==
2708 OverloadedOperatorKind::OO_EqualEqual &&
2709 Function->isDefaulted() && Function->getNumParams() > 0 &&
2710 (Function->getParamDecl(0)->getType()->isReferenceType() ||
2711 Decl->isTriviallyCopyable());
2712 };
2713
2714 if (llvm::none_of(Decl->methods(), IsDefaultedOperatorEqualEqual) &&
2715 llvm::none_of(Decl->friends(), [&](const FriendDecl *Friend) {
2716 if (NamedDecl *ND = Friend->getFriendDecl()) {
2717 return ND->isFunctionOrFunctionTemplate() &&
2718 IsDefaultedOperatorEqualEqual(ND->getAsFunction());
2719 }
2720 return false;
2721 }))
2722 return false;
2723
2724 return llvm::all_of(Decl->bases(),
2725 [](const CXXBaseSpecifier &BS) {
2726 if (const auto *RD = BS.getType()->getAsCXXRecordDecl())
2727 return HasNonDeletedDefaultedEqualityComparison(RD);
2728 return true;
2729 }) &&
2730 llvm::all_of(Decl->fields(), [](const FieldDecl *FD) {
2731 auto Type = FD->getType();
2732 if (Type->isArrayType())
2733 Type = Type->getBaseElementTypeUnsafe()->getCanonicalTypeUnqualified();
2734
2735 if (Type->isReferenceType() || Type->isEnumeralType())
2736 return false;
2737 if (const auto *RD = Type->getAsCXXRecordDecl())
2738 return HasNonDeletedDefaultedEqualityComparison(RD);
2739 return true;
2740 });
2741}
2742
2744 const ASTContext &Context) const {
2745 QualType CanonicalType = getCanonicalType();
2746 if (CanonicalType->isIncompleteType() || CanonicalType->isDependentType() ||
2747 CanonicalType->isEnumeralType() || CanonicalType->isArrayType())
2748 return false;
2749
2750 if (const auto *RD = CanonicalType->getAsCXXRecordDecl()) {
2752 return false;
2753 }
2754
2755 return Context.hasUniqueObjectRepresentations(
2756 CanonicalType, /*CheckIfTriviallyCopyable=*/false);
2757}
2758
2760 return !Context.getLangOpts().ObjCAutoRefCount &&
2761 Context.getLangOpts().ObjCWeak &&
2763}
2764
2767}
2768
2771}
2772
2775}
2776
2779}
2780
2783}
2784
2786 return getTypePtr()->isFunctionPointerType() &&
2788}
2789
2792 if (const auto *RT =
2793 getTypePtr()->getBaseElementTypeUnsafe()->getAs<RecordType>())
2794 if (RT->getDecl()->isNonTrivialToPrimitiveDefaultInitialize())
2795 return PDIK_Struct;
2796
2797 switch (getQualifiers().getObjCLifetime()) {
2799 return PDIK_ARCStrong;
2801 return PDIK_ARCWeak;
2802 default:
2803 return PDIK_Trivial;
2804 }
2805}
2806
2808 if (const auto *RT =
2809 getTypePtr()->getBaseElementTypeUnsafe()->getAs<RecordType>())
2810 if (RT->getDecl()->isNonTrivialToPrimitiveCopy())
2811 return PCK_Struct;
2812
2814 switch (Qs.getObjCLifetime()) {
2816 return PCK_ARCStrong;
2818 return PCK_ARCWeak;
2819 default:
2821 }
2822}
2823
2827}
2828
2829bool Type::isLiteralType(const ASTContext &Ctx) const {
2830 if (isDependentType())
2831 return false;
2832
2833 // C++1y [basic.types]p10:
2834 // A type is a literal type if it is:
2835 // -- cv void; or
2836 if (Ctx.getLangOpts().CPlusPlus14 && isVoidType())
2837 return true;
2838
2839 // C++11 [basic.types]p10:
2840 // A type is a literal type if it is:
2841 // [...]
2842 // -- an array of literal type other than an array of runtime bound; or
2843 if (isVariableArrayType())
2844 return false;
2845 const Type *BaseTy = getBaseElementTypeUnsafe();
2846 assert(BaseTy && "NULL element type");
2847
2848 // Return false for incomplete types after skipping any incomplete array
2849 // types; those are expressly allowed by the standard and thus our API.
2850 if (BaseTy->isIncompleteType())
2851 return false;
2852
2853 // C++11 [basic.types]p10:
2854 // A type is a literal type if it is:
2855 // -- a scalar type; or
2856 // As an extension, Clang treats vector types and complex types as
2857 // literal types.
2858 if (BaseTy->isScalarType() || BaseTy->isVectorType() ||
2859 BaseTy->isAnyComplexType())
2860 return true;
2861 // -- a reference type; or
2862 if (BaseTy->isReferenceType())
2863 return true;
2864 // -- a class type that has all of the following properties:
2865 if (const auto *RT = BaseTy->getAs<RecordType>()) {
2866 // -- a trivial destructor,
2867 // -- every constructor call and full-expression in the
2868 // brace-or-equal-initializers for non-static data members (if any)
2869 // is a constant expression,
2870 // -- it is an aggregate type or has at least one constexpr
2871 // constructor or constructor template that is not a copy or move
2872 // constructor, and
2873 // -- all non-static data members and base classes of literal types
2874 //
2875 // We resolve DR1361 by ignoring the second bullet.
2876 if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl()))
2877 return ClassDecl->isLiteral();
2878
2879 return true;
2880 }
2881
2882 // We treat _Atomic T as a literal type if T is a literal type.
2883 if (const auto *AT = BaseTy->getAs<AtomicType>())
2884 return AT->getValueType()->isLiteralType(Ctx);
2885
2886 // If this type hasn't been deduced yet, then conservatively assume that
2887 // it'll work out to be a literal type.
2888 if (isa<AutoType>(BaseTy->getCanonicalTypeInternal()))
2889 return true;
2890
2891 return false;
2892}
2893
2895 // C++20 [temp.param]p6:
2896 // A structural type is one of the following:
2897 // -- a scalar type; or
2898 // -- a vector type [Clang extension]; or
2899 if (isScalarType() || isVectorType())
2900 return true;
2901 // -- an lvalue reference type; or
2903 return true;
2904 // -- a literal class type [...under some conditions]
2905 if (const CXXRecordDecl *RD = getAsCXXRecordDecl())
2906 return RD->isStructural();
2907 return false;
2908}
2909
2911 if (isDependentType())
2912 return false;
2913
2914 // C++0x [basic.types]p9:
2915 // Scalar types, standard-layout class types, arrays of such types, and
2916 // cv-qualified versions of these types are collectively called
2917 // standard-layout types.
2918 const Type *BaseTy = getBaseElementTypeUnsafe();
2919 assert(BaseTy && "NULL element type");
2920
2921 // Return false for incomplete types after skipping any incomplete array
2922 // types which are expressly allowed by the standard and thus our API.
2923 if (BaseTy->isIncompleteType())
2924 return false;
2925
2926 // As an extension, Clang treats vector types as Scalar types.
2927 if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true;
2928 if (const auto *RT = BaseTy->getAs<RecordType>()) {
2929 if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl()))
2930 if (!ClassDecl->isStandardLayout())
2931 return false;
2932
2933 // Default to 'true' for non-C++ class types.
2934 // FIXME: This is a bit dubious, but plain C structs should trivially meet
2935 // all the requirements of standard layout classes.
2936 return true;
2937 }
2938
2939 // No other types can match.
2940 return false;
2941}
2942
2943// This is effectively the intersection of isTrivialType and
2944// isStandardLayoutType. We implement it directly to avoid redundant
2945// conversions from a type to a CXXRecordDecl.
2946bool QualType::isCXX11PODType(const ASTContext &Context) const {
2947 const Type *ty = getTypePtr();
2948 if (ty->isDependentType())
2949 return false;
2950
2952 return false;
2953
2954 // C++11 [basic.types]p9:
2955 // Scalar types, POD classes, arrays of such types, and cv-qualified
2956 // versions of these types are collectively called trivial types.
2957 const Type *BaseTy = ty->getBaseElementTypeUnsafe();
2958 assert(BaseTy && "NULL element type");
2959
2960 if (BaseTy->isSizelessBuiltinType())
2961 return true;
2962
2963 // Return false for incomplete types after skipping any incomplete array
2964 // types which are expressly allowed by the standard and thus our API.
2965 if (BaseTy->isIncompleteType())
2966 return false;
2967
2968 // As an extension, Clang treats vector types as Scalar types.
2969 if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true;
2970 if (const auto *RT = BaseTy->getAs<RecordType>()) {
2971 if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
2972 // C++11 [class]p10:
2973 // A POD struct is a non-union class that is both a trivial class [...]
2974 if (!ClassDecl->isTrivial()) return false;
2975
2976 // C++11 [class]p10:
2977 // A POD struct is a non-union class that is both a trivial class and
2978 // a standard-layout class [...]
2979 if (!ClassDecl->isStandardLayout()) return false;
2980
2981 // C++11 [class]p10:
2982 // A POD struct is a non-union class that is both a trivial class and
2983 // a standard-layout class, and has no non-static data members of type
2984 // non-POD struct, non-POD union (or array of such types). [...]
2985 //
2986 // We don't directly query the recursive aspect as the requirements for
2987 // both standard-layout classes and trivial classes apply recursively
2988 // already.
2989 }
2990
2991 return true;
2992 }
2993
2994 // No other types can match.
2995 return false;
2996}
2997
2998bool Type::isNothrowT() const {
2999 if (const auto *RD = getAsCXXRecordDecl()) {
3000 IdentifierInfo *II = RD->getIdentifier();
3001 if (II && II->isStr("nothrow_t") && RD->isInStdNamespace())
3002 return true;
3003 }
3004 return false;
3005}
3006
3007bool Type::isAlignValT() const {
3008 if (const auto *ET = getAs<EnumType>()) {
3009 IdentifierInfo *II = ET->getDecl()->getIdentifier();
3010 if (II && II->isStr("align_val_t") && ET->getDecl()->isInStdNamespace())
3011 return true;
3012 }
3013 return false;
3014}
3015
3017 if (const auto *ET = getAs<EnumType>()) {
3018 IdentifierInfo *II = ET->getDecl()->getIdentifier();
3019 if (II && II->isStr("byte") && ET->getDecl()->isInStdNamespace())
3020 return true;
3021 }
3022 return false;
3023}
3024
3026 // Note that this intentionally does not use the canonical type.
3027 switch (getTypeClass()) {
3028 case Builtin:
3029 case Record:
3030 case Enum:
3031 case Typedef:
3032 case Complex:
3033 case TypeOfExpr:
3034 case TypeOf:
3035 case TemplateTypeParm:
3036 case SubstTemplateTypeParm:
3037 case TemplateSpecialization:
3038 case Elaborated:
3039 case DependentName:
3040 case DependentTemplateSpecialization:
3041 case ObjCInterface:
3042 case ObjCObject:
3043 return true;
3044 default:
3045 return false;
3046 }
3047}
3048
3051 switch (TypeSpec) {
3052 default:
3054 case TST_typename:
3056 case TST_class:
3058 case TST_struct:
3060 case TST_interface:
3062 case TST_union:
3064 case TST_enum:
3066 }
3067}
3068
3071 switch(TypeSpec) {
3072 case TST_class:
3073 return TagTypeKind::Class;
3074 case TST_struct:
3075 return TagTypeKind::Struct;
3076 case TST_interface:
3078 case TST_union:
3079 return TagTypeKind::Union;
3080 case TST_enum:
3081 return TagTypeKind::Enum;
3082 }
3083
3084 llvm_unreachable("Type specifier is not a tag type kind.");
3085}
3086
3089 switch (Kind) {
3090 case TagTypeKind::Class:
3096 case TagTypeKind::Union:
3098 case TagTypeKind::Enum:
3100 }
3101 llvm_unreachable("Unknown tag type kind.");
3102}
3103
3106 switch (Keyword) {
3108 return TagTypeKind::Class;
3110 return TagTypeKind::Struct;
3114 return TagTypeKind::Union;
3116 return TagTypeKind::Enum;
3117 case ElaboratedTypeKeyword::None: // Fall through.
3119 llvm_unreachable("Elaborated type keyword is not a tag type kind.");
3120 }
3121 llvm_unreachable("Unknown elaborated type keyword.");
3122}
3123
3124bool
3126 switch (Keyword) {
3129 return false;
3135 return true;
3136 }
3137 llvm_unreachable("Unknown elaborated type keyword.");
3138}
3139
3141 switch (Keyword) {
3143 return {};
3145 return "typename";
3147 return "class";
3149 return "struct";
3151 return "__interface";
3153 return "union";
3155 return "enum";
3156 }
3157
3158 llvm_unreachable("Unknown elaborated type keyword.");
3159}
3160
3161DependentTemplateSpecializationType::DependentTemplateSpecializationType(
3163 const IdentifierInfo *Name, ArrayRef<TemplateArgument> Args, QualType Canon)
3164 : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon,
3165 TypeDependence::DependentInstantiation |
3166 (NNS ? toTypeDependence(NNS->getDependence())
3167 : TypeDependence::None)),
3168 NNS(NNS), Name(Name) {
3169 DependentTemplateSpecializationTypeBits.NumArgs = Args.size();
3170 assert((!NNS || NNS->isDependent()) &&
3171 "DependentTemplateSpecializatonType requires dependent qualifier");
3172 auto *ArgBuffer = const_cast<TemplateArgument *>(template_arguments().data());
3173 for (const TemplateArgument &Arg : Args) {
3174 addDependence(toTypeDependence(Arg.getDependence() &
3175 TemplateArgumentDependence::UnexpandedPack));
3176
3177 new (ArgBuffer++) TemplateArgument(Arg);
3178 }
3179}
3180
3181void
3183 const ASTContext &Context,
3184 ElaboratedTypeKeyword Keyword,
3185 NestedNameSpecifier *Qualifier,
3186 const IdentifierInfo *Name,
3188 ID.AddInteger(llvm::to_underlying(Keyword));
3189 ID.AddPointer(Qualifier);
3190 ID.AddPointer(Name);
3191 for (const TemplateArgument &Arg : Args)
3192 Arg.Profile(ID, Context);
3193}
3194
3196 ElaboratedTypeKeyword Keyword;
3197 if (const auto *Elab = dyn_cast<ElaboratedType>(this))
3198 Keyword = Elab->getKeyword();
3199 else if (const auto *DepName = dyn_cast<DependentNameType>(this))
3200 Keyword = DepName->getKeyword();
3201 else if (const auto *DepTST =
3202 dyn_cast<DependentTemplateSpecializationType>(this))
3203 Keyword = DepTST->getKeyword();
3204 else
3205 return false;
3206
3208}
3209
3210const char *Type::getTypeClassName() const {
3211 switch (TypeBits.TC) {
3212#define ABSTRACT_TYPE(Derived, Base)
3213#define TYPE(Derived, Base) case Derived: return #Derived;
3214#include "clang/AST/TypeNodes.inc"
3215 }
3216
3217 llvm_unreachable("Invalid type class.");
3218}
3219
3220StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
3221 switch (getKind()) {
3222 case Void:
3223 return "void";
3224 case Bool:
3225 return Policy.Bool ? "bool" : "_Bool";
3226 case Char_S:
3227 return "char";
3228 case Char_U:
3229 return "char";
3230 case SChar:
3231 return "signed char";
3232 case Short:
3233 return "short";
3234 case Int:
3235 return "int";
3236 case Long:
3237 return "long";
3238 case LongLong:
3239 return "long long";
3240 case Int128:
3241 return "__int128";
3242 case UChar:
3243 return "unsigned char";
3244 case UShort:
3245 return "unsigned short";
3246 case UInt:
3247 return "unsigned int";
3248 case ULong:
3249 return "unsigned long";
3250 case ULongLong:
3251 return "unsigned long long";
3252 case UInt128:
3253 return "unsigned __int128";
3254 case Half:
3255 return Policy.Half ? "half" : "__fp16";
3256 case BFloat16:
3257 return "__bf16";
3258 case Float:
3259 return "float";
3260 case Double:
3261 return "double";
3262 case LongDouble:
3263 return "long double";
3264 case ShortAccum:
3265 return "short _Accum";
3266 case Accum:
3267 return "_Accum";
3268 case LongAccum:
3269 return "long _Accum";
3270 case UShortAccum:
3271 return "unsigned short _Accum";
3272 case UAccum:
3273 return "unsigned _Accum";
3274 case ULongAccum:
3275 return "unsigned long _Accum";
3276 case BuiltinType::ShortFract:
3277 return "short _Fract";
3278 case BuiltinType::Fract:
3279 return "_Fract";
3280 case BuiltinType::LongFract:
3281 return "long _Fract";
3282 case BuiltinType::UShortFract:
3283 return "unsigned short _Fract";
3284 case BuiltinType::UFract:
3285 return "unsigned _Fract";
3286 case BuiltinType::ULongFract:
3287 return "unsigned long _Fract";
3288 case BuiltinType::SatShortAccum:
3289 return "_Sat short _Accum";
3290 case BuiltinType::SatAccum:
3291 return "_Sat _Accum";
3292 case BuiltinType::SatLongAccum:
3293 return "_Sat long _Accum";
3294 case BuiltinType::SatUShortAccum:
3295 return "_Sat unsigned short _Accum";
3296 case BuiltinType::SatUAccum:
3297 return "_Sat unsigned _Accum";
3298 case BuiltinType::SatULongAccum:
3299 return "_Sat unsigned long _Accum";
3300 case BuiltinType::SatShortFract:
3301 return "_Sat short _Fract";
3302 case BuiltinType::SatFract:
3303 return "_Sat _Fract";
3304 case BuiltinType::SatLongFract:
3305 return "_Sat long _Fract";
3306 case BuiltinType::SatUShortFract:
3307 return "_Sat unsigned short _Fract";
3308 case BuiltinType::SatUFract:
3309 return "_Sat unsigned _Fract";
3310 case BuiltinType::SatULongFract:
3311 return "_Sat unsigned long _Fract";
3312 case Float16:
3313 return "_Float16";
3314 case Float128:
3315 return "__float128";
3316 case Ibm128:
3317 return "__ibm128";
3318 case WChar_S:
3319 case WChar_U:
3320 return Policy.MSWChar ? "__wchar_t" : "wchar_t";
3321 case Char8:
3322 return "char8_t";
3323 case Char16:
3324 return "char16_t";
3325 case Char32:
3326 return "char32_t";
3327 case NullPtr:
3328 return Policy.NullptrTypeInNamespace ? "std::nullptr_t" : "nullptr_t";
3329 case Overload:
3330 return "<overloaded function type>";
3331 case BoundMember:
3332 return "<bound member function type>";
3333 case PseudoObject:
3334 return "<pseudo-object type>";
3335 case Dependent:
3336 return "<dependent type>";
3337 case UnknownAny:
3338 return "<unknown type>";
3339 case ARCUnbridgedCast:
3340 return "<ARC unbridged cast type>";
3341 case BuiltinFn:
3342 return "<builtin fn type>";
3343 case ObjCId:
3344 return "id";
3345 case ObjCClass:
3346 return "Class";
3347 case ObjCSel:
3348 return "SEL";
3349#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3350 case Id: \
3351 return "__" #Access " " #ImgType "_t";
3352#include "clang/Basic/OpenCLImageTypes.def"
3353 case OCLSampler:
3354 return "sampler_t";
3355 case OCLEvent:
3356 return "event_t";
3357 case OCLClkEvent:
3358 return "clk_event_t";
3359 case OCLQueue:
3360 return "queue_t";
3361 case OCLReserveID:
3362 return "reserve_id_t";
3363 case IncompleteMatrixIdx:
3364 return "<incomplete matrix index type>";
3365 case OMPArraySection:
3366 return "<OpenMP array section type>";
3367 case OMPArrayShaping:
3368 return "<OpenMP array shaping type>";
3369 case OMPIterator:
3370 return "<OpenMP iterator type>";
3371#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3372 case Id: \
3373 return #ExtType;
3374#include "clang/Basic/OpenCLExtensionTypes.def"
3375#define SVE_TYPE(Name, Id, SingletonId) \
3376 case Id: \
3377 return Name;
3378#include "clang/Basic/AArch64SVEACLETypes.def"
3379#define PPC_VECTOR_TYPE(Name, Id, Size) \
3380 case Id: \
3381 return #Name;
3382#include "clang/Basic/PPCTypes.def"
3383#define RVV_TYPE(Name, Id, SingletonId) \
3384 case Id: \
3385 return Name;
3386#include "clang/Basic/RISCVVTypes.def"
3387#define WASM_TYPE(Name, Id, SingletonId) \
3388 case Id: \
3389 return Name;
3390#include "clang/Basic/WebAssemblyReferenceTypes.def"
3391 }
3392
3393 llvm_unreachable("Invalid builtin type.");
3394}
3395
3397 // We never wrap type sugar around a PackExpansionType.
3398 if (auto *PET = dyn_cast<PackExpansionType>(getTypePtr()))
3399 return PET->getPattern();
3400 return *this;
3401}
3402
3404 if (const auto *RefType = getTypePtr()->getAs<ReferenceType>())
3405 return RefType->getPointeeType();
3406
3407 // C++0x [basic.lval]:
3408 // Class prvalues can have cv-qualified types; non-class prvalues always
3409 // have cv-unqualified types.
3410 //
3411 // See also C99 6.3.2.1p2.
3412 if (!Context.getLangOpts().CPlusPlus ||
3413 (!getTypePtr()->isDependentType() && !getTypePtr()->isRecordType()))
3414 return getUnqualifiedType();
3415
3416 return *this;
3417}
3418
3420 switch (CC) {
3421 case CC_C: return "cdecl";
3422 case CC_X86StdCall: return "stdcall";
3423 case CC_X86FastCall: return "fastcall";
3424 case CC_X86ThisCall: return "thiscall";
3425 case CC_X86Pascal: return "pascal";
3426 case CC_X86VectorCall: return "vectorcall";
3427 case CC_Win64: return "ms_abi";
3428 case CC_X86_64SysV: return "sysv_abi";
3429 case CC_X86RegCall : return "regcall";
3430 case CC_AAPCS: return "aapcs";
3431 case CC_AAPCS_VFP: return "aapcs-vfp";
3432 case CC_AArch64VectorCall: return "aarch64_vector_pcs";
3433 case CC_AArch64SVEPCS: return "aarch64_sve_pcs";
3434 case CC_AMDGPUKernelCall: return "amdgpu_kernel";
3435 case CC_IntelOclBicc: return "intel_ocl_bicc";
3436 case CC_SpirFunction: return "spir_function";
3437 case CC_OpenCLKernel: return "opencl_kernel";
3438 case CC_Swift: return "swiftcall";
3439 case CC_SwiftAsync: return "swiftasynccall";
3440 case CC_PreserveMost: return "preserve_most";
3441 case CC_PreserveAll: return "preserve_all";
3442 case CC_M68kRTD: return "m68k_rtd";
3443 case CC_PreserveNone: return "preserve_none";
3444 }
3445
3446 llvm_unreachable("Invalid calling convention.");
3447}
3448
3450 assert(Type == EST_Uninstantiated);
3451 NoexceptExpr =
3452 cast<FunctionProtoType>(SourceTemplate->getType())->getNoexceptExpr();
3454}
3455
3456FunctionProtoType::FunctionProtoType(QualType result, ArrayRef<QualType> params,
3457 QualType canonical,
3458 const ExtProtoInfo &epi)
3459 : FunctionType(FunctionProto, result, canonical, result->getDependence(),
3460 epi.ExtInfo) {
3461 FunctionTypeBits.FastTypeQuals = epi.TypeQuals.getFastQualifiers();
3462 FunctionTypeBits.RefQualifier = epi.RefQualifier;
3463 FunctionTypeBits.NumParams = params.size();
3464 assert(getNumParams() == params.size() && "NumParams overflow!");
3465 FunctionTypeBits.ExceptionSpecType = epi.ExceptionSpec.Type;
3466 FunctionTypeBits.HasExtParameterInfos = !!epi.ExtParameterInfos;
3467 FunctionTypeBits.Variadic = epi.Variadic;
3468 FunctionTypeBits.HasTrailingReturn = epi.HasTrailingReturn;
3469
3471 FunctionTypeBits.HasExtraBitfields = true;
3472 auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
3473 ExtraBits = FunctionTypeExtraBitfields();
3474 } else {
3475 FunctionTypeBits.HasExtraBitfields = false;
3476 }
3477
3479 auto &ArmTypeAttrs = *getTrailingObjects<FunctionTypeArmAttributes>();
3480 ArmTypeAttrs = FunctionTypeArmAttributes();
3481
3482 // Also set the bit in FunctionTypeExtraBitfields
3483 auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
3484 ExtraBits.HasArmTypeAttributes = true;
3485 }
3486
3487 // Fill in the trailing argument array.
3488 auto *argSlot = getTrailingObjects<QualType>();
3489 for (unsigned i = 0; i != getNumParams(); ++i) {
3490 addDependence(params[i]->getDependence() &
3491 ~TypeDependence::VariablyModified);
3492 argSlot[i] = params[i];
3493 }
3494
3495 // Propagate the SME ACLE attributes.
3497 auto &ArmTypeAttrs = *getTrailingObjects<FunctionTypeArmAttributes>();
3499 "Not enough bits to encode SME attributes");
3500 ArmTypeAttrs.AArch64SMEAttributes = epi.AArch64SMEAttributes;
3501 }
3502
3503 // Fill in the exception type array if present.
3505 auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
3506 size_t NumExceptions = epi.ExceptionSpec.Exceptions.size();
3507 assert(NumExceptions <= 1023 && "Not enough bits to encode exceptions");
3508 ExtraBits.NumExceptionType = NumExceptions;
3509
3510 assert(hasExtraBitfields() && "missing trailing extra bitfields!");
3511 auto *exnSlot =
3512 reinterpret_cast<QualType *>(getTrailingObjects<ExceptionType>());
3513 unsigned I = 0;
3514 for (QualType ExceptionType : epi.ExceptionSpec.Exceptions) {
3515 // Note that, before C++17, a dependent exception specification does
3516 // *not* make a type dependent; it's not even part of the C++ type
3517 // system.
3519 ExceptionType->getDependence() &
3520 (TypeDependence::Instantiation | TypeDependence::UnexpandedPack));
3521
3522 exnSlot[I++] = ExceptionType;
3523 }
3524 }
3525 // Fill in the Expr * in the exception specification if present.
3527 assert(epi.ExceptionSpec.NoexceptExpr && "computed noexcept with no expr");
3530
3531 // Store the noexcept expression and context.
3532 *getTrailingObjects<Expr *>() = epi.ExceptionSpec.NoexceptExpr;
3533
3536 (TypeDependence::Instantiation | TypeDependence::UnexpandedPack));
3537 }
3538 // Fill in the FunctionDecl * in the exception specification if present.
3540 // Store the function decl from which we will resolve our
3541 // exception specification.
3542 auto **slot = getTrailingObjects<FunctionDecl *>();
3543 slot[0] = epi.ExceptionSpec.SourceDecl;
3544 slot[1] = epi.ExceptionSpec.SourceTemplate;
3545 // This exception specification doesn't make the type dependent, because
3546 // it's not instantiated as part of instantiating the type.
3547 } else if (getExceptionSpecType() == EST_Unevaluated) {
3548 // Store the function decl from which we will resolve our
3549 // exception specification.
3550 auto **slot = getTrailingObjects<FunctionDecl *>();
3551 slot[0] = epi.ExceptionSpec.SourceDecl;
3552 }
3553
3554 // If this is a canonical type, and its exception specification is dependent,
3555 // then it's a dependent type. This only happens in C++17 onwards.
3556 if (isCanonicalUnqualified()) {
3559 assert(hasDependentExceptionSpec() && "type should not be canonical");
3560 addDependence(TypeDependence::DependentInstantiation);
3561 }
3562 } else if (getCanonicalTypeInternal()->isDependentType()) {
3563 // Ask our canonical type whether our exception specification was dependent.
3564 addDependence(TypeDependence::DependentInstantiation);
3565 }
3566
3567 // Fill in the extra parameter info if present.
3568 if (epi.ExtParameterInfos) {
3569 auto *extParamInfos = getTrailingObjects<ExtParameterInfo>();
3570 for (unsigned i = 0; i != getNumParams(); ++i)
3571 extParamInfos[i] = epi.ExtParameterInfos[i];
3572 }
3573
3574 if (epi.TypeQuals.hasNonFastQualifiers()) {
3575 FunctionTypeBits.HasExtQuals = 1;
3576 *getTrailingObjects<Qualifiers>() = epi.TypeQuals;
3577 } else {
3578 FunctionTypeBits.HasExtQuals = 0;
3579 }
3580
3581 // Fill in the Ellipsis location info if present.
3582 if (epi.Variadic) {
3583 auto &EllipsisLoc = *getTrailingObjects<SourceLocation>();
3584 EllipsisLoc = epi.EllipsisLoc;
3585 }
3586}
3587
3589 if (Expr *NE = getNoexceptExpr())
3590 return NE->isValueDependent();
3591 for (QualType ET : exceptions())
3592 // A pack expansion with a non-dependent pattern is still dependent,
3593 // because we don't know whether the pattern is in the exception spec
3594 // or not (that depends on whether the pack has 0 expansions).
3595 if (ET->isDependentType() || ET->getAs<PackExpansionType>())
3596 return true;
3597 return false;
3598}
3599
3601 if (Expr *NE = getNoexceptExpr())
3602 return NE->isInstantiationDependent();
3603 for (QualType ET : exceptions())
3604 if (ET->isInstantiationDependentType())
3605 return true;
3606 return false;
3607}
3608
3610 switch (getExceptionSpecType()) {
3611 case EST_Unparsed:
3612 case EST_Unevaluated:
3613 llvm_unreachable("should not call this with unresolved exception specs");
3614
3615 case EST_DynamicNone:
3616 case EST_BasicNoexcept:
3617 case EST_NoexceptTrue:
3618 case EST_NoThrow:
3619 return CT_Cannot;
3620
3621 case EST_None:
3622 case EST_MSAny:
3623 case EST_NoexceptFalse:
3624 return CT_Can;
3625
3626 case EST_Dynamic:
3627 // A dynamic exception specification is throwing unless every exception
3628 // type is an (unexpanded) pack expansion type.
3629 for (unsigned I = 0; I != getNumExceptions(); ++I)
3631 return CT_Can;
3632 return CT_Dependent;
3633
3634 case EST_Uninstantiated:
3636 return CT_Dependent;
3637 }
3638
3639 llvm_unreachable("unexpected exception specification kind");
3640}
3641
3643 for (unsigned ArgIdx = getNumParams(); ArgIdx; --ArgIdx)
3644 if (isa<PackExpansionType>(getParamType(ArgIdx - 1)))
3645 return true;
3646
3647 return false;
3648}
3649
3650void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result,
3651 const QualType *ArgTys, unsigned NumParams,
3652 const ExtProtoInfo &epi,
3653 const ASTContext &Context, bool Canonical) {
3654 // We have to be careful not to get ambiguous profile encodings.
3655 // Note that valid type pointers are never ambiguous with anything else.
3656 //
3657 // The encoding grammar begins:
3658 // type type* bool int bool
3659 // If that final bool is true, then there is a section for the EH spec:
3660 // bool type*
3661 // This is followed by an optional "consumed argument" section of the
3662 // same length as the first type sequence:
3663 // bool*
3664 // This is followed by the ext info:
3665 // int
3666 // Finally we have a trailing return type flag (bool)
3667 // combined with AArch64 SME Attributes, to save space:
3668 // int
3669 //
3670 // There is no ambiguity between the consumed arguments and an empty EH
3671 // spec because of the leading 'bool' which unambiguously indicates
3672 // whether the following bool is the EH spec or part of the arguments.
3673
3674 ID.AddPointer(Result.getAsOpaquePtr());
3675 for (unsigned i = 0; i != NumParams; ++i)
3676 ID.AddPointer(ArgTys[i].getAsOpaquePtr());
3677 // This method is relatively performance sensitive, so as a performance
3678 // shortcut, use one AddInteger call instead of four for the next four
3679 // fields.
3680 assert(!(unsigned(epi.Variadic) & ~1) &&
3681 !(unsigned(epi.RefQualifier) & ~3) &&
3682 !(unsigned(epi.ExceptionSpec.Type) & ~15) &&
3683 "Values larger than expected.");
3684 ID.AddInteger(unsigned(epi.Variadic) +
3685 (epi.RefQualifier << 1) +
3686 (epi.ExceptionSpec.Type << 3));
3687 ID.Add(epi.TypeQuals);
3688 if (epi.ExceptionSpec.Type == EST_Dynamic) {
3689 for (QualType Ex : epi.ExceptionSpec.Exceptions)
3690 ID.AddPointer(Ex.getAsOpaquePtr());
3691 } else if (isComputedNoexcept(epi.ExceptionSpec.Type)) {
3692 epi.ExceptionSpec.NoexceptExpr->Profile(ID, Context, Canonical);
3693 } else if (epi.ExceptionSpec.Type == EST_Uninstantiated ||
3694 epi.ExceptionSpec.Type == EST_Unevaluated) {
3695 ID.AddPointer(epi.ExceptionSpec.SourceDecl->getCanonicalDecl());
3696 }
3697 if (epi.ExtParameterInfos) {
3698 for (unsigned i = 0; i != NumParams; ++i)
3699 ID.AddInteger(epi.ExtParameterInfos[i].getOpaqueValue());
3700 }
3701
3702 epi.ExtInfo.Profile(ID);
3703 ID.AddInteger((epi.AArch64SMEAttributes << 1) | epi.HasTrailingReturn);
3704}
3705
3706void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID,
3707 const ASTContext &Ctx) {
3710}
3711
3712TypedefType::TypedefType(TypeClass tc, const TypedefNameDecl *D,
3713 QualType Underlying, QualType can)
3714 : Type(tc, can, toSemanticDependence(can->getDependence())),
3715 Decl(const_cast<TypedefNameDecl *>(D)) {
3716 assert(!isa<TypedefType>(can) && "Invalid canonical type");
3717 TypedefBits.hasTypeDifferentFromDecl = !Underlying.isNull();
3718 if (!typeMatchesDecl())
3719 *getTrailingObjects<QualType>() = Underlying;
3720}
3721
3723 return typeMatchesDecl() ? Decl->getUnderlyingType()
3724 : *getTrailingObjects<QualType>();
3725}
3726
3727UsingType::UsingType(const UsingShadowDecl *Found, QualType Underlying,
3728 QualType Canon)
3729 : Type(Using, Canon, toSemanticDependence(Canon->getDependence())),
3730 Found(const_cast<UsingShadowDecl *>(Found)) {
3731 UsingBits.hasTypeDifferentFromDecl = !Underlying.isNull();
3732 if (!typeMatchesDecl())
3733 *getTrailingObjects<QualType>() = Underlying;
3734}
3735
3737 return typeMatchesDecl()
3738 ? QualType(
3739 cast<TypeDecl>(Found->getTargetDecl())->getTypeForDecl(), 0)
3740 : *getTrailingObjects<QualType>();
3741}
3742
3744
3746 // Step over MacroQualifiedTypes from the same macro to find the type
3747 // ultimately qualified by the macro qualifier.
3748 QualType Inner = cast<AttributedType>(getUnderlyingType())->getModifiedType();
3749 while (auto *InnerMQT = dyn_cast<MacroQualifiedType>(Inner)) {
3750 if (InnerMQT->getMacroIdentifier() != getMacroIdentifier())
3751 break;
3752 Inner = InnerMQT->getModifiedType();
3753 }
3754 return Inner;
3755}
3756
3758 : Type(TypeOfExpr,
3759 // We have to protect against 'Can' being invalid through its
3760 // default argument.
3761 Kind == TypeOfKind::Unqualified && !Can.isNull()
3762 ? Can.getAtomicUnqualifiedType()
3763 : Can,
3764 toTypeDependence(E->getDependence()) |
3765 (E->getType()->getDependence() &
3766 TypeDependence::VariablyModified)),
3767 TOExpr(E) {
3768 TypeOfBits.IsUnqual = Kind == TypeOfKind::Unqualified;
3769}
3770
3772 return !TOExpr->isTypeDependent();
3773}
3774
3776 if (isSugared()) {
3778 return TypeOfBits.IsUnqual ? QT.getAtomicUnqualifiedType() : QT;
3779 }
3780 return QualType(this, 0);
3781}
3782
3783void DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID,
3784 const ASTContext &Context, Expr *E,
3785 bool IsUnqual) {
3786 E->Profile(ID, Context, true);
3787 ID.AddBoolean(IsUnqual);
3788}
3789
3791 // C++11 [temp.type]p2: "If an expression e involves a template parameter,
3792 // decltype(e) denotes a unique dependent type." Hence a decltype type is
3793 // type-dependent even if its expression is only instantiation-dependent.
3794 : Type(Decltype, can,
3795 toTypeDependence(E->getDependence()) |
3796 (E->isInstantiationDependent() ? TypeDependence::Dependent
3797 : TypeDependence::None) |
3798 (E->getType()->getDependence() &
3799 TypeDependence::VariablyModified)),
3800 E(E), UnderlyingType(underlyingType) {}
3801
3803
3805 if (isSugared())
3806 return getUnderlyingType();
3807
3808 return QualType(this, 0);
3809}
3810
3812 : DecltypeType(E, UnderlyingType) {}
3813
3814void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID,
3815 const ASTContext &Context, Expr *E) {
3816 E->Profile(ID, Context, true);
3817}
3818
3820 QualType Canonical, QualType Pattern,
3821 Expr *IndexExpr,
3822 ArrayRef<QualType> Expansions)
3823 : Type(PackIndexing, Canonical,
3824 computeDependence(Pattern, IndexExpr, Expansions)),
3825 Context(Context), Pattern(Pattern), IndexExpr(IndexExpr),
3826 Size(Expansions.size()) {
3827
3828 std::uninitialized_copy(Expansions.begin(), Expansions.end(),
3829 getTrailingObjects<QualType>());
3830}
3831
3832std::optional<unsigned> PackIndexingType::getSelectedIndex() const {
3834 return std::nullopt;
3835 // Should only be not a constant for error recovery.
3836 ConstantExpr *CE = dyn_cast<ConstantExpr>(getIndexExpr());
3837 if (!CE)
3838 return std::nullopt;
3839 auto Index = CE->getResultAsAPSInt();
3840 assert(Index.isNonNegative() && "Invalid index");
3841 return static_cast<unsigned>(Index.getExtValue());
3842}
3843
3845PackIndexingType::computeDependence(QualType Pattern, Expr *IndexExpr,
3846 ArrayRef<QualType> Expansions) {
3847 TypeDependence IndexD = toTypeDependence(IndexExpr->getDependence());
3848
3849 TypeDependence TD = IndexD | (IndexExpr->isInstantiationDependent()
3850 ? TypeDependence::DependentInstantiation
3851 : TypeDependence::None);
3852 if (Expansions.empty())
3853 TD |= Pattern->getDependence() & TypeDependence::DependentInstantiation;
3854 else
3855 for (const QualType &T : Expansions)
3856 TD |= T->getDependence();
3857
3858 if (!(IndexD & TypeDependence::UnexpandedPack))
3859 TD &= ~TypeDependence::UnexpandedPack;
3860
3861 // If the pattern does not contain an unexpended pack,
3862 // the type is still dependent, and invalid
3863 if (!Pattern->containsUnexpandedParameterPack())
3864 TD |= TypeDependence::Error | TypeDependence::DependentInstantiation;
3865
3866 return TD;
3867}
3868
3869void PackIndexingType::Profile(llvm::FoldingSetNodeID &ID,
3870 const ASTContext &Context, QualType Pattern,
3871 Expr *E) {
3872 Pattern.Profile(ID);
3873 E->Profile(ID, Context, true);
3874}
3875
3877 QualType UnderlyingType, UTTKind UKind,
3878 QualType CanonicalType)
3879 : Type(UnaryTransform, CanonicalType, BaseType->getDependence()),
3880 BaseType(BaseType), UnderlyingType(UnderlyingType), UKind(UKind) {}
3881
3883 QualType BaseType,
3884 UTTKind UKind)
3885 : UnaryTransformType(BaseType, C.DependentTy, UKind, QualType()) {}
3886
3888 : Type(TC, can,
3889 D->isDependentType() ? TypeDependence::DependentInstantiation
3890 : TypeDependence::None),
3891 decl(const_cast<TagDecl *>(D)) {}
3892
3894 for (auto *I : decl->redecls()) {
3895 if (I->isCompleteDefinition() || I->isBeingDefined())
3896 return I;
3897 }
3898 // If there's no definition (not even in progress), return what we have.
3899 return decl;
3900}
3901
3903 return getInterestingTagDecl(decl);
3904}
3905
3907 return getDecl()->isBeingDefined();
3908}
3909
3911 std::vector<const RecordType*> RecordTypeList;
3912 RecordTypeList.push_back(this);
3913 unsigned NextToCheckIndex = 0;
3914
3915 while (RecordTypeList.size() > NextToCheckIndex) {
3916 for (FieldDecl *FD :
3917 RecordTypeList[NextToCheckIndex]->getDecl()->fields()) {
3918 QualType FieldTy = FD->getType();
3919 if (FieldTy.isConstQualified())
3920 return true;
3921 FieldTy = FieldTy.getCanonicalType();
3922 if (const auto *FieldRecTy = FieldTy->getAs<RecordType>()) {
3923 if (!llvm::is_contained(RecordTypeList, FieldRecTy))
3924 RecordTypeList.push_back(FieldRecTy);
3925 }
3926 }
3927 ++NextToCheckIndex;
3928 }
3929 return false;
3930}
3931
3933 // FIXME: Generate this with TableGen.
3934 switch (getAttrKind()) {
3935 // These are type qualifiers in the traditional C sense: they annotate
3936 // something about a specific value/variable of a type. (They aren't
3937 // always part of the canonical type, though.)
3938 case attr::ObjCGC:
3939 case attr::ObjCOwnership:
3940 case attr::ObjCInertUnsafeUnretained:
3941 case attr::TypeNonNull:
3942 case attr::TypeNullable:
3943 case attr::TypeNullableResult:
3944 case attr::TypeNullUnspecified:
3945 case attr::LifetimeBound:
3946 case attr::AddressSpace:
3947 return true;
3948
3949 // All other type attributes aren't qualifiers; they rewrite the modified
3950 // type to be a semantically different type.
3951 default:
3952 return false;
3953 }
3954}
3955
3957 // FIXME: Generate this with TableGen?
3958 switch (getAttrKind()) {
3959 default: return false;
3960 case attr::Ptr32:
3961 case attr::Ptr64:
3962 case attr::SPtr:
3963 case attr::UPtr:
3964 return true;
3965 }
3966 llvm_unreachable("invalid attr kind");
3967}
3968
3970 return getAttrKind() == attr::WebAssemblyFuncref;
3971}
3972
3974 // FIXME: Generate this with TableGen.
3975 switch (getAttrKind()) {
3976 default: return false;
3977 case attr::Pcs:
3978 case attr::CDecl:
3979 case attr::FastCall:
3980 case attr::StdCall:
3981 case attr::ThisCall:
3982 case attr::RegCall:
3983 case attr::SwiftCall:
3984 case attr::SwiftAsyncCall:
3985 case attr::VectorCall:
3986 case attr::AArch64VectorPcs:
3987 case attr::AArch64SVEPcs:
3988 case attr::AMDGPUKernelCall:
3989 case attr::Pascal:
3990 case attr::MSABI:
3991 case attr::SysVABI:
3992 case attr::IntelOclBicc:
3993 case attr::PreserveMost:
3994 case attr::PreserveAll:
3995 case attr::M68kRTD:
3996 case attr::PreserveNone:
3997 return true;
3998 }
3999 llvm_unreachable("invalid attr kind");
4000}
4001
4003 return cast<CXXRecordDecl>(getInterestingTagDecl(Decl));
4004}
4005
4007 return isCanonicalUnqualified() ? nullptr : getDecl()->getIdentifier();
4008}
4009
4011 unsigned Index) {
4012 if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(D))
4013 return TTP;
4014 return cast<TemplateTypeParmDecl>(
4015 getReplacedTemplateParameterList(D)->getParam(Index));
4016}
4017
4018SubstTemplateTypeParmType::SubstTemplateTypeParmType(
4019 QualType Replacement, Decl *AssociatedDecl, unsigned Index,
4020 std::optional<unsigned> PackIndex)
4021 : Type(SubstTemplateTypeParm, Replacement.getCanonicalType(),
4022 Replacement->getDependence()),
4023 AssociatedDecl(AssociatedDecl) {
4024 SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType =
4025 Replacement != getCanonicalTypeInternal();
4026 if (SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType)
4027 *getTrailingObjects<QualType>() = Replacement;
4028
4029 SubstTemplateTypeParmTypeBits.Index = Index;
4030 SubstTemplateTypeParmTypeBits.PackIndex = PackIndex ? *PackIndex + 1 : 0;
4031 assert(AssociatedDecl != nullptr);
4032}
4033
4036 return ::getReplacedParameter(getAssociatedDecl(), getIndex());
4037}
4038
4039SubstTemplateTypeParmPackType::SubstTemplateTypeParmPackType(
4040 QualType Canon, Decl *AssociatedDecl, unsigned Index, bool Final,
4041 const TemplateArgument &ArgPack)
4042 : Type(SubstTemplateTypeParmPack, Canon,
4043 TypeDependence::DependentInstantiation |
4044 TypeDependence::UnexpandedPack),
4045 Arguments(ArgPack.pack_begin()),
4046 AssociatedDeclAndFinal(AssociatedDecl, Final) {
4048 SubstTemplateTypeParmPackTypeBits.NumArgs = ArgPack.pack_size();
4049 assert(AssociatedDecl != nullptr);
4050}
4051
4053 return AssociatedDeclAndFinal.getPointer();
4054}
4055
4057 return AssociatedDeclAndFinal.getInt();
4058}
4059
4062 return ::getReplacedParameter(getAssociatedDecl(), getIndex());
4063}
4064
4067}
4068
4070 return TemplateArgument(llvm::ArrayRef(Arguments, getNumArgs()));
4071}
4072
4073void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID) {
4075}
4076
4077void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID,
4078 const Decl *AssociatedDecl,
4079 unsigned Index, bool Final,
4080 const TemplateArgument &ArgPack) {
4081 ID.AddPointer(AssociatedDecl);
4082 ID.AddInteger(Index);
4083 ID.AddBoolean(Final);
4084 ID.AddInteger(ArgPack.pack_size());
4085 for (const auto &P : ArgPack.pack_elements())
4086 ID.AddPointer(P.getAsType().getAsOpaquePtr());
4087}
4088
4091 return anyDependentTemplateArguments(Args.arguments(), Converted);
4092}
4093
4096 for (const TemplateArgument &Arg : Converted)
4097 if (Arg.isDependent())
4098 return true;
4099 return false;
4100}
4101
4104 for (const TemplateArgumentLoc &ArgLoc : Args) {
4105 if (ArgLoc.getArgument().isInstantiationDependent())
4106 return true;
4107 }
4108 return false;
4109}
4110
4111TemplateSpecializationType::TemplateSpecializationType(
4113 QualType AliasedType)
4114 : Type(TemplateSpecialization, Canon.isNull() ? QualType(this, 0) : Canon,
4115 (Canon.isNull()
4116 ? TypeDependence::DependentInstantiation
4117 : toSemanticDependence(Canon->getDependence())) |
4118 (toTypeDependence(T.getDependence()) &
4119 TypeDependence::UnexpandedPack)),
4120 Template(T) {
4121 TemplateSpecializationTypeBits.NumArgs = Args.size();
4122 TemplateSpecializationTypeBits.TypeAlias = !AliasedType.isNull();
4123
4124 assert(!T.getAsDependentTemplateName() &&
4125 "Use DependentTemplateSpecializationType for dependent template-name");
4126 assert((T.getKind() == TemplateName::Template ||
4130 "Unexpected template name for TemplateSpecializationType");
4131
4132 auto *TemplateArgs = reinterpret_cast<TemplateArgument *>(this + 1);
4133 for (const TemplateArgument &Arg : Args) {
4134 // Update instantiation-dependent, variably-modified, and error bits.
4135 // If the canonical type exists and is non-dependent, the template
4136 // specialization type can be non-dependent even if one of the type
4137 // arguments is. Given:
4138 // template<typename T> using U = int;
4139 // U<T> is always non-dependent, irrespective of the type T.
4140 // However, U<Ts> contains an unexpanded parameter pack, even though
4141 // its expansion (and thus its desugared type) doesn't.
4142 addDependence(toTypeDependence(Arg.getDependence()) &
4143 ~TypeDependence::Dependent);
4144 if (Arg.getKind() == TemplateArgument::Type)
4145 addDependence(Arg.getAsType()->getDependence() &
4146 TypeDependence::VariablyModified);
4147 new (TemplateArgs++) TemplateArgument(Arg);
4148 }
4149
4150 // Store the aliased type if this is a type alias template specialization.
4151 if (isTypeAlias()) {
4152 auto *Begin = reinterpret_cast<TemplateArgument *>(this + 1);
4153 *reinterpret_cast<QualType *>(Begin + Args.size()) = AliasedType;
4154 }
4155}
4156
4158 assert(isTypeAlias() && "not a type alias template specialization");
4159 return *reinterpret_cast<const QualType *>(template_arguments().end());
4160}
4161
4162void TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
4163 const ASTContext &Ctx) {
4164 Profile(ID, Template, template_arguments(), Ctx);
4165 if (isTypeAlias())
4166 getAliasedType().Profile(ID);
4167}
4168
4169void
4170TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
4171 TemplateName T,
4173 const ASTContext &Context) {
4174 T.Profile(ID);
4175 for (const TemplateArgument &Arg : Args)
4176 Arg.Profile(ID, Context);
4177}
4178
4181 if (!hasNonFastQualifiers())
4183
4184 return Context.getQualifiedType(QT, *this);
4185}
4186
4188QualifierCollector::apply(const ASTContext &Context, const Type *T) const {
4189 if (!hasNonFastQualifiers())
4190 return QualType(T, getFastQualifiers());
4191
4192 return Context.getQualifiedType(T, *this);
4193}
4194
4195void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID,
4196 QualType BaseType,
4197 ArrayRef<QualType> typeArgs,
4199 bool isKindOf) {
4200 ID.AddPointer(BaseType.getAsOpaquePtr());
4201 ID.AddInteger(typeArgs.size());
4202 for (auto typeArg : typeArgs)
4203 ID.AddPointer(typeArg.getAsOpaquePtr());
4204 ID.AddInteger(protocols.size());
4205 for (auto *proto : protocols)
4206 ID.AddPointer(proto);
4207 ID.AddBoolean(isKindOf);
4208}
4209
4210void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) {
4214}
4215
4216void ObjCTypeParamType::Profile(llvm::FoldingSetNodeID &ID,
4217 const ObjCTypeParamDecl *OTPDecl,
4218 QualType CanonicalType,
4219 ArrayRef<ObjCProtocolDecl *> protocols) {
4220 ID.AddPointer(OTPDecl);
4221 ID.AddPointer(CanonicalType.getAsOpaquePtr());
4222 ID.AddInteger(protocols.size());
4223 for (auto *proto : protocols)
4224 ID.AddPointer(proto);
4225}
4226
4227void ObjCTypeParamType::Profile(llvm::FoldingSetNodeID &ID) {
4230}
4231
4232namespace {
4233
4234/// The cached properties of a type.
4235class CachedProperties {
4236 Linkage L;
4237 bool local;
4238
4239public:
4240 CachedProperties(Linkage L, bool local) : L(L), local(local) {}
4241
4242 Linkage getLinkage() const { return L; }
4243 bool hasLocalOrUnnamedType() const { return local; }
4244
4245 friend CachedProperties merge(CachedProperties L, CachedProperties R) {
4246 Linkage MergedLinkage = minLinkage(L.L, R.L);
4247 return CachedProperties(MergedLinkage, L.hasLocalOrUnnamedType() ||
4248 R.hasLocalOrUnnamedType());
4249 }
4250};
4251
4252} // namespace
4253
4254static CachedProperties computeCachedProperties(const Type *T);
4255
4256namespace clang {
4257
4258/// The type-property cache. This is templated so as to be
4259/// instantiated at an internal type to prevent unnecessary symbol
4260/// leakage.
4261template <class Private> class TypePropertyCache {
4262public:
4263 static CachedProperties get(QualType T) {
4264 return get(T.getTypePtr());
4265 }
4266
4267 static CachedProperties get(const Type *T) {
4268 ensure(T);
4269 return CachedProperties(T->TypeBits.getLinkage(),
4270 T->TypeBits.hasLocalOrUnnamedType());
4271 }
4272
4273 static void ensure(const Type *T) {
4274 // If the cache is valid, we're okay.
4275 if (T->TypeBits.isCacheValid()) return;
4276
4277 // If this type is non-canonical, ask its canonical type for the
4278 // relevant information.
4279 if (!T->isCanonicalUnqualified()) {
4280 const Type *CT = T->getCanonicalTypeInternal().getTypePtr();
4281 ensure(CT);
4282 T->TypeBits.CacheValid = true;
4283 T->TypeBits.CachedLinkage = CT->TypeBits.CachedLinkage;
4284 T->TypeBits.CachedLocalOrUnnamed = CT->TypeBits.CachedLocalOrUnnamed;
4285 return;
4286 }
4287
4288 // Compute the cached properties and then set the cache.
4289 CachedProperties Result = computeCachedProperties(T);
4290 T->TypeBits.CacheValid = true;
4291 T->TypeBits.CachedLinkage = llvm::to_underlying(Result.getLinkage());
4292 T->TypeBits.CachedLocalOrUnnamed = Result.hasLocalOrUnnamedType();
4293 }
4294};
4295
4296} // namespace clang
4297
4298// Instantiate the friend template at a private class. In a
4299// reasonable implementation, these symbols will be internal.
4300// It is terrible that this is the best way to accomplish this.
4301namespace {
4302
4303class Private {};
4304
4305} // namespace
4306
4308
4309static CachedProperties computeCachedProperties(const Type *T) {
4310 switch (T->getTypeClass()) {
4311#define TYPE(Class,Base)
4312#define NON_CANONICAL_TYPE(Class,Base) case Type::Class:
4313#include "clang/AST/TypeNodes.inc"
4314 llvm_unreachable("didn't expect a non-canonical type here");
4315
4316#define TYPE(Class,Base)
4317#define DEPENDENT_TYPE(Class,Base) case Type::Class:
4318#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class:
4319#include "clang/AST/TypeNodes.inc"
4320 // Treat instantiation-dependent types as external.
4321 if (!T->isInstantiationDependentType()) T->dump();
4322 assert(T->isInstantiationDependentType());
4323 return CachedProperties(Linkage::External, false);
4324
4325 case Type::Auto:
4326 case Type::DeducedTemplateSpecialization:
4327 // Give non-deduced 'auto' types external linkage. We should only see them
4328 // here in error recovery.
4329 return CachedProperties(Linkage::External, false);
4330
4331 case Type::BitInt:
4332 case Type::Builtin:
4333 // C++ [basic.link]p8:
4334 // A type is said to have linkage if and only if:
4335 // - it is a fundamental type (3.9.1); or
4336 return CachedProperties(Linkage::External, false);
4337
4338 case Type::Record:
4339 case Type::Enum: {
4340 const TagDecl *Tag = cast<TagType>(T)->getDecl();
4341
4342 // C++ [basic.link]p8:
4343 // - it is a class or enumeration type that is named (or has a name
4344 // for linkage purposes (7.1.3)) and the name has linkage; or
4345 // - it is a specialization of a class template (14); or
4346 Linkage L = Tag->getLinkageInternal();
4347 bool IsLocalOrUnnamed =
4349 !Tag->hasNameForLinkage();
4350 return CachedProperties(L, IsLocalOrUnnamed);
4351 }
4352
4353 // C++ [basic.link]p8:
4354 // - it is a compound type (3.9.2) other than a class or enumeration,
4355 // compounded exclusively from types that have linkage; or
4356 case Type::Complex:
4357 return Cache::get(cast<ComplexType>(T)->getElementType());
4358 case Type::Pointer:
4359 return Cache::get(cast<PointerType>(T)->getPointeeType());
4360 case Type::BlockPointer:
4361 return Cache::get(cast<BlockPointerType>(T)->getPointeeType());
4362 case Type::LValueReference:
4363 case Type::RValueReference:
4364 return Cache::get(cast<ReferenceType>(T)->getPointeeType());
4365 case Type::MemberPointer: {
4366 const auto *MPT = cast<MemberPointerType>(T);
4367 return merge(Cache::get(MPT->getClass()),
4368 Cache::get(MPT->getPointeeType()));
4369 }
4370 case Type::ConstantArray:
4371 case Type::IncompleteArray:
4372 case Type::VariableArray:
4373 return Cache::get(cast<ArrayType>(T)->getElementType());
4374 case Type::Vector:
4375 case Type::ExtVector:
4376 return Cache::get(cast<VectorType>(T)->getElementType());
4377 case Type::ConstantMatrix:
4378 return Cache::get(cast<ConstantMatrixType>(T)->getElementType());
4379 case Type::FunctionNoProto:
4380 return Cache::get(cast<FunctionType>(T)->getReturnType());
4381 case Type::FunctionProto: {
4382 const auto *FPT = cast<FunctionProtoType>(T);
4383 CachedProperties result = Cache::get(FPT->getReturnType());
4384 for (const auto &ai : FPT->param_types())
4385 result = merge(result, Cache::get(ai));
4386 return result;
4387 }
4388 case Type::ObjCInterface: {
4389 Linkage L = cast<ObjCInterfaceType>(T)->getDecl()->getLinkageInternal();
4390 return CachedProperties(L, false);
4391 }
4392 case Type::ObjCObject:
4393 return Cache::get(cast<ObjCObjectType>(T)->getBaseType());
4394 case Type::ObjCObjectPointer:
4395 return Cache::get(cast<ObjCObjectPointerType>(T)->getPointeeType());
4396 case Type::Atomic:
4397 return Cache::get(cast<AtomicType>(T)->getValueType());
4398 case Type::Pipe:
4399 return Cache::get(cast<PipeType>(T)->getElementType());
4400 }
4401
4402 llvm_unreachable("unhandled type class");
4403}
4404
4405/// Determine the linkage of this type.
4407 Cache::ensure(this);
4408 return TypeBits.getLinkage();
4409}
4410
4412 Cache::ensure(this);
4413 return TypeBits.hasLocalOrUnnamedType();
4414}
4415
4417 switch (T->getTypeClass()) {
4418#define TYPE(Class,Base)
4419#define NON_CANONICAL_TYPE(Class,Base) case Type::Class:
4420#include "clang/AST/TypeNodes.inc"
4421 llvm_unreachable("didn't expect a non-canonical type here");
4422
4423#define TYPE(Class,Base)
4424#define DEPENDENT_TYPE(Class,Base) case Type::Class:
4425#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class:
4426#include "clang/AST/TypeNodes.inc"
4427 // Treat instantiation-dependent types as external.
4428 assert(T->isInstantiationDependentType());
4429 return LinkageInfo::external();
4430
4431 case Type::BitInt:
4432 case Type::Builtin:
4433 return LinkageInfo::external();
4434
4435 case Type::Auto:
4436 case Type::DeducedTemplateSpecialization:
4437 return LinkageInfo::external();
4438
4439 case Type::Record:
4440 case Type::Enum:
4441 return getDeclLinkageAndVisibility(cast<TagType>(T)->getDecl());
4442
4443 case Type::Complex:
4444 return computeTypeLinkageInfo(cast<ComplexType>(T)->getElementType());
4445 case Type::Pointer:
4446 return computeTypeLinkageInfo(cast<PointerType>(T)->getPointeeType());
4447 case Type::BlockPointer:
4448 return computeTypeLinkageInfo(cast<BlockPointerType>(T)->getPointeeType());
4449 case Type::LValueReference:
4450 case Type::RValueReference:
4451 return computeTypeLinkageInfo(cast<ReferenceType>(T)->getPointeeType());
4452 case Type::MemberPointer: {
4453 const auto *MPT = cast<MemberPointerType>(T);
4454 LinkageInfo LV = computeTypeLinkageInfo(MPT->getClass());
4455 LV.merge(computeTypeLinkageInfo(MPT->getPointeeType()));
4456 return LV;
4457 }
4458 case Type::ConstantArray:
4459 case Type::IncompleteArray:
4460 case Type::VariableArray:
4461 return computeTypeLinkageInfo(cast<ArrayType>(T)->getElementType());
4462 case Type::Vector:
4463 case Type::ExtVector:
4464 return computeTypeLinkageInfo(cast<VectorType>(T)->getElementType());
4465 case Type::ConstantMatrix:
4467 cast<ConstantMatrixType>(T)->getElementType());
4468 case Type::FunctionNoProto:
4469 return computeTypeLinkageInfo(cast<FunctionType>(T)->getReturnType());
4470 case Type::FunctionProto: {
4471 const auto *FPT = cast<FunctionProtoType>(T);
4472 LinkageInfo LV = computeTypeLinkageInfo(FPT->getReturnType());
4473 for (const auto &ai : FPT->param_types())
4475 return LV;
4476 }
4477 case Type::ObjCInterface:
4478 return getDeclLinkageAndVisibility(cast<ObjCInterfaceType>(T)->getDecl());
4479 case Type::ObjCObject:
4480 return computeTypeLinkageInfo(cast<ObjCObjectType>(T)->getBaseType());
4481 case Type::ObjCObjectPointer:
4483 cast<ObjCObjectPointerType>(T)->getPointeeType());
4484 case Type::Atomic:
4485 return computeTypeLinkageInfo(cast<AtomicType>(T)->getValueType());
4486 case Type::Pipe:
4487 return computeTypeLinkageInfo(cast<PipeType>(T)->getElementType());
4488 }
4489
4490 llvm_unreachable("unhandled type class");
4491}
4492
4494 if (!TypeBits.isCacheValid())
4495 return true;
4496
4499 .getLinkage();
4500 return L == TypeBits.getLinkage();
4501}
4502
4504 if (!T->isCanonicalUnqualified())
4506
4508 assert(LV.getLinkage() == T->getLinkage());
4509 return LV;
4510}
4511
4514}
4515
4516std::optional<NullabilityKind> Type::getNullability() const {
4517 QualType Type(this, 0);
4518 while (const auto *AT = Type->getAs<AttributedType>()) {
4519 // Check whether this is an attributed type with nullability
4520 // information.
4521 if (auto Nullability = AT->getImmediateNullability())
4522 return Nullability;
4523
4524 Type = AT->getEquivalentType();
4525 }
4526 return std::nullopt;
4527}
4528
4529bool Type::canHaveNullability(bool ResultIfUnknown) const {
4531
4532 switch (type->getTypeClass()) {
4533 // We'll only see canonical types here.
4534#define NON_CANONICAL_TYPE(Class, Parent) \
4535 case Type::Class: \
4536 llvm_unreachable("non-canonical type");
4537#define TYPE(Class, Parent)
4538#include "clang/AST/TypeNodes.inc"
4539
4540 // Pointer types.
4541 case Type::Pointer:
4542 case Type::BlockPointer:
4543 case Type::MemberPointer:
4544 case Type::ObjCObjectPointer:
4545 return true;
4546
4547 // Dependent types that could instantiate to pointer types.
4548 case Type::UnresolvedUsing:
4549 case Type::TypeOfExpr:
4550 case Type::TypeOf:
4551 case Type::Decltype:
4552 case Type::PackIndexing:
4553 case Type::UnaryTransform:
4554 case Type::TemplateTypeParm:
4555 case Type::SubstTemplateTypeParmPack:
4556 case Type::DependentName:
4557 case Type::DependentTemplateSpecialization:
4558 case Type::Auto:
4559 return ResultIfUnknown;
4560
4561 // Dependent template specializations can instantiate to pointer
4562 // types unless they're known to be specializations of a class
4563 // template.
4564 case Type::TemplateSpecialization:
4565 if (TemplateDecl *templateDecl
4566 = cast<TemplateSpecializationType>(type.getTypePtr())
4567 ->getTemplateName().getAsTemplateDecl()) {
4568 if (isa<ClassTemplateDecl>(templateDecl))
4569 return false;
4570 }
4571 return ResultIfUnknown;
4572
4573 case Type::Builtin:
4574 switch (cast<BuiltinType>(type.getTypePtr())->getKind()) {
4575 // Signed, unsigned, and floating-point types cannot have nullability.
4576#define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
4577#define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
4578#define FLOATING_TYPE(Id, SingletonId) case BuiltinType::Id:
4579#define BUILTIN_TYPE(Id, SingletonId)
4580#include "clang/AST/BuiltinTypes.def"
4581 return false;
4582
4583 // Dependent types that could instantiate to a pointer type.
4584 case BuiltinType::Dependent:
4585 case BuiltinType::Overload:
4586 case BuiltinType::BoundMember:
4587 case BuiltinType::PseudoObject:
4588 case BuiltinType::UnknownAny:
4589 case BuiltinType::ARCUnbridgedCast:
4590 return ResultIfUnknown;
4591
4592 case BuiltinType::Void:
4593 case BuiltinType::ObjCId:
4594 case BuiltinType::ObjCClass:
4595 case BuiltinType::ObjCSel:
4596#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
4597 case BuiltinType::Id:
4598#include "clang/Basic/OpenCLImageTypes.def"
4599#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
4600 case BuiltinType::Id:
4601#include "clang/Basic/OpenCLExtensionTypes.def"
4602 case BuiltinType::OCLSampler:
4603 case BuiltinType::OCLEvent:
4604 case BuiltinType::OCLClkEvent:
4605 case BuiltinType::OCLQueue:
4606 case BuiltinType::OCLReserveID:
4607#define SVE_TYPE(Name, Id, SingletonId) \
4608 case BuiltinType::Id:
4609#include "clang/Basic/AArch64SVEACLETypes.def"
4610#define PPC_VECTOR_TYPE(Name, Id, Size) \
4611 case BuiltinType::Id:
4612#include "clang/Basic/PPCTypes.def"
4613#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
4614#include "clang/Basic/RISCVVTypes.def"
4615#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
4616#include "clang/Basic/WebAssemblyReferenceTypes.def"
4617 case BuiltinType::BuiltinFn:
4618 case BuiltinType::NullPtr:
4619 case BuiltinType::IncompleteMatrixIdx:
4620 case BuiltinType::OMPArraySection:
4621 case BuiltinType::OMPArrayShaping:
4622 case BuiltinType::OMPIterator:
4623 return false;
4624 }
4625 llvm_unreachable("unknown builtin type");
4626
4627 // Non-pointer types.
4628 case Type::Complex:
4629 case Type::LValueReference:
4630 case Type::RValueReference:
4631 case Type::ConstantArray:
4632 case Type::IncompleteArray:
4633 case Type::VariableArray:
4634 case Type::DependentSizedArray:
4635 case Type::DependentVector:
4636 case Type::DependentSizedExtVector:
4637 case Type::Vector:
4638 case Type::ExtVector:
4639 case Type::ConstantMatrix:
4640 case Type::DependentSizedMatrix:
4641 case Type::DependentAddressSpace:
4642 case Type::FunctionProto:
4643 case Type::FunctionNoProto:
4644 case Type::Record:
4645 case Type::DeducedTemplateSpecialization:
4646 case Type::Enum:
4647 case Type::InjectedClassName:
4648 case Type::PackExpansion:
4649 case Type::ObjCObject:
4650 case Type::ObjCInterface:
4651 case Type::Atomic:
4652 case Type::Pipe:
4653 case Type::BitInt:
4654 case Type::DependentBitInt:
4655 return false;
4656 }
4657 llvm_unreachable("bad type kind!");
4658}
4659
4660std::optional<NullabilityKind> AttributedType::getImmediateNullability() const {
4661 if (getAttrKind() == attr::TypeNonNull)
4663 if (getAttrKind() == attr::TypeNullable)
4665 if (getAttrKind() == attr::TypeNullUnspecified)
4667 if (getAttrKind() == attr::TypeNullableResult)
4669 return std::nullopt;
4670}
4671
4672std::optional<NullabilityKind>
4674 QualType AttrTy = T;
4675 if (auto MacroTy = dyn_cast<MacroQualifiedType>(T))
4676 AttrTy = MacroTy->getUnderlyingType();
4677
4678 if (auto attributed = dyn_cast<AttributedType>(AttrTy)) {
4679 if (auto nullability = attributed->getImmediateNullability()) {
4680 T = attributed->getModifiedType();
4681 return nullability;
4682 }
4683 }
4684
4685 return std::nullopt;
4686}
4687
4689 const auto *objcPtr = getAs<ObjCObjectPointerType>();
4690 if (!objcPtr)
4691 return false;
4692
4693 if (objcPtr->isObjCIdType()) {
4694 // id is always okay.
4695 return true;
4696 }
4697
4698 // Blocks are NSObjects.
4699 if (ObjCInterfaceDecl *iface = objcPtr->getInterfaceDecl()) {
4700 if (iface->getIdentifier() != ctx.getNSObjectName())
4701 return false;
4702
4703 // Continue to check qualifiers, below.
4704 } else if (objcPtr->isObjCQualifiedIdType()) {
4705 // Continue to check qualifiers, below.
4706 } else {
4707 return false;
4708 }
4709
4710 // Check protocol qualifiers.
4711 for (ObjCProtocolDecl *proto : objcPtr->quals()) {
4712 // Blocks conform to NSObject and NSCopying.
4713 if (proto->getIdentifier() != ctx.getNSObjectName() &&
4714 proto->getIdentifier() != ctx.getNSCopyingName())
4715 return false;
4716 }
4717
4718 return true;
4719}
4720
4725}
4726
4728 assert(isObjCLifetimeType() &&
4729 "cannot query implicit lifetime for non-inferrable type");
4730
4731 const Type *canon = getCanonicalTypeInternal().getTypePtr();
4732
4733 // Walk down to the base type. We don't care about qualifiers for this.
4734 while (const auto *array = dyn_cast<ArrayType>(canon))
4735 canon = array->getElementType().getTypePtr();
4736
4737 if (const auto *opt = dyn_cast<ObjCObjectPointerType>(canon)) {
4738 // Class and Class<Protocol> don't require retention.
4739 if (opt->getObjectType()->isObjCClass())
4740 return true;
4741 }
4742
4743 return false;
4744}
4745
4747 if (const auto *typedefType = getAs<TypedefType>())
4748 return typedefType->getDecl()->hasAttr<ObjCNSObjectAttr>();
4749 return false;
4750}
4751
4753 if (const auto *typedefType = getAs<TypedefType>())
4754 return typedefType->getDecl()->hasAttr<ObjCIndependentClassAttr>();
4755 return false;
4756}
4757
4759 return isObjCObjectPointerType() ||
4762}
4763
4765 if (isObjCLifetimeType())
4766 return true;
4767 if (const auto *OPT = getAs<PointerType>())
4768 return OPT->getPointeeType()->isObjCIndirectLifetimeType();
4769 if (const auto *Ref = getAs<ReferenceType>())
4770 return Ref->getPointeeType()->isObjCIndirectLifetimeType();
4771 if (const auto *MemPtr = getAs<MemberPointerType>())
4772 return MemPtr->getPointeeType()->isObjCIndirectLifetimeType();
4773 return false;
4774}
4775
4776/// Returns true if objects of this type have lifetime semantics under
4777/// ARC.
4779 const Type *type = this;
4780 while (const ArrayType *array = type->getAsArrayTypeUnsafe())
4781 type = array->getElementType().getTypePtr();
4782 return type->isObjCRetainableType();
4783}
4784
4785/// Determine whether the given type T is a "bridgable" Objective-C type,
4786/// which is either an Objective-C object pointer type or an
4789}
4790
4791/// Determine whether the given type T is a "bridgeable" C type.
4793 const auto *Pointer = getAs<PointerType>();
4794 if (!Pointer)
4795 return false;
4796
4797 QualType Pointee = Pointer->getPointeeType();
4798 return Pointee->isVoidType() || Pointee->isRecordType();
4799}
4800
4801/// Check if the specified type is the CUDA device builtin surface type.
4803 if (const auto *RT = getAs<RecordType>())
4804 return RT->getDecl()->hasAttr<CUDADeviceBuiltinSurfaceTypeAttr>();
4805 return false;
4806}
4807
4808/// Check if the specified type is the CUDA device builtin texture type.
4810 if (const auto *RT = getAs<RecordType>())
4811 return RT->getDecl()->hasAttr<CUDADeviceBuiltinTextureTypeAttr>();
4812 return false;
4813}
4814
4816 if (!isVariablyModifiedType()) return false;
4817
4818 if (const auto *ptr = getAs<PointerType>())
4819 return ptr->getPointeeType()->hasSizedVLAType();
4820 if (const auto *ref = getAs<ReferenceType>())
4821 return ref->getPointeeType()->hasSizedVLAType();
4822 if (const ArrayType *arr = getAsArrayTypeUnsafe()) {
4823 if (isa<VariableArrayType>(arr) &&
4824 cast<VariableArrayType>(arr)->getSizeExpr())
4825 return true;
4826
4827 return arr->getElementType()->hasSizedVLAType();
4828 }
4829
4830 return false;
4831}
4832
4833QualType::DestructionKind QualType::isDestructedTypeImpl(QualType type) {
4834 switch (type.getObjCLifetime()) {
4838 break;
4839
4843 return DK_objc_weak_lifetime;
4844 }
4845
4846 if (const auto *RT =
4847 type->getBaseElementTypeUnsafe()->getAs<RecordType>()) {
4848 const RecordDecl *RD = RT->getDecl();
4849 if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
4850 /// Check if this is a C++ object with a non-trivial destructor.
4851 if (CXXRD->hasDefinition() && !CXXRD->hasTrivialDestructor())
4852 return DK_cxx_destructor;
4853 } else {
4854 /// Check if this is a C struct that is non-trivial to destroy or an array
4855 /// that contains such a struct.
4858 }
4859 }
4860
4861 return DK_none;
4862}
4863
4866}
4867
4869 llvm::APSInt Val, unsigned Scale) {
4870 llvm::FixedPointSemantics FXSema(Val.getBitWidth(), Scale, Val.isSigned(),
4871 /*IsSaturated=*/false,
4872 /*HasUnsignedPadding=*/false);
4873 llvm::APFixedPoint(Val, FXSema).toString(Str);
4874}
4875
4876AutoType::AutoType(QualType DeducedAsType, AutoTypeKeyword Keyword,
4877 TypeDependence ExtraDependence, QualType Canon,
4878 ConceptDecl *TypeConstraintConcept,
4879 ArrayRef<TemplateArgument> TypeConstraintArgs)
4880 : DeducedType(Auto, DeducedAsType, ExtraDependence, Canon) {
4881 AutoTypeBits.Keyword = llvm::to_underlying(Keyword);
4882 AutoTypeBits.NumArgs = TypeConstraintArgs.size();
4883 this->TypeConstraintConcept = TypeConstraintConcept;
4884 assert(TypeConstraintConcept || AutoTypeBits.NumArgs == 0);
4885 if (TypeConstraintConcept) {
4886 auto *ArgBuffer =
4887 const_cast<TemplateArgument *>(getTypeConstraintArguments().data());
4888 for (const TemplateArgument &Arg : TypeConstraintArgs) {
4889 // We only syntactically depend on the constraint arguments. They don't
4890 // affect the deduced type, only its validity.
4891 addDependence(
4892 toSyntacticDependence(toTypeDependence(Arg.getDependence())));
4893
4894 new (ArgBuffer++) TemplateArgument(Arg);
4895 }
4896 }
4897}
4898
4899void AutoType::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4900 QualType Deduced, AutoTypeKeyword Keyword,
4901 bool IsDependent, ConceptDecl *CD,
4902 ArrayRef<TemplateArgument> Arguments) {
4903 ID.AddPointer(Deduced.getAsOpaquePtr());
4904 ID.AddInteger((unsigned)Keyword);
4905 ID.AddBoolean(IsDependent);
4906 ID.AddPointer(CD);
4907 for (const TemplateArgument &Arg : Arguments)
4908 Arg.Profile(ID, Context);
4909}
4910
4911void AutoType::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
4912 Profile(ID, Context, getDeducedType(), getKeyword(), isDependentType(),
4914}
Defines the clang::ASTContext interface.
StringRef P
Provides definitions for the various language-specific address spaces.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the ExceptionSpecificationType enumeration and various utility functions.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
llvm::MachO::Record Record
Definition: MachO.h:28
static bool isRecordType(QualType T)
Defines various enumerations that describe declaration and type specifiers.
Defines the TargetCXXABI class, which abstracts details of the C++ ABI that we're targeting.
static TagDecl * getInterestingTagDecl(TagDecl *decl)
Definition: Type.cpp:3893
#define SUGARED_TYPE_CLASS(Class)
Definition: Type.cpp:899
static bool HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl)
Definition: Type.cpp:2700
static const TemplateTypeParmDecl * getReplacedParameter(Decl *D, unsigned Index)
Definition: Type.cpp:4010
static bool isTriviallyCopyableTypeImpl(const QualType &type, const ASTContext &Context, bool IsCopyConstructible)
Definition: Type.cpp:2620
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:528
#define TRIVIAL_TYPE_CLASS(Class)
Definition: Type.cpp:897
static CachedProperties computeCachedProperties(const Type *T)
Definition: Type.cpp:4309
C Language Family Type Representation.
SourceLocation Begin
Defines the clang::Visibility enumeration and various utility functions.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
BuiltinVectorTypeInfo getBuiltinVectorTypeInfo(const BuiltinType *VecTy) const
Returns the element type, element count and number of vectors (in case of tuple) for a builtin vector...
QualType getAtomicType(QualType T) const
Return the uniqued reference to the atomic type for the specified type.
QualType getParenType(QualType NamedType) const
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type.
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType) const
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent, bool IsPack=false, ConceptDecl *TypeConstraintConcept=nullptr, ArrayRef< TemplateArgument > TypeConstraintArgs={}) const
C++11 deduced auto type.
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl.
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
QualType getVariableArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a variable array of the specified element type.
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
const LangOptions & getLangOpts() const
Definition: ASTContext.h:770
QualType applyObjCProtocolQualifiers(QualType type, ArrayRef< ObjCProtocolDecl * > protocols, bool &hasError, bool allowOnPointerType=false) const
Apply Objective-C protocol qualifiers to the given type.
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
bool hasUniqueObjectRepresentations(QualType Ty, bool CheckIfTriviallyCopyable=true) const
Return true if the specified type has unique object representations according to (C++17 [meta....
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
CanQualType ObjCBuiltinIdTy
Definition: ASTContext.h:1117
IdentifierInfo * getNSObjectName() const
Retrieve the identifier 'NSObject'.
Definition: ASTContext.h:1887
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
QualType getAdjustedType(QualType Orig, QualType New) const
Return the uniqued reference to a type adjusted from the original type to a new type.
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2141
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
QualType getObjCObjectType(QualType Base, ObjCProtocolDecl *const *Protocols, unsigned NumProtocols) const
Legacy interface: cannot provide type arguments or __kindof.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:2315
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
CanQualType UnsignedCharTy
Definition: ASTContext.h:1096
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:1553
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type.
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size.
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:752
QualType getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex) const
Retrieve a substitution-result type.
QualType getIncompleteArrayType(QualType EltTy, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return a unique reference to the type for an incomplete array of the specified element type.
QualType getConstantMatrixType(QualType ElementType, unsigned NumRows, unsigned NumColumns) const
Return the unique reference to the matrix type of the specified element type and size.
IdentifierInfo * getNSCopyingName()
Retrieve the identifier 'NSCopying'.
Definition: ASTContext.h:1896
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: Type.h:2927
QualType getAdjustedType() const
Definition: Type.h:2941
QualType getOriginalType() const
Definition: Type.h:2940
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3147
ArraySizeModifier getSizeModifier() const
Definition: Type.h:3161
QualType getElementType() const
Definition: Type.h:3159
ArrayType(TypeClass tc, QualType et, QualType can, ArraySizeModifier sm, unsigned tq, const Expr *sz=nullptr)
Definition: Type.cpp:139
unsigned getIndexTypeCVRQualifiers() const
Definition: Type.h:3169
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
Definition: Type.h:6732
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:5147
QualType getModifiedType() const
Definition: Type.h:5169
bool isCallingConv() const
Definition: Type.cpp:3973
std::optional< NullabilityKind > getImmediateNullability() const
Definition: Type.cpp:4660
static std::optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
Definition: Type.cpp:4673
bool isMSTypeSpec() const
Definition: Type.cpp:3956
QualType getEquivalentType() const
Definition: Type.h:5170
Kind getAttrKind() const
Definition: Type.h:5165
bool isWebAssemblyFuncrefSpec() const
Definition: Type.cpp:3969
bool isQualifier() const
Does this attribute behave like a type qualifier?
Definition: Type.cpp:3932
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:5524
ArrayRef< TemplateArgument > getTypeConstraintArguments() const
Definition: Type.h:5534
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.cpp:4911
ConceptDecl * getTypeConstraintConcept() const
Definition: Type.h:5539
AutoTypeKeyword getKeyword() const
Definition: Type.h:5555
BitIntType(bool isUnsigned, unsigned NumBits)
Definition: Type.cpp:364
Pointer to a block type.
Definition: Type.h:2978
QualType getPointeeType() const
Definition: Type.h:2990
This class is used for builtin types like 'int'.
Definition: Type.h:2740
Kind getKind() const
Definition: Type.h:2782
StringRef getName(const PrintingPolicy &Policy) const
Definition: Type.cpp:3220
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
bool mayBeNonDynamicClass() const
Definition: DeclCXX.h:596
CXXRecordDecl * getMostRecentNonInjectedDecl()
Definition: DeclCXX.h:549
bool mayBeDynamicClass() const
Definition: DeclCXX.h:590
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:185
Complex values, per C99 6.2.5p11.
Definition: Type.h:2845
QualType getElementType() const
Definition: Type.h:2855
Declaration of a C++20 concept.
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3186
const llvm::APInt & getSize() const
Definition: Type.h:3207
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:162
static unsigned getMaxSizeBits(const ASTContext &Context)
Determine the maximum number of active bits that an array's size can require, which limits the maximu...
Definition: Type.cpp:202
const Expr * getSizeExpr() const
Definition: Type.h:3208
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
Definition: Type.h:3228
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1072
llvm::APSInt getResultAsAPSInt() const
Definition: Expr.cpp:401
Represents a concrete matrix type with constant number of rows and columns.
Definition: Type.h:3710
unsigned getNumColumns() const
Returns the number of columns in the matrix.
Definition: Type.h:3731
unsigned getNumRows() const
Returns the number of rows in the matrix.
Definition: Type.h:3728
ConstantMatrixType(QualType MatrixElementType, unsigned NRows, unsigned NColumns, QualType CanonElementType)
Definition: Type.cpp:324
Represents a pointer type decayed from an array or function type.
Definition: Type.h:2961
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1446
ASTContext & getParentASTContext() const
Definition: DeclBase.h:2105
bool isFunctionOrMethod() const
Definition: DeclBase.h:2128
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
bool isInStdNamespace() const
Definition: DeclBase.cpp:403
bool isFunctionOrFunctionTemplate() const
Whether this declaration is a function or function template.
Definition: DeclBase.h:1119
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
DeclContext * getDeclContext()
Definition: DeclBase.h:453
bool hasAttr() const
Definition: DeclBase.h:582
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:978
Represents the type decltype(expr) (C++11).
Definition: Type.h:4901
QualType desugar() const
Remove a single level of sugar.
Definition: Type.cpp:3804
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.cpp:3802
DecltypeType(Expr *E, QualType underlyingType, QualType can=QualType())
Definition: Type.cpp:3790
QualType getUnderlyingType() const
Definition: Type.h:4912
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
Definition: Type.h:5490
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it has not been deduced.
Definition: Type.h:5511
bool isDeduced() const
Definition: Type.h:5512
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:3424
Expr * getNumBitsExpr() const
Definition: Type.cpp:377
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:6830
DependentBitIntType(bool IsUnsigned, Expr *NumBits)
Definition: Type.cpp:368
bool isUnsigned() const
Definition: Type.cpp:373
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:4933
DependentDecltypeType(Expr *E, QualType UnderlyingTpe)
Definition: Type.cpp:3811
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:3381
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3442
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:3467
QualType getElementType() const
Definition: Type.h:3457
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition: Type.h:3769
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:3789
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:6074
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:4854
DependentUnaryTransformType(const ASTContext &C, QualType BaseType, UTTKind UKind)
Definition: Type.cpp:3882
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:3589
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:5914
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:5952
Represents an enum.
Definition: Decl.h:3832
bool isComplete() const
Returns true if this can be considered a complete type.
Definition: Decl.h:4051
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5118
This represents one expression.
Definition: Expr.h:110
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:175
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:192
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition: Expr.h:221
QualType getType() const
Definition: Expr.h:142
ExprDependence getDependence() const
Definition: Expr.h:162
ExtVectorType - Extended vector type.
Definition: Type.h:3604
Represents a member of a struct/union/class.
Definition: Decl.h:3025
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition: DeclFriend.h:54
Represents a function declaration or definition.
Definition: Decl.h:1959
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4154
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4199
bool hasDependentExceptionSpec() const
Return whether this function has a dependent exception spec.
Definition: Type.cpp:3588
param_type_iterator param_type_begin() const
Definition: Type.h:4591
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:4458
bool isTemplateVariadic() const
Determines whether this function prototype contains a parameter pack at the end.
Definition: Type.cpp:3642
unsigned getNumParams() const
Definition: Type.h:4432
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition: Type.h:4571
QualType getParamType(unsigned i) const
Definition: Type.h:4434
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
Definition: Type.h:4509
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
Definition: Type.cpp:3706
unsigned getNumExceptions() const
Return the number of types in the exception specification.
Definition: Type.h:4501
CanThrowResult canThrow() const
Determine whether this function type has a non-throwing exception specification.
Definition: Type.cpp:3609
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:4443
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
Definition: Type.h:4516
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:4439
ArrayRef< QualType > exceptions() const
Definition: Type.h:4601
bool hasInstantiationDependentExceptionSpec() const
Return whether this function has an instantiation-dependent exception spec.
Definition: Type.cpp:3600
A class which abstracts out some details necessary for making a call.
Definition: Type.h:3910
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3799
ExtInfo getExtInfo() const
Definition: Type.h:4128
static StringRef getNameForCallConv(CallingConv CC)
Definition: Type.cpp:3419
QualType getReturnType() const
Definition: Type.h:4116
One of these records is kept for each identifier that is lexed.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
Represents a C array with an unspecified size.
Definition: Type.h:3246
CXXRecordDecl * getDecl() const
Definition: Type.cpp:4002
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3053
LinkageInfo computeTypeLinkageInfo(const Type *T)
Definition: Type.cpp:4416
LinkageInfo getTypeLinkageAndVisibility(const Type *T)
Definition: Type.cpp:4503
LinkageInfo getDeclLinkageAndVisibility(const NamedDecl *D)
Definition: Decl.cpp:1614
static LinkageInfo external()
Definition: Visibility.h:72
Linkage getLinkage() const
Definition: Visibility.h:88
void merge(LinkageInfo other)
Merge both linkage and visibility.
Definition: Visibility.h:137
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
Definition: Type.h:4785
QualType desugar() const
Definition: Type.cpp:3743
QualType getModifiedType() const
Return this attributed type's modified type with no qualifiers attached to it.
Definition: Type.cpp:3745
QualType getUnderlyingType() const
Definition: Type.h:4801
const IdentifierInfo * getMacroIdentifier() const
Definition: Type.h:4800
Represents a matrix type, as defined in the Matrix Types clang extensions.
Definition: Type.h:3674
QualType getElementType() const
Returns type of the elements being stored in the matrix.
Definition: Type.h:3688
MatrixType(QualType ElementTy, QualType CanonElementTy)
QualType ElementType
The element type of the matrix.
Definition: Type.h:3679
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3089
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Definition: Type.cpp:4864
QualType getPointeeType() const
Definition: Type.h:3105
const Type * getClass() const
Definition: Type.h:3119
This represents a decl that may have a name.
Definition: Decl.h:249
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition: Decl.cpp:1169
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2323
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:2368
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition: DeclObjC.h:2373
Represents an ObjC class declaration.
Definition: DeclObjC.h:1150
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameters of this class.
Definition: DeclObjC.cpp:321
const ObjCObjectType * getSuperClassType() const
Retrieve the superclass type.
Definition: DeclObjC.h:1561
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1538
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:6495
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
Definition: Type.cpp:849
Represents a pointer to an Objective C object.
Definition: Type.h:6551
const ObjCObjectPointerType * stripObjCKindOfTypeAndQuals(const ASTContext &ctx) const
Strip off the Objective-C "kindof" type and (with it) any protocol qualifiers.
Definition: Type.cpp:856
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:6588
QualType getSuperClassType() const
Retrieve the type of the superclass of this object pointer type.
Definition: Type.cpp:1745
bool qual_empty() const
Definition: Type.h:6680
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:6563
ObjCInterfaceDecl * getInterfaceDecl() const
If this pointer points to an Objective @interface type, gets the declaration for that interface.
Definition: Type.h:6603
const ObjCInterfaceType * getInterfaceType() const
If this pointer points to an Objective C @interface type, gets the type for that interface.
Definition: Type.cpp:1736
bool isKindOfType() const
Whether this is a "__kindof" type.
Definition: Type.h:6637
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.cpp:4210
Represents a class type in Objective C.
Definition: Type.h:6297
bool isKindOfTypeAsWritten() const
Whether this is a "__kindof" type as written.
Definition: Type.h:6412
bool isSpecialized() const
Determine whether this object type is "specialized", meaning that it has type arguments.
Definition: Type.cpp:778
ObjCObjectType(QualType Canonical, QualType Base, ArrayRef< QualType > typeArgs, ArrayRef< ObjCProtocolDecl * > protocols, bool isKindOf)
Definition: Type.cpp:756
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments of this object type as they were written.
Definition: Type.h:6407
QualType getBaseType() const
Gets the base type of this object type.
Definition: Type.h:6359
bool isKindOfType() const
Whether this ia a "__kindof" type (semantically).
Definition: Type.cpp:814
bool isSpecializedAsWritten() const
Determine whether this object type was written with type arguments.
Definition: Type.h:6390
ArrayRef< QualType > getTypeArgs() const
Retrieve the type arguments of this object type (semantically).
Definition: Type.cpp:796
bool isUnspecialized() const
Determine whether this object type is "unspecialized", meaning that it has no type arguments.
Definition: Type.h:6396
QualType stripObjCKindOfTypeAndQuals(const ASTContext &ctx) const
Strip off the Objective-C "kindof" type and (with it) any protocol qualifiers.
Definition: Type.cpp:831
void computeSuperClassTypeSlow() const
Definition: Type.cpp:1666
ObjCInterfaceDecl * getInterface() const
Gets the interface declaration for this object type, if the base type really is an interface.
Definition: Type.h:6530
QualType getSuperClassType() const
Retrieve the type of the superclass of this object type.
Definition: Type.h:6423
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2079
void initialize(ArrayRef< ObjCProtocolDecl * > protocols)
Definition: Type.h:6182
ArrayRef< ObjCProtocolDecl * > getProtocols() const
Retrieve all of the protocol qualifiers.
Definition: Type.h:6214
unsigned getNumProtocols() const
Return the number of qualifying protocols in this type, or 0 if there are none.
Definition: Type.h:6203
qual_iterator qual_end() const
Definition: Type.h:6197
qual_iterator qual_begin() const
Definition: Type.h:6196
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:578
unsigned getIndex() const
Retrieve the index into its type parameter list.
Definition: DeclObjC.h:635
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition: DeclObjC.h:658
unsigned size() const
Determine the number of type parameters in this list.
Definition: DeclObjC.h:685
Represents a type parameter type in Objective C.
Definition: Type.h:6223
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.cpp:4227
ObjCTypeParamDecl * getDecl() const
Definition: Type.h:6265
Represents a pack expansion of types.
Definition: Type.h:6112
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Definition: Type.h:6133
PackIndexingType(const ASTContext &Context, QualType Canonical, QualType Pattern, Expr *IndexExpr, ArrayRef< QualType > Expansions={})
Definition: Type.cpp:3819
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4988
Expr * getIndexExpr() const
Definition: Type.h:4960
std::optional< unsigned > getSelectedIndex() const
Definition: Type.cpp:3832
Sugar for parentheses used when specifying types.
Definition: Type.h:2872
QualType getInnerType() const
Definition: Type.h:2881
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2898
QualType getPointeeType() const
Definition: Type.h:2908
A (possibly-)qualified type.
Definition: Type.h:737
bool isTriviallyCopyableType(const ASTContext &Context) const
Return true if this is a trivially copyable type (C++0x [basic.types]p9)
Definition: Type.cpp:2665
QualType IgnoreParens() const
Returns the specified type after dropping any outer-level parentheses.
Definition: Type.h:1107
QualType withFastQualifiers(unsigned TQs) const
Definition: Type.h:993
bool hasNonTrivialToPrimitiveCopyCUnion() const
Check if this is or contains a C union that is non-trivial to copy, which is a union that has a membe...
Definition: Type.h:7048
bool isWebAssemblyFuncrefType() const
Returns true if it is a WebAssembly Funcref Type.
Definition: Type.cpp:2785
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type.
Definition: Type.cpp:3403
@ DK_cxx_destructor
Definition: Type.h:1313
@ DK_nontrivial_c_struct
Definition: Type.h:1316
@ DK_objc_weak_lifetime
Definition: Type.h:1315
@ DK_objc_strong_lifetime
Definition: Type.h:1314
PrimitiveDefaultInitializeKind
Definition: Type.h:1244
@ PDIK_ARCWeak
The type is an Objective-C retainable pointer type that is qualified with the ARC __weak qualifier.
Definition: Type.h:1256
@ PDIK_Trivial
The type does not fall into any of the following categories.
Definition: Type.h:1248
@ PDIK_ARCStrong
The type is an Objective-C retainable pointer type that is qualified with the ARC __strong qualifier.
Definition: Type.h:1252
@ PDIK_Struct
The type is a struct containing a field whose type is not PCK_Trivial.
Definition: Type.h:1259
bool mayBeDynamicClass() const
Returns true if it is a class and it might be dynamic.
Definition: Type.cpp:95
bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const
Definition: Type.cpp:2759
const IdentifierInfo * getBaseTypeIdentifier() const
Retrieves a pointer to the name of the base type.
Definition: Type.cpp:75
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:1190
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
Definition: Type.h:1088
bool isTriviallyCopyConstructibleType(const ASTContext &Context) const
Return true if this is a trivially copyable type.
Definition: Type.cpp:2670
bool isTrivialType(const ASTContext &Context) const
Return true if this is a trivial type per (C++0x [basic.types]p9)
Definition: Type.cpp:2567
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:804
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:2807
bool isTriviallyRelocatableType(const ASTContext &Context) const
Return true if this is a trivially relocatable type.
Definition: Type.cpp:2676
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6902
LangAS getAddressSpace() const
Return the address space of this type.
Definition: Type.h:7027
bool isConstant(const ASTContext &Ctx) const
Definition: Type.h:897
bool hasNonTrivialToPrimitiveDestructCUnion() const
Check if this is or contains a C union that is non-trivial to destruct, which is a union that has a m...
Definition: Type.h:7042
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:6942
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:2518
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition: Type.h:1229
QualType stripObjCKindOfType(const ASTContext &ctx) const
Strip Objective-C "__kindof" types from the given type.
Definition: Type.cpp:1560
QualType getCanonicalType() const
Definition: Type.h:6954
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:6995
bool isTriviallyEqualityComparableType(const ASTContext &Context) const
Return true if this is a trivially equality comparable type.
Definition: Type.cpp:2743
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:1551
bool isWebAssemblyReferenceType() const
Returns true if it is a WebAssembly Reference Type.
Definition: Type.cpp:2777
SplitQualType getSplitDesugaredType() const
Definition: Type.h:1092
std::optional< NonConstantStorageReason > isNonConstantStorage(const ASTContext &Ctx, bool ExcludeCtor, bool ExcludeDtor)
Determine whether instances of this type can be placed in immutable storage.
Definition: Type.cpp:116
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:6923
bool UseExcessPrecision(const ASTContext &Ctx)
Definition: Type.cpp:1509
PrimitiveDefaultInitializeKind isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C struct types.
Definition: Type.cpp:2791
void * getAsOpaquePtr() const
Definition: Type.h:784
bool isWebAssemblyExternrefType() const
Returns true if it is a WebAssembly Externref Type.
Definition: Type.cpp:2781
QualType getNonPackExpansionType() const
Remove an outer pack expansion type (if any) from this type.
Definition: Type.cpp:3396
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:2946
bool mayBeNotDynamicClass() const
Returns true if it is not a class or if the class might not be dynamic.
Definition: Type.cpp:100
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition: Type.h:6974
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:1544
QualType getAtomicUnqualifiedType() const
Remove all qualifiers including _Atomic.
Definition: Type.cpp:1567
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
Definition: Type.h:1323
bool hasNonTrivialObjCLifetime() const
Definition: Type.h:1233
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
Definition: Type.cpp:2510
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:2825
@ PCK_Struct
The type is a struct containing a field whose type is neither PCK_Trivial nor PCK_VolatileTrivial.
Definition: Type.h:1295
@ PCK_Trivial
The type does not fall into any of the following categories.
Definition: Type.h:1274
@ PCK_ARCStrong
The type is an Objective-C retainable pointer type that is qualified with the ARC __strong qualifier.
Definition: Type.h:1283
@ PCK_VolatileTrivial
The type would be trivial except that it is volatile-qualified.
Definition: Type.h:1279
@ PCK_ARCWeak
The type is an Objective-C retainable pointer type that is qualified with the ARC __weak qualifier.
Definition: Type.h:1287
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Check if this is or contains a C union that is non-trivial to default-initialize, which is a union th...
Definition: Type.h:7036
A qualifier set is used to build a set of qualifiers.
Definition: Type.h:6842
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
Definition: Type.h:6849
QualType apply(const ASTContext &Context, QualType QT) const
Apply the collected qualifiers to the given type.
Definition: Type.cpp:4180
The collection of all-type qualifiers we support.
Definition: Type.h:147
GC getObjCGCAttr() const
Definition: Type.h:326
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
Definition: Type.h:175
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
Definition: Type.h:168
@ OCL_None
There is no lifetime qualification on this type.
Definition: Type.h:164
@ OCL_Weak
Reading or writing from this object requires a barrier call.
Definition: Type.h:178
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
Definition: Type.h:181
bool isStrictSupersetOf(Qualifiers Other) const
Determine whether this set of qualifiers is a strict superset of another set of qualifiers,...
Definition: Type.cpp:60
bool hasNonFastQualifiers() const
Return true if the set contains any qualifiers which require an ExtQuals node to be allocated.
Definition: Type.h:431
void addConsistentQualifiers(Qualifiers qs)
Add the qualifiers from the given set to this set, given that they don't conflict.
Definition: Type.h:478
bool hasAddressSpace() const
Definition: Type.h:377
unsigned getFastQualifiers() const
Definition: Type.h:412
bool hasVolatile() const
Definition: Type.h:274
bool hasObjCGCAttr() const
Definition: Type.h:325
bool hasObjCLifetime() const
Definition: Type.h:351
ObjCLifetime getObjCLifetime() const
Definition: Type.h:352
bool empty() const
Definition: Type.h:440
LangAS getAddressSpace() const
Definition: Type.h:378
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3071
Represents a struct/union/class.
Definition: Decl.h:4133
bool hasNonTrivialToPrimitiveDestructCUnion() const
Definition: Decl.h:4243
bool hasNonTrivialToPrimitiveCopyCUnion() const
Definition: Decl.h:4251
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Definition: Decl.h:4235
bool isNonTrivialToPrimitiveDestroy() const
Definition: Decl.h:4227
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5092
RecordDecl * getDecl() const
Definition: Type.h:5102
bool hasConstFields() const
Recursively check all fields in the record for const-ness.
Definition: Type.cpp:3910
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3009
QualType getPointeeTypeAsWritten() const
Definition: Type.h:3025
bool isSpelledAsLValue() const
Definition: Type.h:3022
Encodes a location in the source.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Definition: Stmt.h:84
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical, bool ProfileLambdaExpr=false) const
Produce a unique representation of the given statement.
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: Type.cpp:4052
IdentifierInfo * getIdentifier() const
Definition: Type.cpp:4065
TemplateArgument getArgumentPack() const
Definition: Type.cpp:4069
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.cpp:4073
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: Type.h:5458
const TemplateTypeParmDecl * getReplacedParameter() const
Gets the template parameter declaration that was substituted for.
Definition: Type.cpp:4061
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:5362
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: Type.h:5383
std::optional< unsigned > getPackIndex() const
Definition: Type.h:5392
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
Definition: Type.h:5374
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: Type.h:5390
const TemplateTypeParmDecl * getReplacedParameter() const
Gets the template parameter declaration that was substituted for.
Definition: Type.cpp:4035
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3549
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3672
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3652
bool isStruct() const
Definition: Decl.h:3752
bool isInterface() const
Definition: Decl.h:3753
bool isClass() const
Definition: Decl.h:3754
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type?
Definition: Decl.h:3773
TagType(TypeClass TC, const TagDecl *D, QualType can)
Definition: Type.cpp:3887
TagDecl * getDecl() const
Definition: Type.cpp:3902
bool isBeingDefined() const
Determines whether this type is in the process of being defined.
Definition: Type.cpp:3906
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
Definition: TargetCXXABI.h:136
Exposes information about the current target.
Definition: TargetInfo.h:213
virtual bool hasLegalHalfType() const
Determine whether _Float16 is supported on this target.
Definition: TargetInfo.h:663
virtual bool hasFullBFloat16Type() const
Determine whether the BFloat type is fully supported on this target, i.e arithemtic operations.
Definition: TargetInfo.h:681
virtual bool hasFloat16Type() const
Determine whether the _Float16 type is supported on this target.
Definition: TargetInfo.h:672
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:1291
virtual bool hasBFloat16Type() const
Determine whether the _BFloat16 type is supported on this target.
Definition: TargetInfo.h:675
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:659
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:524
Represents a template argument.
Definition: TemplateBase.h:61
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:438
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:432
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:394
Represents a C++ template name within the type system.
Definition: TemplateName.h:202
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
void Profile(llvm::FoldingSetNodeID &ID)
NameKind getKind() const
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
Definition: TemplateName.h:247
@ Template
A single template declaration.
Definition: TemplateName.h:219
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:238
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
Definition: TemplateName.h:243
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:5632
QualType getAliasedType() const
Get the aliased type, if this is a specialization of a type alias template.
Definition: Type.cpp:4157
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:5700
bool isTypeAlias() const
Determine if this template specialization type is for a type alias template that has been substituted...
Definition: Type.h:5691
static bool anyInstantiationDependentTemplateArguments(ArrayRef< TemplateArgumentLoc > Args)
Definition: Type.cpp:4102
static bool anyDependentTemplateArguments(ArrayRef< TemplateArgumentLoc > Args, ArrayRef< TemplateArgument > Converted)
Determine whether any of the given template arguments are dependent.
Definition: Type.cpp:4094
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
Definition: Type.cpp:4162
Declaration of a template type parameter.
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:5325
IdentifierInfo * getIdentifier() const
Definition: Type.cpp:4006
TypeOfExprType(Expr *E, TypeOfKind Kind, QualType Can=QualType())
Definition: Type.cpp:3757
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.cpp:3771
Expr * getUnderlyingExpr() const
Definition: Type.h:4826
QualType desugar() const
Remove a single level of sugar.
Definition: Type.cpp:3775
The type-property cache.
Definition: Type.cpp:4261
static void ensure(const Type *T)
Definition: Type.cpp:4273
static CachedProperties get(QualType T)
Definition: Type.cpp:4263
static CachedProperties get(const Type *T)
Definition: Type.cpp:4267
An operation on a type.
Definition: TypeVisitor.h:64
A helper class for Type nodes having an ElaboratedTypeKeyword.
Definition: Type.h:5863
static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec)
Converts a type specifier (DeclSpec::TST) into an elaborated type keyword.
Definition: Type.cpp:3050
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition: Type.cpp:3105
static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword)
Definition: Type.cpp:3125
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
Definition: Type.cpp:3140
static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag)
Converts a TagTypeKind into an elaborated type keyword.
Definition: Type.cpp:3088
static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec)
Converts a type specifier (DeclSpec::TST) into a tag type kind.
Definition: Type.cpp:3070
The base class of the type hierarchy.
Definition: Type.h:1606
bool isSizelessType() const
As an extension, we classify types as one of "sized" or "sizeless"; every type is one or the other.
Definition: Type.cpp:2403
bool isStructureType() const
Definition: Type.cpp:589
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1819
bool isBlockPointerType() const
Definition: Type.h:7162
const ObjCObjectPointerType * getAsObjCQualifiedClassType() const
Definition: Type.cpp:1778
bool isLinkageValid() const
True if the computed linkage is valid.
Definition: Type.cpp:4493
bool isVoidType() const
Definition: Type.h:7443
TypedefBitfields TypedefBits
Definition: Type.h:2010
UsingBitfields UsingBits
Definition: Type.h:2011
const ObjCObjectType * getAsObjCQualifiedInterfaceType() const
Definition: Type.cpp:1754
const ObjCObjectPointerType * getAsObjCQualifiedIdType() const
Definition: Type.cpp:1768
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
Definition: Type.cpp:2104
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:1836
QualType getRVVEltType(const ASTContext &Ctx) const
Returns the representative type for the element of an RVV builtin type.
Definition: Type.cpp:2493
const RecordType * getAsUnionType() const
NOTE: getAs*ArrayType are methods on ASTContext.
Definition: Type.cpp:686
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
Definition: Type.cpp:2829
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
Definition: Type.cpp:2083
bool isComplexType() const
isComplexType() does not include complex integers (a GCC extension).
Definition: Type.cpp:627
ArrayTypeBitfields ArrayTypeBits
Definition: Type.h:2005
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type.
Definition: Type.h:7733
bool isUnsignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is unsigned or an enumeration types whose underlying ...
Definition: Type.cpp:2154
bool isIntegralOrUnscopedEnumerationType() const
Determine whether this type is an integral or unscoped enumeration type.
Definition: Type.cpp:2008
VectorTypeBitfields VectorTypeBits
Definition: Type.h:2018
bool isNothrowT() const
Definition: Type.cpp:2998
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:1958
bool isVoidPointerType() const
Definition: Type.cpp:615
const ComplexType * getAsComplexIntegerType() const
Definition: Type.cpp:644
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6....
Definition: Type.cpp:2289
bool isArrayType() const
Definition: Type.h:7220
bool isCharType() const
Definition: Type.cpp:2026
QualType getLocallyUnqualifiedSingleStepDesugaredType() const
Pull a single level of sugar off of this locally-unqualified type.
Definition: Type.cpp:444
bool isFunctionPointerType() const
Definition: Type.h:7188
bool isObjCARCBridgableType() const
Determine whether the given type T is a "bridgable" Objective-C type, which is either an Objective-C ...
Definition: Type.cpp:4787
bool isArithmeticType() const
Definition: Type.cpp:2218
bool isPointerType() const
Definition: Type.h:7154
TypeOfBitfields TypeOfBits
Definition: Type.h:2009
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:7479
bool isSVESizelessBuiltinType() const
Returns true for SVE scalable vector types.
Definition: Type.cpp:2409
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7724
bool isReferenceType() const
Definition: Type.h:7166
bool isEnumeralType() const
Definition: Type.h:7248
void addDependence(TypeDependence D)
Definition: Type.h:2061
bool isObjCNSObjectType() const
Definition: Type.cpp:4746
const ObjCObjectPointerType * getAsObjCInterfacePointerType() const
Definition: Type.cpp:1796
bool isScalarType() const
Definition: Type.h:7538
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:1804
bool isInterfaceType() const
Definition: Type.cpp:601
bool isVariableArrayType() const
Definition: Type.h:7232
bool isChar8Type() const
Definition: Type.cpp:2042
bool isSizelessBuiltinType() const
Definition: Type.cpp:2370
bool isCUDADeviceBuiltinSurfaceType() const
Check if the type is the CUDA device builtin surface type.
Definition: Type.cpp:4802
bool isSveVLSBuiltinType() const
Determines if this is a sizeless type supported by the 'arm_sve_vector_bits' type attribute,...
Definition: Type.cpp:2436
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
Definition: Type.cpp:1995
bool isElaboratedTypeSpecifier() const
Determine wither this type is a C++ elaborated-type-specifier.
Definition: Type.cpp:3195
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:391
bool isAlignValT() const
Definition: Type.cpp:3007
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:651
LinkageInfo getLinkageAndVisibility() const
Determine the linkage and visibility of this type.
Definition: Type.cpp:4512
bool hasUnsignedIntegerRepresentation() const
Determine whether this type has an unsigned integer representation of some sort, e....
Definition: Type.cpp:2173
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition: Type.cpp:2062
bool isWebAssemblyExternrefType() const
Check if this is a WebAssembly Externref Type.
Definition: Type.cpp:2387
bool canHaveNullability(bool ResultIfUnknown=true) const
Determine whether the given type can have a nullability specifier applied to it, i....
Definition: Type.cpp:4529
QualType getSveEltType(const ASTContext &Ctx) const
Returns the representative type for the element of an SVE builtin type.
Definition: Type.cpp:2462
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:2428
bool isLValueReferenceType() const
Definition: Type.h:7170
bool isBitIntType() const
Definition: Type.h:7378
bool isStructuralType() const
Determine if this type is a structural type, per C++20 [temp.param]p7.
Definition: Type.cpp:2894
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2420
bool isAggregateType() const
Determines whether the type is a C++ aggregate type or C aggregate or union type.
Definition: Type.cpp:2275
bool isCARCBridgableType() const
Determine whether the given type T is a "bridgeable" C type.
Definition: Type.cpp:4792
TypeBitfields TypeBits
Definition: Type.h:2004
bool isChar16Type() const
Definition: Type.cpp:2048
bool isAnyComplexType() const
Definition: Type.h:7252
DependentTemplateSpecializationTypeBitfields DependentTemplateSpecializationTypeBits
Definition: Type.h:2023
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type.
Definition: Type.cpp:1948
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:2094
ScalarTypeKind getScalarTypeKind() const
Given that this is a scalar type, classify it.
Definition: Type.cpp:2233
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g....
Definition: Type.cpp:2123
QualType getCanonicalTypeInternal() const
Definition: Type.h:2703
const RecordType * getAsStructureType() const
Definition: Type.cpp:667
const char * getTypeClassName() const
Definition: Type.cpp:3210
bool isWebAssemblyTableType() const
Returns true if this is a WebAssembly table type: either an array of reference types,...
Definition: Type.cpp:2393
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition: Type.h:7607
bool isObjCBoxableRecordType() const
Definition: Type.cpp:595
void dump() const
Definition: ASTDumper.cpp:196
bool isChar32Type() const
Definition: Type.cpp:2054
bool isStandardLayoutType() const
Test if this type is a standard-layout type.
Definition: Type.cpp:2910
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Definition: Type.h:2438
bool isComplexIntegerType() const
Definition: Type.cpp:633
bool isUnscopedEnumerationType() const
Definition: Type.cpp:2019
bool isStdByteType() const
Definition: Type.cpp:3016
bool isCUDADeviceBuiltinTextureType() const
Check if the type is the CUDA device builtin texture type.
Definition: Type.cpp:4809
bool isBlockCompatibleObjCPointerType(ASTContext &ctx) const
Definition: Type.cpp:4688
bool isObjCClassOrClassKindOfType() const
Whether the type is Objective-C 'Class' or a __kindof type of an Class type, e.g.,...
Definition: Type.cpp:732
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition: Type.h:7710
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
Definition: Type.cpp:4778
bool isObjectType() const
Determine whether this type is an object type.
Definition: Type.h:2175
bool isObjCIndirectLifetimeType() const
Definition: Type.cpp:4764
bool hasUnnamedOrLocalType() const
Whether this type is or contains a local or unnamed type.
Definition: Type.cpp:4411
Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const
Return the implicit lifetime for this type, which must not be dependent.
Definition: Type.cpp:4721
FunctionTypeBitfields FunctionTypeBits
Definition: Type.h:2013
bool isObjCQualifiedInterfaceType() const
Definition: Type.cpp:1764
bool isSpecifierType() const
Returns true if this type can be represented by some set of type specifiers.
Definition: Type.cpp:3025
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2299
bool isObjCObjectPointerType() const
Definition: Type.h:7282
TypeDependence getDependence() const
Definition: Type.h:2409
bool hasFloatingRepresentation() const
Determine whether this type has a floating-point representation of some sort, e.g....
Definition: Type.cpp:2195
bool isStructureOrClassType() const
Definition: Type.cpp:607
bool isVectorType() const
Definition: Type.h:7256
bool isRVVVLSBuiltinType() const
Determines if this is a sizeless type supported by the 'riscv_rvv_vector_bits' type attribute,...
Definition: Type.cpp:2475
bool isRealFloatingType() const
Floating point categories.
Definition: Type.cpp:2203
bool isRVVSizelessBuiltinType() const
Returns true for RVV scalable vector types.
Definition: Type.cpp:2423
std::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:1574
Linkage getLinkage() const
Determine the linkage of this type.
Definition: Type.cpp:4406
ObjCObjectTypeBitfields ObjCObjectTypeBits
Definition: Type.h:2014
ScalarTypeKind
Definition: Type.h:2393
@ STK_FloatingComplex
Definition: Type.h:2402
@ STK_Floating
Definition: Type.h:2400
@ STK_BlockPointer
Definition: Type.h:2395
@ STK_Bool
Definition: Type.h:2398
@ STK_ObjCObjectPointer
Definition: Type.h:2396
@ STK_FixedPoint
Definition: Type.h:2403
@ STK_IntegralComplex
Definition: Type.h:2401
@ STK_CPointer
Definition: Type.h:2394
@ STK_Integral
Definition: Type.h:2399
@ STK_MemberPointer
Definition: Type.h:2397
bool isFloatingType() const
Definition: Type.cpp:2186
const ObjCObjectType * getAsObjCInterfaceType() const
Definition: Type.cpp:1788
bool isWideCharType() const
Definition: Type.cpp:2035
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:2133
bool isRealType() const
Definition: Type.cpp:2209
bool isClassType() const
Definition: Type.cpp:583
bool hasSizedVLAType() const
Whether this type involves a variable-length array type with a definite size.
Definition: Type.cpp:4815
TypeClass getTypeClass() const
Definition: Type.h:2074
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition: Type.h:2100
bool hasAutoForTrailingReturnType() const
Determine whether this type was written with a leading 'auto' corresponding to a trailing return type...
Definition: Type.cpp:1953
bool isObjCIdOrObjectKindOfType(const ASTContext &ctx, const ObjCObjectType *&bound) const
Whether the type is Objective-C 'id' or a __kindof type of an object type, e.g., __kindof NSView * or...
Definition: Type.cpp:706
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7657
SubstTemplateTypeParmPackTypeBitfields SubstTemplateTypeParmPackTypeBits
Definition: Type.h:2020
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs,...
Definition: Type.cpp:565
bool isObjCARCImplicitlyUnretainedType() const
Determines if this type, which must satisfy isObjCLifetimeType(), is implicitly __unsafe_unretained r...
Definition: Type.cpp:4727
bool isRecordType() const
Definition: Type.h:7244
TemplateSpecializationTypeBitfields TemplateSpecializationTypeBits
Definition: Type.h:2021
bool isObjCRetainableType() const
Definition: Type.cpp:4758
std::optional< NullabilityKind > getNullability() const
Determine the nullability of the given type.
Definition: Type.cpp:4516
bool isObjCIndependentClassType() const
Definition: Type.cpp:4752
bool isUnionType() const
Definition: Type.cpp:621
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:1827
bool isSizelessVectorType() const
Returns true for all scalable vector types.
Definition: Type.cpp:2405
bool isScopedEnumeralType() const
Determine whether this type is a scoped enumeration type.
Definition: Type.cpp:638
bool acceptsObjCTypeParams() const
Determines if this is an ObjC interface type that may accept type parameters.
Definition: Type.cpp:1655
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition: Type.cpp:1823
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3399
QualType getUnderlyingType() const
Definition: Decl.h:3454
QualType desugar() const
Definition: Type.cpp:3722
bool typeMatchesDecl() const
Definition: Type.h:4768
A unary type transform, which is a type constructed from another.
Definition: Type.h:5009
UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind, QualType CanonicalTy)
Definition: Type.cpp:3876
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3313
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition: DeclCXX.h:3377
QualType getUnderlyingType() const
Definition: Type.cpp:3736
bool typeMatchesDecl() const
Definition: Type.h:4736
QualType getType() const
Definition: Decl.h:717
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3290
SourceRange getBracketsRange() const
Definition: Type.h:3315
Expr * getSizeExpr() const
Definition: Type.h:3309
Represents a GCC generic vector type.
Definition: Type.h:3512
unsigned getNumElements() const
Definition: Type.h:3527
VectorType(QualType vecType, unsigned nElements, QualType canonType, VectorKind vecKind)
Definition: Type.cpp:353
VectorKind getVectorKind() const
Definition: Type.h:3532
QualType getElementType() const
Definition: Type.h:3526
Defines the Linkage enumeration and various utility functions.
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< TypedefType > typedefType
Matches typedef types.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
The JSON file list parser is used to communicate input to InstallAPI.
@ Private
'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel loop', and 'serial loop' constru...
@ Vector
'vector' clause, allowed on 'loop', Combined, and 'routine' directives.
@ TST_struct
Definition: Specifiers.h:81
@ TST_class
Definition: Specifiers.h:82
@ TST_union
Definition: Specifiers.h:80
@ TST_typename
Definition: Specifiers.h:84
@ TST_enum
Definition: Specifiers.h:79
@ TST_interface
Definition: Specifiers.h:83
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition: Type.h:1565
CanThrowResult
Possible results from evaluation of a noexcept expression.
void initialize(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema)
Linkage minLinkage(Linkage L1, Linkage L2)
Compute the minimum linkage given two linkages.
Definition: Linkage.h:129
@ Nullable
Values of this type can be null.
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
@ NonNull
Values of this type can never be null.
ExprDependence computeDependence(FullExpr *E)
TypeOfKind
The kind of 'typeof' expression we're after.
Definition: Type.h:718
TypeDependence toTypeDependence(ExprDependence D)
ExprDependence turnValueToTypeDependence(ExprDependence D)
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition: Linkage.h:24
@ External
External linkage, which indicates that the entity can be referred to from other translation units.
ObjCSubstitutionContext
The kind of type we are substituting Objective-C type arguments into.
Definition: Type.h:700
@ Superclass
The superclass of a type.
@ Result
The result type of a method or function.
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition: Type.h:3144
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
TemplateParameterList * getReplacedTemplateParameterList(Decl *D)
Internal helper used by Subst* nodes to retrieve the parameter list for their AssociatedDecl.
TagTypeKind
The kind of a tag type.
Definition: Type.h:5842
@ Interface
The "__interface" keyword.
@ Struct
The "struct" keyword.
@ Class
The "class" keyword.
@ Union
The "union" keyword.
@ Enum
The "enum" keyword.
void FixedPointValueToString(SmallVectorImpl< char > &Str, llvm::APSInt Val, unsigned Scale)
Definition: Type.cpp:4868
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:275
@ CC_X86Pascal
Definition: Specifiers.h:281
@ CC_Swift
Definition: Specifiers.h:290
@ CC_IntelOclBicc
Definition: Specifiers.h:287
@ CC_OpenCLKernel
Definition: Specifiers.h:289
@ CC_PreserveMost
Definition: Specifiers.h:292
@ CC_Win64
Definition: Specifiers.h:282
@ CC_X86ThisCall
Definition: Specifiers.h:279
@ CC_AArch64VectorCall
Definition: Specifiers.h:294
@ CC_AAPCS
Definition: Specifiers.h:285
@ CC_PreserveNone
Definition: Specifiers.h:298
@ CC_C
Definition: Specifiers.h:276
@ CC_AMDGPUKernelCall
Definition: Specifiers.h:296
@ CC_M68kRTD
Definition: Specifiers.h:297
@ CC_SwiftAsync
Definition: Specifiers.h:291
@ CC_X86RegCall
Definition: Specifiers.h:284
@ CC_X86VectorCall
Definition: Specifiers.h:280
@ CC_SpirFunction
Definition: Specifiers.h:288
@ CC_AArch64SVEPCS
Definition: Specifiers.h:295
@ CC_X86StdCall
Definition: Specifiers.h:277
@ CC_X86_64SysV
Definition: Specifiers.h:283
@ CC_PreserveAll
Definition: Specifiers.h:293
@ CC_X86FastCall
Definition: Specifiers.h:278
@ CC_AAPCS_VFP
Definition: Specifiers.h:286
VectorKind
Definition: Type.h:3475
@ None
The alignment was not explicit in code.
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:5817
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
@ None
No keyword precedes the qualified type name.
@ Struct
The "struct" keyword introduces the elaborated-type-specifier.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ Union
The "union" keyword introduces the elaborated-type-specifier.
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
TypeDependence toSemanticDependence(TypeDependence D)
TypeDependence toSyntacticDependence(TypeDependence D)
@ Other
Other implicit parameter.
@ EST_DependentNoexcept
noexcept(expression), value-dependent
@ EST_DynamicNone
throw()
@ EST_Uninstantiated
not instantiated yet
@ EST_Unparsed
not parsed yet
@ EST_NoThrow
Microsoft __declspec(nothrow) extension.
@ EST_None
no exception specification
@ EST_MSAny
Microsoft throw(...) extension.
@ EST_BasicNoexcept
noexcept
@ EST_NoexceptFalse
noexcept(expression), evals to 'false'
@ EST_Unevaluated
not evaluated yet, for special member function
@ EST_NoexceptTrue
noexcept(expression), evals to 'true'
@ EST_Dynamic
throw(T1, T2)
#define false
Definition: stdbool.h:22
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: Type.h:4262
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:4266
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:4252
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:4255
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:4258
Extra information about a function prototype.
Definition: Type.h:4278
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:4285
bool requiresFunctionProtoTypeArmAttributes() const
Definition: Type.h:4308
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:4286
bool requiresFunctionProtoTypeExtraBitfields() const
Definition: Type.h:4303
A simple holder for various uncommon bits which do not fit in FunctionTypeBitfields.
Definition: Type.h:4042
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
unsigned Bool
Whether we can use 'bool' rather than '_Bool' (even if the language doesn't actually have 'bool',...
unsigned NullptrTypeInNamespace
Whether 'nullptr_t' is in namespace 'std' or not.
unsigned Half
When true, print the half-precision floating-point type as 'half' instead of '__fp16'.
unsigned MSWChar
When true, print the built-in wchar_t type as __wchar_t.
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:670
const Type * Ty
The locally-unqualified type.
Definition: Type.h:672
Qualifiers Quals
The local qualifiers.
Definition: Type.h:675