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