clang 24.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"
34#include "clang/Basic/LLVM.h"
36#include "clang/Basic/Linkage.h"
41#include "llvm/ADT/APInt.h"
42#include "llvm/ADT/APSInt.h"
43#include "llvm/ADT/ArrayRef.h"
44#include "llvm/ADT/FoldingSet.h"
45#include "llvm/ADT/STLExtras.h"
46#include "llvm/ADT/SmallVector.h"
47#include "llvm/Support/ErrorHandling.h"
48#include "llvm/Support/MathExtras.h"
49#include <algorithm>
50#include <cassert>
51#include <cstdint>
52#include <cstring>
53#include <optional>
54
55using namespace clang;
56
58 return (*this != Other) &&
59 // CVR qualifiers superset
60 (((Mask & CVRMask) | (Other.Mask & CVRMask)) == (Mask & CVRMask)) &&
61 // ObjC GC qualifiers superset
62 ((getObjCGCAttr() == Other.getObjCGCAttr()) ||
63 (hasObjCGCAttr() && !Other.hasObjCGCAttr())) &&
64 // Address space superset.
65 ((getAddressSpace() == Other.getAddressSpace()) ||
66 (hasAddressSpace() && !Other.hasAddressSpace())) &&
67 // Lifetime qualifier superset.
68 ((getObjCLifetime() == Other.getObjCLifetime()) ||
69 (hasObjCLifetime() && !Other.hasObjCLifetime()));
70}
71
73 const ASTContext &Ctx) {
74 // In OpenCLC v2.0 s6.5.5: every address space except for __constant can be
75 // used as __generic.
76 return (A == LangAS::opencl_generic && B != LangAS::opencl_constant) ||
77 // We also define global_device and global_host address spaces,
78 // to distinguish global pointers allocated on host from pointers
79 // allocated on device, which are a subset of __global.
82 (A == LangAS::sycl_global &&
84 // Consider pointer size address spaces to be equivalent to default.
87 // Default is a superset of SYCL address spaces.
88 (A == LangAS::Default &&
92 // In HIP device compilation, any cuda address space is allowed
93 // to implicitly cast into the default address space.
94 (A == LangAS::Default &&
97 // In HLSL, the this pointer for member functions points to the default
98 // address space. This causes a problem if the structure is in
99 // a different address space. We want to allow casting from these
100 // address spaces to default to work around this problem.
101 (A == LangAS::Default && B == LangAS::hlsl_private) ||
102 (A == LangAS::Default && B == LangAS::hlsl_device) ||
103 (A == LangAS::Default && B == LangAS::hlsl_input) ||
104 (A == LangAS::Default && B == LangAS::hlsl_output) ||
106 // Conversions from target specific address spaces may be legal
107 // depending on the target information.
109}
110
112 const Type *ty = getTypePtr();
113 NamedDecl *ND = nullptr;
114 if (const auto *DNT = ty->getAs<DependentNameType>())
115 return DNT->getIdentifier();
116 if (ty->isPointerOrReferenceType())
118 if (const auto *TT = ty->getAs<TagType>())
119 ND = TT->getDecl();
120 else if (ty->getTypeClass() == Type::Typedef)
121 ND = ty->castAs<TypedefType>()->getDecl();
122 else if (ty->isArrayType())
123 return ty->castAsArrayTypeUnsafe()
126
127 if (ND)
128 return ND->getIdentifier();
129 return nullptr;
130}
131
133 QualType QT = *this;
134 while (true) {
135 const Type *T = QT.getTypePtr();
136 switch (T->getTypeClass()) {
137 default:
138 return false;
139 case Type::Pointer:
140 QT = cast<PointerType>(T)->getPointeeType();
141 break;
142 case Type::BlockPointer:
143 QT = cast<BlockPointerType>(T)->getPointeeType();
144 break;
145 case Type::MemberPointer:
146 QT = cast<MemberPointerType>(T)->getPointeeType();
147 break;
148 case Type::LValueReference:
149 case Type::RValueReference:
150 QT = cast<ReferenceType>(T)->getPointeeType();
151 break;
152 case Type::PackExpansion:
153 QT = cast<PackExpansionType>(T)->getPattern();
154 break;
155 case Type::Paren:
156 case Type::ConstantArray:
157 case Type::DependentSizedArray:
158 case Type::IncompleteArray:
159 case Type::VariableArray:
160 case Type::FunctionProto:
161 case Type::FunctionNoProto:
162 return true;
163 }
164 }
165}
166
168 const auto *ClassDecl = getTypePtr()->getPointeeCXXRecordDecl();
169 return ClassDecl && ClassDecl->mayBeDynamicClass();
170}
171
173 const auto *ClassDecl = getTypePtr()->getPointeeCXXRecordDecl();
174 return !ClassDecl || ClassDecl->mayBeNonDynamicClass();
175}
176
177bool QualType::isConstant(QualType T, const ASTContext &Ctx) {
178 if (T.isConstQualified())
179 return true;
180
181 if (const ArrayType *AT = Ctx.getAsArrayType(T))
182 return AT->getElementType().isConstant(Ctx);
183
184 return T.getAddressSpace() == LangAS::opencl_constant;
185}
186
187std::optional<QualType::NonConstantStorageReason>
188QualType::isNonConstantStorage(const ASTContext &Ctx, bool ExcludeCtor,
189 bool ExcludeDtor) {
190 if (!isConstant(Ctx) && !(*this)->isReferenceType())
192 if (!Ctx.getLangOpts().CPlusPlus)
193 return std::nullopt;
194 if (const CXXRecordDecl *Record =
196 if (!ExcludeCtor)
198 if (Record->hasMutableFields())
200 if (!Record->hasTrivialDestructor() && !ExcludeDtor)
202 }
203 return std::nullopt;
204}
205
206// C++ [temp.dep.type]p1:
207// A type is dependent if it is...
208// - an array type constructed from any dependent type or whose
209// size is specified by a constant expression that is
210// value-dependent,
212 ArraySizeModifier sm, unsigned tq, const Expr *sz)
213 // Note, we need to check for DependentSizedArrayType explicitly here
214 // because we use a DependentSizedArrayType with no size expression as the
215 // type of a dependent array of unknown bound with a dependent braced
216 // initializer:
217 //
218 // template<int ...N> int arr[] = {N...};
219 : Type(tc, can,
220 et->getDependence() |
221 (sz ? toTypeDependence(
223 : TypeDependence::None) |
224 (tc == VariableArray ? TypeDependence::VariablyModified
225 : TypeDependence::None) |
226 (tc == DependentSizedArray
227 ? TypeDependence::DependentInstantiation
228 : TypeDependence::None)),
229 ElementType(et) {
230 ArrayTypeBits.IndexTypeQuals = tq;
231 ArrayTypeBits.SizeModifier = llvm::to_underlying(sm);
232}
233
235ConstantArrayType::Create(const ASTContext &Ctx, QualType ET, QualType Can,
236 const llvm::APInt &Sz, const Expr *SzExpr,
237 ArraySizeModifier SzMod, unsigned Qual) {
238 bool NeedsExternalSize = SzExpr != nullptr || Sz.ugt(0x0FFFFFFFFFFFFFFF) ||
239 Sz.getBitWidth() > 0xFF;
240 if (!NeedsExternalSize)
241 return new (Ctx, alignof(ConstantArrayType)) ConstantArrayType(
242 ET, Can, Sz.getBitWidth(), Sz.getZExtValue(), SzMod, Qual);
243
244 auto *SzPtr = new (Ctx, alignof(ConstantArrayType::ExternalSize))
245 ConstantArrayType::ExternalSize(Sz, SzExpr);
246 return new (Ctx, alignof(ConstantArrayType))
247 ConstantArrayType(ET, Can, SzPtr, SzMod, Qual);
248}
249
250unsigned
252 QualType ElementType,
253 const llvm::APInt &NumElements) {
254 uint64_t ElementSize = Context.getTypeSizeInChars(ElementType).getQuantity();
255
256 // Fast path the common cases so we can avoid the conservative computation
257 // below, which in common cases allocates "large" APSInt values, which are
258 // slow.
259
260 // If the element size is a power of 2, we can directly compute the additional
261 // number of addressing bits beyond those required for the element count.
262 if (llvm::isPowerOf2_64(ElementSize)) {
263 return NumElements.getActiveBits() + llvm::Log2_64(ElementSize);
264 }
265
266 // If both the element count and element size fit in 32-bits, we can do the
267 // computation directly in 64-bits.
268 if ((ElementSize >> 32) == 0 && NumElements.getBitWidth() <= 64 &&
269 (NumElements.getZExtValue() >> 32) == 0) {
270 uint64_t TotalSize = NumElements.getZExtValue() * ElementSize;
271 return llvm::bit_width(TotalSize);
272 }
273
274 // Otherwise, use APSInt to handle arbitrary sized values.
275 llvm::APSInt SizeExtended(NumElements, true);
276 unsigned SizeTypeBits = Context.getTypeSize(Context.getSizeType());
277 SizeExtended = SizeExtended.extend(
278 std::max(SizeTypeBits, SizeExtended.getBitWidth()) * 2);
279
280 llvm::APSInt TotalSize(llvm::APInt(SizeExtended.getBitWidth(), ElementSize));
281 TotalSize *= SizeExtended;
282
283 return TotalSize.getActiveBits();
284}
285
286unsigned
290
292 unsigned Bits = Context.getTypeSize(Context.getSizeType());
293
294 // Limit the number of bits in size_t so that maximal bit size fits 64 bit
295 // integer (see PR8256). We can do this as currently there is no hardware
296 // that supports full 64-bit virtual space.
297 if (Bits > 61)
298 Bits = 61;
299
300 return Bits;
301}
302
303void ConstantArrayType::Profile(llvm::FoldingSetNodeID &ID,
304 const ASTContext &Context, QualType ET,
305 uint64_t ArraySize, const Expr *SizeExpr,
306 ArraySizeModifier SizeMod, unsigned TypeQuals) {
307 ID.AddPointer(ET.getAsOpaquePtr());
308 ID.AddInteger(ArraySize);
309 ID.AddInteger(llvm::to_underlying(SizeMod));
310 ID.AddInteger(TypeQuals);
311 ID.AddBoolean(SizeExpr != nullptr);
312 if (SizeExpr)
313 SizeExpr->Profile(ID, Context, true);
314}
315
321
322DependentSizedArrayType::DependentSizedArrayType(QualType et, QualType can,
323 Expr *e, ArraySizeModifier sm,
324 unsigned tq)
325 : ArrayType(DependentSizedArray, et, can, sm, tq, e), SizeExpr((Stmt *)e) {}
326
327void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID,
328 const ASTContext &Context, QualType ET,
329 ArraySizeModifier SizeMod,
330 unsigned TypeQuals, Expr *E) {
331 ID.AddPointer(ET.getAsOpaquePtr());
332 ID.AddInteger(llvm::to_underlying(SizeMod));
333 ID.AddInteger(TypeQuals);
334 if (E)
335 E->Profile(ID, Context, true);
336}
337
338DependentVectorType::DependentVectorType(QualType ElementType,
339 QualType CanonType, Expr *SizeExpr,
340 SourceLocation Loc, VectorKind VecKind)
341 : Type(DependentVector, CanonType,
342 TypeDependence::DependentInstantiation |
343 ElementType->getDependence() |
344 (SizeExpr ? toTypeDependence(SizeExpr->getDependence())
345 : TypeDependence::None)),
346 ElementType(ElementType), SizeExpr(SizeExpr), Loc(Loc) {
347 VectorTypeBits.VecKind = llvm::to_underlying(VecKind);
348}
349
350void DependentVectorType::Profile(llvm::FoldingSetNodeID &ID,
351 const ASTContext &Context,
352 QualType ElementType, const Expr *SizeExpr,
353 VectorKind VecKind) {
354 ID.AddPointer(ElementType.getAsOpaquePtr());
355 ID.AddInteger(llvm::to_underlying(VecKind));
356 SizeExpr->Profile(ID, Context, true);
357}
358
359DependentSizedExtVectorType::DependentSizedExtVectorType(QualType ElementType,
360 QualType can,
361 Expr *SizeExpr,
362 SourceLocation loc)
363 : Type(DependentSizedExtVector, can,
364 TypeDependence::DependentInstantiation |
365 ElementType->getDependence() |
366 (SizeExpr ? toTypeDependence(SizeExpr->getDependence())
367 : TypeDependence::None)),
368 SizeExpr(SizeExpr), ElementType(ElementType), loc(loc) {}
369
370void DependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID,
371 const ASTContext &Context,
372 QualType ElementType,
373 Expr *SizeExpr) {
374 ID.AddPointer(ElementType.getAsOpaquePtr());
375 SizeExpr->Profile(ID, Context, true);
376}
377
378DependentAddressSpaceType::DependentAddressSpaceType(QualType PointeeType,
379 QualType can,
380 Expr *AddrSpaceExpr,
381 SourceLocation loc)
382 : Type(DependentAddressSpace, can,
383 TypeDependence::DependentInstantiation |
384 PointeeType->getDependence() |
385 (AddrSpaceExpr ? toTypeDependence(AddrSpaceExpr->getDependence())
386 : TypeDependence::None)),
387 AddrSpaceExpr(AddrSpaceExpr), PointeeType(PointeeType), loc(loc) {}
388
389void DependentAddressSpaceType::Profile(llvm::FoldingSetNodeID &ID,
390 const ASTContext &Context,
391 QualType PointeeType,
392 Expr *AddrSpaceExpr) {
393 ID.AddPointer(PointeeType.getAsOpaquePtr());
394 AddrSpaceExpr->Profile(ID, Context, true);
395}
396
398 const Expr *RowExpr, const Expr *ColumnExpr)
399 : Type(tc, canonType,
400 (RowExpr ? (matrixType->getDependence() | TypeDependence::Dependent |
401 TypeDependence::Instantiation |
402 (matrixType->isVariablyModifiedType()
403 ? TypeDependence::VariablyModified
404 : TypeDependence::None) |
405 (matrixType->containsUnexpandedParameterPack() ||
406 (RowExpr &&
408 (ColumnExpr &&
410 ? TypeDependence::UnexpandedPack
412 : matrixType->getDependence())),
413 ElementType(matrixType) {}
414
416 unsigned nColumns, QualType canonType)
417 : ConstantMatrixType(ConstantMatrix, matrixType, nRows, nColumns,
418 canonType) {}
419
421 unsigned nRows, unsigned nColumns,
422 QualType canonType)
423 : MatrixType(tc, matrixType, canonType), NumRows(nRows),
424 NumColumns(nColumns) {}
425
426DependentSizedMatrixType::DependentSizedMatrixType(QualType ElementType,
427 QualType CanonicalType,
428 Expr *RowExpr,
429 Expr *ColumnExpr,
430 SourceLocation loc)
431 : MatrixType(DependentSizedMatrix, ElementType, CanonicalType, RowExpr,
432 ColumnExpr),
433 RowExpr(RowExpr), ColumnExpr(ColumnExpr), loc(loc) {}
434
435void DependentSizedMatrixType::Profile(llvm::FoldingSetNodeID &ID,
436 const ASTContext &CTX,
437 QualType ElementType, Expr *RowExpr,
438 Expr *ColumnExpr) {
439 ID.AddPointer(ElementType.getAsOpaquePtr());
440 RowExpr->Profile(ID, CTX, true);
441 ColumnExpr->Profile(ID, CTX, true);
442}
443
444VectorType::VectorType(QualType vecType, unsigned nElements, QualType canonType,
445 VectorKind vecKind)
446 : VectorType(Vector, vecType, nElements, canonType, vecKind) {}
447
448VectorType::VectorType(TypeClass tc, QualType vecType, unsigned nElements,
449 QualType canonType, VectorKind vecKind)
450 : Type(tc, canonType, vecType->getDependence()), ElementType(vecType) {
451 VectorTypeBits.VecKind = llvm::to_underlying(vecKind);
452 VectorTypeBits.NumElements = nElements;
453}
454
456 if (ctx.getLangOpts().HLSL)
457 return false;
458 return isExtVectorBoolType();
459}
460
461BitIntType::BitIntType(bool IsUnsigned, unsigned NumBits)
462 : Type(BitInt, QualType{}, TypeDependence::None), IsUnsigned(IsUnsigned),
463 NumBits(NumBits) {}
464
465DependentBitIntType::DependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr)
466 : Type(DependentBitInt, QualType{},
467 toTypeDependence(NumBitsExpr->getDependence())),
468 ExprAndUnsigned(NumBitsExpr, IsUnsigned) {}
469
471 return ExprAndUnsigned.getInt();
472}
473
475 return ExprAndUnsigned.getPointer();
476}
477
478void DependentBitIntType::Profile(llvm::FoldingSetNodeID &ID,
479 const ASTContext &Context, bool IsUnsigned,
480 Expr *NumBitsExpr) {
481 ID.AddBoolean(IsUnsigned);
482 NumBitsExpr->Profile(ID, Context, true);
483}
484
486 return llvm::any_of(dependent_decls(),
487 [](const TypeCoupledDeclRefInfo &Info) {
488 return isa<FieldDecl>(Info.getDecl());
489 });
490}
491
492void CountAttributedType::Profile(llvm::FoldingSetNodeID &ID,
493 QualType WrappedTy, Expr *CountExpr,
494 bool CountInBytes, bool OrNull) {
495 ID.AddPointer(WrappedTy.getAsOpaquePtr());
496 ID.AddBoolean(CountInBytes);
497 ID.AddBoolean(OrNull);
498 // We profile it as a pointer as the StmtProfiler considers parameter
499 // expressions on function declaration and function definition as the
500 // same, resulting in count expression being evaluated with ParamDecl
501 // not in the function scope.
502 ID.AddPointer(CountExpr);
503}
504
505/// getArrayElementTypeNoTypeQual - If this is an array type, return the
506/// element type of the array, potentially with type qualifiers missing.
507/// This method should never be used when type qualifiers are meaningful.
509 // If this is directly an array type, return it.
510 if (const auto *ATy = dyn_cast<ArrayType>(this))
511 return ATy->getElementType().getTypePtr();
512
513 // If the canonical form of this type isn't the right kind, reject it.
514 if (!isa<ArrayType>(CanonicalType))
515 return nullptr;
516
517 // If this is a typedef for an array type, strip the typedef off without
518 // losing all typedef information.
520 ->getElementType()
521 .getTypePtr();
522}
523
524/// getDesugaredType - Return the specified type with any "sugar" removed from
525/// the type. This takes off typedefs, typeof's etc. If the outer level of
526/// the type is already concrete, it returns it unmodified. This is similar
527/// to getting the canonical type, but it doesn't remove *all* typedefs. For
528/// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
529/// concrete.
532 return Context.getQualifiedType(split.Ty, split.Quals);
533}
534
535QualType QualType::getSingleStepDesugaredTypeImpl(QualType type,
536 const ASTContext &Context) {
537 SplitQualType split = type.split();
539 return Context.getQualifiedType(desugar, split.Quals);
540}
541
542// Check that no type class is polymorphic. LLVM style RTTI should be used
543// instead. If absolutely needed an exception can still be added here by
544// defining the appropriate macro (but please don't do this).
545#define TYPE(CLASS, BASE) \
546 static_assert(!std::is_polymorphic<CLASS##Type>::value, \
547 #CLASS "Type should not be polymorphic!");
548#include "clang/AST/TypeNodes.inc"
549
550// Check that no type class has a non-trival destructor. Types are
551// allocated with the BumpPtrAllocator from ASTContext and therefore
552// their destructor is not executed.
553#define TYPE(CLASS, BASE) \
554 static_assert(std::is_trivially_destructible<CLASS##Type>::value, \
555 #CLASS "Type should be trivially destructible!");
556#include "clang/AST/TypeNodes.inc"
557
559 switch (getTypeClass()) {
560#define ABSTRACT_TYPE(Class, Parent)
561#define TYPE(Class, Parent) \
562 case Type::Class: { \
563 const auto *ty = cast<Class##Type>(this); \
564 if (!ty->isSugared()) \
565 return QualType(ty, 0); \
566 return ty->desugar(); \
567 }
568#include "clang/AST/TypeNodes.inc"
569 }
570 llvm_unreachable("bad type kind!");
571}
572
575
576 QualType Cur = T;
577 while (true) {
578 const Type *CurTy = Qs.strip(Cur);
579 switch (CurTy->getTypeClass()) {
580#define ABSTRACT_TYPE(Class, Parent)
581#define TYPE(Class, Parent) \
582 case Type::Class: { \
583 const auto *Ty = cast<Class##Type>(CurTy); \
584 if (!Ty->isSugared()) \
585 return SplitQualType(Ty, Qs); \
586 Cur = Ty->desugar(); \
587 break; \
588 }
589#include "clang/AST/TypeNodes.inc"
590 }
591 }
592}
593
594SplitQualType QualType::getSplitUnqualifiedTypeImpl(QualType type) {
595 SplitQualType split = type.split();
596
597 // All the qualifiers we've seen so far.
598 Qualifiers quals = split.Quals;
599
600 // The last type node we saw with any nodes inside it.
601 const Type *lastTypeWithQuals = split.Ty;
602
603 while (true) {
604 QualType next;
605
606 // Do a single-step desugar, aborting the loop if the type isn't
607 // sugared.
608 switch (split.Ty->getTypeClass()) {
609#define ABSTRACT_TYPE(Class, Parent)
610#define TYPE(Class, Parent) \
611 case Type::Class: { \
612 const auto *ty = cast<Class##Type>(split.Ty); \
613 if (!ty->isSugared()) \
614 goto done; \
615 next = ty->desugar(); \
616 break; \
617 }
618#include "clang/AST/TypeNodes.inc"
619 }
620
621 // Otherwise, split the underlying type. If that yields qualifiers,
622 // update the information.
623 split = next.split();
624 if (!split.Quals.empty()) {
625 lastTypeWithQuals = split.Ty;
626 quals.addConsistentQualifiers(split.Quals);
627 }
628 }
629
630done:
631 return SplitQualType(lastTypeWithQuals, quals);
632}
633
635 // FIXME: this seems inherently un-qualifiers-safe.
636 while (const auto *PT = T->getAs<ParenType>())
637 T = PT->getInnerType();
638 return T;
639}
640
641/// This will check for a T (which should be a Type which can act as
642/// sugar, such as a TypedefType) by removing any existing sugar until it
643/// reaches a T or a non-sugared type.
644template <typename T> static const T *getAsSugar(const Type *Cur) {
645 while (true) {
646 if (const auto *Sugar = dyn_cast<T>(Cur))
647 return Sugar;
648 switch (Cur->getTypeClass()) {
649#define ABSTRACT_TYPE(Class, Parent)
650#define TYPE(Class, Parent) \
651 case Type::Class: { \
652 const auto *Ty = cast<Class##Type>(Cur); \
653 if (!Ty->isSugared()) \
654 return 0; \
655 Cur = Ty->desugar().getTypePtr(); \
656 break; \
657 }
658#include "clang/AST/TypeNodes.inc"
659 }
660 }
661}
662
663template <> const TypedefType *Type::getAs() const {
664 return getAsSugar<TypedefType>(this);
665}
666
667template <> const UsingType *Type::getAs() const {
668 return getAsSugar<UsingType>(this);
669}
670
671template <> const TemplateSpecializationType *Type::getAs() const {
673}
674
675template <> const AttributedType *Type::getAs() const {
676 return getAsSugar<AttributedType>(this);
677}
678
679template <> const BoundsAttributedType *Type::getAs() const {
681}
682
683template <> const CountAttributedType *Type::getAs() const {
685}
686
687/// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic
688/// sugar off the given type. This should produce an object of the
689/// same dynamic type as the canonical type.
691 const Type *Cur = this;
692
693 while (true) {
694 switch (Cur->getTypeClass()) {
695#define ABSTRACT_TYPE(Class, Parent)
696#define TYPE(Class, Parent) \
697 case Class: { \
698 const auto *Ty = cast<Class##Type>(Cur); \
699 if (!Ty->isSugared()) \
700 return Cur; \
701 Cur = Ty->desugar().getTypePtr(); \
702 break; \
703 }
704#include "clang/AST/TypeNodes.inc"
705 }
706 }
707}
708
709bool Type::isClassType() const {
710 if (const auto *RT = getAsCanonical<RecordType>())
711 return RT->getDecl()->isClass();
712 return false;
713}
714
716 if (const auto *RT = getAsCanonical<RecordType>())
717 return RT->getDecl()->isStruct();
718 return false;
719}
720
722 const auto *RT = getAsCanonical<RecordType>();
723 if (!RT)
724 return false;
725 const auto *Decl = RT->getDecl();
726 if (!Decl->isStruct())
727 return false;
728 return Decl->getDefinitionOrSelf()->hasFlexibleArrayMember();
729}
730
732 if (const auto *RD = getAsRecordDecl())
733 return RD->hasAttr<ObjCBoxableAttr>();
734 return false;
735}
736
738 if (const auto *RT = getAsCanonical<RecordType>())
739 return RT->getDecl()->isInterface();
740 return false;
741}
742
744 if (const auto *RT = getAsCanonical<RecordType>())
745 return RT->getDecl()->isStructureOrClass();
746 return false;
747}
748
750 if (const auto *PT = getAsCanonical<PointerType>())
751 return PT->getPointeeType()->isVoidType();
752 return false;
753}
754
755bool Type::isUnionType() const {
756 if (const auto *RT = getAsCanonical<RecordType>())
757 return RT->getDecl()->isUnion();
758 return false;
759}
760
762 if (const auto *CT = getAsCanonical<ComplexType>())
763 return CT->getElementType()->isFloatingType();
764 return false;
765}
766
768 // Check for GCC complex integer extension.
770}
771
773 if (const auto *ET = getAsCanonical<EnumType>())
774 return ET->getDecl()->isScoped();
775 return false;
776}
777
781
783 if (const auto *Complex = getAs<ComplexType>())
784 if (Complex->getElementType()->isIntegerType())
785 return Complex;
786 return nullptr;
787}
788
790 if (const auto *PT = getAs<PointerType>())
791 return PT->getPointeeType();
792 if (const auto *OPT = getAs<ObjCObjectPointerType>())
793 return OPT->getPointeeType();
794 if (const auto *BPT = getAs<BlockPointerType>())
795 return BPT->getPointeeType();
796 if (const auto *RT = getAs<ReferenceType>())
797 return RT->getPointeeType();
798 if (const auto *MPT = getAs<MemberPointerType>())
799 return MPT->getPointeeType();
800 if (const auto *DT = getAs<DecayedType>())
801 return DT->getPointeeType();
802 return {};
803}
804
805const RecordType *Type::getAsStructureType() const {
806 // If this is directly a structure type, return it.
807 if (const auto *RT = dyn_cast<RecordType>(this)) {
808 if (RT->getDecl()->isStruct())
809 return RT;
810 }
811
812 // If the canonical form of this type isn't the right kind, reject it.
813 if (const auto *RT = dyn_cast<RecordType>(CanonicalType)) {
814 if (!RT->getDecl()->isStruct())
815 return nullptr;
816
817 // If this is a typedef for a structure type, strip the typedef off without
818 // losing all typedef information.
820 }
821 return nullptr;
822}
823
824const RecordType *Type::getAsUnionType() const {
825 // If this is directly a union type, return it.
826 if (const auto *RT = dyn_cast<RecordType>(this)) {
827 if (RT->getDecl()->isUnion())
828 return RT;
829 }
830
831 // If the canonical form of this type isn't the right kind, reject it.
832 if (const auto *RT = dyn_cast<RecordType>(CanonicalType)) {
833 if (!RT->getDecl()->isUnion())
834 return nullptr;
835
836 // If this is a typedef for a union type, strip the typedef off without
837 // losing all typedef information.
839 }
840
841 return nullptr;
842}
843
845 const ObjCObjectType *&bound) const {
846 bound = nullptr;
847
848 const auto *OPT = getAs<ObjCObjectPointerType>();
849 if (!OPT)
850 return false;
851
852 // Easy case: id.
853 if (OPT->isObjCIdType())
854 return true;
855
856 // If it's not a __kindof type, reject it now.
857 if (!OPT->isKindOfType())
858 return false;
859
860 // If it's Class or qualified Class, it's not an object type.
861 if (OPT->isObjCClassType() || OPT->isObjCQualifiedClassType())
862 return false;
863
864 // Figure out the type bound for the __kindof type.
865 bound = OPT->getObjectType()
866 ->stripObjCKindOfTypeAndQuals(ctx)
867 ->getAs<ObjCObjectType>();
868 return true;
869}
870
872 const auto *OPT = getAs<ObjCObjectPointerType>();
873 if (!OPT)
874 return false;
875
876 // Easy case: Class.
877 if (OPT->isObjCClassType())
878 return true;
879
880 // If it's not a __kindof type, reject it now.
881 if (!OPT->isKindOfType())
882 return false;
883
884 // If it's Class or qualified Class, it's a class __kindof type.
885 return OPT->isObjCClassType() || OPT->isObjCQualifiedClassType();
886}
887
888ObjCTypeParamType::ObjCTypeParamType(const ObjCTypeParamDecl *D, QualType can,
890 : Type(ObjCTypeParam, can, toSemanticDependence(can->getDependence())),
891 OTPDecl(const_cast<ObjCTypeParamDecl *>(D)) {
892 initialize(protocols);
893}
894
895ObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base,
896 ArrayRef<QualType> typeArgs,
898 bool isKindOf)
899 : Type(ObjCObject, Canonical, Base->getDependence()), BaseType(Base) {
900 ObjCObjectTypeBits.IsKindOf = isKindOf;
901
902 ObjCObjectTypeBits.NumTypeArgs = typeArgs.size();
903 assert(getTypeArgsAsWritten().size() == typeArgs.size() &&
904 "bitfield overflow in type argument count");
905 if (!typeArgs.empty())
906 memcpy(getTypeArgStorage(), typeArgs.data(),
907 typeArgs.size() * sizeof(QualType));
908
909 for (auto typeArg : typeArgs) {
910 addDependence(typeArg->getDependence() & ~TypeDependence::VariablyModified);
911 }
912 // Initialize the protocol qualifiers. The protocol storage is known
913 // after we set number of type arguments.
914 initialize(protocols);
915}
916
917bool ObjCObjectType::isSpecialized() const {
918 // If we have type arguments written here, the type is specialized.
919 if (ObjCObjectTypeBits.NumTypeArgs > 0)
920 return true;
921
922 // Otherwise, check whether the base type is specialized.
923 if (const auto objcObject = getBaseType()->getAs<ObjCObjectType>()) {
924 // Terminate when we reach an interface type.
925 if (isa<ObjCInterfaceType>(objcObject))
926 return false;
927
928 return objcObject->isSpecialized();
929 }
930
931 // Not specialized.
932 return false;
933}
934
935ArrayRef<QualType> ObjCObjectType::getTypeArgs() const {
936 // We have type arguments written on this type.
937 if (isSpecializedAsWritten())
938 return getTypeArgsAsWritten();
939
940 // Look at the base type, which might have type arguments.
941 if (const auto objcObject = getBaseType()->getAs<ObjCObjectType>()) {
942 // Terminate when we reach an interface type.
943 if (isa<ObjCInterfaceType>(objcObject))
944 return {};
945
946 return objcObject->getTypeArgs();
947 }
948
949 // No type arguments.
950 return {};
951}
952
953bool ObjCObjectType::isKindOfType() const {
954 if (isKindOfTypeAsWritten())
955 return true;
956
957 // Look at the base type, which might have type arguments.
958 if (const auto objcObject = getBaseType()->getAs<ObjCObjectType>()) {
959 // Terminate when we reach an interface type.
960 if (isa<ObjCInterfaceType>(objcObject))
961 return false;
962
963 return objcObject->isKindOfType();
964 }
965
966 // Not a "__kindof" type.
967 return false;
968}
969
971ObjCObjectType::stripObjCKindOfTypeAndQuals(const ASTContext &ctx) const {
972 if (!isKindOfType() && qual_empty())
973 return QualType(this, 0);
974
975 // Recursively strip __kindof.
976 SplitQualType splitBaseType = getBaseType().split();
977 QualType baseType(splitBaseType.Ty, 0);
978 if (const auto *baseObj = splitBaseType.Ty->getAs<ObjCObjectType>())
979 baseType = baseObj->stripObjCKindOfTypeAndQuals(ctx);
980
981 return ctx.getObjCObjectType(
982 ctx.getQualifiedType(baseType, splitBaseType.Quals),
983 getTypeArgsAsWritten(),
984 /*protocols=*/{},
985 /*isKindOf=*/false);
986}
987
989 ObjCInterfaceDecl *Canon = Decl->getCanonicalDecl();
990 if (ObjCInterfaceDecl *Def = Canon->getDefinition())
991 return Def;
992 return Canon;
993}
994
996 const ASTContext &ctx) const {
997 if (!isKindOfType() && qual_empty())
998 return this;
999
1000 QualType obj = getObjectType()->stripObjCKindOfTypeAndQuals(ctx);
1001 return ctx.getObjCObjectPointerType(obj)->castAs<ObjCObjectPointerType>();
1002}
1003
1004namespace {
1005
1006/// Visitor used to perform a simple type transformation that does not change
1007/// the semantics of the type.
1008template <typename Derived>
1009struct SimpleTransformVisitor : public TypeVisitor<Derived, QualType> {
1010 ASTContext &Ctx;
1011
1012 QualType recurse(QualType type) {
1013 // Split out the qualifiers from the type.
1014 SplitQualType splitType = type.split();
1015
1016 // Visit the type itself.
1017 QualType result = static_cast<Derived *>(this)->Visit(splitType.Ty);
1018 if (result.isNull())
1019 return result;
1020
1021 // Reconstruct the transformed type by applying the local qualifiers
1022 // from the split type.
1023 return Ctx.getQualifiedType(result, splitType.Quals);
1024 }
1025
1026public:
1027 explicit SimpleTransformVisitor(ASTContext &ctx) : Ctx(ctx) {}
1028
1029 // None of the clients of this transformation can occur where
1030 // there are dependent types, so skip dependent types.
1031#define TYPE(Class, Base)
1032#define DEPENDENT_TYPE(Class, Base) \
1033 QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); }
1034#include "clang/AST/TypeNodes.inc"
1035
1036#define TRIVIAL_TYPE_CLASS(Class) \
1037 QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); }
1038#define SUGARED_TYPE_CLASS(Class) \
1039 QualType Visit##Class##Type(const Class##Type *T) { \
1040 if (!T->isSugared()) \
1041 return QualType(T, 0); \
1042 QualType desugaredType = recurse(T->desugar()); \
1043 if (desugaredType.isNull()) \
1044 return {}; \
1045 if (desugaredType.getAsOpaquePtr() == T->desugar().getAsOpaquePtr()) \
1046 return QualType(T, 0); \
1047 return desugaredType; \
1048 }
1049
1051
1052 QualType VisitComplexType(const ComplexType *T) {
1053 QualType elementType = recurse(T->getElementType());
1054 if (elementType.isNull())
1055 return {};
1056
1057 if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
1058 return QualType(T, 0);
1059
1060 return Ctx.getComplexType(elementType);
1061 }
1062
1063 QualType VisitPointerType(const PointerType *T) {
1064 QualType pointeeType = recurse(T->getPointeeType());
1065 if (pointeeType.isNull())
1066 return {};
1067
1068 if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
1069 return QualType(T, 0);
1070
1071 return Ctx.getPointerType(pointeeType);
1072 }
1073
1074 QualType VisitBlockPointerType(const BlockPointerType *T) {
1075 QualType pointeeType = recurse(T->getPointeeType());
1076 if (pointeeType.isNull())
1077 return {};
1078
1079 if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
1080 return QualType(T, 0);
1081
1082 return Ctx.getBlockPointerType(pointeeType);
1083 }
1084
1085 QualType VisitLValueReferenceType(const LValueReferenceType *T) {
1086 QualType pointeeType = recurse(T->getPointeeTypeAsWritten());
1087 if (pointeeType.isNull())
1088 return {};
1089
1090 if (pointeeType.getAsOpaquePtr() ==
1091 T->getPointeeTypeAsWritten().getAsOpaquePtr())
1092 return QualType(T, 0);
1093
1094 return Ctx.getLValueReferenceType(pointeeType, T->isSpelledAsLValue());
1095 }
1096
1097 QualType VisitRValueReferenceType(const RValueReferenceType *T) {
1098 QualType pointeeType = recurse(T->getPointeeTypeAsWritten());
1099 if (pointeeType.isNull())
1100 return {};
1101
1102 if (pointeeType.getAsOpaquePtr() ==
1103 T->getPointeeTypeAsWritten().getAsOpaquePtr())
1104 return QualType(T, 0);
1105
1106 return Ctx.getRValueReferenceType(pointeeType);
1107 }
1108
1109 QualType VisitMemberPointerType(const MemberPointerType *T) {
1110 QualType pointeeType = recurse(T->getPointeeType());
1111 if (pointeeType.isNull())
1112 return {};
1113
1114 if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
1115 return QualType(T, 0);
1116
1117 return Ctx.getMemberPointerType(pointeeType, T->getQualifier(),
1118 T->getMostRecentCXXRecordDecl());
1119 }
1120
1121 QualType VisitConstantArrayType(const ConstantArrayType *T) {
1122 QualType elementType = recurse(T->getElementType());
1123 if (elementType.isNull())
1124 return {};
1125
1126 if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
1127 return QualType(T, 0);
1128
1129 return Ctx.getConstantArrayType(elementType, T->getSize(), T->getSizeExpr(),
1130 T->getSizeModifier(),
1131 T->getIndexTypeCVRQualifiers());
1132 }
1133
1134 QualType VisitVariableArrayType(const VariableArrayType *T) {
1135 QualType elementType = recurse(T->getElementType());
1136 if (elementType.isNull())
1137 return {};
1138
1139 if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
1140 return QualType(T, 0);
1141
1142 return Ctx.getVariableArrayType(elementType, T->getSizeExpr(),
1143 T->getSizeModifier(),
1144 T->getIndexTypeCVRQualifiers());
1145 }
1146
1147 QualType VisitIncompleteArrayType(const IncompleteArrayType *T) {
1148 QualType elementType = recurse(T->getElementType());
1149 if (elementType.isNull())
1150 return {};
1151
1152 if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
1153 return QualType(T, 0);
1154
1155 return Ctx.getIncompleteArrayType(elementType, T->getSizeModifier(),
1156 T->getIndexTypeCVRQualifiers());
1157 }
1158
1159 QualType VisitVectorType(const VectorType *T) {
1160 QualType elementType = recurse(T->getElementType());
1161 if (elementType.isNull())
1162 return {};
1163
1164 if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
1165 return QualType(T, 0);
1166
1167 return Ctx.getVectorType(elementType, T->getNumElements(),
1168 T->getVectorKind());
1169 }
1170
1171 QualType VisitExtVectorType(const ExtVectorType *T) {
1172 QualType elementType = recurse(T->getElementType());
1173 if (elementType.isNull())
1174 return {};
1175
1176 if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
1177 return QualType(T, 0);
1178
1179 return Ctx.getExtVectorType(elementType, T->getNumElements());
1180 }
1181
1182 QualType VisitConstantMatrixType(const ConstantMatrixType *T) {
1183 QualType elementType = recurse(T->getElementType());
1184 if (elementType.isNull())
1185 return {};
1186 if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr())
1187 return QualType(T, 0);
1188
1189 return Ctx.getConstantMatrixType(elementType, T->getNumRows(),
1190 T->getNumColumns());
1191 }
1192
1193 QualType VisitOverflowBehaviorType(const OverflowBehaviorType *T) {
1194 QualType UnderlyingType = recurse(T->getUnderlyingType());
1195 if (UnderlyingType.isNull())
1196 return {};
1197
1198 if (UnderlyingType.getAsOpaquePtr() ==
1199 T->getUnderlyingType().getAsOpaquePtr())
1200 return QualType(T, 0);
1201
1202 return Ctx.getOverflowBehaviorType(T->getBehaviorKind(), UnderlyingType);
1203 }
1204
1205 QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1206 QualType returnType = recurse(T->getReturnType());
1207 if (returnType.isNull())
1208 return {};
1209
1210 if (returnType.getAsOpaquePtr() == T->getReturnType().getAsOpaquePtr())
1211 return QualType(T, 0);
1212
1213 return Ctx.getFunctionNoProtoType(returnType, T->getExtInfo());
1214 }
1215
1216 QualType VisitFunctionProtoType(const FunctionProtoType *T) {
1217 QualType returnType = recurse(T->getReturnType());
1218 if (returnType.isNull())
1219 return {};
1220
1221 // Transform parameter types.
1222 SmallVector<QualType, 4> paramTypes;
1223 bool paramChanged = false;
1224 for (auto paramType : T->getParamTypes()) {
1225 QualType newParamType = recurse(paramType);
1226 if (newParamType.isNull())
1227 return {};
1228
1229 if (newParamType.getAsOpaquePtr() != paramType.getAsOpaquePtr())
1230 paramChanged = true;
1231
1232 paramTypes.push_back(newParamType);
1233 }
1234
1235 // Transform extended info.
1236 FunctionProtoType::ExtProtoInfo info = T->getExtProtoInfo();
1237 bool exceptionChanged = false;
1238 if (info.ExceptionSpec.Type == EST_Dynamic) {
1239 SmallVector<QualType, 4> exceptionTypes;
1240 for (auto exceptionType : info.ExceptionSpec.Exceptions) {
1241 QualType newExceptionType = recurse(exceptionType);
1242 if (newExceptionType.isNull())
1243 return {};
1244
1245 if (newExceptionType.getAsOpaquePtr() != exceptionType.getAsOpaquePtr())
1246 exceptionChanged = true;
1247
1248 exceptionTypes.push_back(newExceptionType);
1249 }
1250
1251 if (exceptionChanged) {
1252 info.ExceptionSpec.Exceptions =
1253 llvm::ArrayRef(exceptionTypes).copy(Ctx);
1254 }
1255 }
1256
1257 if (returnType.getAsOpaquePtr() == T->getReturnType().getAsOpaquePtr() &&
1258 !paramChanged && !exceptionChanged)
1259 return QualType(T, 0);
1260
1261 return Ctx.getFunctionType(returnType, paramTypes, info);
1262 }
1263
1264 QualType VisitParenType(const ParenType *T) {
1265 QualType innerType = recurse(T->getInnerType());
1266 if (innerType.isNull())
1267 return {};
1268
1269 if (innerType.getAsOpaquePtr() == T->getInnerType().getAsOpaquePtr())
1270 return QualType(T, 0);
1271
1272 return Ctx.getParenType(innerType);
1273 }
1274
1276 SUGARED_TYPE_CLASS(ObjCTypeParam)
1277 SUGARED_TYPE_CLASS(MacroQualified)
1278
1279 QualType VisitAdjustedType(const AdjustedType *T) {
1280 QualType originalType = recurse(T->getOriginalType());
1281 if (originalType.isNull())
1282 return {};
1283
1284 QualType adjustedType = recurse(T->getAdjustedType());
1285 if (adjustedType.isNull())
1286 return {};
1287
1288 if (originalType.getAsOpaquePtr() ==
1289 T->getOriginalType().getAsOpaquePtr() &&
1290 adjustedType.getAsOpaquePtr() == T->getAdjustedType().getAsOpaquePtr())
1291 return QualType(T, 0);
1292
1293 return Ctx.getAdjustedType(originalType, adjustedType);
1294 }
1295
1296 QualType VisitDecayedType(const DecayedType *T) {
1297 QualType originalType = recurse(T->getOriginalType());
1298 if (originalType.isNull())
1299 return {};
1300
1301 if (originalType.getAsOpaquePtr() == T->getOriginalType().getAsOpaquePtr())
1302 return QualType(T, 0);
1303
1304 return Ctx.getDecayedType(originalType);
1305 }
1306
1307 QualType VisitArrayParameterType(const ArrayParameterType *T) {
1308 QualType ArrTy = VisitConstantArrayType(T);
1309 if (ArrTy.isNull())
1310 return {};
1311
1312 return Ctx.getArrayParameterType(ArrTy);
1313 }
1314
1315 SUGARED_TYPE_CLASS(TypeOfExpr)
1316 SUGARED_TYPE_CLASS(TypeOf)
1317 SUGARED_TYPE_CLASS(Decltype)
1318 SUGARED_TYPE_CLASS(UnaryTransform)
1321
1322 QualType VisitAttributedType(const AttributedType *T) {
1323 QualType modifiedType = recurse(T->getModifiedType());
1324 if (modifiedType.isNull())
1325 return {};
1326
1327 QualType equivalentType = recurse(T->getEquivalentType());
1328 if (equivalentType.isNull())
1329 return {};
1330
1331 if (modifiedType.getAsOpaquePtr() ==
1332 T->getModifiedType().getAsOpaquePtr() &&
1333 equivalentType.getAsOpaquePtr() ==
1334 T->getEquivalentType().getAsOpaquePtr())
1335 return QualType(T, 0);
1336
1337 return Ctx.getAttributedType(T->getAttrKind(), modifiedType, equivalentType,
1338 T->getAttr());
1339 }
1340
1341 QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
1342 QualType replacementType = recurse(T->getReplacementType());
1343 if (replacementType.isNull())
1344 return {};
1345
1346 if (replacementType.getAsOpaquePtr() ==
1347 T->getReplacementType().getAsOpaquePtr())
1348 return QualType(T, 0);
1349
1351 replacementType, T->getAssociatedDecl(), T->getIndex(),
1352 T->getPackIndex(), T->getFinal());
1353 }
1354
1355 // FIXME: Non-trivial to implement, but important for C++
1356 SUGARED_TYPE_CLASS(TemplateSpecialization)
1357
1358 QualType VisitAutoType(const AutoType *T) {
1359 if (!T->isDeduced())
1360 return QualType(T, 0);
1361
1362 QualType deducedType = recurse(T->getDeducedType());
1363 if (deducedType.isNull())
1364 return {};
1365
1366 if (deducedType == T->getDeducedType())
1367 return QualType(T, 0);
1368
1369 return Ctx.getAutoType(T->getDeducedKind(), deducedType, T->getKeyword(),
1370 T->getTypeConstraintConcept(),
1371 T->getTypeConstraintArguments());
1372 }
1373
1374 QualType VisitObjCObjectType(const ObjCObjectType *T) {
1375 QualType baseType = recurse(T->getBaseType());
1376 if (baseType.isNull())
1377 return {};
1378
1379 // Transform type arguments.
1380 bool typeArgChanged = false;
1381 SmallVector<QualType, 4> typeArgs;
1382 for (auto typeArg : T->getTypeArgsAsWritten()) {
1383 QualType newTypeArg = recurse(typeArg);
1384 if (newTypeArg.isNull())
1385 return {};
1386
1387 if (newTypeArg.getAsOpaquePtr() != typeArg.getAsOpaquePtr())
1388 typeArgChanged = true;
1389
1390 typeArgs.push_back(newTypeArg);
1391 }
1392
1393 if (baseType.getAsOpaquePtr() == T->getBaseType().getAsOpaquePtr() &&
1394 !typeArgChanged)
1395 return QualType(T, 0);
1396
1397 return Ctx.getObjCObjectType(
1398 baseType, typeArgs,
1399 llvm::ArrayRef(T->qual_begin(), T->getNumProtocols()),
1400 T->isKindOfTypeAsWritten());
1401 }
1402
1403 TRIVIAL_TYPE_CLASS(ObjCInterface)
1404
1405 QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1406 QualType pointeeType = recurse(T->getPointeeType());
1407 if (pointeeType.isNull())
1408 return {};
1409
1410 if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr())
1411 return QualType(T, 0);
1412
1413 return Ctx.getObjCObjectPointerType(pointeeType);
1414 }
1415
1416 QualType VisitAtomicType(const AtomicType *T) {
1417 QualType valueType = recurse(T->getValueType());
1418 if (valueType.isNull())
1419 return {};
1420
1421 if (valueType.getAsOpaquePtr() == T->getValueType().getAsOpaquePtr())
1422 return QualType(T, 0);
1423
1424 return Ctx.getAtomicType(valueType);
1425 }
1426
1427#undef TRIVIAL_TYPE_CLASS
1428#undef SUGARED_TYPE_CLASS
1429};
1430
1431struct SubstObjCTypeArgsVisitor
1432 : public SimpleTransformVisitor<SubstObjCTypeArgsVisitor> {
1433 using BaseType = SimpleTransformVisitor<SubstObjCTypeArgsVisitor>;
1434
1435 ArrayRef<QualType> TypeArgs;
1436 ObjCSubstitutionContext SubstContext;
1437
1438 SubstObjCTypeArgsVisitor(ASTContext &ctx, ArrayRef<QualType> typeArgs,
1440 : BaseType(ctx), TypeArgs(typeArgs), SubstContext(context) {}
1441
1442 QualType VisitObjCTypeParamType(const ObjCTypeParamType *OTPTy) {
1443 // Replace an Objective-C type parameter reference with the corresponding
1444 // type argument.
1445 ObjCTypeParamDecl *typeParam = OTPTy->getDecl();
1446 // If we have type arguments, use them.
1447 if (!TypeArgs.empty()) {
1448 QualType argType = TypeArgs[typeParam->getIndex()];
1449 if (OTPTy->qual_empty())
1450 return argType;
1451
1452 // Apply protocol lists if exists.
1453 bool hasError;
1454 SmallVector<ObjCProtocolDecl *, 8> protocolsVec;
1455 protocolsVec.append(OTPTy->qual_begin(), OTPTy->qual_end());
1456 ArrayRef<ObjCProtocolDecl *> protocolsToApply = protocolsVec;
1457 return Ctx.applyObjCProtocolQualifiers(
1458 argType, protocolsToApply, hasError, true /*allowOnPointerType*/);
1459 }
1460
1461 switch (SubstContext) {
1462 case ObjCSubstitutionContext::Ordinary:
1463 case ObjCSubstitutionContext::Parameter:
1464 case ObjCSubstitutionContext::Superclass:
1465 // Substitute the bound.
1466 return typeParam->getUnderlyingType();
1467
1468 case ObjCSubstitutionContext::Result:
1469 case ObjCSubstitutionContext::Property: {
1470 // Substitute the __kindof form of the underlying type.
1471 const auto *objPtr =
1472 typeParam->getUnderlyingType()->castAs<ObjCObjectPointerType>();
1473
1474 // __kindof types, id, and Class don't need an additional
1475 // __kindof.
1476 if (objPtr->isKindOfType() || objPtr->isObjCIdOrClassType())
1477 return typeParam->getUnderlyingType();
1478
1479 // Add __kindof.
1480 const auto *obj = objPtr->getObjectType();
1481 QualType resultTy = Ctx.getObjCObjectType(
1482 obj->getBaseType(), obj->getTypeArgsAsWritten(), obj->getProtocols(),
1483 /*isKindOf=*/true);
1484
1485 // Rebuild object pointer type.
1486 return Ctx.getObjCObjectPointerType(resultTy);
1487 }
1488 }
1489 llvm_unreachable("Unexpected ObjCSubstitutionContext!");
1490 }
1491
1492 QualType VisitFunctionType(const FunctionType *funcType) {
1493 // If we have a function type, update the substitution context
1494 // appropriately.
1495
1496 // Substitute result type.
1497 QualType returnType = funcType->getReturnType().substObjCTypeArgs(
1498 Ctx, TypeArgs, ObjCSubstitutionContext::Result);
1499 if (returnType.isNull())
1500 return {};
1501
1502 // Handle non-prototyped functions, which only substitute into the result
1503 // type.
1504 if (isa<FunctionNoProtoType>(funcType)) {
1505 // If the return type was unchanged, do nothing.
1506 if (returnType.getAsOpaquePtr() ==
1507 funcType->getReturnType().getAsOpaquePtr())
1508 return BaseType::VisitFunctionType(funcType);
1509
1510 // Otherwise, build a new type.
1511 return Ctx.getFunctionNoProtoType(returnType, funcType->getExtInfo());
1512 }
1513
1514 const auto *funcProtoType = cast<FunctionProtoType>(funcType);
1515
1516 // Transform parameter types.
1517 SmallVector<QualType, 4> paramTypes;
1518 bool paramChanged = false;
1519 for (auto paramType : funcProtoType->getParamTypes()) {
1520 QualType newParamType = paramType.substObjCTypeArgs(
1521 Ctx, TypeArgs, ObjCSubstitutionContext::Parameter);
1522 if (newParamType.isNull())
1523 return {};
1524
1525 if (newParamType.getAsOpaquePtr() != paramType.getAsOpaquePtr())
1526 paramChanged = true;
1527
1528 paramTypes.push_back(newParamType);
1529 }
1530
1531 // Transform extended info.
1532 FunctionProtoType::ExtProtoInfo info = funcProtoType->getExtProtoInfo();
1533 bool exceptionChanged = false;
1534 if (info.ExceptionSpec.Type == EST_Dynamic) {
1535 SmallVector<QualType, 4> exceptionTypes;
1536 for (auto exceptionType : info.ExceptionSpec.Exceptions) {
1537 QualType newExceptionType = exceptionType.substObjCTypeArgs(
1538 Ctx, TypeArgs, ObjCSubstitutionContext::Ordinary);
1539 if (newExceptionType.isNull())
1540 return {};
1541
1542 if (newExceptionType.getAsOpaquePtr() != exceptionType.getAsOpaquePtr())
1543 exceptionChanged = true;
1544
1545 exceptionTypes.push_back(newExceptionType);
1546 }
1547
1548 if (exceptionChanged) {
1549 info.ExceptionSpec.Exceptions =
1550 llvm::ArrayRef(exceptionTypes).copy(Ctx);
1551 }
1552 }
1553
1554 if (returnType.getAsOpaquePtr() ==
1555 funcProtoType->getReturnType().getAsOpaquePtr() &&
1556 !paramChanged && !exceptionChanged)
1557 return BaseType::VisitFunctionType(funcType);
1558
1559 return Ctx.getFunctionType(returnType, paramTypes, info);
1560 }
1561
1562 QualType VisitObjCObjectType(const ObjCObjectType *objcObjectType) {
1563 // Substitute into the type arguments of a specialized Objective-C object
1564 // type.
1565 if (objcObjectType->isSpecializedAsWritten()) {
1566 SmallVector<QualType, 4> newTypeArgs;
1567 bool anyChanged = false;
1568 for (auto typeArg : objcObjectType->getTypeArgsAsWritten()) {
1569 QualType newTypeArg = typeArg.substObjCTypeArgs(
1570 Ctx, TypeArgs, ObjCSubstitutionContext::Ordinary);
1571 if (newTypeArg.isNull())
1572 return {};
1573
1574 if (newTypeArg.getAsOpaquePtr() != typeArg.getAsOpaquePtr()) {
1575 // If we're substituting based on an unspecialized context type,
1576 // produce an unspecialized type.
1577 ArrayRef<ObjCProtocolDecl *> protocols(
1578 objcObjectType->qual_begin(), objcObjectType->getNumProtocols());
1579 if (TypeArgs.empty() &&
1580 SubstContext != ObjCSubstitutionContext::Superclass) {
1581 return Ctx.getObjCObjectType(
1582 objcObjectType->getBaseType(), {}, protocols,
1583 objcObjectType->isKindOfTypeAsWritten());
1584 }
1585
1586 anyChanged = true;
1587 }
1588
1589 newTypeArgs.push_back(newTypeArg);
1590 }
1591
1592 if (anyChanged) {
1593 ArrayRef<ObjCProtocolDecl *> protocols(
1594 objcObjectType->qual_begin(), objcObjectType->getNumProtocols());
1595 return Ctx.getObjCObjectType(objcObjectType->getBaseType(), newTypeArgs,
1596 protocols,
1597 objcObjectType->isKindOfTypeAsWritten());
1598 }
1599 }
1600
1601 return BaseType::VisitObjCObjectType(objcObjectType);
1602 }
1603
1604 QualType VisitAttributedType(const AttributedType *attrType) {
1605 QualType newType = BaseType::VisitAttributedType(attrType);
1606 if (newType.isNull())
1607 return {};
1608
1609 const auto *newAttrType = dyn_cast<AttributedType>(newType.getTypePtr());
1610 if (!newAttrType || newAttrType->getAttrKind() != attr::ObjCKindOf)
1611 return newType;
1612
1613 // Find out if it's an Objective-C object or object pointer type;
1614 QualType newEquivType = newAttrType->getEquivalentType();
1615 const ObjCObjectPointerType *ptrType =
1616 newEquivType->getAs<ObjCObjectPointerType>();
1617 const ObjCObjectType *objType = ptrType
1618 ? ptrType->getObjectType()
1619 : newEquivType->getAs<ObjCObjectType>();
1620 if (!objType)
1621 return newType;
1622
1623 // Rebuild the "equivalent" type, which pushes __kindof down into
1624 // the object type.
1625 newEquivType = Ctx.getObjCObjectType(
1626 objType->getBaseType(), objType->getTypeArgsAsWritten(),
1627 objType->getProtocols(),
1628 // There is no need to apply kindof on an unqualified id type.
1629 /*isKindOf=*/objType->isObjCUnqualifiedId() ? false : true);
1630
1631 // If we started with an object pointer type, rebuild it.
1632 if (ptrType)
1633 newEquivType = Ctx.getObjCObjectPointerType(newEquivType);
1634
1635 // Rebuild the attributed type.
1636 return Ctx.getAttributedType(newAttrType->getAttrKind(),
1637 newAttrType->getModifiedType(), newEquivType,
1638 newAttrType->getAttr());
1639 }
1640};
1641
1642struct StripNullabilityTypeVisitor
1643 : public SimpleTransformVisitor<StripNullabilityTypeVisitor> {
1644 using BaseType = SimpleTransformVisitor<StripNullabilityTypeVisitor>;
1645
1646 explicit StripNullabilityTypeVisitor(ASTContext &ctx) : BaseType(ctx) {}
1647
1648 QualType VisitAttributedType(const AttributedType *attrType) {
1649 QualType type(attrType, 0);
1650 if (AttributedType::stripOuterNullability(type)) {
1651 while (AttributedType::stripOuterNullability(type)) {
1652 }
1653 return BaseType::recurse(type);
1654 }
1655
1656 return BaseType::VisitAttributedType(attrType);
1657 }
1658};
1659
1660struct StripObjCKindOfTypeVisitor
1661 : public SimpleTransformVisitor<StripObjCKindOfTypeVisitor> {
1662 using BaseType = SimpleTransformVisitor<StripObjCKindOfTypeVisitor>;
1663
1664 explicit StripObjCKindOfTypeVisitor(ASTContext &ctx) : BaseType(ctx) {}
1665
1666 QualType VisitObjCObjectType(const ObjCObjectType *objType) {
1667 if (!objType->isKindOfType())
1668 return BaseType::VisitObjCObjectType(objType);
1669
1670 QualType baseType = objType->getBaseType().stripObjCKindOfType(Ctx);
1671 return Ctx.getObjCObjectType(baseType, objType->getTypeArgsAsWritten(),
1672 objType->getProtocols(),
1673 /*isKindOf=*/false);
1674 }
1675};
1676
1677} // namespace
1678
1680 const BuiltinType *BT = getTypePtr()->getAs<BuiltinType>();
1681 if (!BT) {
1682 const VectorType *VT = getTypePtr()->getAs<VectorType>();
1683 if (VT) {
1684 QualType ElementType = VT->getElementType();
1685 return ElementType.UseExcessPrecision(Ctx);
1686 }
1687 } else {
1688 switch (BT->getKind()) {
1689 case BuiltinType::Kind::Float16: {
1690 const TargetInfo &TI = Ctx.getTargetInfo();
1691 if (TI.hasFloat16Type() && !TI.hasFastHalfType() &&
1692 Ctx.getLangOpts().getFloat16ExcessPrecision() !=
1693 Ctx.getLangOpts().ExcessPrecisionKind::FPP_None)
1694 return true;
1695 break;
1696 }
1697 case BuiltinType::Kind::BFloat16: {
1698 const TargetInfo &TI = Ctx.getTargetInfo();
1699 if (TI.hasBFloat16Type() && !TI.hasFullBFloat16Type() &&
1700 Ctx.getLangOpts().getBFloat16ExcessPrecision() !=
1701 Ctx.getLangOpts().ExcessPrecisionKind::FPP_None)
1702 return true;
1703 break;
1704 }
1705 default:
1706 return false;
1707 }
1708 }
1709 return false;
1710}
1711
1712/// Substitute the given type arguments for Objective-C type
1713/// parameters within the given type, recursively.
1715 ArrayRef<QualType> typeArgs,
1716 ObjCSubstitutionContext context) const {
1717 SubstObjCTypeArgsVisitor visitor(ctx, typeArgs, context);
1718 return visitor.recurse(*this);
1719}
1720
1722 const DeclContext *dc,
1723 ObjCSubstitutionContext context) const {
1724 if (auto subs = objectType->getObjCSubstitutions(dc))
1725 return substObjCTypeArgs(dc->getParentASTContext(), *subs, context);
1726
1727 return *this;
1728}
1729
1731 // FIXME: Because ASTContext::getAttributedType() is non-const.
1732 auto &ctx = const_cast<ASTContext &>(constCtx);
1733 StripObjCKindOfTypeVisitor visitor(ctx);
1734 return visitor.recurse(*this);
1735}
1736
1738 // FIXME: SimpleTransformVisitor currently takes a non-const ASTContext
1739 // because some rebuild paths use non-const ASTContext factory APIs.
1740 auto &ctx = const_cast<ASTContext &>(constCtx);
1741 StripNullabilityTypeVisitor visitor(ctx);
1742 return visitor.recurse(*this);
1743}
1744
1746 QualType T = *this;
1747 if (const auto AT = T.getTypePtr()->getAs<AtomicType>())
1748 T = AT->getValueType();
1749 return T.getUnqualifiedType();
1750}
1751
1752std::optional<ArrayRef<QualType>>
1754 // Look through method scopes.
1755 if (const auto method = dyn_cast<ObjCMethodDecl>(dc))
1756 dc = method->getDeclContext();
1757
1758 // Find the class or category in which the type we're substituting
1759 // was declared.
1760 const auto *dcClassDecl = dyn_cast<ObjCInterfaceDecl>(dc);
1761 const ObjCCategoryDecl *dcCategoryDecl = nullptr;
1762 ObjCTypeParamList *dcTypeParams = nullptr;
1763 if (dcClassDecl) {
1764 // If the class does not have any type parameters, there's no
1765 // substitution to do.
1766 dcTypeParams = dcClassDecl->getTypeParamList();
1767 if (!dcTypeParams)
1768 return std::nullopt;
1769 } else {
1770 // If we are in neither a class nor a category, there's no
1771 // substitution to perform.
1772 dcCategoryDecl = dyn_cast<ObjCCategoryDecl>(dc);
1773 if (!dcCategoryDecl)
1774 return std::nullopt;
1775
1776 // If the category does not have any type parameters, there's no
1777 // substitution to do.
1778 dcTypeParams = dcCategoryDecl->getTypeParamList();
1779 if (!dcTypeParams)
1780 return std::nullopt;
1781
1782 dcClassDecl = dcCategoryDecl->getClassInterface();
1783 if (!dcClassDecl)
1784 return std::nullopt;
1785 }
1786 assert(dcTypeParams && "No substitutions to perform");
1787 assert(dcClassDecl && "No class context");
1788
1789 // Find the underlying object type.
1790 const ObjCObjectType *objectType;
1791 if (const auto *objectPointerType = getAs<ObjCObjectPointerType>()) {
1792 objectType = objectPointerType->getObjectType();
1793 } else if (getAs<BlockPointerType>()) {
1794 ASTContext &ctx = dc->getParentASTContext();
1795 objectType = ctx.getObjCObjectType(ctx.ObjCBuiltinIdTy, {}, {})
1797 } else {
1798 objectType = getAs<ObjCObjectType>();
1799 }
1800
1801 /// Extract the class from the receiver object type.
1802 ObjCInterfaceDecl *curClassDecl =
1803 objectType ? objectType->getInterface() : nullptr;
1804 if (!curClassDecl) {
1805 // If we don't have a context type (e.g., this is "id" or some
1806 // variant thereof), substitute the bounds.
1807 return llvm::ArrayRef<QualType>();
1808 }
1809
1810 // Follow the superclass chain until we've mapped the receiver type
1811 // to the same class as the context.
1812 while (curClassDecl != dcClassDecl) {
1813 // Map to the superclass type.
1814 QualType superType = objectType->getSuperClassType();
1815 if (superType.isNull()) {
1816 objectType = nullptr;
1817 break;
1818 }
1819
1820 objectType = superType->castAs<ObjCObjectType>();
1821 curClassDecl = objectType->getInterface();
1822 }
1823
1824 // If we don't have a receiver type, or the receiver type does not
1825 // have type arguments, substitute in the defaults.
1826 if (!objectType || objectType->isUnspecialized()) {
1827 return llvm::ArrayRef<QualType>();
1828 }
1829
1830 // The receiver type has the type arguments we want.
1831 return objectType->getTypeArgs();
1832}
1833
1835 if (auto *IfaceT = getAsObjCInterfaceType()) {
1836 if (auto *ID = IfaceT->getInterface()) {
1837 if (ID->getTypeParamList())
1838 return true;
1839 }
1840 }
1841
1842 return false;
1843}
1844
1845void ObjCObjectType::computeSuperClassTypeSlow() const {
1846 // Retrieve the class declaration for this type. If there isn't one
1847 // (e.g., this is some variant of "id" or "Class"), then there is no
1848 // superclass type.
1849 ObjCInterfaceDecl *classDecl = getInterface();
1850 if (!classDecl) {
1851 CachedSuperClassType.setInt(true);
1852 return;
1853 }
1854
1855 // Extract the superclass type.
1856 const ObjCObjectType *superClassObjTy = classDecl->getSuperClassType();
1857 if (!superClassObjTy) {
1858 CachedSuperClassType.setInt(true);
1859 return;
1860 }
1861
1862 ObjCInterfaceDecl *superClassDecl = superClassObjTy->getInterface();
1863 if (!superClassDecl) {
1864 CachedSuperClassType.setInt(true);
1865 return;
1866 }
1867
1868 // If the superclass doesn't have type parameters, then there is no
1869 // substitution to perform.
1870 QualType superClassType(superClassObjTy, 0);
1871 ObjCTypeParamList *superClassTypeParams = superClassDecl->getTypeParamList();
1872 if (!superClassTypeParams) {
1873 CachedSuperClassType.setPointerAndInt(
1874 superClassType->castAs<ObjCObjectType>(), true);
1875 return;
1876 }
1877
1878 // If the superclass reference is unspecialized, return it.
1879 if (superClassObjTy->isUnspecialized()) {
1880 CachedSuperClassType.setPointerAndInt(superClassObjTy, true);
1881 return;
1882 }
1883
1884 // If the subclass is not parameterized, there aren't any type
1885 // parameters in the superclass reference to substitute.
1886 ObjCTypeParamList *typeParams = classDecl->getTypeParamList();
1887 if (!typeParams) {
1888 CachedSuperClassType.setPointerAndInt(
1889 superClassType->castAs<ObjCObjectType>(), true);
1890 return;
1891 }
1892
1893 // If the subclass type isn't specialized, return the unspecialized
1894 // superclass.
1895 if (isUnspecialized()) {
1896 QualType unspecializedSuper =
1898 superClassObjTy->getInterface());
1899 CachedSuperClassType.setPointerAndInt(
1900 unspecializedSuper->castAs<ObjCObjectType>(), true);
1901 return;
1902 }
1903
1904 // Substitute the provided type arguments into the superclass type.
1905 ArrayRef<QualType> typeArgs = getTypeArgs();
1906 assert(typeArgs.size() == typeParams->size());
1907 CachedSuperClassType.setPointerAndInt(
1908 superClassType
1909 .substObjCTypeArgs(classDecl->getASTContext(), typeArgs,
1911 ->castAs<ObjCObjectType>(),
1912 true);
1913}
1914
1916 if (auto interfaceDecl = getObjectType()->getInterface()) {
1917 return interfaceDecl->getASTContext()
1918 .getObjCInterfaceType(interfaceDecl)
1919 ->castAs<ObjCInterfaceType>();
1920 }
1921
1922 return nullptr;
1923}
1924
1926 QualType superObjectType = getObjectType()->getSuperClassType();
1927 if (superObjectType.isNull())
1928 return superObjectType;
1929
1931 return ctx.getObjCObjectPointerType(superObjectType);
1932}
1933
1935 // There is no sugar for ObjCObjectType's, just return the canonical
1936 // type pointer if it is the right class. There is no typedef information to
1937 // return and these cannot be Address-space qualified.
1938 if (const auto *T = getAs<ObjCObjectType>())
1939 if (T->getNumProtocols() && T->getInterface())
1940 return T;
1941 return nullptr;
1942}
1943
1945 return getAsObjCQualifiedInterfaceType() != nullptr;
1946}
1947
1949 // There is no sugar for ObjCQualifiedIdType's, just return the canonical
1950 // type pointer if it is the right class.
1951 if (const auto *OPT = getAs<ObjCObjectPointerType>()) {
1952 if (OPT->isObjCQualifiedIdType())
1953 return OPT;
1954 }
1955 return nullptr;
1956}
1957
1959 // There is no sugar for ObjCQualifiedClassType's, just return the canonical
1960 // type pointer if it is the right class.
1961 if (const auto *OPT = getAs<ObjCObjectPointerType>()) {
1962 if (OPT->isObjCQualifiedClassType())
1963 return OPT;
1964 }
1965 return nullptr;
1966}
1967
1969 if (const auto *OT = getAs<ObjCObjectType>()) {
1970 if (OT->getInterface())
1971 return OT;
1972 }
1973 return nullptr;
1974}
1975
1977 if (const auto *OPT = getAs<ObjCObjectPointerType>()) {
1978 if (OPT->getInterfaceType())
1979 return OPT;
1980 }
1981 return nullptr;
1982}
1983
1985 QualType PointeeType;
1986 if (const auto *PT = getAsCanonical<PointerType>())
1987 PointeeType = PT->getPointeeType();
1988 else if (const auto *RT = getAsCanonical<ReferenceType>())
1989 PointeeType = RT->getPointeeType();
1990 else
1991 return nullptr;
1992 return PointeeType->getAsCXXRecordDecl();
1993}
1994
1995const TemplateSpecializationType *
1997 const auto *TST = getAs<TemplateSpecializationType>();
1998 while (TST && TST->isTypeAlias())
1999 TST = TST->desugar()->getAs<TemplateSpecializationType>();
2000 return TST;
2001}
2002
2004 switch (getTypeClass()) {
2005 case Type::DependentName:
2006 return cast<DependentNameType>(this)->getQualifier();
2007 case Type::TemplateSpecialization:
2009 ->getTemplateName()
2010 .getQualifier();
2011 case Type::Enum:
2012 case Type::Record:
2013 case Type::InjectedClassName:
2014 return cast<TagType>(this)->getQualifier();
2015 case Type::Typedef:
2016 return cast<TypedefType>(this)->getQualifier();
2017 case Type::UnresolvedUsing:
2018 return cast<UnresolvedUsingType>(this)->getQualifier();
2019 case Type::Using:
2020 return cast<UsingType>(this)->getQualifier();
2021 default:
2022 return std::nullopt;
2023 }
2024}
2025
2027 const Type *Cur = this;
2028 while (const auto *AT = Cur->getAs<AttributedType>()) {
2029 if (AT->getAttrKind() == AK)
2030 return true;
2031 Cur = AT->getEquivalentType().getTypePtr();
2032 }
2033 return false;
2034}
2035
2036namespace {
2037
2038class GetContainedDeducedTypeVisitor
2039 : public TypeVisitor<GetContainedDeducedTypeVisitor, Type *> {
2040 bool Syntactic;
2041
2042public:
2043 GetContainedDeducedTypeVisitor(bool Syntactic = false)
2044 : Syntactic(Syntactic) {}
2045
2046 using TypeVisitor<GetContainedDeducedTypeVisitor, Type *>::Visit;
2047
2048 Type *Visit(QualType T) {
2049 if (T.isNull())
2050 return nullptr;
2051 return Visit(T.getTypePtr());
2052 }
2053
2054 // The deduced type itself.
2055 Type *VisitDeducedType(const DeducedType *AT) {
2056 return const_cast<DeducedType *>(AT);
2057 }
2058
2059 // Only these types can contain the desired 'auto' type.
2060 Type *VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
2061 return Visit(T->getReplacementType());
2062 }
2063
2064 Type *VisitPointerType(const PointerType *T) {
2065 return Visit(T->getPointeeType());
2066 }
2067
2068 Type *VisitBlockPointerType(const BlockPointerType *T) {
2069 return Visit(T->getPointeeType());
2070 }
2071
2072 Type *VisitReferenceType(const ReferenceType *T) {
2073 return Visit(T->getPointeeTypeAsWritten());
2074 }
2075
2076 Type *VisitMemberPointerType(const MemberPointerType *T) {
2077 return Visit(T->getPointeeType());
2078 }
2079
2080 Type *VisitArrayType(const ArrayType *T) {
2081 return Visit(T->getElementType());
2082 }
2083
2084 Type *VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *T) {
2085 return Visit(T->getElementType());
2086 }
2087
2088 Type *VisitVectorType(const VectorType *T) {
2089 return Visit(T->getElementType());
2090 }
2091
2092 Type *VisitDependentSizedMatrixType(const DependentSizedMatrixType *T) {
2093 return Visit(T->getElementType());
2094 }
2095
2096 Type *VisitConstantMatrixType(const ConstantMatrixType *T) {
2097 return Visit(T->getElementType());
2098 }
2099
2100 Type *VisitFunctionProtoType(const FunctionProtoType *T) {
2101 if (Syntactic && T->hasTrailingReturn())
2102 return const_cast<FunctionProtoType *>(T);
2103 return VisitFunctionType(T);
2104 }
2105
2106 Type *VisitFunctionType(const FunctionType *T) {
2107 return Visit(T->getReturnType());
2108 }
2109
2110 Type *VisitParenType(const ParenType *T) { return Visit(T->getInnerType()); }
2111
2112 Type *VisitAttributedType(const AttributedType *T) {
2113 return Visit(T->getModifiedType());
2114 }
2115
2116 Type *VisitMacroQualifiedType(const MacroQualifiedType *T) {
2117 return Visit(T->getUnderlyingType());
2118 }
2119
2120 Type *VisitOverflowBehaviorType(const OverflowBehaviorType *T) {
2121 return Visit(T->getUnderlyingType());
2122 }
2123
2124 Type *VisitAdjustedType(const AdjustedType *T) {
2125 return Visit(T->getOriginalType());
2126 }
2127
2128 Type *VisitPackExpansionType(const PackExpansionType *T) {
2129 return Visit(T->getPattern());
2130 }
2131
2132 Type *VisitAtomicType(const AtomicType *T) {
2133 return Visit(T->getValueType());
2134 }
2135};
2136
2137} // namespace
2138
2139DeducedType *Type::getContainedDeducedType() const {
2140 return cast_or_null<DeducedType>(
2141 GetContainedDeducedTypeVisitor().Visit(this));
2142}
2143
2145 return isa_and_nonnull<FunctionType>(
2146 GetContainedDeducedTypeVisitor(true).Visit(this));
2147}
2148
2150 if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
2151 return VT->getElementType()->isIntegerType();
2152 if (CanonicalType->isSveVLSBuiltinType()) {
2153 const auto *VT = cast<BuiltinType>(CanonicalType);
2154 return VT->getKind() == BuiltinType::SveBool ||
2155 (VT->getKind() >= BuiltinType::SveInt8 &&
2156 VT->getKind() <= BuiltinType::SveUint64);
2157 }
2158 if (CanonicalType->isRVVVLSBuiltinType()) {
2159 const auto *VT = cast<BuiltinType>(CanonicalType);
2160 return (VT->getKind() >= BuiltinType::RvvInt8mf8 &&
2161 VT->getKind() <= BuiltinType::RvvUint64m8);
2162 }
2163
2164 return isIntegerType();
2165}
2166
2167/// Determine whether this type is an integral type.
2168///
2169/// This routine determines whether the given type is an integral type per
2170/// C++ [basic.fundamental]p7. Although the C standard does not define the
2171/// term "integral type", it has a similar term "integer type", and in C++
2172/// the two terms are equivalent. However, C's "integer type" includes
2173/// enumeration types, while C++'s "integer type" does not. The \c ASTContext
2174/// parameter is used to determine whether we should be following the C or
2175/// C++ rules when determining whether this type is an integral/integer type.
2176///
2177/// For cases where C permits "an integer type" and C++ permits "an integral
2178/// type", use this routine.
2179///
2180/// For cases where C permits "an integer type" and C++ permits "an integral
2181/// or enumeration type", use \c isIntegralOrEnumerationType() instead.
2182///
2183/// \param Ctx The context in which this type occurs.
2184///
2185/// \returns true if the type is considered an integral type, false otherwise.
2186bool Type::isIntegralType(const ASTContext &Ctx) const {
2187 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2188 return BT->isInteger();
2189
2190 // Complete enum types are integral in C.
2191 if (!Ctx.getLangOpts().CPlusPlus) {
2192 if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
2193 return IsEnumDeclComplete(ET->getDecl());
2194
2195 if (const OverflowBehaviorType *OBT =
2196 dyn_cast<OverflowBehaviorType>(CanonicalType))
2197 return OBT->getUnderlyingType()->isIntegralOrEnumerationType();
2198 }
2199
2200 return isBitIntType();
2201}
2202
2204 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2205 return BT->isInteger();
2206
2207 if (const auto *OBT = dyn_cast<OverflowBehaviorType>(CanonicalType))
2208 return OBT->getUnderlyingType()->isIntegerType();
2209
2210 if (isBitIntType())
2211 return true;
2212
2214}
2215
2217 if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
2218 return !ET->getDecl()->isScoped();
2219
2220 return false;
2221}
2222
2223bool Type::isCharType() const {
2224 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2225 return BT->getKind() == BuiltinType::Char_U ||
2226 BT->getKind() == BuiltinType::UChar ||
2227 BT->getKind() == BuiltinType::Char_S ||
2228 BT->getKind() == BuiltinType::SChar;
2229 return false;
2230}
2231
2233 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2234 return BT->getKind() == BuiltinType::WChar_S ||
2235 BT->getKind() == BuiltinType::WChar_U;
2236 return false;
2237}
2238
2239bool Type::isChar8Type() const {
2240 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
2241 return BT->getKind() == BuiltinType::Char8;
2242 return false;
2243}
2244
2246 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2247 return BT->getKind() == BuiltinType::Char16;
2248 return false;
2249}
2250
2252 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2253 return BT->getKind() == BuiltinType::Char32;
2254 return false;
2255}
2256
2257/// Determine whether this type is any of the built-in character
2258/// types.
2260 const auto *BT = dyn_cast<BuiltinType>(CanonicalType);
2261 if (!BT)
2262 return false;
2263 switch (BT->getKind()) {
2264 default:
2265 return false;
2266 case BuiltinType::Char_U:
2267 case BuiltinType::UChar:
2268 case BuiltinType::WChar_U:
2269 case BuiltinType::Char8:
2270 case BuiltinType::Char16:
2271 case BuiltinType::Char32:
2272 case BuiltinType::Char_S:
2273 case BuiltinType::SChar:
2274 case BuiltinType::WChar_S:
2275 return true;
2276 }
2277}
2278
2280 const auto *BT = dyn_cast<BuiltinType>(CanonicalType);
2281 if (!BT)
2282 return false;
2283 switch (BT->getKind()) {
2284 default:
2285 return false;
2286 case BuiltinType::Char8:
2287 case BuiltinType::Char16:
2288 case BuiltinType::Char32:
2289 return true;
2290 }
2291}
2292
2293/// isSignedIntegerType - Return true if this is an integer type that is
2294/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
2295/// an enum decl which has a signed representation
2297 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2298 return BT->isSignedInteger();
2299
2300 if (const auto *ED = getAsEnumDecl()) {
2301 // Incomplete enum types are not treated as integer types.
2302 // FIXME: In C++, enum types are never integer types.
2303 if (!ED->isComplete() || ED->isScoped())
2304 return false;
2305 return ED->getIntegerType()->isSignedIntegerType();
2306 }
2307
2308 if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2309 return IT->isSigned();
2310 if (const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2311 return IT->isSigned();
2312
2313 if (const auto *OBT = dyn_cast<OverflowBehaviorType>(CanonicalType))
2314 return OBT->getUnderlyingType()->isSignedIntegerType();
2315
2316 return false;
2317}
2318
2320 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2321 return BT->isSignedInteger();
2322
2323 if (const auto *ED = getAsEnumDecl()) {
2324 if (!ED->isComplete())
2325 return false;
2326 return ED->getIntegerType()->isSignedIntegerType();
2327 }
2328
2329 if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2330 return IT->isSigned();
2331 if (const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2332 return IT->isSigned();
2333
2334 if (const auto *OBT = dyn_cast<OverflowBehaviorType>(CanonicalType))
2335 return OBT->getUnderlyingType()->isSignedIntegerOrEnumerationType();
2336
2337 return false;
2338}
2339
2341 if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
2342 return VT->getElementType()->isSignedIntegerOrEnumerationType();
2343
2344 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2345 switch (BT->getKind()) {
2346#define SVE_VECTOR_TYPE_INT(Name, MangledName, Id, SingletonId, NumEls, \
2347 ElBits, NF, IsSigned) \
2348 case BuiltinType::Id: \
2349 return IsSigned;
2350#include "clang/Basic/AArch64ACLETypes.def"
2351 default:
2352 break;
2353 }
2354 }
2355
2357}
2358
2359/// isUnsignedIntegerType - Return true if this is an integer type that is
2360/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
2361/// decl which has an unsigned representation
2363 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2364 return BT->isUnsignedInteger();
2365
2366 if (const auto *ED = getAsEnumDecl()) {
2367 // Incomplete enum types are not treated as integer types.
2368 // FIXME: In C++, enum types are never integer types.
2369 if (!ED->isComplete() || ED->isScoped())
2370 return false;
2371 return ED->getIntegerType()->isUnsignedIntegerType();
2372 }
2373
2374 if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2375 return IT->isUnsigned();
2376 if (const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2377 return IT->isUnsigned();
2378
2379 if (const auto *OBT = dyn_cast<OverflowBehaviorType>(CanonicalType))
2380 return OBT->getUnderlyingType()->isUnsignedIntegerType();
2381
2382 return false;
2383}
2384
2386 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2387 return BT->isUnsignedInteger();
2388
2389 if (const auto *ED = getAsEnumDecl()) {
2390 if (!ED->isComplete())
2391 return false;
2392 return ED->getIntegerType()->isUnsignedIntegerType();
2393 }
2394
2395 if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2396 return IT->isUnsigned();
2397 if (const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2398 return IT->isUnsigned();
2399
2400 if (const auto *OBT = dyn_cast<OverflowBehaviorType>(CanonicalType))
2401 return OBT->getUnderlyingType()->isUnsignedIntegerOrEnumerationType();
2402
2403 return false;
2404}
2405
2407 if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
2408 return VT->getElementType()->isUnsignedIntegerOrEnumerationType();
2409 if (const auto *VT = dyn_cast<MatrixType>(CanonicalType))
2410 return VT->getElementType()->isUnsignedIntegerOrEnumerationType();
2411 if (CanonicalType->isSveVLSBuiltinType()) {
2412 const auto *VT = cast<BuiltinType>(CanonicalType);
2413 return VT->getKind() >= BuiltinType::SveUint8 &&
2414 VT->getKind() <= BuiltinType::SveUint64;
2415 }
2417}
2418
2420 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2421 return BT->isFloatingPoint();
2422 if (const auto *CT = dyn_cast<ComplexType>(CanonicalType))
2423 return CT->getElementType()->isFloatingType();
2424 return false;
2425}
2426
2428 if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
2429 return VT->getElementType()->isFloatingType();
2430 if (const auto *MT = dyn_cast<MatrixType>(CanonicalType))
2431 return MT->getElementType()->isFloatingType();
2432 return isFloatingType();
2433}
2434
2436 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2437 return BT->isFloatingPoint();
2438 return false;
2439}
2440
2441bool Type::isRealType() const {
2442 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2443 return BT->getKind() >= BuiltinType::Bool &&
2444 BT->getKind() <= BuiltinType::Ibm128;
2445 if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2446 const auto *ED = ET->getDecl();
2447 return !ED->isScoped() && ED->getDefinitionOrSelf()->isComplete();
2448 }
2449 return isBitIntType();
2450}
2451
2453 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2454 return BT->getKind() >= BuiltinType::Bool &&
2455 BT->getKind() <= BuiltinType::Ibm128;
2456 if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2457 // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
2458 // If a body isn't seen by the time we get here, return false.
2459 //
2460 // C++0x: Enumerations are not arithmetic types. For now, just return
2461 // false for scoped enumerations since that will disable any
2462 // unwanted implicit conversions.
2463 const auto *ED = ET->getDecl();
2464 return !ED->isScoped() && ED->getDefinitionOrSelf()->isComplete();
2465 }
2466
2467 if (isOverflowBehaviorType() &&
2469 return true;
2470
2471 return isa<ComplexType>(CanonicalType) || isBitIntType();
2472}
2473
2475 if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
2476 return VT->getElementType()->isBooleanType();
2477 if (const auto *ED = getAsEnumDecl())
2478 return ED->isComplete() && ED->getIntegerType()->isBooleanType();
2479 if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2480 return IT->getNumBits() == 1;
2481 return isBooleanType();
2482}
2483
2485 assert(isScalarType());
2486
2487 const Type *T = CanonicalType.getTypePtr();
2488 if (const auto *BT = dyn_cast<BuiltinType>(T)) {
2489 if (BT->getKind() == BuiltinType::Bool)
2490 return STK_Bool;
2491 if (BT->getKind() == BuiltinType::NullPtr)
2492 return STK_CPointer;
2493 if (BT->isInteger())
2494 return STK_Integral;
2495 if (BT->isFloatingPoint())
2496 return STK_Floating;
2497 if (BT->isFixedPointType())
2498 return STK_FixedPoint;
2499 llvm_unreachable("unknown scalar builtin type");
2500 } else if (isa<PointerType>(T)) {
2501 return STK_CPointer;
2502 } else if (isa<BlockPointerType>(T)) {
2503 return STK_BlockPointer;
2504 } else if (isa<ObjCObjectPointerType>(T)) {
2505 return STK_ObjCObjectPointer;
2506 } else if (isa<MemberPointerType>(T)) {
2507 return STK_MemberPointer;
2508 } else if (isa<EnumType>(T)) {
2509 assert(T->castAsEnumDecl()->isComplete());
2510 return STK_Integral;
2511 } else if (const auto *CT = dyn_cast<ComplexType>(T)) {
2512 if (CT->getElementType()->isRealFloatingType())
2513 return STK_FloatingComplex;
2514 return STK_IntegralComplex;
2515 } else if (isBitIntType()) {
2516 return STK_Integral;
2517 } else if (isa<OverflowBehaviorType>(T)) {
2518 return STK_Integral;
2519 }
2520
2521 llvm_unreachable("unknown scalar type");
2522}
2523
2524/// Determines whether the type is a C++ aggregate type or C
2525/// aggregate or union type.
2526///
2527/// An aggregate type is an array or a class type (struct, union, or
2528/// class) that has no user-declared constructors, no private or
2529/// protected non-static data members, no base classes, and no virtual
2530/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type
2531/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also
2532/// includes union types.
2534 if (const auto *Record = dyn_cast<RecordType>(CanonicalType)) {
2535 if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl()))
2536 return ClassDecl->isAggregate();
2537
2538 return true;
2539 }
2540
2541 return isa<ArrayType>(CanonicalType);
2542}
2543
2544/// isConstantSizeType - Return true if this is not a variable sized type,
2545/// according to the rules of C99 6.7.5p3. It is not legal to call this on
2546/// incomplete types or dependent types.
2548 assert(!isIncompleteType() && "This doesn't make sense for incomplete types");
2549 assert(!isDependentType() && "This doesn't make sense for dependent types");
2550 // The VAT must have a size, as it is known to be complete.
2551 return !isa<VariableArrayType>(CanonicalType);
2552}
2553
2554/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1)
2555/// - a type that can describe objects, but which lacks information needed to
2556/// determine its size.
2558 if (Def)
2559 *Def = nullptr;
2560
2561 switch (CanonicalType->getTypeClass()) {
2562 default:
2563 return false;
2564 case Builtin:
2565 // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never
2566 // be completed.
2567 return isVoidType();
2568 case Enum: {
2569 auto *EnumD = castAsEnumDecl();
2570 if (Def)
2571 *Def = EnumD;
2572 return !EnumD->isComplete();
2573 }
2574 case Record: {
2575 // A tagged type (struct/union/enum/class) is incomplete if the decl is a
2576 // forward declaration, but not a full definition (C99 6.2.5p22).
2577 auto *Rec = castAsRecordDecl();
2578 if (Def)
2579 *Def = Rec;
2580 return !Rec->isCompleteDefinition();
2581 }
2582 case InjectedClassName: {
2583 auto *Rec = castAsCXXRecordDecl();
2584 if (!Rec->isBeingDefined())
2585 return false;
2586 if (Def)
2587 *Def = Rec;
2588 return true;
2589 }
2590 case ConstantArray:
2591 case VariableArray:
2592 // An array is incomplete if its element type is incomplete
2593 // (C++ [dcl.array]p1).
2594 // We don't handle dependent-sized arrays (dependent types are never treated
2595 // as incomplete).
2596 return cast<ArrayType>(CanonicalType)
2597 ->getElementType()
2598 ->isIncompleteType(Def);
2599 case IncompleteArray:
2600 // An array of unknown size is an incomplete type (C99 6.2.5p22).
2601 return true;
2602 case MemberPointer: {
2603 // Member pointers in the MS ABI have special behavior in
2604 // RequireCompleteType: they attach a MSInheritanceAttr to the CXXRecordDecl
2605 // to indicate which inheritance model to use.
2606 // The inheritance attribute might only be present on the most recent
2607 // CXXRecordDecl.
2608 const CXXRecordDecl *RD =
2609 cast<MemberPointerType>(CanonicalType)->getMostRecentCXXRecordDecl();
2610 // Member pointers with dependent class types don't get special treatment.
2611 if (!RD || RD->isDependentType())
2612 return false;
2613 ASTContext &Context = RD->getASTContext();
2614 // Member pointers not in the MS ABI don't get special treatment.
2615 if (!Context.getTargetInfo().getCXXABI().isMicrosoft())
2616 return false;
2617 // Nothing interesting to do if the inheritance attribute is already set.
2618 if (RD->hasAttr<MSInheritanceAttr>())
2619 return false;
2620 return true;
2621 }
2622 case ObjCObject:
2623 return cast<ObjCObjectType>(CanonicalType)
2624 ->getBaseType()
2625 ->isIncompleteType(Def);
2626 case ObjCInterface: {
2627 // ObjC interfaces are incomplete if they are @class, not @interface.
2629 cast<ObjCInterfaceType>(CanonicalType)->getDecl();
2630 if (Def)
2631 *Def = Interface;
2632 return !Interface->hasDefinition();
2633 }
2634 }
2635}
2636
2638 if (!isIncompleteType())
2639 return false;
2640
2641 // Forward declarations of structs, classes, enums, and unions could be later
2642 // completed in a compilation unit by providing a type definition.
2643 if (isa<TagType>(CanonicalType))
2644 return false;
2645
2646 // Other types are incompletable.
2647 //
2648 // E.g. `char[]` and `void`. The type is incomplete and no future
2649 // type declarations can make the type complete.
2650 return true;
2651}
2652
2655 return true;
2656
2657 if (const BuiltinType *BT = getAs<BuiltinType>()) {
2658 switch (BT->getKind()) {
2659 // WebAssembly reference types
2660#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2661#include "clang/Basic/WebAssemblyReferenceTypes.def"
2662 // HLSL intangible types
2663#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2664#include "clang/Basic/HLSLIntangibleTypes.def"
2665 // AMDGPU feature predicate type
2666 case BuiltinType::AMDGPUFeaturePredicate:
2667 return true;
2668 default:
2669 return false;
2670 }
2671 }
2672 return false;
2673}
2674
2676 if (const auto *BT = getAs<BuiltinType>())
2677 return BT->getKind() == BuiltinType::WasmExternRef;
2678 return false;
2679}
2680
2682 if (const auto *ATy = dyn_cast<ArrayType>(this))
2683 return ATy->getElementType().isWebAssemblyReferenceType();
2684
2685 if (const auto *PTy = dyn_cast<PointerType>(this))
2686 return PTy->getPointeeType().isWebAssemblyReferenceType();
2687
2688 return false;
2689}
2690
2692
2696
2698 if (const BuiltinType *BT = getAs<BuiltinType>()) {
2699 switch (BT->getKind()) {
2700 // SVE Types
2701#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
2702 case BuiltinType::Id: \
2703 return true;
2704#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
2705 case BuiltinType::Id: \
2706 return true;
2707#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId) \
2708 case BuiltinType::Id: \
2709 return true;
2710#include "clang/Basic/AArch64ACLETypes.def"
2711 default:
2712 return false;
2713 }
2714 }
2715 return false;
2716}
2717
2719 if (const BuiltinType *BT = getAs<BuiltinType>()) {
2720 switch (BT->getKind()) {
2721#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2722#include "clang/Basic/RISCVVTypes.def"
2723 return true;
2724 default:
2725 return false;
2726 }
2727 }
2728 return false;
2729}
2730
2732 if (const BuiltinType *BT = getAs<BuiltinType>()) {
2733 switch (BT->getKind()) {
2734 case BuiltinType::SveInt8:
2735 case BuiltinType::SveInt16:
2736 case BuiltinType::SveInt32:
2737 case BuiltinType::SveInt64:
2738 case BuiltinType::SveUint8:
2739 case BuiltinType::SveUint16:
2740 case BuiltinType::SveUint32:
2741 case BuiltinType::SveUint64:
2742 case BuiltinType::SveFloat16:
2743 case BuiltinType::SveFloat32:
2744 case BuiltinType::SveFloat64:
2745 case BuiltinType::SveBFloat16:
2746 case BuiltinType::SveBool:
2747 case BuiltinType::SveBoolx2:
2748 case BuiltinType::SveBoolx4:
2749 case BuiltinType::SveMFloat8:
2750 return true;
2751 default:
2752 return false;
2753 }
2754 }
2755 return false;
2756}
2757
2759 assert(isSizelessVectorType() && "Must be sizeless vector type");
2760 // Currently supports SVE and RVV
2762 return getSveEltType(Ctx);
2763
2765 return getRVVEltType(Ctx);
2766
2767 llvm_unreachable("Unhandled type");
2768}
2769
2771 assert(isSveVLSBuiltinType() && "unsupported type!");
2772
2773 const BuiltinType *BTy = castAs<BuiltinType>();
2774 if (BTy->getKind() == BuiltinType::SveBool)
2775 // Represent predicates as i8 rather than i1 to avoid any layout issues.
2776 // The type is bitcasted to a scalable predicate type when casting between
2777 // scalable and fixed-length vectors.
2778 return Ctx.UnsignedCharTy;
2779 else
2780 return Ctx.getBuiltinVectorTypeInfo(BTy).ElementType;
2781}
2782
2784 if (const BuiltinType *BT = getAs<BuiltinType>()) {
2785 switch (BT->getKind()) {
2786#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, \
2787 IsFP, IsBF) \
2788 case BuiltinType::Id: \
2789 return NF == 1;
2790#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls) \
2791 case BuiltinType::Id: \
2792 return true;
2793#include "clang/Basic/RISCVVTypes.def"
2794 default:
2795 return false;
2796 }
2797 }
2798 return false;
2799}
2800
2802 assert(isRVVVLSBuiltinType() && "unsupported type!");
2803
2804 const BuiltinType *BTy = castAs<BuiltinType>();
2805
2806 switch (BTy->getKind()) {
2807#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls) \
2808 case BuiltinType::Id: \
2809 return Ctx.UnsignedCharTy;
2810 default:
2811 return Ctx.getBuiltinVectorTypeInfo(BTy).ElementType;
2812#include "clang/Basic/RISCVVTypes.def"
2813 }
2814
2815 llvm_unreachable("Unhandled type");
2816}
2817
2818bool QualType::isPODType(const ASTContext &Context) const {
2819 if (Context.getLangOpts().HLSL &&
2820 getTypePtr()->isHLSLStandardLayoutRecordOrArrayOf())
2821 return true;
2822
2823 // C++11 has a more relaxed definition of POD.
2824 if (Context.getLangOpts().CPlusPlus11)
2825 return isCXX11PODType(Context);
2826
2827 return isCXX98PODType(Context);
2828}
2829
2830bool QualType::isCXX98PODType(const ASTContext &Context) const {
2831 // The compiler shouldn't query this for incomplete types, but the user might.
2832 // We return false for that case. Except for incomplete arrays of PODs, which
2833 // are PODs according to the standard.
2834 if (isNull())
2835 return false;
2836
2837 if ((*this)->isIncompleteArrayType())
2838 return Context.getBaseElementType(*this).isCXX98PODType(Context);
2839
2840 if ((*this)->isIncompleteType())
2841 return false;
2842
2844 return false;
2845
2846 QualType CanonicalType = getTypePtr()->CanonicalType;
2847
2848 // Any type that is, or contains, address discriminated data is never POD.
2849 if (Context.containsAddressDiscriminatedPointerAuth(CanonicalType))
2850 return false;
2851
2852 switch (CanonicalType->getTypeClass()) {
2853 // Everything not explicitly mentioned is not POD.
2854 default:
2855 return false;
2856 case Type::VariableArray:
2857 case Type::ConstantArray:
2858 // IncompleteArray is handled above.
2859 return Context.getBaseElementType(*this).isCXX98PODType(Context);
2860
2861 case Type::ObjCObjectPointer:
2862 case Type::BlockPointer:
2863 case Type::Builtin:
2864 case Type::Complex:
2865 case Type::Pointer:
2866 case Type::MemberPointer:
2867 case Type::Vector:
2868 case Type::ExtVector:
2869 case Type::BitInt:
2870 case Type::OverflowBehavior:
2871 return true;
2872
2873 case Type::Enum:
2874 return true;
2875
2876 case Type::Record:
2877 if (const auto *ClassDecl =
2878 dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl()))
2879 return ClassDecl->isPOD();
2880
2881 // C struct/union is POD.
2882 return true;
2883 }
2884}
2885
2886bool QualType::isTrivialType(const ASTContext &Context) const {
2887 // The compiler shouldn't query this for incomplete types, but the user might.
2888 // We return false for that case. Except for incomplete arrays of PODs, which
2889 // are PODs according to the standard.
2890 if (isNull())
2891 return false;
2892
2893 if ((*this)->isArrayType())
2894 return Context.getBaseElementType(*this).isTrivialType(Context);
2895
2896 if ((*this)->isSizelessBuiltinType())
2897 return true;
2898
2899 // Return false for incomplete types after skipping any incomplete array
2900 // types which are expressly allowed by the standard and thus our API.
2901 if ((*this)->isIncompleteType())
2902 return false;
2903
2905 return false;
2906
2907 QualType CanonicalType = getTypePtr()->CanonicalType;
2908 if (CanonicalType->isDependentType())
2909 return false;
2910
2911 // Any type that is, or contains, address discriminated data is never a
2912 // trivial type.
2913 if (Context.containsAddressDiscriminatedPointerAuth(CanonicalType))
2914 return false;
2915
2916 // C++0x [basic.types]p9:
2917 // Scalar types, trivial class types, arrays of such types, and
2918 // cv-qualified versions of these types are collectively called trivial
2919 // types.
2920
2921 // As an extension, Clang treats vector types as Scalar types.
2922 if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
2923 return true;
2924
2925 if (const auto *ClassDecl = CanonicalType->getAsCXXRecordDecl()) {
2926 // C++20 [class]p6:
2927 // A trivial class is a class that is trivially copyable, and
2928 // has one or more eligible default constructors such that each is
2929 // trivial.
2930 // FIXME: We should merge this definition of triviality into
2931 // CXXRecordDecl::isTrivial. Currently it computes the wrong thing.
2932 return ClassDecl->hasTrivialDefaultConstructor() &&
2933 !ClassDecl->hasNonTrivialDefaultConstructor() &&
2934 ClassDecl->isTriviallyCopyable();
2935 }
2936
2937 if (isa<RecordType>(CanonicalType))
2938 return true;
2939
2940 // No other types can match.
2941 return false;
2942}
2943
2945 const ASTContext &Context,
2946 bool IsCopyConstructible) {
2947 if (type->isArrayType())
2948 return isTriviallyCopyableTypeImpl(Context.getBaseElementType(type),
2949 Context, IsCopyConstructible);
2950
2951 if (type.hasNonTrivialObjCLifetime())
2952 return false;
2953
2954 // C++11 [basic.types]p9 - See Core 2094
2955 // Scalar types, trivially copyable class types, arrays of such types, and
2956 // cv-qualified versions of these types are collectively
2957 // called trivially copy constructible types.
2958
2959 QualType CanonicalType = type.getCanonicalType();
2960 if (CanonicalType->isDependentType())
2961 return false;
2962
2963 if (CanonicalType->isSizelessBuiltinType())
2964 return true;
2965
2966 // Return false for incomplete types after skipping any incomplete array types
2967 // which are expressly allowed by the standard and thus our API.
2968 if (CanonicalType->isIncompleteType())
2969 return false;
2970
2971 if (CanonicalType.hasAddressDiscriminatedPointerAuth())
2972 return false;
2973
2974 // As an extension, Clang treats vector and matrix types as Scalar types.
2975 if (CanonicalType->isScalarType() || CanonicalType->isVectorType() ||
2976 CanonicalType->isMatrixType())
2977 return true;
2978
2979 // Mfloat8 type is a special case as it not scalar, but is still trivially
2980 // copyable.
2981 if (CanonicalType->isMFloat8Type())
2982 return true;
2983
2984 if (const auto *RD = CanonicalType->getAsRecordDecl()) {
2985 if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RD)) {
2986 if (IsCopyConstructible)
2987 return ClassDecl->isTriviallyCopyConstructible();
2988 return ClassDecl->isTriviallyCopyable();
2989 }
2990 return !RD->isNonTrivialToPrimitiveCopy();
2991 }
2992 // No other types can match.
2993 return false;
2994}
2995
2997 return isTriviallyCopyableTypeImpl(*this, Context,
2998 /*IsCopyConstructible=*/false);
2999}
3000
3001// FIXME: each call will trigger a full computation, cache the result.
3003 auto CanonicalType = getCanonicalType();
3004 if (CanonicalType.hasNonTrivialObjCLifetime())
3005 return false;
3006 if (CanonicalType->isArrayType())
3007 return Context.getBaseElementType(CanonicalType)
3008 .isBitwiseCloneableType(Context);
3009
3010 if (CanonicalType->isIncompleteType())
3011 return false;
3012
3013 // Any type that is, or contains, address discriminated data is never
3014 // bitwise clonable.
3015 if (Context.containsAddressDiscriminatedPointerAuth(CanonicalType))
3016 return false;
3017
3018 const auto *RD = CanonicalType->getAsRecordDecl(); // struct/union/class
3019 if (!RD)
3020 return true;
3021
3022 if (RD->isInvalidDecl())
3023 return false;
3024
3025 // Never allow memcpy when we're adding poisoned padding bits to the struct.
3026 // Accessing these posioned bits will trigger false alarms on
3027 // SanitizeAddressFieldPadding etc.
3028 if (RD->mayInsertExtraPadding())
3029 return false;
3030
3031 for (auto *const Field : RD->fields()) {
3032 if (!Field->getType().isBitwiseCloneableType(Context))
3033 return false;
3034 }
3035
3036 if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
3037 for (auto Base : CXXRD->bases())
3038 if (!Base.getType().isBitwiseCloneableType(Context))
3039 return false;
3040 for (auto VBase : CXXRD->vbases())
3041 if (!VBase.getType().isBitwiseCloneableType(Context))
3042 return false;
3043 }
3044 return true;
3045}
3046
3048 const ASTContext &Context) const {
3049 return isTriviallyCopyableTypeImpl(*this, Context,
3050 /*IsCopyConstructible=*/true);
3051}
3052
3054 return !Context.getLangOpts().ObjCAutoRefCount &&
3055 Context.getLangOpts().ObjCWeak &&
3057}
3058
3060 const RecordDecl *RD) {
3062}
3063
3066}
3067
3070}
3071
3075
3079
3085
3087 if (const auto *OBT = getCanonicalType()->getAs<OverflowBehaviorType>())
3088 return OBT->getBehaviorKind() ==
3089 OverflowBehaviorType::OverflowBehaviorKind::Wrap;
3090
3091 return false;
3092}
3093
3095 if (const auto *OBT = getCanonicalType()->getAs<OverflowBehaviorType>())
3096 return OBT->getBehaviorKind() ==
3097 OverflowBehaviorType::OverflowBehaviorKind::Trap;
3098
3099 return false;
3100}
3101
3104 if (const auto *RD =
3105 getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
3107 return PDIK_Struct;
3108
3109 switch (getQualifiers().getObjCLifetime()) {
3111 return PDIK_ARCStrong;
3113 return PDIK_ARCWeak;
3114 default:
3115 return PDIK_Trivial;
3116 }
3117}
3118
3120 if (const auto *RD =
3121 getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
3123 return PCK_Struct;
3124
3126 switch (Qs.getObjCLifetime()) {
3128 return PCK_ARCStrong;
3130 return PCK_ARCWeak;
3131 default:
3133 return PCK_PtrAuth;
3135 }
3136}
3137
3142
3143bool Type::isLiteralType(const ASTContext &Ctx) const {
3144 if (isDependentType())
3145 return false;
3146
3147 // C++1y [basic.types]p10:
3148 // A type is a literal type if it is:
3149 // -- cv void; or
3150 if (Ctx.getLangOpts().CPlusPlus14 && isVoidType())
3151 return true;
3152
3153 // C++11 [basic.types]p10:
3154 // A type is a literal type if it is:
3155 // [...]
3156 // -- an array of literal type other than an array of runtime bound; or
3157 if (isVariableArrayType())
3158 return false;
3159 const Type *BaseTy = getBaseElementTypeUnsafe();
3160 assert(BaseTy && "NULL element type");
3161
3162 // Return false for incomplete types after skipping any incomplete array
3163 // types; those are expressly allowed by the standard and thus our API.
3164 if (BaseTy->isIncompleteType())
3165 return false;
3166
3167 // C++11 [basic.types]p10:
3168 // A type is a literal type if it is:
3169 // -- a scalar type; or
3170 // As an extension, Clang treats vector types and complex types as
3171 // literal types.
3172 if (BaseTy->isScalarType() || BaseTy->isVectorType() ||
3173 BaseTy->isAnyComplexType())
3174 return true;
3175 // Matrices with constant numbers of rows and columns are also literal types
3176 // in HLSL.
3177 if (Ctx.getLangOpts().HLSL && BaseTy->isConstantMatrixType())
3178 return true;
3179 // -- a reference type; or
3180 if (BaseTy->isReferenceType())
3181 return true;
3182 // -- a class type that has all of the following properties:
3183 if (const auto *RD = BaseTy->getAsRecordDecl()) {
3184 // -- a trivial destructor,
3185 // -- every constructor call and full-expression in the
3186 // brace-or-equal-initializers for non-static data members (if any)
3187 // is a constant expression,
3188 // -- it is an aggregate type or has at least one constexpr
3189 // constructor or constructor template that is not a copy or move
3190 // constructor, and
3191 // -- all non-static data members and base classes of literal types
3192 //
3193 // We resolve DR1361 by ignoring the second bullet.
3194 if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RD))
3195 return ClassDecl->isLiteral();
3196
3197 return true;
3198 }
3199
3200 // We treat _Atomic T as a literal type if T is a literal type.
3201 if (const auto *AT = BaseTy->getAs<AtomicType>())
3202 return AT->getValueType()->isLiteralType(Ctx);
3203
3204 if (const auto *OBT = BaseTy->getAs<OverflowBehaviorType>())
3205 return OBT->getUnderlyingType()->isLiteralType(Ctx);
3206
3207 // If this type hasn't been deduced yet, then conservatively assume that
3208 // it'll work out to be a literal type.
3210 return true;
3211
3212 return false;
3213}
3214
3216 // C++20 [temp.param]p6:
3217 // A structural type is one of the following:
3218 // -- a scalar type; or
3219 // -- a vector type [Clang extension]; or
3220 if (isScalarType() || isVectorType())
3221 return true;
3222 // -- an lvalue reference type; or
3224 return true;
3225 // -- a literal class type [...under some conditions]
3226 if (const CXXRecordDecl *RD = getAsCXXRecordDecl())
3227 return RD->isStructural();
3228 return false;
3229}
3230
3232 if (isDependentType())
3233 return false;
3234
3235 // C++0x [basic.types]p9:
3236 // Scalar types, standard-layout class types, arrays of such types, and
3237 // cv-qualified versions of these types are collectively called
3238 // standard-layout types.
3239 const Type *BaseTy = getBaseElementTypeUnsafe();
3240 assert(BaseTy && "NULL element type");
3241
3242 // Return false for incomplete types after skipping any incomplete array
3243 // types which are expressly allowed by the standard and thus our API.
3244 if (BaseTy->isIncompleteType())
3245 return false;
3246
3247 // As an extension, Clang treats vector types as Scalar types.
3248 if (BaseTy->isScalarType() || BaseTy->isVectorType())
3249 return true;
3250 if (const auto *RD = BaseTy->getAsRecordDecl()) {
3251 if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RD);
3252 ClassDecl && !ClassDecl->isStandardLayout())
3253 return false;
3254
3255 // Default to 'true' for non-C++ class types.
3256 // FIXME: This is a bit dubious, but plain C structs should trivially meet
3257 // all the requirements of standard layout classes.
3258 return true;
3259 }
3260
3261 // No other types can match.
3262 return false;
3263}
3264
3265// This is effectively the intersection of isTrivialType and
3266// isStandardLayoutType. We implement it directly to avoid redundant
3267// conversions from a type to a CXXRecordDecl.
3268bool QualType::isCXX11PODType(const ASTContext &Context) const {
3269 const Type *ty = getTypePtr();
3270 if (ty->isDependentType())
3271 return false;
3272
3274 return false;
3275
3276 // C++11 [basic.types]p9:
3277 // Scalar types, POD classes, arrays of such types, and cv-qualified
3278 // versions of these types are collectively called trivial types.
3279 const Type *BaseTy = ty->getBaseElementTypeUnsafe();
3280 assert(BaseTy && "NULL element type");
3281
3282 if (BaseTy->isSizelessBuiltinType())
3283 return true;
3284
3285 // Return false for incomplete types after skipping any incomplete array
3286 // types which are expressly allowed by the standard and thus our API.
3287 if (BaseTy->isIncompleteType())
3288 return false;
3289
3290 // Any type that is, or contains, address discriminated data is non-POD.
3291 if (Context.containsAddressDiscriminatedPointerAuth(*this))
3292 return false;
3293
3294 // As an extension, Clang treats vector types as Scalar types.
3295 if (BaseTy->isScalarType() || BaseTy->isVectorType())
3296 return true;
3297 if (const auto *RD = BaseTy->getAsRecordDecl()) {
3298 if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RD)) {
3299 // C++11 [class]p10:
3300 // A POD struct is a non-union class that is both a trivial class [...]
3301 if (!ClassDecl->isTrivial())
3302 return false;
3303
3304 // C++11 [class]p10:
3305 // A POD struct is a non-union class that is both a trivial class and
3306 // a standard-layout class [...]
3307 if (!ClassDecl->isStandardLayout())
3308 return false;
3309
3310 // C++11 [class]p10:
3311 // A POD struct is a non-union class that is both a trivial class and
3312 // a standard-layout class, and has no non-static data members of type
3313 // non-POD struct, non-POD union (or array of such types). [...]
3314 //
3315 // We don't directly query the recursive aspect as the requirements for
3316 // both standard-layout classes and trivial classes apply recursively
3317 // already.
3318 }
3319
3320 return true;
3321 }
3322
3323 // No other types can match.
3324 return false;
3325}
3326
3327bool Type::isNothrowT() const {
3328 if (const auto *RD = getAsCXXRecordDecl()) {
3329 IdentifierInfo *II = RD->getIdentifier();
3330 if (II && II->isStr("nothrow_t") && RD->isInStdNamespace())
3331 return true;
3332 }
3333 return false;
3334}
3335
3336bool Type::isAlignValT() const {
3337 if (const auto *ET = getAsCanonical<EnumType>()) {
3338 const auto *ED = ET->getDecl();
3339 IdentifierInfo *II = ED->getIdentifier();
3340 if (II && II->isStr("align_val_t") && ED->isInStdNamespace())
3341 return true;
3342 }
3343 return false;
3344}
3345
3347 if (const auto *ET = getAsCanonical<EnumType>()) {
3348 const auto *ED = ET->getDecl();
3349 IdentifierInfo *II = ED->getIdentifier();
3350 if (II && II->isStr("byte") && ED->isInStdNamespace())
3351 return true;
3352 }
3353 return false;
3354}
3355
3357 // Note that this intentionally does not use the canonical type.
3358 switch (getTypeClass()) {
3359 case Builtin:
3360 case Record:
3361 case Enum:
3362 case Typedef:
3363 case Complex:
3364 case TypeOfExpr:
3365 case TypeOf:
3366 case TemplateTypeParm:
3367 case SubstTemplateTypeParm:
3368 case TemplateSpecialization:
3369 case DependentName:
3370 case ObjCInterface:
3371 case ObjCObject:
3372 return true;
3373 default:
3374 return false;
3375 }
3376}
3377
3379 switch (TypeSpec) {
3380 default:
3382 case TST_typename:
3384 case TST_class:
3386 case TST_struct:
3388 case TST_interface:
3390 case TST_union:
3392 case TST_enum:
3394 }
3395}
3396
3398 switch (TypeSpec) {
3399 case TST_class:
3400 return TagTypeKind::Class;
3401 case TST_struct:
3402 return TagTypeKind::Struct;
3403 case TST_interface:
3405 case TST_union:
3406 return TagTypeKind::Union;
3407 case TST_enum:
3408 return TagTypeKind::Enum;
3409 }
3410
3411 llvm_unreachable("Type specifier is not a tag type kind.");
3412}
3413
3416 switch (Kind) {
3417 case TagTypeKind::Class:
3423 case TagTypeKind::Union:
3425 case TagTypeKind::Enum:
3427 }
3428 llvm_unreachable("Unknown tag type kind.");
3429}
3430
3433 switch (Keyword) {
3435 return TagTypeKind::Class;
3437 return TagTypeKind::Struct;
3441 return TagTypeKind::Union;
3443 return TagTypeKind::Enum;
3444 case ElaboratedTypeKeyword::None: // Fall through.
3446 llvm_unreachable("Elaborated type keyword is not a tag type kind.");
3447 }
3448 llvm_unreachable("Unknown elaborated type keyword.");
3449}
3450
3452 switch (Keyword) {
3455 return false;
3461 return true;
3462 }
3463 llvm_unreachable("Unknown elaborated type keyword.");
3464}
3465
3467 switch (Keyword) {
3469 return {};
3471 return "typename";
3473 return "class";
3475 return "struct";
3477 return "__interface";
3479 return "union";
3481 return "enum";
3482 }
3483
3484 llvm_unreachable("Unknown elaborated type keyword.");
3485}
3486
3489 if (const auto *TST = dyn_cast<TemplateSpecializationType>(this))
3490 Keyword = TST->getKeyword();
3491 else if (const auto *DepName = dyn_cast<DependentNameType>(this))
3492 Keyword = DepName->getKeyword();
3493 else if (const auto *T = dyn_cast<TagType>(this))
3494 Keyword = T->getKeyword();
3495 else if (const auto *T = dyn_cast<TypedefType>(this))
3496 Keyword = T->getKeyword();
3497 else if (const auto *T = dyn_cast<UnresolvedUsingType>(this))
3498 Keyword = T->getKeyword();
3499 else if (const auto *T = dyn_cast<UsingType>(this))
3500 Keyword = T->getKeyword();
3501 else
3502 return false;
3503
3505}
3506
3507const char *Type::getTypeClassName() const {
3508 switch (TypeBits.TC) {
3509#define ABSTRACT_TYPE(Derived, Base)
3510#define TYPE(Derived, Base) \
3511 case Derived: \
3512 return #Derived;
3513#include "clang/AST/TypeNodes.inc"
3514 }
3515
3516 llvm_unreachable("Invalid type class.");
3517}
3518
3519StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
3520 switch (getKind()) {
3521 case Void:
3522 return "void";
3523 case Bool:
3524 return Policy.Bool ? "bool" : "_Bool";
3525 case Char_S:
3526 return "char";
3527 case Char_U:
3528 return "char";
3529 case SChar:
3530 return "signed char";
3531 case Short:
3532 return "short";
3533 case Int:
3534 return "int";
3535 case Long:
3536 return "long";
3537 case LongLong:
3538 return "long long";
3539 case Int128:
3540 return "__int128";
3541 case UChar:
3542 return "unsigned char";
3543 case UShort:
3544 return "unsigned short";
3545 case UInt:
3546 return "unsigned int";
3547 case ULong:
3548 return "unsigned long";
3549 case ULongLong:
3550 return "unsigned long long";
3551 case UInt128:
3552 return "unsigned __int128";
3553 case Half:
3554 return Policy.Half ? "half" : "__fp16";
3555 case BFloat16:
3556 return "__bf16";
3557 case Float:
3558 return "float";
3559 case Double:
3560 return "double";
3561 case LongDouble:
3562 return "long double";
3563 case ShortAccum:
3564 return "short _Accum";
3565 case Accum:
3566 return "_Accum";
3567 case LongAccum:
3568 return "long _Accum";
3569 case UShortAccum:
3570 return "unsigned short _Accum";
3571 case UAccum:
3572 return "unsigned _Accum";
3573 case ULongAccum:
3574 return "unsigned long _Accum";
3575 case BuiltinType::ShortFract:
3576 return "short _Fract";
3577 case BuiltinType::Fract:
3578 return "_Fract";
3579 case BuiltinType::LongFract:
3580 return "long _Fract";
3581 case BuiltinType::UShortFract:
3582 return "unsigned short _Fract";
3583 case BuiltinType::UFract:
3584 return "unsigned _Fract";
3585 case BuiltinType::ULongFract:
3586 return "unsigned long _Fract";
3587 case BuiltinType::SatShortAccum:
3588 return "_Sat short _Accum";
3589 case BuiltinType::SatAccum:
3590 return "_Sat _Accum";
3591 case BuiltinType::SatLongAccum:
3592 return "_Sat long _Accum";
3593 case BuiltinType::SatUShortAccum:
3594 return "_Sat unsigned short _Accum";
3595 case BuiltinType::SatUAccum:
3596 return "_Sat unsigned _Accum";
3597 case BuiltinType::SatULongAccum:
3598 return "_Sat unsigned long _Accum";
3599 case BuiltinType::SatShortFract:
3600 return "_Sat short _Fract";
3601 case BuiltinType::SatFract:
3602 return "_Sat _Fract";
3603 case BuiltinType::SatLongFract:
3604 return "_Sat long _Fract";
3605 case BuiltinType::SatUShortFract:
3606 return "_Sat unsigned short _Fract";
3607 case BuiltinType::SatUFract:
3608 return "_Sat unsigned _Fract";
3609 case BuiltinType::SatULongFract:
3610 return "_Sat unsigned long _Fract";
3611 case Float16:
3612 return "_Float16";
3613 case Float128:
3614 return "__float128";
3615 case Ibm128:
3616 return "__ibm128";
3617 case WChar_S:
3618 case WChar_U:
3619 return Policy.MSWChar ? "__wchar_t" : "wchar_t";
3620 case Char8:
3621 return "char8_t";
3622 case Char16:
3623 return "char16_t";
3624 case Char32:
3625 return "char32_t";
3626 case NullPtr:
3627 return Policy.NullptrTypeInNamespace ? "std::nullptr_t" : "nullptr_t";
3628 case Overload:
3629 return "<overloaded function type>";
3630 case BoundMember:
3631 return "<bound member function type>";
3632 case UnresolvedTemplate:
3633 return "<unresolved template type>";
3634 case PseudoObject:
3635 return "<pseudo-object type>";
3636 case Dependent:
3637 return "<dependent type>";
3638 case UnknownAny:
3639 return "<unknown type>";
3640 case ARCUnbridgedCast:
3641 return "<ARC unbridged cast type>";
3642 case BuiltinFn:
3643 return "<builtin fn type>";
3644 case ObjCId:
3645 return "id";
3646 case ObjCClass:
3647 return "Class";
3648 case ObjCSel:
3649 return "SEL";
3650#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3651 case Id: \
3652 return "__" #Access " " #ImgType "_t";
3653#include "clang/Basic/OpenCLImageTypes.def"
3654 case OCLSampler:
3655 return "sampler_t";
3656 case OCLEvent:
3657 return "event_t";
3658 case OCLClkEvent:
3659 return "clk_event_t";
3660 case OCLQueue:
3661 return "queue_t";
3662 case OCLReserveID:
3663 return "reserve_id_t";
3664 case IncompleteMatrixIdx:
3665 return "<incomplete matrix index type>";
3666 case ArraySection:
3667 return "<array section type>";
3668 case OMPArrayShaping:
3669 return "<OpenMP array shaping type>";
3670 case OMPIterator:
3671 return "<OpenMP iterator type>";
3672#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3673 case Id: \
3674 return #ExtType;
3675#include "clang/Basic/OpenCLExtensionTypes.def"
3676#define SVE_TYPE(Name, Id, SingletonId) \
3677 case Id: \
3678 return #Name;
3679#include "clang/Basic/AArch64ACLETypes.def"
3680#define PPC_VECTOR_TYPE(Name, Id, Size) \
3681 case Id: \
3682 return #Name;
3683#include "clang/Basic/PPCTypes.def"
3684#define RVV_TYPE(Name, Id, SingletonId) \
3685 case Id: \
3686 return Name;
3687#include "clang/Basic/RISCVVTypes.def"
3688#define WASM_TYPE(Name, Id, SingletonId) \
3689 case Id: \
3690 return Name;
3691#include "clang/Basic/WebAssemblyReferenceTypes.def"
3692#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
3693 case Id: \
3694 return Name;
3695#include "clang/Basic/AMDGPUTypes.def"
3696#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3697 case Id: \
3698 return #Name;
3699#include "clang/Basic/HLSLIntangibleTypes.def"
3700#define SPIRV_TYPE(Name, Id, SingletonId) \
3701 case Id: \
3702 return Name;
3703#include "clang/Basic/SPIRVTypes.def"
3704 }
3705
3706 llvm_unreachable("Invalid builtin type.");
3707}
3708
3710 // We never wrap type sugar around a PackExpansionType.
3711 if (auto *PET = dyn_cast<PackExpansionType>(getTypePtr()))
3712 return PET->getPattern();
3713 return *this;
3714}
3715
3717 if (const auto *RefType = getTypePtr()->getAs<ReferenceType>())
3718 return RefType->getPointeeType();
3719
3720 // C++0x [basic.lval]:
3721 // Class prvalues can have cv-qualified types; non-class prvalues always
3722 // have cv-unqualified types.
3723 //
3724 // See also C99 6.3.2.1p2.
3725 if (!Context.getLangOpts().CPlusPlus ||
3726 (!getTypePtr()->isDependentType() && !getTypePtr()->isRecordType()))
3727 return getUnqualifiedType();
3728
3729 return *this;
3730}
3731
3733 if (const auto *FPT = getAs<FunctionProtoType>())
3734 return FPT->hasCFIUncheckedCallee();
3735 return false;
3736}
3737
3739 switch (CC) {
3740 case CC_C:
3741 return "cdecl";
3742 case CC_X86StdCall:
3743 return "stdcall";
3744 case CC_X86FastCall:
3745 return "fastcall";
3746 case CC_X86ThisCall:
3747 return "thiscall";
3748 case CC_X86Pascal:
3749 return "pascal";
3750 case CC_X86VectorCall:
3751 return "vectorcall";
3752 case CC_Win64:
3753 return "ms_abi";
3754 case CC_X86_64SysV:
3755 return "sysv_abi";
3756 case CC_X86RegCall:
3757 return "regcall";
3758 case CC_AAPCS:
3759 return "aapcs";
3760 case CC_AAPCS_VFP:
3761 return "aapcs-vfp";
3763 return "aarch64_vector_pcs";
3764 case CC_AArch64SVEPCS:
3765 return "aarch64_sve_pcs";
3766 case CC_IntelOclBicc:
3767 return "intel_ocl_bicc";
3768 case CC_DeviceKernel:
3769 return "device_kernel";
3770 case CC_Swift:
3771 return "swiftcall";
3772 case CC_SwiftAsync:
3773 return "swiftasynccall";
3774 case CC_PreserveMost:
3775 return "preserve_most";
3776 case CC_PreserveAll:
3777 return "preserve_all";
3778 case CC_M68kRTD:
3779 return "m68k_rtd";
3780 case CC_PreserveNone:
3781 return "preserve_none";
3782 // clang-format off
3783 case CC_RISCVVectorCall: return "riscv_vector_cc";
3784#define CC_VLS_CASE(ABI_VLEN) \
3785 case CC_RISCVVLSCall_##ABI_VLEN: return "riscv_vls_cc(" #ABI_VLEN ")";
3786 CC_VLS_CASE(32)
3787 CC_VLS_CASE(64)
3788 CC_VLS_CASE(128)
3789 CC_VLS_CASE(256)
3790 CC_VLS_CASE(512)
3791 CC_VLS_CASE(1024)
3792 CC_VLS_CASE(2048)
3793 CC_VLS_CASE(4096)
3794 CC_VLS_CASE(8192)
3795 CC_VLS_CASE(16384)
3796 CC_VLS_CASE(32768)
3797 CC_VLS_CASE(65536)
3798#undef CC_VLS_CASE
3799 // clang-format on
3800 }
3801
3802 llvm_unreachable("Invalid calling convention.");
3803}
3804
3811
3812FunctionProtoType::FunctionProtoType(QualType result, ArrayRef<QualType> params,
3813 QualType canonical,
3814 const ExtProtoInfo &epi)
3815 : FunctionType(FunctionProto, result, canonical, result->getDependence(),
3816 epi.ExtInfo) {
3817 FunctionTypeBits.FastTypeQuals = epi.TypeQuals.getFastQualifiers();
3818 FunctionTypeBits.RefQualifier = epi.RefQualifier;
3819 FunctionTypeBits.NumParams = params.size();
3820 assert(getNumParams() == params.size() && "NumParams overflow!");
3821 FunctionTypeBits.ExceptionSpecType = epi.ExceptionSpec.Type;
3822 FunctionTypeBits.HasExtParameterInfos = !!epi.ExtParameterInfos;
3823 FunctionTypeBits.Variadic = epi.Variadic;
3824 FunctionTypeBits.HasTrailingReturn = epi.HasTrailingReturn;
3825 FunctionTypeBits.CFIUncheckedCallee = epi.CFIUncheckedCallee;
3826
3828 FunctionTypeBits.HasExtraBitfields = true;
3829 auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
3830 ExtraBits = FunctionTypeExtraBitfields();
3831 } else {
3832 FunctionTypeBits.HasExtraBitfields = false;
3833 }
3834
3835 // Propagate any extra attribute information.
3837 auto &ExtraAttrInfo = *getTrailingObjects<FunctionTypeExtraAttributeInfo>();
3838 ExtraAttrInfo.CFISalt = epi.ExtraAttributeInfo.CFISalt;
3839
3840 // Also set the bit in FunctionTypeExtraBitfields.
3841 auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
3842 ExtraBits.HasExtraAttributeInfo = true;
3843 }
3844
3846 auto &ArmTypeAttrs = *getTrailingObjects<FunctionTypeArmAttributes>();
3847 ArmTypeAttrs = FunctionTypeArmAttributes();
3848
3849 // Also set the bit in FunctionTypeExtraBitfields
3850 auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
3851 ExtraBits.HasArmTypeAttributes = true;
3852 }
3853
3854 // Fill in the trailing argument array.
3855 auto *argSlot = getTrailingObjects<QualType>();
3856 for (unsigned i = 0; i != getNumParams(); ++i) {
3857 addDependence(params[i]->getDependence() &
3858 ~TypeDependence::VariablyModified);
3859 argSlot[i] = params[i];
3860 }
3861
3862 // Propagate the SME ACLE attributes.
3864 auto &ArmTypeAttrs = *getTrailingObjects<FunctionTypeArmAttributes>();
3866 "Not enough bits to encode SME attributes");
3867 ArmTypeAttrs.AArch64SMEAttributes = epi.AArch64SMEAttributes;
3868 }
3869
3870 // Fill in the exception type array if present.
3872 auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
3873 size_t NumExceptions = epi.ExceptionSpec.Exceptions.size();
3874 assert(NumExceptions <= 1023 && "Not enough bits to encode exceptions");
3875 ExtraBits.NumExceptionType = NumExceptions;
3876
3877 assert(hasExtraBitfields() && "missing trailing extra bitfields!");
3878 auto *exnSlot =
3879 reinterpret_cast<QualType *>(getTrailingObjects<ExceptionType>());
3880 unsigned I = 0;
3881 for (QualType ExceptionType : epi.ExceptionSpec.Exceptions) {
3882 // Note that, before C++17, a dependent exception specification does
3883 // *not* make a type dependent; it's not even part of the C++ type
3884 // system.
3886 ExceptionType->getDependence() &
3887 (TypeDependence::Instantiation | TypeDependence::UnexpandedPack));
3888
3889 exnSlot[I++] = ExceptionType;
3890 }
3891 }
3892 // Fill in the Expr * in the exception specification if present.
3894 assert(epi.ExceptionSpec.NoexceptExpr && "computed noexcept with no expr");
3897
3898 // Store the noexcept expression and context.
3899 *getTrailingObjects<Expr *>() = epi.ExceptionSpec.NoexceptExpr;
3900
3903 (TypeDependence::Instantiation | TypeDependence::UnexpandedPack));
3904 }
3905 // Fill in the FunctionDecl * in the exception specification if present.
3907 // Store the function decl from which we will resolve our
3908 // exception specification.
3909 auto **slot = getTrailingObjects<FunctionDecl *>();
3910 slot[0] = epi.ExceptionSpec.SourceDecl;
3911 slot[1] = epi.ExceptionSpec.SourceTemplate;
3912 // This exception specification doesn't make the type dependent, because
3913 // it's not instantiated as part of instantiating the type.
3914 } else if (getExceptionSpecType() == EST_Unevaluated) {
3915 // Store the function decl from which we will resolve our
3916 // exception specification.
3917 auto **slot = getTrailingObjects<FunctionDecl *>();
3918 slot[0] = epi.ExceptionSpec.SourceDecl;
3919 }
3920
3921 // If this is a canonical type, and its exception specification is dependent,
3922 // then it's a dependent type. This only happens in C++17 onwards.
3923 if (isCanonicalUnqualified()) {
3926 assert(hasDependentExceptionSpec() && "type should not be canonical");
3927 addDependence(TypeDependence::DependentInstantiation);
3928 }
3929 } else if (getCanonicalTypeInternal()->isDependentType()) {
3930 // Ask our canonical type whether our exception specification was dependent.
3931 addDependence(TypeDependence::DependentInstantiation);
3932 }
3933
3934 // Fill in the extra parameter info if present.
3935 if (epi.ExtParameterInfos) {
3936 auto *extParamInfos = getTrailingObjects<ExtParameterInfo>();
3937 for (unsigned i = 0; i != getNumParams(); ++i)
3938 extParamInfos[i] = epi.ExtParameterInfos[i];
3939 }
3940
3941 if (epi.TypeQuals.hasNonFastQualifiers()) {
3942 FunctionTypeBits.HasExtQuals = 1;
3943 *getTrailingObjects<Qualifiers>() = epi.TypeQuals;
3944 } else {
3945 FunctionTypeBits.HasExtQuals = 0;
3946 }
3947
3948 // Fill in the Ellipsis location info if present.
3949 if (epi.Variadic) {
3950 auto &EllipsisLoc = *getTrailingObjects<SourceLocation>();
3951 EllipsisLoc = epi.EllipsisLoc;
3952 }
3953
3954 if (!epi.FunctionEffects.empty()) {
3955 auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
3956 size_t EffectsCount = epi.FunctionEffects.size();
3957 ExtraBits.NumFunctionEffects = EffectsCount;
3958 assert(ExtraBits.NumFunctionEffects == EffectsCount &&
3959 "effect bitfield overflow");
3960
3961 ArrayRef<FunctionEffect> SrcFX = epi.FunctionEffects.effects();
3962 auto *DestFX = getTrailingObjects<FunctionEffect>();
3963 llvm::uninitialized_copy(SrcFX, DestFX);
3964
3965 ArrayRef<EffectConditionExpr> SrcConds = epi.FunctionEffects.conditions();
3966 if (!SrcConds.empty()) {
3967 ExtraBits.EffectsHaveConditions = true;
3968 auto *DestConds = getTrailingObjects<EffectConditionExpr>();
3969 llvm::uninitialized_copy(SrcConds, DestConds);
3970 assert(llvm::any_of(SrcConds,
3971 [](const EffectConditionExpr &EC) {
3972 if (const Expr *E = EC.getCondition())
3973 return E->isTypeDependent() ||
3974 E->isValueDependent();
3975 return false;
3976 }) &&
3977 "expected a dependent expression among the conditions");
3978 addDependence(TypeDependence::DependentInstantiation);
3979 }
3980 }
3981}
3982
3984 if (Expr *NE = getNoexceptExpr())
3985 return NE->isValueDependent();
3986 for (QualType ET : exceptions())
3987 // A pack expansion with a non-dependent pattern is still dependent,
3988 // because we don't know whether the pattern is in the exception spec
3989 // or not (that depends on whether the pack has 0 expansions).
3990 if (ET->isDependentType() || ET->getAs<PackExpansionType>())
3991 return true;
3992 return false;
3993}
3994
3996 if (Expr *NE = getNoexceptExpr())
3997 return NE->isInstantiationDependent();
3998 for (QualType ET : exceptions())
4000 return true;
4001 return false;
4002}
4003
4005 switch (getExceptionSpecType()) {
4006 case EST_Unparsed:
4007 case EST_Unevaluated:
4008 llvm_unreachable("should not call this with unresolved exception specs");
4009
4010 case EST_DynamicNone:
4011 case EST_BasicNoexcept:
4012 case EST_NoexceptTrue:
4013 case EST_NoThrow:
4014 return CT_Cannot;
4015
4016 case EST_None:
4017 case EST_MSAny:
4018 case EST_NoexceptFalse:
4019 return CT_Can;
4020
4021 case EST_Dynamic:
4022 // A dynamic exception specification is throwing unless every exception
4023 // type is an (unexpanded) pack expansion type.
4024 for (unsigned I = 0; I != getNumExceptions(); ++I)
4026 return CT_Can;
4027 return CT_Dependent;
4028
4029 case EST_Uninstantiated:
4031 return CT_Dependent;
4032 }
4033
4034 llvm_unreachable("unexpected exception specification kind");
4035}
4036
4038 for (unsigned ArgIdx = getNumParams(); ArgIdx; --ArgIdx)
4039 if (isa<PackExpansionType>(getParamType(ArgIdx - 1)))
4040 return true;
4041
4042 return false;
4043}
4044
4045void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result,
4046 const QualType *ArgTys, unsigned NumParams,
4047 const ExtProtoInfo &epi,
4048 const ASTContext &Context, bool Canonical) {
4049 // We have to be careful not to get ambiguous profile encodings.
4050 // Note that valid type pointers are never ambiguous with anything else.
4051 //
4052 // The encoding grammar begins:
4053 // type type* bool int bool
4054 // If that final bool is true, then there is a section for the EH spec:
4055 // bool type*
4056 // This is followed by an optional "consumed argument" section of the
4057 // same length as the first type sequence:
4058 // bool*
4059 // This is followed by the ext info:
4060 // int
4061 // Finally we have a trailing return type flag (bool)
4062 // combined with AArch64 SME Attributes and extra attribute info, to save
4063 // space:
4064 // int
4065 // combined with any FunctionEffects
4066 //
4067 // There is no ambiguity between the consumed arguments and an empty EH
4068 // spec because of the leading 'bool' which unambiguously indicates
4069 // whether the following bool is the EH spec or part of the arguments.
4070
4071 ID.AddPointer(Result.getAsOpaquePtr());
4072 for (unsigned i = 0; i != NumParams; ++i)
4073 ID.AddPointer(ArgTys[i].getAsOpaquePtr());
4074 // This method is relatively performance sensitive, so as a performance
4075 // shortcut, use one AddInteger call instead of four for the next four
4076 // fields.
4077 assert(!(unsigned(epi.Variadic) & ~1) && !(unsigned(epi.RefQualifier) & ~3) &&
4078 !(unsigned(epi.ExceptionSpec.Type) & ~15) &&
4079 "Values larger than expected.");
4080 ID.AddInteger(unsigned(epi.Variadic) + (epi.RefQualifier << 1) +
4081 (epi.ExceptionSpec.Type << 3));
4082 ID.Add(epi.TypeQuals);
4083 if (epi.ExceptionSpec.Type == EST_Dynamic) {
4084 for (QualType Ex : epi.ExceptionSpec.Exceptions)
4085 ID.AddPointer(Ex.getAsOpaquePtr());
4086 } else if (isComputedNoexcept(epi.ExceptionSpec.Type)) {
4087 epi.ExceptionSpec.NoexceptExpr->Profile(ID, Context, Canonical);
4088 } else if (epi.ExceptionSpec.Type == EST_Uninstantiated ||
4089 epi.ExceptionSpec.Type == EST_Unevaluated) {
4090 ID.AddPointer(epi.ExceptionSpec.SourceDecl->getCanonicalDecl());
4091 }
4092 if (epi.ExtParameterInfos) {
4093 for (unsigned i = 0; i != NumParams; ++i)
4094 ID.AddInteger(epi.ExtParameterInfos[i].getOpaqueValue());
4095 }
4096
4097 epi.ExtInfo.Profile(ID);
4098 epi.ExtraAttributeInfo.Profile(ID);
4099
4100 unsigned EffectCount = epi.FunctionEffects.size();
4101 bool HasConds = !epi.FunctionEffects.Conditions.empty();
4102
4103 ID.AddInteger((EffectCount << 3) | (HasConds << 2) |
4104 (epi.AArch64SMEAttributes << 1) | epi.HasTrailingReturn);
4105 ID.AddInteger(epi.CFIUncheckedCallee);
4106
4107 for (unsigned Idx = 0; Idx != EffectCount; ++Idx) {
4108 ID.AddInteger(epi.FunctionEffects.Effects[Idx].toOpaqueInt32());
4109 if (HasConds)
4110 ID.AddPointer(epi.FunctionEffects.Conditions[Idx].getCondition());
4111 }
4112}
4113
4114void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID,
4115 const ASTContext &Ctx) {
4118}
4119
4121 : Data(D, Deref << DerefShift) {}
4122
4124 return Data.getInt() & DerefMask;
4125}
4126ValueDecl *TypeCoupledDeclRefInfo::getDecl() const { return Data.getPointer(); }
4127unsigned TypeCoupledDeclRefInfo::getInt() const { return Data.getInt(); }
4129 return Data.getOpaqueValue();
4130}
4132 const TypeCoupledDeclRefInfo &Other) const {
4133 return getOpaqueValue() == Other.getOpaqueValue();
4134}
4136 Data.setFromOpaqueValue(V);
4137}
4138
4139OverflowBehaviorType::OverflowBehaviorType(
4140 QualType Canon, QualType Underlying,
4141 OverflowBehaviorType::OverflowBehaviorKind Kind)
4142 : Type(OverflowBehavior, Canon, Underlying->getDependence()),
4143 UnderlyingType(Underlying), BehaviorKind(Kind) {}
4144
4146 QualType Canon)
4147 : Type(TC, Canon, Wrapped->getDependence()), WrappedTy(Wrapped) {}
4148
4149CountAttributedType::CountAttributedType(
4150 QualType Wrapped, QualType Canon, Expr *CountExpr, bool CountInBytes,
4151 bool OrNull, ArrayRef<TypeCoupledDeclRefInfo> CoupledDecls)
4152 : BoundsAttributedType(CountAttributed, Wrapped, Canon),
4153 CountExpr(CountExpr) {
4154 CountAttributedTypeBits.NumCoupledDecls = CoupledDecls.size();
4155 CountAttributedTypeBits.CountInBytes = CountInBytes;
4156 CountAttributedTypeBits.OrNull = OrNull;
4157 auto *DeclSlot = getTrailingObjects();
4158 llvm::copy(CoupledDecls, DeclSlot);
4159 Decls = llvm::ArrayRef(DeclSlot, CoupledDecls.size());
4160}
4161
4162StringRef CountAttributedType::getAttributeName(bool WithMacroPrefix) const {
4163// TODO: This method isn't really ideal because it doesn't return the spelling
4164// of the attribute that was used in the user's code. This method is used for
4165// diagnostics so the fact it doesn't use the spelling of the attribute in
4166// the user's code could be confusing (#113585).
4167#define ENUMERATE_ATTRS(PREFIX) \
4168 do { \
4169 if (isCountInBytes()) { \
4170 if (isOrNull()) \
4171 return PREFIX "sized_by_or_null"; \
4172 return PREFIX "sized_by"; \
4173 } \
4174 if (isOrNull()) \
4175 return PREFIX "counted_by_or_null"; \
4176 return PREFIX "counted_by"; \
4177 } while (0)
4178
4179 if (WithMacroPrefix)
4180 ENUMERATE_ATTRS("__");
4181 else
4182 ENUMERATE_ATTRS("");
4183
4184#undef ENUMERATE_ATTRS
4185}
4186
4187TypedefType::TypedefType(TypeClass TC, ElaboratedTypeKeyword Keyword,
4188 NestedNameSpecifier Qualifier,
4189 const TypedefNameDecl *D, QualType UnderlyingType,
4190 bool HasTypeDifferentFromDecl)
4192 Keyword, TC, UnderlyingType.getCanonicalType(),
4193 toSemanticDependence(UnderlyingType->getDependence()) |
4194 (Qualifier
4195 ? toTypeDependence(Qualifier.getDependence() &
4196 ~NestedNameSpecifierDependence::Dependent)
4197 : TypeDependence{})),
4198 Decl(const_cast<TypedefNameDecl *>(D)) {
4199 if ((TypedefBits.hasQualifier = !!Qualifier))
4200 *getTrailingObjects<NestedNameSpecifier>() = Qualifier;
4201 if ((TypedefBits.hasTypeDifferentFromDecl = HasTypeDifferentFromDecl))
4202 *getTrailingObjects<QualType>() = UnderlyingType;
4203}
4204
4206 return typeMatchesDecl() ? Decl->getUnderlyingType()
4207 : *getTrailingObjects<QualType>();
4208}
4209
4210UnresolvedUsingType::UnresolvedUsingType(ElaboratedTypeKeyword Keyword,
4211 NestedNameSpecifier Qualifier,
4213 const Type *CanonicalType)
4215 Keyword, UnresolvedUsing, QualType(CanonicalType, 0),
4216 TypeDependence::DependentInstantiation |
4217 (Qualifier
4218 ? toTypeDependence(Qualifier.getDependence() &
4219 ~NestedNameSpecifierDependence::Dependent)
4220 : TypeDependence{})),
4221 Decl(const_cast<UnresolvedUsingTypenameDecl *>(D)) {
4222 if ((UnresolvedUsingBits.hasQualifier = !!Qualifier))
4223 *getTrailingObjects<NestedNameSpecifier>() = Qualifier;
4224}
4225
4226UsingType::UsingType(ElaboratedTypeKeyword Keyword,
4227 NestedNameSpecifier Qualifier, const UsingShadowDecl *D,
4228 QualType UnderlyingType)
4229 : TypeWithKeyword(Keyword, Using, UnderlyingType.getCanonicalType(),
4230 toSemanticDependence(UnderlyingType->getDependence())),
4231 D(const_cast<UsingShadowDecl *>(D)), UnderlyingType(UnderlyingType) {
4232 if ((UsingBits.hasQualifier = !!Qualifier))
4233 *getTrailingObjects() = Qualifier;
4234}
4235
4237
4239 // Step over MacroQualifiedTypes from the same macro to find the type
4240 // ultimately qualified by the macro qualifier.
4241 QualType Inner = cast<AttributedType>(getUnderlyingType())->getModifiedType();
4242 while (auto *InnerMQT = dyn_cast<MacroQualifiedType>(Inner)) {
4243 if (InnerMQT->getMacroIdentifier() != getMacroIdentifier())
4244 break;
4245 Inner = InnerMQT->getModifiedType();
4246 }
4247 return Inner;
4248}
4249
4251 TypeOfKind Kind, QualType Can)
4252 : Type(TypeOfExpr,
4253 // We have to protect against 'Can' being invalid through its
4254 // default argument.
4255 Kind == TypeOfKind::Unqualified && !Can.isNull()
4256 ? Context.getUnqualifiedArrayType(Can).getAtomicUnqualifiedType()
4257 : Can,
4259 (E->getType()->getDependence() &
4260 TypeDependence::VariablyModified)),
4261 TOExpr(E), Context(Context) {
4262 TypeOfBits.Kind = static_cast<unsigned>(Kind);
4263}
4264
4265bool TypeOfExprType::isSugared() const { return !TOExpr->isTypeDependent(); }
4266
4268 if (isSugared()) {
4271 ? Context.getUnqualifiedArrayType(QT).getAtomicUnqualifiedType()
4272 : QT;
4273 }
4274 return QualType(this, 0);
4275}
4276
4277void DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID,
4278 const ASTContext &Context, Expr *E,
4279 bool IsUnqual) {
4280 E->Profile(ID, Context, true);
4281 ID.AddBoolean(IsUnqual);
4282}
4283
4284TypeOfType::TypeOfType(const ASTContext &Context, QualType T, QualType Can,
4285 TypeOfKind Kind)
4286 : Type(TypeOf,
4287 Kind == TypeOfKind::Unqualified
4288 ? Context.getUnqualifiedArrayType(Can).getAtomicUnqualifiedType()
4289 : Can,
4290 T->getDependence()),
4291 TOType(T), Context(Context) {
4292 TypeOfBits.Kind = static_cast<unsigned>(Kind);
4293}
4294
4295QualType TypeOfType::desugar() const {
4296 QualType QT = getUnmodifiedType();
4298 ? Context.getUnqualifiedArrayType(QT).getAtomicUnqualifiedType()
4299 : QT;
4300}
4301
4302DecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can)
4303 // C++11 [temp.type]p2: "If an expression e involves a template parameter,
4304 // decltype(e) denotes a unique dependent type." Hence a decltype type is
4305 // type-dependent even if its expression is only instantiation-dependent.
4306 : Type(Decltype, can,
4307 toTypeDependence(E->getDependence()) |
4308 (E->isInstantiationDependent() ? TypeDependence::Dependent
4309 : TypeDependence::None) |
4310 (E->getType()->getDependence() &
4311 TypeDependence::VariablyModified)),
4312 E(E), UnderlyingType(underlyingType) {}
4313
4314bool DecltypeType::isSugared() const { return !E->isInstantiationDependent(); }
4315
4316QualType DecltypeType::desugar() const {
4317 if (isSugared())
4318 return getUnderlyingType();
4319
4320 return QualType(this, 0);
4321}
4322
4323DependentDecltypeType::DependentDecltypeType(Expr *E)
4324 : DecltypeType(E, QualType()) {}
4325
4326void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID,
4327 const ASTContext &Context, Expr *E) {
4328 E->Profile(ID, Context, true);
4329}
4330
4331PackIndexingType::PackIndexingType(QualType Canonical, QualType Pattern,
4332 Expr *IndexExpr, bool FullySubstituted,
4333 ArrayRef<QualType> Expansions)
4334 : Type(PackIndexing, Canonical,
4335 computeDependence(Pattern, IndexExpr, Expansions)),
4336 Pattern(Pattern), IndexExpr(IndexExpr), Size(Expansions.size()),
4337 FullySubstituted(FullySubstituted) {
4338
4339 llvm::uninitialized_copy(Expansions, getTrailingObjects());
4340}
4341
4342UnsignedOrNone PackIndexingType::getSelectedIndex() const {
4343 if (isInstantiationDependentType())
4344 return std::nullopt;
4345 // Should only be not a constant for error recovery.
4346 ConstantExpr *CE = dyn_cast<ConstantExpr>(getIndexExpr());
4347 if (!CE)
4348 return std::nullopt;
4349 auto Index = CE->getResultAsAPSInt();
4350 assert(Index.isNonNegative() && "Invalid index");
4351 return static_cast<unsigned>(Index.getExtValue());
4352}
4353
4355PackIndexingType::computeDependence(QualType Pattern, Expr *IndexExpr,
4356 ArrayRef<QualType> Expansions) {
4357 TypeDependence IndexD = toTypeDependence(IndexExpr->getDependence());
4358
4359 TypeDependence TD = IndexD | (IndexExpr->isInstantiationDependent()
4360 ? TypeDependence::DependentInstantiation
4361 : TypeDependence::None);
4362 if (Expansions.empty())
4363 TD |= Pattern->getDependence() & TypeDependence::DependentInstantiation;
4364 else
4365 for (const QualType &T : Expansions)
4366 TD |= T->getDependence();
4367
4368 if (!(IndexD & TypeDependence::UnexpandedPack))
4369 TD &= ~TypeDependence::UnexpandedPack;
4370
4371 // If the pattern does not contain an unexpended pack,
4372 // the type is still dependent, and invalid
4373 if (!Pattern->containsUnexpandedParameterPack())
4374 TD |= TypeDependence::Error | TypeDependence::DependentInstantiation;
4375
4376 return TD;
4377}
4378
4379void PackIndexingType::Profile(llvm::FoldingSetNodeID &ID,
4380 const ASTContext &Context) {
4381 Profile(ID, Context, getPattern(), getIndexExpr(), isFullySubstituted(),
4382 getExpansions());
4383}
4384
4385void PackIndexingType::Profile(llvm::FoldingSetNodeID &ID,
4386 const ASTContext &Context, QualType Pattern,
4387 Expr *E, bool FullySubstituted,
4388 ArrayRef<QualType> Expansions) {
4389
4390 E->Profile(ID, Context, true);
4391 ID.AddBoolean(FullySubstituted);
4392 if (!Expansions.empty()) {
4393 ID.AddInteger(Expansions.size());
4394 for (QualType T : Expansions)
4395 T.getCanonicalType().Profile(ID);
4396 } else {
4397 Pattern.Profile(ID);
4398 }
4399}
4400
4401UnaryTransformType::UnaryTransformType(QualType BaseType,
4402 QualType UnderlyingType, UTTKind UKind,
4403 QualType CanonicalType)
4404 : Type(UnaryTransform, CanonicalType, BaseType->getDependence()),
4405 BaseType(BaseType), UnderlyingType(UnderlyingType), UKind(UKind) {}
4406
4407TagType::TagType(TypeClass TC, ElaboratedTypeKeyword Keyword,
4408 NestedNameSpecifier Qualifier, const TagDecl *Tag,
4409 bool OwnsTag, bool ISInjected, const Type *CanonicalType)
4411 Keyword, TC, QualType(CanonicalType, 0),
4412 (Tag->isDependentType() ? TypeDependence::DependentInstantiation
4413 : TypeDependence::None) |
4414 (Qualifier
4415 ? toTypeDependence(Qualifier.getDependence() &
4416 ~NestedNameSpecifierDependence::Dependent)
4417 : TypeDependence{})),
4418 decl(const_cast<TagDecl *>(Tag)) {
4419 if ((TagTypeBits.HasQualifier = !!Qualifier))
4420 getTrailingQualifier() = Qualifier;
4421 TagTypeBits.OwnsTag = !!OwnsTag;
4422 TagTypeBits.IsInjected = ISInjected;
4423}
4424
4425void *TagType::getTrailingPointer() const {
4426 switch (getTypeClass()) {
4427 case Type::Enum:
4428 return const_cast<EnumType *>(cast<EnumType>(this) + 1);
4429 case Type::Record:
4430 return const_cast<RecordType *>(cast<RecordType>(this) + 1);
4431 case Type::InjectedClassName:
4432 return const_cast<InjectedClassNameType *>(
4433 cast<InjectedClassNameType>(this) + 1);
4434 default:
4435 llvm_unreachable("unexpected type class");
4436 }
4437}
4438
4439NestedNameSpecifier &TagType::getTrailingQualifier() const {
4440 assert(TagTypeBits.HasQualifier);
4441 return *reinterpret_cast<NestedNameSpecifier *>(llvm::alignAddr(
4442 getTrailingPointer(), llvm::Align::Of<NestedNameSpecifier *>()));
4443}
4444
4445NestedNameSpecifier TagType::getQualifier() const {
4446 return TagTypeBits.HasQualifier ? getTrailingQualifier() : std::nullopt;
4447}
4448
4449ClassTemplateDecl *TagType::getTemplateDecl() const {
4450 auto *Decl = dyn_cast<CXXRecordDecl>(decl);
4451 if (!Decl)
4452 return nullptr;
4453 if (auto *RD = dyn_cast<ClassTemplateSpecializationDecl>(Decl))
4454 return RD->getSpecializedTemplate();
4455 return Decl->getDescribedClassTemplate();
4456}
4457
4458TemplateName TagType::getTemplateName(const ASTContext &Ctx) const {
4459 auto *TD = getTemplateDecl();
4460 if (!TD)
4461 return TemplateName();
4462 if (isCanonicalUnqualified())
4463 return TemplateName(TD);
4464 return Ctx.getQualifiedTemplateName(getQualifier(), /*TemplateKeyword=*/false,
4465 TemplateName(TD));
4466}
4467
4469TagType::getTemplateArgs(const ASTContext &Ctx) const {
4470 auto *Decl = dyn_cast<CXXRecordDecl>(decl);
4471 if (!Decl)
4472 return {};
4473
4474 if (auto *RD = dyn_cast<ClassTemplateSpecializationDecl>(Decl))
4475 return RD->getTemplateArgs().asArray();
4476 if (ClassTemplateDecl *TD = Decl->getDescribedClassTemplate())
4477 return TD->getTemplateParameters()->getInjectedTemplateArgs(Ctx);
4478 return {};
4479}
4480
4481bool RecordType::hasConstFields() const {
4482 std::vector<const RecordType *> RecordTypeList;
4483 RecordTypeList.push_back(this);
4484 unsigned NextToCheckIndex = 0;
4485
4486 while (RecordTypeList.size() > NextToCheckIndex) {
4487 for (FieldDecl *FD : RecordTypeList[NextToCheckIndex]
4488 ->getDecl()
4489 ->getDefinitionOrSelf()
4490 ->fields()) {
4491 QualType FieldTy = FD->getType();
4492 if (FieldTy.isConstQualified())
4493 return true;
4494 FieldTy = FieldTy.getCanonicalType();
4495 if (const auto *FieldRecTy = FieldTy->getAsCanonical<RecordType>()) {
4496 if (!llvm::is_contained(RecordTypeList, FieldRecTy))
4497 RecordTypeList.push_back(FieldRecTy);
4498 }
4499 }
4500 ++NextToCheckIndex;
4501 }
4502 return false;
4503}
4504
4505InjectedClassNameType::InjectedClassNameType(ElaboratedTypeKeyword Keyword,
4506 NestedNameSpecifier Qualifier,
4507 const TagDecl *TD, bool IsInjected,
4508 const Type *CanonicalType)
4509 : TagType(TypeClass::InjectedClassName, Keyword, Qualifier, TD,
4510 /*OwnsTag=*/false, IsInjected, CanonicalType) {}
4511
4512AttributedType::AttributedType(QualType canon, const Attr *attr,
4513 QualType modified, QualType equivalent)
4514 : AttributedType(canon, attr->getKind(), attr, modified, equivalent) {}
4515
4516AttributedType::AttributedType(QualType canon, attr::Kind attrKind,
4517 const Attr *attr, QualType modified,
4518 QualType equivalent)
4519 : Type(Attributed, canon, equivalent->getDependence()), Attribute(attr),
4520 ModifiedType(modified), EquivalentType(equivalent) {
4521 AttributedTypeBits.AttrKind = attrKind;
4522 assert(!attr || attr->getKind() == attrKind);
4523}
4524
4525bool AttributedType::isQualifier() const {
4526 // FIXME: Generate this with TableGen.
4527 switch (getAttrKind()) {
4528 // These are type qualifiers in the traditional C sense: they annotate
4529 // something about a specific value/variable of a type. (They aren't
4530 // always part of the canonical type, though.)
4531 case attr::ObjCGC:
4532 case attr::ObjCOwnership:
4533 case attr::ObjCInertUnsafeUnretained:
4534 case attr::TypeNonNull:
4535 case attr::TypeNullable:
4536 case attr::TypeNullableResult:
4537 case attr::TypeNullUnspecified:
4538 case attr::LifetimeBound:
4539 case attr::AddressSpace:
4540 return true;
4541
4542 // All other type attributes aren't qualifiers; they rewrite the modified
4543 // type to be a semantically different type.
4544 default:
4545 return false;
4546 }
4547}
4548
4549bool AttributedType::isMSTypeSpec() const {
4550 // FIXME: Generate this with TableGen?
4551 switch (getAttrKind()) {
4552 default:
4553 return false;
4554 case attr::Ptr32:
4555 case attr::Ptr64:
4556 case attr::SPtr:
4557 case attr::UPtr:
4558 return true;
4559 }
4560 llvm_unreachable("invalid attr kind");
4561}
4562
4563bool AttributedType::isWebAssemblyFuncrefSpec() const {
4564 return getAttrKind() == attr::WebAssemblyFuncref;
4565}
4566
4567bool AttributedType::isCallingConv() const {
4568 // FIXME: Generate this with TableGen.
4569 switch (getAttrKind()) {
4570 default:
4571 return false;
4572 case attr::Pcs:
4573 case attr::CDecl:
4574 case attr::FastCall:
4575 case attr::StdCall:
4576 case attr::ThisCall:
4577 case attr::RegCall:
4578 case attr::SwiftCall:
4579 case attr::SwiftAsyncCall:
4580 case attr::VectorCall:
4581 case attr::AArch64VectorPcs:
4582 case attr::AArch64SVEPcs:
4583 case attr::DeviceKernel:
4584 case attr::Pascal:
4585 case attr::MSABI:
4586 case attr::SysVABI:
4587 case attr::IntelOclBicc:
4588 case attr::PreserveMost:
4589 case attr::PreserveAll:
4590 case attr::M68kRTD:
4591 case attr::PreserveNone:
4592 case attr::RISCVVectorCC:
4593 case attr::RISCVVLSCC:
4594 return true;
4595 }
4596 llvm_unreachable("invalid attr kind");
4597}
4598
4599IdentifierInfo *TemplateTypeParmType::getIdentifier() const {
4600 return isCanonicalUnqualified() ? nullptr : getDecl()->getIdentifier();
4601}
4602
4603SubstTemplateTypeParmType::SubstTemplateTypeParmType(QualType Replacement,
4604 Decl *AssociatedDecl,
4605 unsigned Index,
4607 bool Final)
4608 : Type(SubstTemplateTypeParm, Replacement.getCanonicalType(),
4609 Replacement->getDependence()),
4610 AssociatedDecl(AssociatedDecl) {
4611 SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType =
4612 Replacement != getCanonicalTypeInternal();
4613 if (SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType)
4614 *getTrailingObjects() = Replacement;
4615
4616 SubstTemplateTypeParmTypeBits.Index = Index;
4617 SubstTemplateTypeParmTypeBits.Final = Final;
4619 PackIndex.toInternalRepresentation();
4620 assert(AssociatedDecl != nullptr);
4621}
4622
4624SubstTemplateTypeParmType::getReplacedParameter() const {
4625 return cast<TemplateTypeParmDecl>(std::get<0>(
4626 getReplacedTemplateParameter(getAssociatedDecl(), getIndex())));
4627}
4628
4629void SubstTemplateTypeParmType::Profile(llvm::FoldingSetNodeID &ID,
4630 QualType Replacement,
4631 const Decl *AssociatedDecl,
4632 unsigned Index,
4633 UnsignedOrNone PackIndex, bool Final) {
4634 Replacement.Profile(ID);
4635 ID.AddPointer(AssociatedDecl);
4636 ID.AddInteger(Index);
4637 ID.AddInteger(PackIndex.toInternalRepresentation());
4638 ID.AddBoolean(Final);
4639}
4640
4641SubstPackType::SubstPackType(TypeClass Derived, QualType Canon,
4642 const TemplateArgument &ArgPack)
4643 : Type(Derived, Canon,
4644 TypeDependence::DependentInstantiation |
4645 TypeDependence::UnexpandedPack),
4646 Arguments(ArgPack.pack_begin()) {
4647 assert(llvm::all_of(
4648 ArgPack.pack_elements(),
4649 [](auto &P) { return P.getKind() == TemplateArgument::Type; }) &&
4650 "non-type argument to SubstPackType?");
4651 SubstPackTypeBits.NumArgs = ArgPack.pack_size();
4652}
4653
4654TemplateArgument SubstPackType::getArgumentPack() const {
4655 return TemplateArgument(llvm::ArrayRef(Arguments, getNumArgs()));
4656}
4657
4658void SubstPackType::Profile(llvm::FoldingSetNodeID &ID) {
4659 Profile(ID, getArgumentPack());
4660}
4661
4662void SubstPackType::Profile(llvm::FoldingSetNodeID &ID,
4663 const TemplateArgument &ArgPack) {
4664 ID.AddInteger(ArgPack.pack_size());
4665 for (const auto &P : ArgPack.pack_elements())
4666 ID.AddPointer(P.getAsType().getAsOpaquePtr());
4667}
4668
4669SubstTemplateTypeParmPackType::SubstTemplateTypeParmPackType(
4670 QualType Canon, Decl *AssociatedDecl, unsigned Index, bool Final,
4671 const TemplateArgument &ArgPack)
4672 : SubstPackType(SubstTemplateTypeParmPack, Canon, ArgPack),
4673 AssociatedDeclAndFinal(AssociatedDecl, Final) {
4674 assert(AssociatedDecl != nullptr);
4675
4676 SubstPackTypeBits.SubstTemplTypeParmPackIndex = Index;
4677 assert(getNumArgs() == ArgPack.pack_size() &&
4678 "Parent bitfields in SubstPackType were overwritten."
4679 "Check NumSubstPackTypeBits.");
4680}
4681
4682Decl *SubstTemplateTypeParmPackType::getAssociatedDecl() const {
4683 return AssociatedDeclAndFinal.getPointer();
4684}
4685
4686bool SubstTemplateTypeParmPackType::getFinal() const {
4687 return AssociatedDeclAndFinal.getInt();
4688}
4689
4691SubstTemplateTypeParmPackType::getReplacedParameter() const {
4692 return cast<TemplateTypeParmDecl>(std::get<0>(
4693 getReplacedTemplateParameter(getAssociatedDecl(), getIndex())));
4694}
4695
4696IdentifierInfo *SubstTemplateTypeParmPackType::getIdentifier() const {
4697 return getReplacedParameter()->getIdentifier();
4698}
4699
4700void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID) {
4701 Profile(ID, getAssociatedDecl(), getIndex(), getFinal(), getArgumentPack());
4702}
4703
4704void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID,
4705 const Decl *AssociatedDecl,
4706 unsigned Index, bool Final,
4707 const TemplateArgument &ArgPack) {
4708 ID.AddPointer(AssociatedDecl);
4709 ID.AddInteger(Index);
4710 ID.AddBoolean(Final);
4711 SubstPackType::Profile(ID, ArgPack);
4712}
4713
4714SubstBuiltinTemplatePackType::SubstBuiltinTemplatePackType(
4715 QualType Canon, const TemplateArgument &ArgPack)
4716 : SubstPackType(SubstBuiltinTemplatePack, Canon, ArgPack) {}
4717
4718bool TemplateSpecializationType::anyDependentTemplateArguments(
4719 const TemplateArgumentListInfo &Args,
4720 ArrayRef<TemplateArgument> Converted) {
4721 return anyDependentTemplateArguments(Args.arguments(), Converted);
4722}
4723
4724bool TemplateSpecializationType::anyDependentTemplateArguments(
4726 for (const TemplateArgument &Arg : Converted)
4727 if (Arg.isDependent())
4728 return true;
4729 return false;
4730}
4731
4732bool TemplateSpecializationType::anyInstantiationDependentTemplateArguments(
4734 for (const TemplateArgumentLoc &ArgLoc : Args) {
4735 if (ArgLoc.getArgument().isInstantiationDependent())
4736 return true;
4737 }
4738 return false;
4739}
4740
4741static TypeDependence
4743 TypeDependence D = Underlying.isNull()
4744 ? TypeDependence::DependentInstantiation
4745 : toSemanticDependence(Underlying->getDependence());
4746 D |= toTypeDependence(T.getDependence()) & TypeDependence::UnexpandedPack;
4748 if (Underlying.isNull()) // Dependent, will produce a pack on substitution.
4749 D |= TypeDependence::UnexpandedPack;
4750 else
4751 D |= (Underlying->getDependence() & TypeDependence::UnexpandedPack);
4752 }
4753 return D;
4754}
4755
4756TemplateSpecializationType::TemplateSpecializationType(
4758 ArrayRef<TemplateArgument> Args, QualType Underlying)
4760 Underlying.isNull() ? QualType(this, 0)
4761 : Underlying.getCanonicalType(),
4763 Template(T) {
4764 TemplateSpecializationTypeBits.NumArgs = Args.size();
4765 TemplateSpecializationTypeBits.TypeAlias = IsAlias;
4766
4767 auto *TemplateArgs =
4768 const_cast<TemplateArgument *>(template_arguments().data());
4769 for (const TemplateArgument &Arg : Args) {
4770 // Update instantiation-dependent, variably-modified, and error bits.
4771 // If the canonical type exists and is non-dependent, the template
4772 // specialization type can be non-dependent even if one of the type
4773 // arguments is. Given:
4774 // template<typename T> using U = int;
4775 // U<T> is always non-dependent, irrespective of the type T.
4776 // However, U<Ts> contains an unexpanded parameter pack, even though
4777 // its expansion (and thus its desugared type) doesn't.
4778 addDependence(toTypeDependence(Arg.getDependence()) &
4779 ~TypeDependence::Dependent);
4780 if (Arg.getKind() == TemplateArgument::Type)
4781 addDependence(Arg.getAsType()->getDependence() &
4782 TypeDependence::VariablyModified);
4783 new (TemplateArgs++) TemplateArgument(Arg);
4784 }
4785
4786 // Store the aliased type after the template arguments, if this is a type
4787 // alias template specialization.
4788 if (IsAlias)
4789 *reinterpret_cast<QualType *>(TemplateArgs) = Underlying;
4790}
4791
4792QualType TemplateSpecializationType::getAliasedType() const {
4793 assert(isTypeAlias() && "not a type alias template specialization");
4794 return *reinterpret_cast<const QualType *>(template_arguments().end());
4795}
4796
4797bool clang::TemplateSpecializationType::isSugared() const {
4798 return !isDependentType() || isCurrentInstantiation() || isTypeAlias() ||
4800 isa<SubstBuiltinTemplatePackType>(*getCanonicalTypeInternal()));
4801}
4802
4803void TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
4804 const ASTContext &Ctx) {
4805 Profile(ID, getKeyword(), Template, template_arguments(),
4806 isSugared() ? desugar() : QualType(), Ctx);
4807}
4808
4809void TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
4813 QualType Underlying,
4814 const ASTContext &Context) {
4815 ID.AddInteger(llvm::to_underlying(Keyword));
4816 T.Profile(ID);
4817 Underlying.Profile(ID);
4818
4819 ID.AddInteger(Args.size());
4820 for (const TemplateArgument &Arg : Args)
4821 Arg.Profile(ID, Context);
4822}
4823
4825 QualType QT) const {
4826 if (!hasNonFastQualifiers())
4828
4829 return Context.getQualifiedType(QT, *this);
4830}
4831
4833 const Type *T) const {
4834 if (!hasNonFastQualifiers())
4835 return QualType(T, getFastQualifiers());
4836
4837 return Context.getQualifiedType(T, *this);
4838}
4839
4840void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID, QualType BaseType,
4841 ArrayRef<QualType> typeArgs,
4843 bool isKindOf) {
4844 ID.AddPointer(BaseType.getAsOpaquePtr());
4845 ID.AddInteger(typeArgs.size());
4846 for (auto typeArg : typeArgs)
4847 ID.AddPointer(typeArg.getAsOpaquePtr());
4848 ID.AddInteger(protocols.size());
4849 for (auto *proto : protocols)
4850 ID.AddPointer(proto);
4851 ID.AddBoolean(isKindOf);
4852}
4853
4854void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) {
4855 Profile(ID, getBaseType(), getTypeArgsAsWritten(),
4856 llvm::ArrayRef(qual_begin(), getNumProtocols()),
4857 isKindOfTypeAsWritten());
4858}
4859
4860void ObjCTypeParamType::Profile(llvm::FoldingSetNodeID &ID,
4861 const ObjCTypeParamDecl *OTPDecl,
4862 QualType CanonicalType,
4863 ArrayRef<ObjCProtocolDecl *> protocols) {
4864 ID.AddPointer(OTPDecl);
4865 ID.AddPointer(CanonicalType.getAsOpaquePtr());
4866 ID.AddInteger(protocols.size());
4867 for (auto *proto : protocols)
4868 ID.AddPointer(proto);
4869}
4870
4871void ObjCTypeParamType::Profile(llvm::FoldingSetNodeID &ID) {
4872 Profile(ID, getDecl(), getCanonicalTypeInternal(),
4873 llvm::ArrayRef(qual_begin(), getNumProtocols()));
4874}
4875
4876namespace {
4877
4878/// The cached properties of a type.
4879class CachedProperties {
4880 Linkage L;
4881 bool local;
4882
4883public:
4884 CachedProperties(Linkage L, bool local) : L(L), local(local) {}
4885
4886 Linkage getLinkage() const { return L; }
4887 bool hasLocalOrUnnamedType() const { return local; }
4888
4889 friend CachedProperties merge(CachedProperties L, CachedProperties R) {
4890 Linkage MergedLinkage = minLinkage(L.L, R.L);
4891 return CachedProperties(MergedLinkage, L.hasLocalOrUnnamedType() ||
4892 R.hasLocalOrUnnamedType());
4893 }
4894};
4895
4896} // namespace
4897
4898static CachedProperties computeCachedProperties(const Type *T);
4899
4900namespace clang {
4901
4902/// The type-property cache. This is templated so as to be
4903/// instantiated at an internal type to prevent unnecessary symbol
4904/// leakage.
4905template <class Private> class TypePropertyCache {
4906public:
4907 static CachedProperties get(QualType T) { return get(T.getTypePtr()); }
4908
4909 static CachedProperties get(const Type *T) {
4910 ensure(T);
4911 return CachedProperties(T->TypeBits.getLinkage(),
4912 T->TypeBits.hasLocalOrUnnamedType());
4913 }
4914
4915 static void ensure(const Type *T) {
4916 // If the cache is valid, we're okay.
4917 if (T->TypeBits.isCacheValid())
4918 return;
4919
4920 // If this type is non-canonical, ask its canonical type for the
4921 // relevant information.
4922 if (!T->isCanonicalUnqualified()) {
4923 const Type *CT = T->getCanonicalTypeInternal().getTypePtr();
4924 ensure(CT);
4925 T->TypeBits.CacheValid = true;
4926 T->TypeBits.CachedLinkage = CT->TypeBits.CachedLinkage;
4927 T->TypeBits.CachedLocalOrUnnamed = CT->TypeBits.CachedLocalOrUnnamed;
4928 return;
4929 }
4930
4931 // Compute the cached properties and then set the cache.
4932 CachedProperties Result = computeCachedProperties(T);
4933 T->TypeBits.CacheValid = true;
4934 T->TypeBits.CachedLinkage = llvm::to_underlying(Result.getLinkage());
4935 T->TypeBits.CachedLocalOrUnnamed = Result.hasLocalOrUnnamedType();
4936 }
4937};
4938
4939} // namespace clang
4940
4941// Instantiate the friend template at a private class. In a
4942// reasonable implementation, these symbols will be internal.
4943// It is terrible that this is the best way to accomplish this.
4944namespace {
4945
4946class Private {};
4947
4948} // namespace
4949
4951
4952static CachedProperties computeCachedProperties(const Type *T) {
4953 switch (T->getTypeClass()) {
4954#define TYPE(Class, Base)
4955#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
4956#include "clang/AST/TypeNodes.inc"
4957 llvm_unreachable("didn't expect a non-canonical type here");
4958
4959#define TYPE(Class, Base)
4960#define DEPENDENT_TYPE(Class, Base) case Type::Class:
4961#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
4962#include "clang/AST/TypeNodes.inc"
4963 // Treat instantiation-dependent types as external.
4964 assert(T->isInstantiationDependentType());
4965 return CachedProperties(Linkage::External, false);
4966
4967 case Type::Auto:
4968 case Type::DeducedTemplateSpecialization:
4969 // Give non-deduced 'auto' types external linkage. We should only see them
4970 // here in error recovery.
4971 return CachedProperties(Linkage::External, false);
4972
4973 case Type::BitInt:
4974 case Type::Builtin:
4975 // C++ [basic.link]p8:
4976 // A type is said to have linkage if and only if:
4977 // - it is a fundamental type (3.9.1); or
4978 return CachedProperties(Linkage::External, false);
4979
4980 case Type::Record:
4981 case Type::Enum: {
4982 const auto *Tag = cast<TagType>(T)->getDecl()->getDefinitionOrSelf();
4983
4984 // C++ [basic.link]p8:
4985 // - it is a class or enumeration type that is named (or has a name
4986 // for linkage purposes (7.1.3)) and the name has linkage; or
4987 // - it is a specialization of a class template (14); or
4988 Linkage L = Tag->getLinkageInternal();
4989 bool IsLocalOrUnnamed = Tag->getDeclContext()->isFunctionOrMethod() ||
4990 !Tag->hasNameForLinkage();
4991 return CachedProperties(L, IsLocalOrUnnamed);
4992 }
4993
4994 // C++ [basic.link]p8:
4995 // - it is a compound type (3.9.2) other than a class or enumeration,
4996 // compounded exclusively from types that have linkage; or
4997 case Type::Complex:
4998 return Cache::get(cast<ComplexType>(T)->getElementType());
4999 case Type::Pointer:
5001 case Type::BlockPointer:
5003 case Type::LValueReference:
5004 case Type::RValueReference:
5006 case Type::MemberPointer: {
5007 const auto *MPT = cast<MemberPointerType>(T);
5008 CachedProperties Cls = [&] {
5009 if (MPT->isSugared())
5010 MPT = cast<MemberPointerType>(MPT->getCanonicalTypeInternal());
5011 return Cache::get(MPT->getQualifier().getAsType());
5012 }();
5013 return merge(Cls, Cache::get(MPT->getPointeeType()));
5014 }
5015 case Type::ConstantArray:
5016 case Type::IncompleteArray:
5017 case Type::VariableArray:
5018 case Type::ArrayParameter:
5019 return Cache::get(cast<ArrayType>(T)->getElementType());
5020 case Type::Vector:
5021 case Type::ExtVector:
5022 return Cache::get(cast<VectorType>(T)->getElementType());
5023 case Type::ConstantMatrix:
5024 return Cache::get(cast<ConstantMatrixType>(T)->getElementType());
5025 case Type::FunctionNoProto:
5026 return Cache::get(cast<FunctionType>(T)->getReturnType());
5027 case Type::FunctionProto: {
5028 const auto *FPT = cast<FunctionProtoType>(T);
5029 CachedProperties result = Cache::get(FPT->getReturnType());
5030 for (const auto &ai : FPT->param_types())
5031 result = merge(result, Cache::get(ai));
5032 return result;
5033 }
5034 case Type::ObjCInterface: {
5035 Linkage L = cast<ObjCInterfaceType>(T)->getDecl()->getLinkageInternal();
5036 return CachedProperties(L, false);
5037 }
5038 case Type::ObjCObject:
5039 return Cache::get(cast<ObjCObjectType>(T)->getBaseType());
5040 case Type::ObjCObjectPointer:
5042 case Type::Atomic:
5043 return Cache::get(cast<AtomicType>(T)->getValueType());
5044 case Type::Pipe:
5045 return Cache::get(cast<PipeType>(T)->getElementType());
5046 case Type::HLSLAttributedResource:
5047 return Cache::get(cast<HLSLAttributedResourceType>(T)->getWrappedType());
5048 case Type::HLSLInlineSpirv:
5049 return CachedProperties(Linkage::External, false);
5050 case Type::OverflowBehavior:
5052 }
5053
5054 llvm_unreachable("unhandled type class");
5055}
5056
5057/// Determine the linkage of this type.
5059 Cache::ensure(this);
5060 return TypeBits.getLinkage();
5061}
5062
5064 Cache::ensure(this);
5065 return TypeBits.hasLocalOrUnnamedType();
5066}
5067
5069 switch (T->getTypeClass()) {
5070#define TYPE(Class, Base)
5071#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
5072#include "clang/AST/TypeNodes.inc"
5073 llvm_unreachable("didn't expect a non-canonical type here");
5074
5075#define TYPE(Class, Base)
5076#define DEPENDENT_TYPE(Class, Base) case Type::Class:
5077#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
5078#include "clang/AST/TypeNodes.inc"
5079 // Treat instantiation-dependent types as external.
5080 assert(T->isInstantiationDependentType());
5081 return LinkageInfo::external();
5082
5083 case Type::BitInt:
5084 case Type::Builtin:
5085 return LinkageInfo::external();
5086
5087 case Type::Auto:
5088 case Type::DeducedTemplateSpecialization:
5089 return LinkageInfo::external();
5090
5091 case Type::Record:
5092 case Type::Enum:
5094 cast<TagType>(T)->getDecl()->getDefinitionOrSelf());
5095
5096 case Type::Complex:
5097 return computeTypeLinkageInfo(cast<ComplexType>(T)->getElementType());
5098 case Type::Pointer:
5100 case Type::BlockPointer:
5102 case Type::LValueReference:
5103 case Type::RValueReference:
5105 case Type::MemberPointer: {
5106 const auto *MPT = cast<MemberPointerType>(T);
5107 LinkageInfo LV;
5108 if (auto *D = MPT->getMostRecentCXXRecordDecl()) {
5110 } else {
5111 LV.merge(computeTypeLinkageInfo(MPT->getQualifier().getAsType()));
5112 }
5113 LV.merge(computeTypeLinkageInfo(MPT->getPointeeType()));
5114 return LV;
5115 }
5116 case Type::ConstantArray:
5117 case Type::IncompleteArray:
5118 case Type::VariableArray:
5119 case Type::ArrayParameter:
5120 return computeTypeLinkageInfo(cast<ArrayType>(T)->getElementType());
5121 case Type::Vector:
5122 case Type::ExtVector:
5123 return computeTypeLinkageInfo(cast<VectorType>(T)->getElementType());
5124 case Type::ConstantMatrix:
5126 cast<ConstantMatrixType>(T)->getElementType());
5127 case Type::FunctionNoProto:
5128 return computeTypeLinkageInfo(cast<FunctionType>(T)->getReturnType());
5129 case Type::FunctionProto: {
5130 const auto *FPT = cast<FunctionProtoType>(T);
5131 LinkageInfo LV = computeTypeLinkageInfo(FPT->getReturnType());
5132 for (const auto &ai : FPT->param_types())
5134 return LV;
5135 }
5136 case Type::ObjCInterface:
5138 case Type::ObjCObject:
5139 return computeTypeLinkageInfo(cast<ObjCObjectType>(T)->getBaseType());
5140 case Type::ObjCObjectPointer:
5143 case Type::Atomic:
5144 return computeTypeLinkageInfo(cast<AtomicType>(T)->getValueType());
5145 case Type::Pipe:
5146 return computeTypeLinkageInfo(cast<PipeType>(T)->getElementType());
5147 case Type::OverflowBehavior:
5150 case Type::HLSLAttributedResource:
5152 ->getContainedType()
5153 ->getCanonicalTypeInternal());
5154 case Type::HLSLInlineSpirv:
5155 return LinkageInfo::external();
5156 }
5157
5158 llvm_unreachable("unhandled type class");
5159}
5160
5162 if (!TypeBits.isCacheValid())
5163 return true;
5164
5167 .getLinkage();
5168 return L == TypeBits.getLinkage();
5169}
5170
5172 if (!T->isCanonicalUnqualified())
5173 return computeTypeLinkageInfo(T->getCanonicalTypeInternal());
5174
5176 assert(LV.getLinkage() == T->getLinkage());
5177 return LV;
5178}
5179
5183
5185 QualType Type(this, 0);
5186 while (const auto *AT = Type->getAs<AttributedType>()) {
5187 // Check whether this is an attributed type with nullability
5188 // information.
5189 if (auto Nullability = AT->getImmediateNullability())
5190 return Nullability;
5191
5192 Type = AT->getEquivalentType();
5193 }
5194 return std::nullopt;
5195}
5196
5197bool Type::canHaveNullability(bool ResultIfUnknown) const {
5199
5200 switch (type->getTypeClass()) {
5201#define NON_CANONICAL_TYPE(Class, Parent) \
5202 /* We'll only see canonical types here. */ \
5203 case Type::Class: \
5204 llvm_unreachable("non-canonical type");
5205#define TYPE(Class, Parent)
5206#include "clang/AST/TypeNodes.inc"
5207
5208 // Pointer types.
5209 case Type::Pointer:
5210 case Type::BlockPointer:
5211 case Type::MemberPointer:
5212 case Type::ObjCObjectPointer:
5213 return true;
5214
5215 // Dependent types that could instantiate to pointer types.
5216 case Type::UnresolvedUsing:
5217 case Type::TypeOfExpr:
5218 case Type::TypeOf:
5219 case Type::Decltype:
5220 case Type::PackIndexing:
5221 case Type::UnaryTransform:
5222 case Type::TemplateTypeParm:
5223 case Type::SubstTemplateTypeParmPack:
5224 case Type::SubstBuiltinTemplatePack:
5225 case Type::DependentName:
5226 case Type::Auto:
5227 return ResultIfUnknown;
5228
5229 // Dependent template specializations could instantiate to pointer types.
5230 case Type::TemplateSpecialization:
5231 // If it's a known class template, we can already check if it's nullable.
5232 if (TemplateDecl *templateDecl =
5234 ->getTemplateName()
5235 .getAsTemplateDecl())
5236 if (auto *CTD = dyn_cast<ClassTemplateDecl>(templateDecl))
5237 return llvm::any_of(
5238 CTD->redecls(), [](const RedeclarableTemplateDecl *RTD) {
5239 return RTD->getTemplatedDecl()->hasAttr<TypeNullableAttr>();
5240 });
5241 return ResultIfUnknown;
5242
5243 case Type::Builtin:
5244 switch (cast<BuiltinType>(type.getTypePtr())->getKind()) {
5245 // Signed, unsigned, and floating-point types cannot have nullability.
5246#define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
5247#define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
5248#define FLOATING_TYPE(Id, SingletonId) case BuiltinType::Id:
5249#define BUILTIN_TYPE(Id, SingletonId)
5250#include "clang/AST/BuiltinTypes.def"
5251 return false;
5252
5253 case BuiltinType::UnresolvedTemplate:
5254 // Dependent types that could instantiate to a pointer type.
5255 case BuiltinType::Dependent:
5256 case BuiltinType::Overload:
5257 case BuiltinType::BoundMember:
5258 case BuiltinType::PseudoObject:
5259 case BuiltinType::UnknownAny:
5260 case BuiltinType::ARCUnbridgedCast:
5261 return ResultIfUnknown;
5262
5263 case BuiltinType::Void:
5264 case BuiltinType::ObjCId:
5265 case BuiltinType::ObjCClass:
5266 case BuiltinType::ObjCSel:
5267#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
5268 case BuiltinType::Id:
5269#include "clang/Basic/OpenCLImageTypes.def"
5270#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) case BuiltinType::Id:
5271#include "clang/Basic/OpenCLExtensionTypes.def"
5272 case BuiltinType::OCLSampler:
5273 case BuiltinType::OCLEvent:
5274 case BuiltinType::OCLClkEvent:
5275 case BuiltinType::OCLQueue:
5276 case BuiltinType::OCLReserveID:
5277#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
5278#include "clang/Basic/AArch64ACLETypes.def"
5279#define PPC_VECTOR_TYPE(Name, Id, Size) case BuiltinType::Id:
5280#include "clang/Basic/PPCTypes.def"
5281#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
5282#include "clang/Basic/RISCVVTypes.def"
5283#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
5284#include "clang/Basic/WebAssemblyReferenceTypes.def"
5285#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) case BuiltinType::Id:
5286#include "clang/Basic/AMDGPUTypes.def"
5287#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
5288#include "clang/Basic/HLSLIntangibleTypes.def"
5289#define SPIRV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
5290#include "clang/Basic/SPIRVTypes.def"
5291 case BuiltinType::BuiltinFn:
5292 case BuiltinType::NullPtr:
5293 case BuiltinType::IncompleteMatrixIdx:
5294 case BuiltinType::ArraySection:
5295 case BuiltinType::OMPArrayShaping:
5296 case BuiltinType::OMPIterator:
5297 return false;
5298 }
5299 llvm_unreachable("unknown builtin type");
5300
5301 case Type::Record: {
5302 const auto *RD = cast<RecordType>(type)->getDecl();
5303 // For template specializations, look only at primary template attributes.
5304 // This is a consistent regardless of whether the instantiation is known.
5305 if (const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
5306 return llvm::any_of(
5307 CTSD->getSpecializedTemplate()->redecls(),
5308 [](const RedeclarableTemplateDecl *RTD) {
5309 return RTD->getTemplatedDecl()->hasAttr<TypeNullableAttr>();
5310 });
5311 return llvm::any_of(RD->redecls(), [](const TagDecl *RD) {
5312 return RD->hasAttr<TypeNullableAttr>();
5313 });
5314 }
5315
5316 // Non-pointer types.
5317 case Type::Complex:
5318 case Type::LValueReference:
5319 case Type::RValueReference:
5320 case Type::ConstantArray:
5321 case Type::IncompleteArray:
5322 case Type::VariableArray:
5323 case Type::DependentSizedArray:
5324 case Type::DependentVector:
5325 case Type::DependentSizedExtVector:
5326 case Type::Vector:
5327 case Type::ExtVector:
5328 case Type::ConstantMatrix:
5329 case Type::DependentSizedMatrix:
5330 case Type::DependentAddressSpace:
5331 case Type::FunctionProto:
5332 case Type::FunctionNoProto:
5333 case Type::DeducedTemplateSpecialization:
5334 case Type::Enum:
5335 case Type::InjectedClassName:
5336 case Type::PackExpansion:
5337 case Type::ObjCObject:
5338 case Type::ObjCInterface:
5339 case Type::Atomic:
5340 case Type::Pipe:
5341 case Type::BitInt:
5342 case Type::DependentBitInt:
5343 case Type::ArrayParameter:
5344 case Type::HLSLAttributedResource:
5345 case Type::HLSLInlineSpirv:
5346 case Type::OverflowBehavior:
5347 return false;
5348 }
5349 llvm_unreachable("bad type kind!");
5350}
5351
5352NullabilityKindOrNone AttributedType::getImmediateNullability() const {
5353 if (getAttrKind() == attr::TypeNonNull)
5355 if (getAttrKind() == attr::TypeNullable)
5357 if (getAttrKind() == attr::TypeNullUnspecified)
5359 if (getAttrKind() == attr::TypeNullableResult)
5361 return std::nullopt;
5362}
5363
5364NullabilityKindOrNone AttributedType::stripOuterNullability(QualType &T) {
5365 QualType AttrTy = T;
5366 if (auto MacroTy = dyn_cast<MacroQualifiedType>(T))
5367 AttrTy = MacroTy->getUnderlyingType();
5368
5369 if (auto attributed = dyn_cast<AttributedType>(AttrTy)) {
5370 if (auto nullability = attributed->getImmediateNullability()) {
5371 T = attributed->getModifiedType();
5372 return nullability;
5373 }
5374 }
5375
5376 return std::nullopt;
5377}
5378
5379void AttributedType::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx,
5380 Kind attrKind, QualType modified,
5381 QualType equivalent, const Attr *attr) {
5382 ID.AddInteger(attrKind);
5383 ID.AddPointer(modified.getAsOpaquePtr());
5384 ID.AddPointer(equivalent.getAsOpaquePtr());
5385 if (attr)
5386 attr->Profile(ID, Ctx);
5387}
5388
5390 if (!isIntegralType(Ctx) || isEnumeralType())
5391 return false;
5392 return Ctx.getTypeSize(this) == Ctx.getTypeSize(Ctx.VoidPtrTy);
5393}
5394
5396 const auto *objcPtr = getAs<ObjCObjectPointerType>();
5397 if (!objcPtr)
5398 return false;
5399
5400 if (objcPtr->isObjCIdType()) {
5401 // id is always okay.
5402 return true;
5403 }
5404
5405 // Blocks are NSObjects.
5406 if (ObjCInterfaceDecl *iface = objcPtr->getInterfaceDecl()) {
5407 if (iface->getIdentifier() != ctx.getNSObjectName())
5408 return false;
5409
5410 // Continue to check qualifiers, below.
5411 } else if (objcPtr->isObjCQualifiedIdType()) {
5412 // Continue to check qualifiers, below.
5413 } else {
5414 return false;
5415 }
5416
5417 // Check protocol qualifiers.
5418 for (ObjCProtocolDecl *proto : objcPtr->quals()) {
5419 // Blocks conform to NSObject and NSCopying.
5420 if (proto->getIdentifier() != ctx.getNSObjectName() &&
5421 proto->getIdentifier() != ctx.getNSCopyingName())
5422 return false;
5423 }
5424
5425 return true;
5426}
5427
5433
5435 assert(isObjCLifetimeType() &&
5436 "cannot query implicit lifetime for non-inferrable type");
5437
5438 const Type *canon = getCanonicalTypeInternal().getTypePtr();
5439
5440 // Walk down to the base type. We don't care about qualifiers for this.
5441 while (const auto *array = dyn_cast<ArrayType>(canon))
5442 canon = array->getElementType().getTypePtr();
5443
5444 if (const auto *opt = dyn_cast<ObjCObjectPointerType>(canon)) {
5445 // Class and Class<Protocol> don't require retention.
5446 if (opt->getObjectType()->isObjCClass())
5447 return true;
5448 }
5449
5450 return false;
5451}
5452
5454 if (const auto *typedefType = getAs<TypedefType>())
5455 return typedefType->getDecl()->hasAttr<ObjCNSObjectAttr>();
5456 return false;
5457}
5458
5460 if (const auto *typedefType = getAs<TypedefType>())
5461 return typedefType->getDecl()->hasAttr<ObjCIndependentClassAttr>();
5462 return false;
5463}
5464
5469
5471 if (isObjCLifetimeType())
5472 return true;
5473 if (const auto *OPT = getAs<PointerType>())
5474 return OPT->getPointeeType()->isObjCIndirectLifetimeType();
5475 if (const auto *Ref = getAs<ReferenceType>())
5476 return Ref->getPointeeType()->isObjCIndirectLifetimeType();
5477 if (const auto *MemPtr = getAs<MemberPointerType>())
5478 return MemPtr->getPointeeType()->isObjCIndirectLifetimeType();
5479 return false;
5480}
5481
5482/// Returns true if objects of this type have lifetime semantics under
5483/// ARC.
5485 const Type *type = this;
5486 while (const ArrayType *array = type->getAsArrayTypeUnsafe())
5487 type = array->getElementType().getTypePtr();
5488 return type->isObjCRetainableType();
5489}
5490
5491/// Determine whether the given type T is a "bridgable" Objective-C type,
5492/// which is either an Objective-C object pointer type or an
5496
5497/// Determine whether the given type T is a "bridgeable" C type.
5499 const auto *Pointer = getAsCanonical<PointerType>();
5500 if (!Pointer)
5501 return false;
5502
5503 QualType Pointee = Pointer->getPointeeType();
5504 return Pointee->isVoidType() || Pointee->isRecordType();
5505}
5506
5507/// Check if the specified type is the CUDA device builtin surface type.
5509 if (const auto *RT = getAsCanonical<RecordType>())
5510 return RT->getDecl()
5511 ->getMostRecentDecl()
5512 ->hasAttr<CUDADeviceBuiltinSurfaceTypeAttr>();
5513 return false;
5514}
5515
5516/// Check if the specified type is the CUDA device builtin texture type.
5518 if (const auto *RT = getAsCanonical<RecordType>())
5519 return RT->getDecl()
5520 ->getMostRecentDecl()
5521 ->hasAttr<CUDADeviceBuiltinTextureTypeAttr>();
5522 return false;
5523}
5524
5525static bool isAMDGPUNamedBarrierTypeImpl(const Type *Ty, bool AllowWrappers) {
5526 // This query does not care about qualifiers at all.
5527 Ty = Ty->getUnqualifiedDesugaredType();
5528
5529 // Unwrap arrays.
5530 while (isa<ArrayType>(Ty))
5532
5533 if (const auto *BT = dyn_cast<BuiltinType>(Ty))
5534 return BT->getKind() == BuiltinType::AMDGPUNamedWorkgroupBarrier;
5535 if (AllowWrappers) {
5536 if (const auto *RT = dyn_cast<RecordType>(Ty))
5537 return RT->getDecl()->hasAttr<AMDGPUNamedBarrierWrapperAttr>();
5538 }
5539 return false;
5540}
5541
5543 return isAMDGPUNamedBarrierTypeImpl(this, /*AllowWrappers=*/false);
5544}
5545
5547 return isAMDGPUNamedBarrierTypeImpl(this, /*AllowWrappers=*/true);
5548}
5549
5552 return false;
5553
5554 if (const auto *ptr = getAs<PointerType>())
5555 return ptr->getPointeeType()->hasSizedVLAType();
5556 if (const auto *ref = getAs<ReferenceType>())
5557 return ref->getPointeeType()->hasSizedVLAType();
5558 if (const ArrayType *arr = getAsArrayTypeUnsafe()) {
5559 if (isa<VariableArrayType>(arr) &&
5560 cast<VariableArrayType>(arr)->getSizeExpr())
5561 return true;
5562
5563 return arr->getElementType()->hasSizedVLAType();
5564 }
5565
5566 return false;
5567}
5568
5570 return HLSLAttributedResourceType::findHandleTypeOnResource(this) != nullptr;
5571}
5572
5574 const Type *Ty = getUnqualifiedDesugaredType();
5575 if (!Ty->isArrayType())
5576 return false;
5577 while (isa<ArrayType>(Ty))
5579 return Ty->isHLSLResourceRecord();
5580}
5581
5583 const Type *Ty = getUnqualifiedDesugaredType();
5584
5585 // check if it's a builtin type first
5586 if (Ty->isBuiltinType())
5587 return Ty->isHLSLBuiltinIntangibleType();
5588
5589 // unwrap arrays
5590 while (isa<ArrayType>(Ty))
5592
5593 const RecordType *RT =
5594 dyn_cast<RecordType>(Ty->getUnqualifiedDesugaredType());
5595 if (!RT)
5596 return false;
5597
5598 CXXRecordDecl *RD = RT->getAsCXXRecordDecl();
5599 assert(RD != nullptr &&
5600 "all HLSL structs and classes should be CXXRecordDecl");
5601 assert(RD->isCompleteDefinition() && "expecting complete type");
5602 return RD->isHLSLIntangible();
5603}
5604
5606 const Type *BaseTy = getBaseElementTypeUnsafe();
5607 if (const auto *RD =
5608 dyn_cast_or_null<CXXRecordDecl>(BaseTy->getAsRecordDecl())) {
5609 if (!RD->isHLSLBuiltinRecord() && RD->isStandardLayout())
5610 return true;
5611 }
5612 return false;
5613}
5614
5615QualType::DestructionKind QualType::isDestructedTypeImpl(QualType type) {
5616 switch (type.getObjCLifetime()) {
5620 break;
5621
5625 return DK_objc_weak_lifetime;
5626 }
5627
5628 if (const auto *RD = type->getBaseElementTypeUnsafe()->getAsRecordDecl()) {
5629 if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
5630 /// Check if this is a C++ object with a non-trivial destructor.
5631 if (CXXRD->hasDefinition() && !CXXRD->hasTrivialDestructor())
5632 return DK_cxx_destructor;
5633 } else {
5634 /// Check if this is a C struct that is non-trivial to destroy or an array
5635 /// that contains such a struct.
5638 }
5639 }
5640
5641 return DK_none;
5642}
5643
5644static bool
5646 llvm::SmallPtrSetImpl<const Decl *> &Seen) {
5647 if (const auto *Arr = Context.getAsArrayType(Ty))
5648 Ty = Context.getBaseElementType(Arr);
5649
5650 if (const auto *AttrTy = Ty->getAs<AttributedType>())
5651 Ty = AttrTy->getModifiedType();
5652
5653 assert(!Ty->isIncompleteType() &&
5654 "Incomplete types cannot be evaluated for laundering");
5655
5656 const auto *Record = Ty->getAsCXXRecordDecl();
5657 if (!Record)
5658 return false;
5659
5660 // We've already checked this type, or are in the process of checking it.
5661 if (!Seen.insert(Record).second)
5662 return false;
5663
5664 if (Record->isDynamicClass())
5665 return true;
5666
5667 for (FieldDecl *F : Record->fields()) {
5668 if (requiresBuiltinLaunderImpl(Context, F->getType(), Seen))
5669 return true;
5670 }
5671 return false;
5672}
5673
5676 return requiresBuiltinLaunderImpl(Context, *this, Seen);
5677}
5678
5681 *D2 = getQualifier().getAsRecordDecl();
5682 assert(!D1 == !D2);
5683 return D1 != D2 && D1->getCanonicalDecl() != D2->getCanonicalDecl();
5684}
5685
5686void MemberPointerType::Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
5687 const NestedNameSpecifier Qualifier,
5688 const CXXRecordDecl *Cls) {
5689 ID.AddPointer(Pointee.getAsOpaquePtr());
5690 Qualifier.Profile(ID);
5691 if (Cls)
5692 ID.AddPointer(Cls->getCanonicalDecl());
5693}
5694
5695CXXRecordDecl *MemberPointerType::getCXXRecordDecl() const {
5696 return dyn_cast<MemberPointerType>(getCanonicalTypeInternal())
5697 ->getQualifier()
5698 .getAsRecordDecl();
5699}
5700
5702 auto *RD = getCXXRecordDecl();
5703 if (!RD)
5704 return nullptr;
5705 return RD->getMostRecentDecl();
5706}
5707
5709 llvm::APSInt Val, unsigned Scale) {
5710 llvm::FixedPointSemantics FXSema(Val.getBitWidth(), Scale, Val.isSigned(),
5711 /*IsSaturated=*/false,
5712 /*HasUnsignedPadding=*/false);
5713 llvm::APFixedPoint(Val, FXSema).toString(Str);
5714}
5715
5716DeducedType::DeducedType(TypeClass TC, DeducedKind DK,
5717 QualType DeducedAsTypeOrCanon)
5718 : Type(TC, /*canon=*/DK == DeducedKind::Deduced
5719 ? DeducedAsTypeOrCanon.getCanonicalType()
5720 : DeducedAsTypeOrCanon,
5722 DeducedTypeBits.Kind = llvm::to_underlying(DK);
5723 switch (DK) {
5725 break;
5727 assert(!DeducedAsTypeOrCanon.isNull() && "Deduced type cannot be null");
5728 addDependence(DeducedAsTypeOrCanon->getDependence() &
5729 ~TypeDependence::VariablyModified);
5730 DeducedAsType = DeducedAsTypeOrCanon;
5731 break;
5733 addDependence(TypeDependence::UnexpandedPack);
5734 [[fallthrough]];
5736 addDependence(TypeDependence::DependentInstantiation);
5737 break;
5738 }
5739 assert(getDeducedKind() == DK && "DeducedKind does not match the type state");
5740}
5741
5742AutoType::AutoType(DeducedKind DK, QualType DeducedAsTypeOrCanon,
5743 AutoTypeKeyword Keyword, TemplateDecl *TypeConstraintConcept,
5744 ArrayRef<TemplateArgument> TypeConstraintArgs)
5745 : DeducedType(Auto, DK, DeducedAsTypeOrCanon) {
5746 AutoTypeBits.Keyword = llvm::to_underlying(Keyword);
5747 AutoTypeBits.NumArgs = TypeConstraintArgs.size();
5748 this->TypeConstraintConcept = TypeConstraintConcept;
5749 assert(TypeConstraintConcept || AutoTypeBits.NumArgs == 0);
5750 if (TypeConstraintConcept) {
5751 auto Dep = TypeDependence::None;
5752 if (const auto *TTP =
5753 dyn_cast<TemplateTemplateParmDecl>(TypeConstraintConcept))
5754 Dep = TypeDependence::DependentInstantiation |
5755 (TTP->isParameterPack() ? TypeDependence::UnexpandedPack
5756 : TypeDependence::None);
5757
5758 auto *ArgBuffer =
5759 const_cast<TemplateArgument *>(getTypeConstraintArguments().data());
5760 for (const TemplateArgument &Arg : TypeConstraintArgs) {
5761 Dep |= toTypeDependence(Arg.getDependence());
5762 new (ArgBuffer++) TemplateArgument(Arg);
5763 }
5764 // A deduced AutoType only syntactically depends on its constraints.
5765 if (DK == DeducedKind::Deduced)
5766 Dep = toSyntacticDependence(Dep);
5767 addDependence(Dep);
5768 }
5769}
5770
5771void AutoType::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
5774 ArrayRef<TemplateArgument> Arguments) {
5775 DeducedType::Profile(ID, DK, Deduced);
5776 ID.AddInteger(llvm::to_underlying(Keyword));
5777 ID.AddPointer(CD);
5778 for (const TemplateArgument &Arg : Arguments)
5779 Arg.Profile(ID, Context);
5780}
5781
5782void AutoType::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
5783 Profile(ID, Context, getDeducedKind(), getDeducedType(), getKeyword(),
5784 getTypeConstraintConcept(), getTypeConstraintArguments());
5785}
5786
5788 switch (kind()) {
5789 case Kind::NonBlocking:
5790 return Kind::Blocking;
5791 case Kind::Blocking:
5792 return Kind::NonBlocking;
5794 return Kind::Allocating;
5795 case Kind::Allocating:
5796 return Kind::NonAllocating;
5797 }
5798 llvm_unreachable("unknown effect kind");
5799}
5800
5801StringRef FunctionEffect::name() const {
5802 switch (kind()) {
5803 case Kind::NonBlocking:
5804 return "nonblocking";
5806 return "nonallocating";
5807 case Kind::Blocking:
5808 return "blocking";
5809 case Kind::Allocating:
5810 return "allocating";
5811 }
5812 llvm_unreachable("unknown effect kind");
5813}
5814
5816 const Decl &Callee, FunctionEffectKindSet CalleeFX) const {
5817 switch (kind()) {
5819 case Kind::NonBlocking: {
5820 for (FunctionEffect Effect : CalleeFX) {
5821 // nonblocking/nonallocating cannot call allocating.
5822 if (Effect.kind() == Kind::Allocating)
5823 return Effect;
5824 // nonblocking cannot call blocking.
5825 if (kind() == Kind::NonBlocking && Effect.kind() == Kind::Blocking)
5826 return Effect;
5827 }
5828 return std::nullopt;
5829 }
5830
5831 case Kind::Allocating:
5832 case Kind::Blocking:
5833 assert(0 && "effectProhibitingInference with non-inferable effect kind");
5834 break;
5835 }
5836 llvm_unreachable("unknown effect kind");
5837}
5838
5840 bool Direct, FunctionEffectKindSet CalleeFX) const {
5841 switch (kind()) {
5843 case Kind::NonBlocking: {
5844 const Kind CallerKind = kind();
5845 for (FunctionEffect Effect : CalleeFX) {
5846 const Kind EK = Effect.kind();
5847 // Does callee have same or stronger constraint?
5848 if (EK == CallerKind ||
5849 (CallerKind == Kind::NonAllocating && EK == Kind::NonBlocking)) {
5850 return false; // no diagnostic
5851 }
5852 }
5853 return true; // warning
5854 }
5855 case Kind::Allocating:
5856 case Kind::Blocking:
5857 return false;
5858 }
5859 llvm_unreachable("unknown effect kind");
5860}
5861
5862// =====
5863
5865 Conflicts &Errs) {
5866 FunctionEffect::Kind NewOppositeKind = NewEC.Effect.oppositeKind();
5867 Expr *NewCondition = NewEC.Cond.getCondition();
5868
5869 // The index at which insertion will take place; default is at end
5870 // but we might find an earlier insertion point.
5871 unsigned InsertIdx = Effects.size();
5872 unsigned Idx = 0;
5873 for (const FunctionEffectWithCondition &EC : *this) {
5874 // Note about effects with conditions: They are considered distinct from
5875 // those without conditions; they are potentially unique, redundant, or
5876 // in conflict, but we can't tell which until the condition is evaluated.
5877 if (EC.Cond.getCondition() == nullptr && NewCondition == nullptr) {
5878 if (EC.Effect.kind() == NewEC.Effect.kind()) {
5879 // There is no condition, and the effect kind is already present,
5880 // so just fail to insert the new one (creating a duplicate),
5881 // and return success.
5882 return true;
5883 }
5884
5885 if (EC.Effect.kind() == NewOppositeKind) {
5886 Errs.push_back({EC, NewEC});
5887 return false;
5888 }
5889 }
5890
5891 if (NewEC.Effect.kind() < EC.Effect.kind() && InsertIdx > Idx)
5892 InsertIdx = Idx;
5893
5894 ++Idx;
5895 }
5896
5897 if (NewCondition || !Conditions.empty()) {
5898 if (Conditions.empty() && !Effects.empty())
5899 Conditions.resize(Effects.size());
5900 Conditions.insert(Conditions.begin() + InsertIdx,
5901 NewEC.Cond.getCondition());
5902 }
5903 Effects.insert(Effects.begin() + InsertIdx, NewEC.Effect);
5904 return true;
5905}
5906
5908 for (const auto &Item : Set)
5909 insert(Item, Errs);
5910 return Errs.empty();
5911}
5912
5914 FunctionEffectsRef RHS) {
5917
5918 // We could use std::set_intersection but that would require expanding the
5919 // container interface to include push_back, making it available to clients
5920 // who might fail to maintain invariants.
5921 auto IterA = LHS.begin(), EndA = LHS.end();
5922 auto IterB = RHS.begin(), EndB = RHS.end();
5923
5924 auto FEWCLess = [](const FunctionEffectWithCondition &LHS,
5925 const FunctionEffectWithCondition &RHS) {
5926 return std::tuple(LHS.Effect, uintptr_t(LHS.Cond.getCondition())) <
5927 std::tuple(RHS.Effect, uintptr_t(RHS.Cond.getCondition()));
5928 };
5929
5930 while (IterA != EndA && IterB != EndB) {
5931 FunctionEffectWithCondition A = *IterA;
5932 FunctionEffectWithCondition B = *IterB;
5933 if (FEWCLess(A, B))
5934 ++IterA;
5935 else if (FEWCLess(B, A))
5936 ++IterB;
5937 else {
5938 Result.insert(A, Errs);
5939 ++IterA;
5940 ++IterB;
5941 }
5942 }
5943
5944 // Insertion shouldn't be able to fail; that would mean both input
5945 // sets contained conflicts.
5946 assert(Errs.empty() && "conflict shouldn't be possible in getIntersection");
5947
5948 return Result;
5949}
5950
5953 Conflicts &Errs) {
5954 // Optimize for either of the two sets being empty (very common).
5955 if (LHS.empty())
5956 return FunctionEffectSet(RHS);
5957
5958 FunctionEffectSet Combined(LHS);
5959 Combined.insert(RHS, Errs);
5960 return Combined;
5961}
5962
5963namespace clang {
5964
5965raw_ostream &operator<<(raw_ostream &OS,
5966 const FunctionEffectWithCondition &CFE) {
5967 OS << CFE.Effect.name();
5968 if (Expr *E = CFE.Cond.getCondition()) {
5969 OS << '(';
5970 E->dump();
5971 OS << ')';
5972 }
5973 return OS;
5974}
5975
5976} // namespace clang
5977
5978LLVM_DUMP_METHOD void FunctionEffectsRef::dump(llvm::raw_ostream &OS) const {
5979 OS << "Effects{";
5980 llvm::interleaveComma(*this, OS);
5981 OS << "}";
5982}
5983
5984LLVM_DUMP_METHOD void FunctionEffectSet::dump(llvm::raw_ostream &OS) const {
5985 FunctionEffectsRef(*this).dump(OS);
5986}
5987
5988LLVM_DUMP_METHOD void FunctionEffectKindSet::dump(llvm::raw_ostream &OS) const {
5989 OS << "Effects{";
5990 llvm::interleaveComma(*this, OS);
5991 OS << "}";
5992}
5993
5997 assert(llvm::is_sorted(FX) && "effects should be sorted");
5998 assert((Conds.empty() || Conds.size() == FX.size()) &&
5999 "effects size should match conditions size");
6000 return FunctionEffectsRef(FX, Conds);
6001}
6002
6004 std::string Result(Effect.name().str());
6005 if (Cond.getCondition() != nullptr)
6006 Result += "(expr)";
6007 return Result;
6008}
6009
6010const HLSLAttributedResourceType *
6011HLSLAttributedResourceType::findHandleTypeOnResource(const Type *RT) {
6012 // If the type RT is an HLSL resource class, the first field must
6013 // be the resource handle of type HLSLAttributedResourceType
6014 const clang::Type *Ty = RT->getUnqualifiedDesugaredType();
6015 if (const RecordDecl *RD = Ty->getAsCXXRecordDecl()) {
6016 if (!RD->fields().empty()) {
6017 const auto &FirstFD = RD->fields().begin();
6018 return dyn_cast<HLSLAttributedResourceType>(
6019 FirstFD->getType().getTypePtr());
6020 }
6021 }
6022 return nullptr;
6023}
6024
6025StringRef PredefinedSugarType::getName(Kind KD) {
6026 switch (KD) {
6027 case Kind::SizeT:
6028 return "__size_t";
6029 case Kind::SignedSizeT:
6030 return "__signed_size_t";
6031 case Kind::PtrdiffT:
6032 return "__ptrdiff_t";
6033 }
6034 llvm_unreachable("unexpected kind");
6035}
Defines the clang::ASTContext interface.
#define V(N, I)
Provides definitions for the various language-specific address spaces.
static std::optional< NonLoc > getIndex(ProgramStateRef State, const ElementRegion *ER, CharKind CK)
static Decl::Kind getKind(const Decl *D)
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.
TokenType getType() const
Returns the token's type, e.g.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
#define CC_VLS_CASE(ABI_VLEN)
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:31
static QualType getUnderlyingType(const SubRegion *R)
static RecordDecl * getAsRecordDecl(QualType BaseType, HeuristicResolver &Resolver)
static bool isRecordType(QualType T)
Defines various enumerations that describe declaration and type specifiers.
static QualType getPointeeType(const MemRegion *R)
Defines the TargetCXXABI class, which abstracts details of the C++ ABI that we're targeting.
static TypeDependence getTemplateSpecializationTypeDependence(QualType Underlying, TemplateName T)
Definition Type.cpp:4742
#define ENUMERATE_ATTRS(PREFIX)
#define SUGARED_TYPE_CLASS(Class)
Definition Type.cpp:1038
static bool isAMDGPUNamedBarrierTypeImpl(const Type *Ty, bool AllowWrappers)
Definition Type.cpp:5525
static bool requiresBuiltinLaunderImpl(const ASTContext &Context, QualType Ty, llvm::SmallPtrSetImpl< const Decl * > &Seen)
Definition Type.cpp:5645
TypePropertyCache< Private > Cache
Definition Type.cpp:4950
static bool isTriviallyCopyableTypeImpl(const QualType &type, const ASTContext &Context, bool IsCopyConstructible)
Definition Type.cpp:2944
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:644
#define TRIVIAL_TYPE_CLASS(Class)
Definition Type.cpp:1036
static CachedProperties computeCachedProperties(const Type *T)
Definition Type.cpp:4952
C Language Family Type Representation.
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:223
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 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 getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType, const Attr *attr=nullptr) const
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
QualType getArrayParameterType(QualType Ty) const
Return the uniqued reference to a specified array parameter type from the original array type.
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 getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, UnsignedOrNone PackIndex, bool Final) const
Retrieve a substitution-result type.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
CanQualType VoidPtrTy
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:980
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.
QualType getAutoType(DeducedKind DK, QualType DeducedAsType, AutoTypeKeyword Keyword, TemplateDecl *TypeConstraintConcept=nullptr, ArrayRef< TemplateArgument > TypeConstraintArgs={}) const
C++11 deduced auto type.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
CanQualType ObjCBuiltinIdTy
IdentifierInfo * getNSObjectName() const
Retrieve the identifier 'NSObject'.
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.
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.
QualType getVariableArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return a non-unique reference to the type for a variable array of the specified element type.
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.
CanQualType UnsignedCharTy
TemplateName getQualifiedTemplateName(NestedNameSpecifier Qualifier, bool TemplateKeyword, TemplateName Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
QualType getMemberPointerType(QualType T, NestedNameSpecifier Qualifier, const CXXRecordDecl *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
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:942
QualType getOverflowBehaviorType(const OverflowBehaviorAttr *Attr, QualType Wrapped) const
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'.
QualType getConstantArrayType(const ASTContext &Ctx) const
Definition Type.cpp:316
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3836
ArraySizeModifier getSizeModifier() const
Definition TypeBase.h:3850
Qualifiers getIndexTypeQualifiers() const
Definition TypeBase.h:3854
QualType getElementType() const
Definition TypeBase.h:3848
ArrayType(TypeClass tc, QualType et, QualType can, ArraySizeModifier sm, unsigned tq, const Expr *sz=nullptr)
Definition Type.cpp:211
Attr - This represents one attribute.
Definition Attr.h:46
BitIntType(bool isUnsigned, unsigned NumBits)
Definition Type.cpp:461
[BoundsSafety] Represents a parent type class for CountAttributedType and similar sugar types that wi...
Definition TypeBase.h:3468
BoundsAttributedType(TypeClass TC, QualType Wrapped, QualType Canon)
Definition Type.cpp:4145
decl_range dependent_decls() const
Definition TypeBase.h:3488
bool referencesFieldDecls() const
Definition Type.cpp:485
This class is used for builtin types like 'int'.
Definition TypeBase.h:3241
Kind getKind() const
Definition TypeBase.h:3292
StringRef getName(const PrintingPolicy &Policy) const
Definition Type.cpp:3519
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
bool isHLSLIntangible() const
Returns true if the class contains HLSL intangible type, either as a field or in base class.
Definition DeclCXX.h:1561
bool mayBeNonDynamicClass() const
Definition DeclCXX.h:586
bool mayBeDynamicClass() const
Definition DeclCXX.h:580
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition DeclCXX.h:522
Declaration of a class template.
Complex values, per C99 6.2.5p11.
Definition TypeBase.h:3355
Represents the canonical version of C arrays with a specified constant size.
Definition TypeBase.h:3874
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:251
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:291
friend class ASTContext
Definition TypeBase.h:3875
const Expr * getSizeExpr() const
Return a pointer to the size expression.
Definition TypeBase.h:3970
llvm::APInt getSize() const
Return the constant array size as an APInt.
Definition TypeBase.h:3930
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
Definition TypeBase.h:3989
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1093
llvm::APSInt getResultAsAPSInt() const
Definition Expr.cpp:407
ConstantMatrixType(QualType MatrixElementType, unsigned NRows, unsigned NColumns, QualType CanonElementType)
Definition Type.cpp:415
unsigned NumRows
Number of rows and columns.
Definition TypeBase.h:4506
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition TypeBase.h:3516
void Profile(llvm::FoldingSetNodeID &ID)
Definition TypeBase.h:3552
StringRef getAttributeName(bool WithMacroPrefix) const
Definition Type.cpp:4162
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1466
ASTContext & getParentASTContext() const
Definition DeclBase.h:2155
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
bool isInStdNamespace() const
Definition DeclBase.cpp:453
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:550
bool hasAttr() const
Definition DeclBase.h:585
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition TypeBase.h:4197
Expr * getNumBitsExpr() const
Definition Type.cpp:474
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition TypeBase.h:8401
DependentBitIntType(bool IsUnsigned, Expr *NumBits)
Definition Type.cpp:465
bool isUnsigned() const
Definition Type.cpp:470
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition TypeBase.h:4154
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition TypeBase.h:4240
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition TypeBase.h:4607
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition TypeBase.h:6371
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition TypeBase.h:4366
Expr * getCondition() const
Definition TypeBase.h:5148
This represents one expression.
Definition Expr.h:112
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition Expr.h:177
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition Expr.h:223
QualType getType() const
Definition Expr.h:144
ExprDependence getDependence() const
Definition Expr.h:164
Represents a member of a struct/union/class.
Definition Decl.h:3294
A mutable set of FunctionEffect::Kind.
Definition TypeBase.h:5275
void dump(llvm::raw_ostream &OS) const
Definition Type.cpp:5988
bool insert(const FunctionEffectWithCondition &NewEC, Conflicts &Errs)
Definition Type.cpp:5864
SmallVector< Conflict > Conflicts
Definition TypeBase.h:5389
static FunctionEffectSet getIntersection(FunctionEffectsRef LHS, FunctionEffectsRef RHS)
Definition Type.cpp:5913
void dump(llvm::raw_ostream &OS) const
Definition Type.cpp:5984
static FunctionEffectSet getUnion(FunctionEffectsRef LHS, FunctionEffectsRef RHS, Conflicts &Errs)
Definition Type.cpp:5951
Kind kind() const
The kind of the effect.
Definition TypeBase.h:5073
Kind
Identifies the particular effect.
Definition TypeBase.h:5037
bool shouldDiagnoseFunctionCall(bool Direct, FunctionEffectKindSet CalleeFX) const
Definition Type.cpp:5839
StringRef name() const
The description printed in diagnostics, e.g. 'nonblocking'.
Definition Type.cpp:5801
Kind oppositeKind() const
Return the opposite kind, for effects which have opposites.
Definition Type.cpp:5787
std::optional< FunctionEffect > effectProhibitingInference(const Decl &Callee, FunctionEffectKindSet CalleeFX) const
Determine whether the effect is allowed to be inferred on the callee, which is either a FunctionDecl ...
Definition Type.cpp:5815
An immutable set of FunctionEffects and possibly conditions attached to them.
Definition TypeBase.h:5221
void dump(llvm::raw_ostream &OS) const
Definition Type.cpp:5978
ArrayRef< FunctionEffect > effects() const
Definition TypeBase.h:5254
iterator begin() const
Definition TypeBase.h:5259
ArrayRef< EffectConditionExpr > conditions() const
Definition TypeBase.h:5255
static FunctionEffectsRef create(ArrayRef< FunctionEffect > FX, ArrayRef< EffectConditionExpr > Conds)
Asserts invariants.
Definition Type.cpp:5995
iterator end() const
Definition TypeBase.h:5260
bool hasDependentExceptionSpec() const
Return whether this function has a dependent exception spec.
Definition Type.cpp:3983
param_type_iterator param_type_begin() const
Definition TypeBase.h:5865
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition TypeBase.h:5728
bool isTemplateVariadic() const
Determines whether this function prototype contains a parameter pack at the end.
Definition Type.cpp:4037
unsigned getNumParams() const
Definition TypeBase.h:5699
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition TypeBase.h:5841
QualType getParamType(unsigned i) const
Definition TypeBase.h:5701
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
Definition TypeBase.h:5779
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
Definition Type.cpp:4114
friend class ASTContext
Definition TypeBase.h:5422
unsigned getNumExceptions() const
Return the number of types in the exception specification.
Definition TypeBase.h:5771
CanThrowResult canThrow() const
Determine whether this function type has a non-throwing exception specification.
Definition Type.cpp:4004
ExtProtoInfo getExtProtoInfo() const
Definition TypeBase.h:5710
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
Definition TypeBase.h:5786
ArrayRef< QualType > getParamTypes() const
Definition TypeBase.h:5706
ArrayRef< QualType > exceptions() const
Definition TypeBase.h:5875
bool hasInstantiationDependentExceptionSpec() const
Return whether this function has an instantiation-dependent exception spec.
Definition Type.cpp:3995
A class which abstracts out some details necessary for making a call.
Definition TypeBase.h:4728
ExtInfo getExtInfo() const
Definition TypeBase.h:4973
static StringRef getNameForCallConv(CallingConv CC)
Definition Type.cpp:3738
bool getCFIUncheckedCalleeAttr() const
Determine whether this is a function prototype that includes the cfi_unchecked_callee attribute.
Definition Type.cpp:3732
QualType getReturnType() const
Definition TypeBase.h:4957
FunctionType(TypeClass tc, QualType res, QualType Canonical, TypeDependence Dependence, ExtInfo Info)
Definition TypeBase.h:4943
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.
LinkageInfo computeTypeLinkageInfo(const Type *T)
Definition Type.cpp:5068
LinkageInfo getTypeLinkageAndVisibility(const Type *T)
Definition Type.cpp:5171
LinkageInfo getDeclLinkageAndVisibility(const NamedDecl *D)
Definition Decl.cpp:1629
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
QualType desugar() const
Definition Type.cpp:4236
QualType getModifiedType() const
Return this attributed type's modified type with no qualifiers attached to it.
Definition Type.cpp:4238
QualType getUnderlyingType() const
Definition TypeBase.h:6316
const IdentifierInfo * getMacroIdentifier() const
Definition TypeBase.h:6315
Represents a matrix type, as defined in the Matrix Types clang extensions.
Definition TypeBase.h:4451
MatrixType(QualType ElementTy, QualType CanonElementTy)
QualType ElementType
The element type of the matrix.
Definition TypeBase.h:4456
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:3799
bool isSugared() const
Definition Type.cpp:5679
void Profile(llvm::FoldingSetNodeID &ID)
Definition TypeBase.h:3810
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Note: this can trigger extra deserialization when external AST sources are used.
Definition Type.cpp:5701
This represents a decl that may have a name.
Definition Decl.h:274
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:295
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier, or null.
ObjCCategoryDecl - Represents a category declaration.
Definition DeclObjC.h:2335
ObjCInterfaceDecl * getClassInterface()
Definition DeclObjC.h:2378
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition DeclObjC.h:2383
Represents an ObjC class declaration.
Definition DeclObjC.h:1160
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameters of this class.
Definition DeclObjC.cpp:319
const ObjCObjectType * getSuperClassType() const
Retrieve the superclass type.
Definition DeclObjC.h:1571
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition DeclObjC.h:1921
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition DeclObjC.h:1548
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition TypeBase.h:8066
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
Definition Type.cpp:988
Represents a pointer to an Objective C object.
Definition TypeBase.h:8122
const ObjCObjectPointerType * stripObjCKindOfTypeAndQuals(const ASTContext &ctx) const
Strip off the Objective-C "kindof" type and (with it) any protocol qualifiers.
Definition Type.cpp:995
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
Definition TypeBase.h:8159
QualType getSuperClassType() const
Retrieve the type of the superclass of this object pointer type.
Definition Type.cpp:1925
ObjCInterfaceDecl * getInterfaceDecl() const
If this pointer points to an Objective @interface type, gets the declaration for that interface.
Definition TypeBase.h:8174
const ObjCInterfaceType * getInterfaceType() const
If this pointer points to an Objective C @interface type, gets the type for that interface.
Definition Type.cpp:1915
bool isKindOfType() const
Whether this is a "__kindof" type.
Definition TypeBase.h:8208
Represents an Objective-C protocol declaration.
Definition DeclObjC.h:2090
Represents the declaration of an Objective-C type parameter.
Definition DeclObjC.h:581
unsigned getIndex() const
Retrieve the index into its type parameter list.
Definition DeclObjC.h:639
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition DeclObjC.h:665
unsigned size() const
Determine the number of type parameters in this list.
Definition DeclObjC.h:692
A (possibly-)qualified type.
Definition TypeBase.h:938
bool hasAddressDiscriminatedPointerAuth() const
Definition TypeBase.h:1473
bool isTriviallyCopyableType(const ASTContext &Context) const
Return true if this is a trivially copyable type (C++0x [basic.types]p9)
Definition Type.cpp:2996
QualType IgnoreParens() const
Returns the specified type after dropping any outer-level parentheses.
Definition TypeBase.h:1331
QualType withFastQualifiers(unsigned TQs) const
Definition TypeBase.h:1217
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:85
bool isWebAssemblyFuncrefType() const
Returns true if it is a WebAssembly Funcref Type.
Definition Type.cpp:3080
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type.
Definition Type.cpp:3716
@ PDIK_ARCWeak
The type is an Objective-C retainable pointer type that is qualified with the ARC __weak qualifier.
Definition TypeBase.h:1491
@ PDIK_Trivial
The type does not fall into any of the following categories.
Definition TypeBase.h:1483
@ PDIK_ARCStrong
The type is an Objective-C retainable pointer type that is qualified with the ARC __strong qualifier.
Definition TypeBase.h:1487
@ PDIK_Struct
The type is a struct containing a field whose type is not PCK_Trivial.
Definition TypeBase.h:1494
bool mayBeDynamicClass() const
Returns true if it is a class and it might be dynamic.
Definition Type.cpp:167
bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const
Definition Type.cpp:3053
const IdentifierInfo * getBaseTypeIdentifier() const
Retrieves a pointer to the name of the base type.
Definition Type.cpp:111
bool isBitwiseCloneableType(const ASTContext &Context) const
Return true if the type is safe to bitwise copy using memcpy/memmove.
Definition Type.cpp:3002
void Profile(llvm::FoldingSetNodeID &ID) const
Definition TypeBase.h:1414
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
Definition TypeBase.h:1312
bool isTriviallyCopyConstructibleType(const ASTContext &Context) const
Return true if this is a trivially copyable type.
Definition Type.cpp:3047
bool isTrivialType(const ASTContext &Context) const
Return true if this is a trivial type per (C++0x [basic.types]p9)
Definition Type.cpp:2886
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1005
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:3119
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8504
LangAS getAddressSpace() const
Return the address space of this type.
Definition TypeBase.h:8630
bool isConstant(const ASTContext &Ctx) const
Definition TypeBase.h:1098
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:79
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition TypeBase.h:8544
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:2830
bool hasPostfixDeclaratorSyntax() const
Returns true if the type uses postfix declarator syntax, i.e.
Definition Type.cpp:132
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition TypeBase.h:1454
QualType stripObjCKindOfType(const ASTContext &ctx) const
Strip Objective-C "__kindof" types from the given type.
Definition Type.cpp:1730
QualType getCanonicalType() const
Definition TypeBase.h:8556
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition TypeBase.h:8598
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:1721
bool isWebAssemblyReferenceType() const
Returns true if it is a WebAssembly Reference Type.
Definition Type.cpp:3072
SplitQualType getSplitDesugaredType() const
Definition TypeBase.h:1316
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:188
QualType()=default
bool isTrapType() const
Returns true if it is a OverflowBehaviorType of Trap kind.
Definition Type.cpp:3094
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition TypeBase.h:8525
bool UseExcessPrecision(const ASTContext &Ctx)
Definition Type.cpp:1679
PrimitiveDefaultInitializeKind isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C struct types.
Definition Type.cpp:3103
void * getAsOpaquePtr() const
Definition TypeBase.h:985
QualType stripNullability(const ASTContext &ctx) const
Strip nullability attributes from the given type.
Definition Type.cpp:1737
bool isWebAssemblyExternrefType() const
Returns true if it is a WebAssembly Externref Type.
Definition Type.cpp:3076
QualType getNonPackExpansionType() const
Remove an outer pack expansion type (if any) from this type.
Definition Type.cpp:3709
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:3268
bool mayBeNotDynamicClass() const
Returns true if it is not a class or if the class might not be dynamic.
Definition Type.cpp:172
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition TypeBase.h:8577
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:1714
QualType getAtomicUnqualifiedType() const
Remove all qualifiers including _Atomic.
Definition Type.cpp:1745
bool requiresBuiltinLaunder(const ASTContext &Context) const
Returns true if this type requires laundering by checking if it is a dynamic class type,...
Definition Type.cpp:5674
bool isWrapType() const
Returns true if it is a OverflowBehaviorType of Wrap kind.
Definition Type.cpp:3086
bool hasNonTrivialObjCLifetime() const
Definition TypeBase.h:1458
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
Definition Type.cpp:2818
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:3139
@ PCK_Struct
The type is a struct containing a field whose type is neither PCK_Trivial nor PCK_VolatileTrivial.
Definition TypeBase.h:1533
@ PCK_Trivial
The type does not fall into any of the following categories.
Definition TypeBase.h:1509
@ PCK_ARCStrong
The type is an Objective-C retainable pointer type that is qualified with the ARC __strong qualifier.
Definition TypeBase.h:1518
@ PCK_VolatileTrivial
The type would be trivial except that it is volatile-qualified.
Definition TypeBase.h:1514
@ PCK_PtrAuth
The type is an address-discriminated signed pointer type.
Definition TypeBase.h:1525
@ PCK_ARCWeak
The type is an Objective-C retainable pointer type that is qualified with the ARC __weak qualifier.
Definition TypeBase.h:1522
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:73
A qualifier set is used to build a set of qualifiers.
Definition TypeBase.h:8444
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
Definition TypeBase.h:8451
QualType apply(const ASTContext &Context, QualType QT) const
Apply the collected qualifiers to the given type.
Definition Type.cpp:4824
The collection of all-type qualifiers we support.
Definition TypeBase.h:332
GC getObjCGCAttr() const
Definition TypeBase.h:520
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
Definition TypeBase.h:362
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
Definition TypeBase.h:355
@ OCL_None
There is no lifetime qualification on this type.
Definition TypeBase.h:351
@ OCL_Weak
Reading or writing from this object requires a barrier call.
Definition TypeBase.h:365
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
Definition TypeBase.h:368
bool isStrictSupersetOf(Qualifiers Other) const
Determine whether this set of qualifiers is a strict superset of another set of qualifiers,...
Definition Type.cpp:57
bool hasNonFastQualifiers() const
Return true if the set contains any qualifiers which require an ExtQuals node to be allocated.
Definition TypeBase.h:639
void addConsistentQualifiers(Qualifiers qs)
Add the qualifiers from the given set to this set, given that they don't conflict.
Definition TypeBase.h:690
static bool isTargetAddressSpaceSupersetOf(LangAS A, LangAS B, const ASTContext &Ctx)
Definition Type.cpp:72
bool hasAddressSpace() const
Definition TypeBase.h:571
unsigned getFastQualifiers() const
Definition TypeBase.h:620
bool hasVolatile() const
Definition TypeBase.h:468
bool hasObjCGCAttr() const
Definition TypeBase.h:519
bool hasObjCLifetime() const
Definition TypeBase.h:545
ObjCLifetime getObjCLifetime() const
Definition TypeBase.h:546
LangAS getAddressSpace() const
Definition TypeBase.h:572
Qualifiers()=default
Represents a struct/union/class.
Definition Decl.h:4459
bool hasNonTrivialToPrimitiveDestructCUnion() const
Definition Decl.h:4569
bool hasNonTrivialToPrimitiveCopyCUnion() const
Definition Decl.h:4577
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Definition Decl.h:4561
bool isNonTrivialToPrimitiveDestroy() const
Definition Decl.h:4553
bool isNonTrivialToPrimitiveCopy() const
Definition Decl.h:4545
field_range fields() const
Definition Decl.h:4662
RecordDecl * getMostRecentDecl()
Definition Decl.h:4485
bool isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C structs.
Definition Decl.h:4537
Declaration of a redeclarable template.
Encodes a location in the source.
Stmt - This represents one statement.
Definition Stmt.h:85
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical, bool ProfileLambdaExpr=false) const
Produce a unique representation of the given statement.
void dump() const
Dumps the specified AST fragment and all subtrees to llvm::errs().
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3851
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3952
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Definition Decl.h:4097
bool isDependentType() const
Whether this declaration declares a type that is dependent, i.e., a type that somehow depends on temp...
Definition Decl.h:3997
Exposes information about the current target.
Definition TargetInfo.h:227
virtual bool hasFullBFloat16Type() const
Determine whether the BFloat type is fully supported on this target, i.e arithemtic operations.
Definition TargetInfo.h:736
virtual bool hasFastHalfType() const
Determine whether the target has fast native support for operations on half types.
Definition TargetInfo.h:718
virtual bool hasFloat16Type() const
Determine whether the _Float16 type is supported on this target.
Definition TargetInfo.h:727
virtual bool hasBFloat16Type() const
Determine whether the _BFloat16 type is supported on this target.
Definition TargetInfo.h:730
virtual bool isAddressSpaceSupersetOf(LangAS A, LangAS B) const
Returns true if an address space can be safely converted to another.
Definition TargetInfo.h:517
A convenient class for passing around template argument information.
ArrayRef< TemplateArgumentLoc > arguments() const
Location wrapper for a TemplateArgument.
Represents a template argument.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Type
The template argument is a type.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Represents a C++ template name within the type system.
Declaration of a template type parameter.
[BoundsSafety] Represents information of declarations referenced by the arguments of the counted_by a...
Definition TypeBase.h:3436
ValueDecl * getDecl() const
Definition Type.cpp:4126
bool operator==(const TypeCoupledDeclRefInfo &Other) const
Definition Type.cpp:4131
void * getOpaqueValue() const
Definition Type.cpp:4128
TypeCoupledDeclRefInfo(ValueDecl *D=nullptr, bool Deref=false)
D is to a declaration referenced by the argument of attribute.
Definition Type.cpp:4120
unsigned getInt() const
Definition Type.cpp:4127
void setFromOpaqueValue(void *V)
Definition Type.cpp:4135
bool isSugared() const
Returns whether this type directly provides sugar.
Definition Type.cpp:4265
TypeOfKind getKind() const
Returns the kind of 'typeof' type this is.
Definition TypeBase.h:6346
TypeOfExprType(const ASTContext &Context, Expr *E, TypeOfKind Kind, QualType Can=QualType())
Definition Type.cpp:4250
friend class ASTContext
Definition TypeBase.h:6337
Expr * getUnderlyingExpr() const
Definition TypeBase.h:6343
QualType desugar() const
Remove a single level of sugar.
Definition Type.cpp:4267
The type-property cache.
Definition Type.cpp:4905
static void ensure(const Type *T)
Definition Type.cpp:4915
static CachedProperties get(QualType T)
Definition Type.cpp:4907
static CachedProperties get(const Type *T)
Definition Type.cpp:4909
An operation on a type.
Definition TypeVisitor.h:64
A helper class for Type nodes having an ElaboratedTypeKeyword.
Definition TypeBase.h:6108
The base class of the type hierarchy.
Definition TypeBase.h:1879
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:2691
bool isStructureType() const
Definition Type.cpp:715
bool isBlockPointerType() const
Definition TypeBase.h:8761
const ObjCObjectPointerType * getAsObjCQualifiedClassType() const
Definition Type.cpp:1958
bool isLinkageValid() const
True if the computed linkage is valid.
Definition Type.cpp:5161
bool isVoidType() const
Definition TypeBase.h:9113
TypedefBitfields TypedefBits
Definition TypeBase.h:2383
UsingBitfields UsingBits
Definition TypeBase.h:2385
bool isBooleanType() const
Definition TypeBase.h:9250
const ObjCObjectType * getAsObjCQualifiedInterfaceType() const
Definition Type.cpp:1934
const ObjCObjectPointerType * getAsObjCQualifiedIdType() const
Definition Type.cpp:1948
const TemplateSpecializationType * getAsNonAliasTemplateSpecializationType() const
Look through sugar for an instance of TemplateSpecializationType which is not a type alias,...
Definition Type.cpp:1996
bool isMFloat8Type() const
Definition TypeBase.h:9138
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
Definition Type.cpp:2319
bool isPackedVectorBoolType(const ASTContext &ctx) const
Definition Type.cpp:455
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:2026
bool isAlwaysIncompleteType() const
Definition Type.cpp:2637
QualType getRVVEltType(const ASTContext &Ctx) const
Returns the representative type for the element of an RVV builtin type.
Definition Type.cpp:2801
const RecordType * getAsUnionType() const
NOTE: getAs*ArrayType are methods on ASTContext.
Definition Type.cpp:824
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
Definition Type.cpp:3143
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
Definition Type.cpp:2296
bool isComplexType() const
isComplexType() does not include complex integers (a GCC extension).
Definition Type.cpp:761
ArrayTypeBitfields ArrayTypeBits
Definition TypeBase.h:2377
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type.
Definition TypeBase.h:9416
bool isUnsignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is unsigned or an enumeration types whose underlying ...
Definition Type.cpp:2385
bool isIntegralOrUnscopedEnumerationType() const
Determine whether this type is an integral or unscoped enumeration type.
Definition Type.cpp:2203
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition Type.h:26
VectorTypeBitfields VectorTypeBits
Definition TypeBase.h:2392
SubstPackTypeBitfields SubstPackTypeBits
Definition TypeBase.h:2395
bool isNothrowT() const
Definition Type.cpp:3327
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition Type.h:41
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:2149
bool isVoidPointerType() const
Definition Type.cpp:749
const ComplexType * getAsComplexIntegerType() const
Definition Type.cpp:782
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6....
Definition Type.cpp:2547
bool isArrayType() const
Definition TypeBase.h:8840
bool isCharType() const
Definition Type.cpp:2223
QualType getLocallyUnqualifiedSingleStepDesugaredType() const
Pull a single level of sugar off of this locally-unqualified type.
Definition Type.cpp:558
bool isFunctionPointerType() const
Definition TypeBase.h:8808
bool isCountAttributedType() const
Definition Type.cpp:778
bool isObjCARCBridgableType() const
Determine whether the given type T is a "bridgable" Objective-C type, which is either an Objective-C ...
Definition Type.cpp:5493
CXXRecordDecl * castAsCXXRecordDecl() const
Definition Type.h:36
bool isArithmeticType() const
Definition Type.cpp:2452
bool isConstantMatrixType() const
Definition TypeBase.h:8908
bool isHLSLBuiltinIntangibleType() const
Definition TypeBase.h:9058
TypeOfBitfields TypeOfBits
Definition TypeBase.h:2382
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition TypeBase.h:9157
bool isSVESizelessBuiltinType() const
Returns true for SVE scalable vector types.
Definition Type.cpp:2697
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9407
bool isReferenceType() const
Definition TypeBase.h:8765
bool isHLSLIntangibleType() const
Definition Type.cpp:5582
bool isEnumeralType() const
Definition TypeBase.h:8872
void addDependence(TypeDependence D)
Definition TypeBase.h:2436
bool isObjCNSObjectType() const
Definition Type.cpp:5453
Type(TypeClass tc, QualType canon, TypeDependence Dependence)
Definition TypeBase.h:2413
const ObjCObjectPointerType * getAsObjCInterfacePointerType() const
Definition Type.cpp:1976
NestedNameSpecifier getPrefix() const
If this type represents a qualified-id, this returns its nested name specifier.
Definition Type.cpp:2003
bool isScalarType() const
Definition TypeBase.h:9219
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:1984
bool isInterfaceType() const
Definition Type.cpp:737
bool isVariableArrayType() const
Definition TypeBase.h:8852
bool isChar8Type() const
Definition Type.cpp:2239
bool isSizelessBuiltinType() const
Definition Type.cpp:2653
bool isAMDGPUNamedBarrierTypeOrWrapper() const
Check if the type is the AMDGPU named barrier type/a RecordType of a named barrier wrapper,...
Definition Type.cpp:5546
bool isCUDADeviceBuiltinSurfaceType() const
Check if the type is the CUDA device builtin surface type.
Definition Type.cpp:5508
bool isSveVLSBuiltinType() const
Determines if this is a sizeless type supported by the 'arm_sve_vector_bits' type attribute,...
Definition Type.cpp:2731
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
Definition Type.cpp:2186
bool isElaboratedTypeSpecifier() const
Determine wither this type is a C++ elaborated-type-specifier.
Definition Type.cpp:3487
CountAttributedTypeBitfields CountAttributedTypeBits
Definition TypeBase.h:2398
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:508
bool isAlignValT() const
Definition Type.cpp:3336
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:789
LinkageInfo getLinkageAndVisibility() const
Determine the linkage and visibility of this type.
Definition Type.cpp:5180
bool hasUnsignedIntegerRepresentation() const
Determine whether this type has an unsigned integer representation of some sort, e....
Definition Type.cpp:2406
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition Type.cpp:2259
bool isExtVectorBoolType() const
Definition TypeBase.h:8888
bool isWebAssemblyExternrefType() const
Check if this is a WebAssembly Externref Type.
Definition Type.cpp:2675
bool canHaveNullability(bool ResultIfUnknown=true) const
Determine whether the given type can have a nullability specifier applied to it, i....
Definition Type.cpp:5197
QualType getSveEltType(const ASTContext &Ctx) const
Returns the representative type for the element of an SVE builtin type.
Definition Type.cpp:2770
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition TypeBase.h:2867
bool isLValueReferenceType() const
Definition TypeBase.h:8769
bool isBitIntType() const
Definition TypeBase.h:9016
bool isBuiltinType() const
Helper methods to distinguish type categories.
Definition TypeBase.h:8864
bool isStructuralType() const
Determine if this type is a structural type, per C++20 [temp.param]p7.
Definition Type.cpp:3215
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition TypeBase.h:2859
bool isAggregateType() const
Determines whether the type is a C++ aggregate type or C aggregate or union type.
Definition Type.cpp:2533
bool isCARCBridgableType() const
Determine whether the given type T is a "bridgeable" C type.
Definition Type.cpp:5498
bool isSignableIntegerType(const ASTContext &Ctx) const
Definition Type.cpp:5389
RecordDecl * castAsRecordDecl() const
Definition Type.h:48
TypeBitfields TypeBits
Definition TypeBase.h:2376
bool isChar16Type() const
Definition Type.cpp:2245
bool isAnyComplexType() const
Definition TypeBase.h:8876
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type.
Definition Type.cpp:2139
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition TypeBase.h:2469
ScalarTypeKind getScalarTypeKind() const
Given that this is a scalar type, classify it.
Definition Type.cpp:2484
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g....
Definition Type.cpp:2340
QualType getCanonicalTypeInternal() const
Definition TypeBase.h:3196
friend class ASTContext
Definition TypeBase.h:2411
const RecordType * getAsStructureType() const
Definition Type.cpp:805
const char * getTypeClassName() const
Definition Type.cpp:3507
bool isWebAssemblyTableType() const
Returns true if this is a WebAssembly table type: either an array of reference types,...
Definition Type.cpp:2681
@ PtrdiffT
The "ptrdiff_t" type.
Definition TypeBase.h:2344
@ SizeT
The "size_t" type.
Definition TypeBase.h:2338
@ SignedSizeT
The signed integer type corresponding to "size_t".
Definition TypeBase.h:2341
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition TypeBase.h:9293
bool isHLSLStandardLayoutRecordOrArrayOf() const
Definition Type.cpp:5605
AttributedTypeBitfields AttributedTypeBits
Definition TypeBase.h:2379
bool isObjCBoxableRecordType() const
Definition Type.cpp:731
bool isMatrixType() const
Definition TypeBase.h:8904
bool isChar32Type() const
Definition Type.cpp:2251
bool isStandardLayoutType() const
Test if this type is a standard-layout type.
Definition Type.cpp:3231
TagTypeBitfields TagTypeBits
Definition TypeBase.h:2391
bool isOverflowBehaviorType() const
Definition TypeBase.h:8912
EnumDecl * castAsEnumDecl() const
Definition Type.h:59
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Definition TypeBase.h:2877
bool isComplexIntegerType() const
Definition Type.cpp:767
bool isUnscopedEnumerationType() const
Definition Type.cpp:2216
bool isStdByteType() const
Definition Type.cpp:3346
UnresolvedUsingBitfields UnresolvedUsingBits
Definition TypeBase.h:2384
bool isCUDADeviceBuiltinTextureType() const
Check if the type is the CUDA device builtin texture type.
Definition Type.cpp:5517
bool isBlockCompatibleObjCPointerType(ASTContext &ctx) const
Definition Type.cpp:5395
bool isObjCClassOrClassKindOfType() const
Whether the type is Objective-C 'Class' or a __kindof type of an Class type, e.g.,...
Definition Type.cpp:871
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition TypeBase.h:9393
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
Definition Type.cpp:5484
bool isHLSLResourceRecord() const
Definition Type.cpp:5569
EnumDecl * getAsEnumDecl() const
Retrieves the EnumDecl this type refers to.
Definition Type.h:53
bool isObjCIndirectLifetimeType() const
Definition Type.cpp:5470
bool hasUnnamedOrLocalType() const
Whether this type is or contains a local or unnamed type.
Definition Type.cpp:5063
bool isPointerOrReferenceType() const
Definition TypeBase.h:8745
Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const
Return the implicit lifetime for this type, which must not be dependent.
Definition Type.cpp:5428
FunctionTypeBitfields FunctionTypeBits
Definition TypeBase.h:2387
bool isObjCQualifiedInterfaceType() const
Definition Type.cpp:1944
bool isSpecifierType() const
Returns true if this type can be represented by some set of type specifiers.
Definition Type.cpp:3356
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition Type.cpp:2557
bool isObjCObjectPointerType() const
Definition TypeBase.h:8920
SubstTemplateTypeParmTypeBitfields SubstTemplateTypeParmTypeBits
Definition TypeBase.h:2394
bool isStructureTypeWithFlexibleArrayMember() const
Definition Type.cpp:721
TypeDependence getDependence() const
Definition TypeBase.h:2848
bool hasFloatingRepresentation() const
Determine whether this type has a floating-point representation of some sort, e.g....
Definition Type.cpp:2427
bool isStructureOrClassType() const
Definition Type.cpp:743
bool isAMDGPUNamedBarrierType() const
Check if the type is the AMDGPU named barrier type, or an array thereof.
Definition Type.cpp:5542
bool isVectorType() const
Definition TypeBase.h:8880
bool isRVVVLSBuiltinType() const
Determines if this is a sizeless type supported by the 'riscv_rvv_vector_bits' type attribute,...
Definition Type.cpp:2783
bool isRealFloatingType() const
Floating point categories.
Definition Type.cpp:2435
bool isRVVSizelessBuiltinType() const
Returns true for RVV scalable vector types.
Definition Type.cpp:2718
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:1753
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
Definition TypeBase.h:2998
Linkage getLinkage() const
Determine the linkage of this type.
Definition Type.cpp:5058
ObjCObjectTypeBitfields ObjCObjectTypeBits
Definition TypeBase.h:2388
@ STK_FloatingComplex
Definition TypeBase.h:2841
@ STK_ObjCObjectPointer
Definition TypeBase.h:2835
@ STK_IntegralComplex
Definition TypeBase.h:2840
@ STK_MemberPointer
Definition TypeBase.h:2836
bool isFloatingType() const
Definition Type.cpp:2419
const ObjCObjectType * getAsObjCInterfaceType() const
Definition Type.cpp:1968
bool isWideCharType() const
Definition Type.cpp:2232
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:2362
bool isRealType() const
Definition Type.cpp:2441
bool isClassType() const
Definition Type.cpp:709
bool hasSizedVLAType() const
Whether this type involves a variable-length array type with a definite size.
Definition Type.cpp:5550
TypeClass getTypeClass() const
Definition TypeBase.h:2449
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition TypeBase.h:2475
bool hasAutoForTrailingReturnType() const
Determine whether this type was written with a leading 'auto' corresponding to a trailing return type...
Definition Type.cpp:2144
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:844
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9340
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs,...
Definition Type.cpp:690
bool isObjCARCImplicitlyUnretainedType() const
Determines if this type, which must satisfy isObjCLifetimeType(), is implicitly __unsafe_unretained r...
Definition Type.cpp:5434
bool isRecordType() const
Definition TypeBase.h:8868
bool isHLSLResourceRecordArray() const
Definition Type.cpp:5573
bool isObjCRetainableType() const
Definition Type.cpp:5465
bool isObjCIndependentClassType() const
Definition Type.cpp:5459
bool isUnionType() const
Definition Type.cpp:755
bool isSizelessVectorType() const
Returns true for all scalable vector types.
Definition Type.cpp:2693
bool isScopedEnumeralType() const
Determine whether this type is a scoped enumeration type.
Definition Type.cpp:772
NullabilityKindOrNone getNullability() const
Determine the nullability of the given type.
Definition Type.cpp:5184
bool acceptsObjCTypeParams() const
Determines if this is an ObjC interface type that may accept type parameters.
Definition Type.cpp:1834
QualType getSizelessVectorEltType(const ASTContext &Ctx) const
Returns the representative type for the element of a sizeless vector builtin type.
Definition Type.cpp:2758
bool isUnicodeCharacterType() const
Definition Type.cpp:2279
bool hasBooleanRepresentation() const
Determine whether this type has a boolean representation – i.e., it is a boolean type,...
Definition Type.cpp:2474
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3696
QualType getUnderlyingType() const
Definition Decl.h:3751
QualType desugar() const
Definition Type.cpp:4205
bool typeMatchesDecl() const
Definition TypeBase.h:6274
Represents a dependent using declaration which was marked with typename.
Definition DeclCXX.h:4062
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3424
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
Represents a GCC generic vector type.
Definition TypeBase.h:4289
VectorType(QualType vecType, unsigned nElements, QualType canonType, VectorKind vecKind)
Definition Type.cpp:444
QualType ElementType
The element type of the vector.
Definition TypeBase.h:4294
QualType getElementType() const
Definition TypeBase.h:4303
Defines the Linkage enumeration and various utility functions.
Defines the clang::TargetInfo interface.
mlir::Type getBaseType(mlir::Value varPtr)
@ AttributedType
The l-value was considered opaque, so the alignment was determined from a type, but that type was an ...
const internal::VariadicAllOfMatcher< Attr > attr
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
const AstTypeMatcher< TypedefType > typedefType
void info(bool Verbose, unsigned Level, const char *Fmt, Ts &&...Args)
Prints an indented note to stderr when Verbose is set.
Definition Utils.h:57
RangeSelector merge(RangeSelector First, RangeSelector Second)
Selects the merge of the two ranges, i.e.
Top level wrappers for InstallAPI frontend operations.
@ TST_struct
Definition Specifiers.h:82
@ TST_class
Definition Specifiers.h:83
@ TST_union
Definition Specifiers.h:81
@ TST_typename
Definition Specifiers.h:85
@ TST_enum
Definition Specifiers.h:80
@ TST_interface
Definition Specifiers.h:84
@ Overload
This is a legitimate overload: the existing declarations are functions or function templates with dif...
Definition Sema.h:821
bool isa(CodeGen::Address addr)
Definition Address.h:330
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition TypeBase.h:1838
CanThrowResult
Possible results from evaluation of a noexcept expression.
TypeDependenceScope::TypeDependence TypeDependence
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.
Definition Specifiers.h:351
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
Definition Specifiers.h:356
@ NonNull
Values of this type can never be null.
Definition Specifiers.h:349
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
Definition Parser.h:61
bool IsEnumDeclComplete(EnumDecl *ED)
Check if the given decl is complete.
Definition Decl.h:5502
bool isPackProducingBuiltinTemplateName(TemplateName N)
ExprDependence computeDependence(FullExpr *E)
@ Private
'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel loop', and 'serial loop' constru...
@ Vector
'vector' clause, allowed on 'loop', Combined, and 'routine' directives.
TypeOfKind
The kind of 'typeof' expression we're after.
Definition TypeBase.h:919
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
TypeDependence toTypeDependence(ExprDependence D)
ExprDependence turnValueToTypeDependence(ExprDependence D)
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
Definition Parser.h:142
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.
Definition Linkage.h:58
ObjCSubstitutionContext
The kind of type we are substituting Objective-C type arguments into.
Definition TypeBase.h:901
@ Superclass
The superclass of a type.
Definition TypeBase.h:915
@ Result
The result type of a method or function.
Definition TypeBase.h:906
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition TypeBase.h:3833
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
@ Template
We are parsing a template declaration.
Definition Parser.h:81
TagTypeKind
The kind of a tag type.
Definition TypeBase.h:6045
@ Interface
The "__interface" keyword.
Definition TypeBase.h:6050
@ Struct
The "struct" keyword.
Definition TypeBase.h:6047
@ Class
The "class" keyword.
Definition TypeBase.h:6056
@ Union
The "union" keyword.
Definition TypeBase.h:6053
@ Enum
The "enum" keyword.
Definition TypeBase.h:6059
@ Keyword
The name has been typo-corrected to a keyword.
Definition Sema.h:557
@ Type
The name was classified as a type.
Definition Sema.h:559
LangAS
Defines the address space values used by the address space qualifier of QualType.
void FixedPointValueToString(SmallVectorImpl< char > &Str, llvm::APSInt Val, unsigned Scale)
Definition Type.cpp:5708
DeducedKind
Definition TypeBase.h:1811
@ Deduced
The normal deduced case.
Definition TypeBase.h:1818
@ Undeduced
Not deduced yet. This is for example an 'auto' which was just parsed.
Definition TypeBase.h:1813
@ DeducedAsPack
Same as above, but additionally this represents a case where the deduced entity itself is a pack.
Definition TypeBase.h:1834
@ DeducedAsDependent
This is a special case where the initializer is dependent, so we can't deduce a type yet.
Definition TypeBase.h:1828
std::tuple< NamedDecl *, TemplateArgument > getReplacedTemplateParameter(Decl *D, unsigned Index)
Internal helper used by Subst* nodes to retrieve a parameter from the AssociatedDecl,...
bool isPtrSizeAddressSpace(LangAS AS)
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition Specifiers.h:279
@ CC_X86Pascal
Definition Specifiers.h:285
@ CC_Swift
Definition Specifiers.h:293
@ CC_IntelOclBicc
Definition Specifiers.h:291
@ CC_PreserveMost
Definition Specifiers.h:295
@ CC_Win64
Definition Specifiers.h:286
@ CC_X86ThisCall
Definition Specifiers.h:283
@ CC_AArch64VectorCall
Definition Specifiers.h:297
@ CC_DeviceKernel
Definition Specifiers.h:292
@ CC_AAPCS
Definition Specifiers.h:289
@ CC_PreserveNone
Definition Specifiers.h:300
@ CC_M68kRTD
Definition Specifiers.h:299
@ CC_SwiftAsync
Definition Specifiers.h:294
@ CC_X86RegCall
Definition Specifiers.h:288
@ CC_RISCVVectorCall
Definition Specifiers.h:301
@ CC_X86VectorCall
Definition Specifiers.h:284
@ CC_AArch64SVEPCS
Definition Specifiers.h:298
@ CC_X86StdCall
Definition Specifiers.h:281
@ CC_X86_64SysV
Definition Specifiers.h:287
@ CC_PreserveAll
Definition Specifiers.h:296
@ CC_X86FastCall
Definition Specifiers.h:282
@ CC_AAPCS_VFP
Definition Specifiers.h:290
U cast(CodeGen::Address addr)
Definition Address.h:327
@ None
The alignment was not explicit in code.
Definition ASTContext.h:176
@ PackIndex
Index of a pack indexing expression or specifier.
Definition Sema.h:846
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition TypeBase.h:6020
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6025
@ None
No keyword precedes the qualified type name.
Definition TypeBase.h:6041
@ Struct
The "struct" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6022
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6031
@ Union
The "union" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6028
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6034
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition TypeBase.h:6038
TypeDependence toSemanticDependence(TypeDependence D)
TypeDependence toSyntacticDependence(TypeDependence D)
@ Other
Other implicit parameter.
Definition Decl.h:1774
@ EST_DependentNoexcept
noexcept(expression), value-dependent
@ 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)
OptionalUnsigned< NullabilityKind > NullabilityKindOrNone
Definition Specifiers.h:363
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
#define false
Definition stdbool.h:26
A FunctionEffect plus a potential boolean expression determining whether the effect is declared (e....
Definition TypeBase.h:5158
FunctionEffectWithCondition(FunctionEffect E, const EffectConditionExpr &C)
Definition TypeBase.h:5162
std::string description() const
Return a textual description of the effect, and its condition, if any.
Definition Type.cpp:6003
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition TypeBase.h:5490
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5494
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5480
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5483
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5486
Extra information about a function prototype.
Definition TypeBase.h:5506
FunctionTypeExtraAttributeInfo ExtraAttributeInfo
Definition TypeBase.h:5514
bool requiresFunctionProtoTypeArmAttributes() const
Definition TypeBase.h:5552
const ExtParameterInfo * ExtParameterInfos
Definition TypeBase.h:5511
bool requiresFunctionProtoTypeExtraAttributeInfo() const
Definition TypeBase.h:5556
bool requiresFunctionProtoTypeExtraBitfields() const
Definition TypeBase.h:5545
StringRef CFISalt
A CFI "salt" that differentiates functions with the same prototype.
Definition TypeBase.h:4883
A simple holder for various uncommon bits which do not fit in FunctionTypeBitfields.
Definition TypeBase.h:4857
static StringRef getKeywordName(ElaboratedTypeKeyword Keyword)
Definition Type.cpp:3466
static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag)
Converts a TagTypeKind into an elaborated type keyword.
Definition Type.cpp:3415
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition Type.cpp:3432
static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec)
Converts a type specifier (DeclSpec::TST) into a tag type kind.
Definition Type.cpp:3397
static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword)
Definition Type.cpp:3451
static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec)
Converts a type specifier (DeclSpec::TST) into an elaborated type keyword.
Definition Type.cpp:3378
Describes how types, statements, expressions, and declarations should be printed.
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 TypeBase.h:871
const Type * Ty
The locally-unqualified type.
Definition TypeBase.h:873
Qualifiers Quals
The local qualifiers.
Definition TypeBase.h:876