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 (CanonicalType->isSveVLSBuiltinType()) {
2249 const auto *VT = cast<BuiltinType>(CanonicalType);
2250 return VT->getKind() == BuiltinType::SveBool ||
2251 (VT->getKind() >= BuiltinType::SveInt8 &&
2252 VT->getKind() <= BuiltinType::SveUint64);
2253 }
2254 if (CanonicalType->isRVVVLSBuiltinType()) {
2255 const auto *VT = cast<BuiltinType>(CanonicalType);
2256 return (VT->getKind() >= BuiltinType::RvvInt8mf8 &&
2257 VT->getKind() <= BuiltinType::RvvUint64m8);
2258 }
2259
2260 return isIntegerType();
2261}
2262
2263/// Determine whether this type is an integral type.
2264///
2265/// This routine determines whether the given type is an integral type per
2266/// C++ [basic.fundamental]p7. Although the C standard does not define the
2267/// term "integral type", it has a similar term "integer type", and in C++
2268/// the two terms are equivalent. However, C's "integer type" includes
2269/// enumeration types, while C++'s "integer type" does not. The \c ASTContext
2270/// parameter is used to determine whether we should be following the C or
2271/// C++ rules when determining whether this type is an integral/integer type.
2272///
2273/// For cases where C permits "an integer type" and C++ permits "an integral
2274/// type", use this routine.
2275///
2276/// For cases where C permits "an integer type" and C++ permits "an integral
2277/// or enumeration type", use \c isIntegralOrEnumerationType() instead.
2278///
2279/// \param Ctx The context in which this type occurs.
2280///
2281/// \returns true if the type is considered an integral type, false otherwise.
2282bool Type::isIntegralType(const ASTContext &Ctx) const {
2283 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2284 return BT->isInteger();
2285
2286 // Complete enum types are integral in C.
2287 if (!Ctx.getLangOpts().CPlusPlus) {
2288 if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
2289 return IsEnumDeclComplete(ET->getDecl());
2290
2291 if (const OverflowBehaviorType *OBT =
2292 dyn_cast<OverflowBehaviorType>(CanonicalType))
2293 return OBT->getUnderlyingType()->isIntegralOrEnumerationType();
2294 }
2295
2296 return isBitIntType();
2297}
2298
2300 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2301 return BT->isInteger();
2302
2303 if (const auto *OBT = dyn_cast<OverflowBehaviorType>(CanonicalType))
2304 return OBT->getUnderlyingType()->isIntegerType();
2305
2306 if (isBitIntType())
2307 return true;
2308
2310}
2311
2313 if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
2314 return !ET->getDecl()->isScoped();
2315
2316 return false;
2317}
2318
2319bool Type::isCharType() const {
2320 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2321 return BT->getKind() == BuiltinType::Char_U ||
2322 BT->getKind() == BuiltinType::UChar ||
2323 BT->getKind() == BuiltinType::Char_S ||
2324 BT->getKind() == BuiltinType::SChar;
2325 return false;
2326}
2327
2329 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2330 return BT->getKind() == BuiltinType::WChar_S ||
2331 BT->getKind() == BuiltinType::WChar_U;
2332 return false;
2333}
2334
2335bool Type::isChar8Type() const {
2336 if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
2337 return BT->getKind() == BuiltinType::Char8;
2338 return false;
2339}
2340
2342 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2343 return BT->getKind() == BuiltinType::Char16;
2344 return false;
2345}
2346
2348 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2349 return BT->getKind() == BuiltinType::Char32;
2350 return false;
2351}
2352
2353/// Determine whether this type is any of the built-in character
2354/// types.
2356 const auto *BT = dyn_cast<BuiltinType>(CanonicalType);
2357 if (!BT)
2358 return false;
2359 switch (BT->getKind()) {
2360 default:
2361 return false;
2362 case BuiltinType::Char_U:
2363 case BuiltinType::UChar:
2364 case BuiltinType::WChar_U:
2365 case BuiltinType::Char8:
2366 case BuiltinType::Char16:
2367 case BuiltinType::Char32:
2368 case BuiltinType::Char_S:
2369 case BuiltinType::SChar:
2370 case BuiltinType::WChar_S:
2371 return true;
2372 }
2373}
2374
2376 const auto *BT = dyn_cast<BuiltinType>(CanonicalType);
2377 if (!BT)
2378 return false;
2379 switch (BT->getKind()) {
2380 default:
2381 return false;
2382 case BuiltinType::Char8:
2383 case BuiltinType::Char16:
2384 case BuiltinType::Char32:
2385 return true;
2386 }
2387}
2388
2389/// isSignedIntegerType - Return true if this is an integer type that is
2390/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
2391/// an enum decl which has a signed representation
2393 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2394 return BT->isSignedInteger();
2395
2396 if (const auto *ED = getAsEnumDecl()) {
2397 // Incomplete enum types are not treated as integer types.
2398 // FIXME: In C++, enum types are never integer types.
2399 if (!ED->isComplete() || ED->isScoped())
2400 return false;
2401 return ED->getIntegerType()->isSignedIntegerType();
2402 }
2403
2404 if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2405 return IT->isSigned();
2406 if (const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2407 return IT->isSigned();
2408
2409 if (const auto *OBT = dyn_cast<OverflowBehaviorType>(CanonicalType))
2410 return OBT->getUnderlyingType()->isSignedIntegerType();
2411
2412 return false;
2413}
2414
2416 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2417 return BT->isSignedInteger();
2418
2419 if (const auto *ED = getAsEnumDecl()) {
2420 if (!ED->isComplete())
2421 return false;
2422 return ED->getIntegerType()->isSignedIntegerType();
2423 }
2424
2425 if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2426 return IT->isSigned();
2427 if (const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2428 return IT->isSigned();
2429
2430 if (const auto *OBT = dyn_cast<OverflowBehaviorType>(CanonicalType))
2431 return OBT->getUnderlyingType()->isSignedIntegerOrEnumerationType();
2432
2433 return false;
2434}
2435
2437 if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
2438 return VT->getElementType()->isSignedIntegerOrEnumerationType();
2439 if (const auto *MT = dyn_cast<MatrixType>(CanonicalType))
2440 return MT->getElementType()->isSignedIntegerOrEnumerationType();
2441
2442 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2443 switch (BT->getKind()) {
2444#define SVE_VECTOR_TYPE_INT(Name, MangledName, Id, SingletonId, NumEls, \
2445 ElBits, NF, IsSigned) \
2446 case BuiltinType::Id: \
2447 return IsSigned;
2448#include "clang/Basic/AArch64ACLETypes.def"
2449 default:
2450 break;
2451 }
2452 }
2453
2455}
2456
2457/// isUnsignedIntegerType - Return true if this is an integer type that is
2458/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
2459/// decl which has an unsigned representation
2461 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2462 return BT->isUnsignedInteger();
2463
2464 if (const auto *ED = getAsEnumDecl()) {
2465 // Incomplete enum types are not treated as integer types.
2466 // FIXME: In C++, enum types are never integer types.
2467 if (!ED->isComplete() || ED->isScoped())
2468 return false;
2469 return ED->getIntegerType()->isUnsignedIntegerType();
2470 }
2471
2472 if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2473 return IT->isUnsigned();
2474 if (const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2475 return IT->isUnsigned();
2476
2477 if (const auto *OBT = dyn_cast<OverflowBehaviorType>(CanonicalType))
2478 return OBT->getUnderlyingType()->isUnsignedIntegerType();
2479
2480 return false;
2481}
2482
2484 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2485 return BT->isUnsignedInteger();
2486
2487 if (const auto *ED = getAsEnumDecl()) {
2488 if (!ED->isComplete())
2489 return false;
2490 return ED->getIntegerType()->isUnsignedIntegerType();
2491 }
2492
2493 if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2494 return IT->isUnsigned();
2495 if (const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2496 return IT->isUnsigned();
2497
2498 if (const auto *OBT = dyn_cast<OverflowBehaviorType>(CanonicalType))
2499 return OBT->getUnderlyingType()->isUnsignedIntegerOrEnumerationType();
2500
2501 return false;
2502}
2503
2505 if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
2506 return VT->getElementType()->isUnsignedIntegerOrEnumerationType();
2507 if (const auto *VT = dyn_cast<MatrixType>(CanonicalType))
2508 return VT->getElementType()->isUnsignedIntegerOrEnumerationType();
2509 if (CanonicalType->isSveVLSBuiltinType()) {
2510 const auto *VT = cast<BuiltinType>(CanonicalType);
2511 return VT->getKind() >= BuiltinType::SveUint8 &&
2512 VT->getKind() <= BuiltinType::SveUint64;
2513 }
2515}
2516
2518 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2519 return BT->isFloatingPoint();
2520 if (const auto *CT = dyn_cast<ComplexType>(CanonicalType))
2521 return CT->getElementType()->isFloatingType();
2522 return false;
2523}
2524
2526 if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
2527 return VT->getElementType()->isFloatingType();
2528 if (const auto *MT = dyn_cast<MatrixType>(CanonicalType))
2529 return MT->getElementType()->isFloatingType();
2530 return isFloatingType();
2531}
2532
2534 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2535 return BT->isFloatingPoint();
2536 return false;
2537}
2538
2539bool Type::isRealType() const {
2540 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2541 return BT->getKind() >= BuiltinType::Bool &&
2542 BT->getKind() <= BuiltinType::Ibm128;
2543 if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2544 const auto *ED = ET->getDecl();
2545 return !ED->isScoped() && ED->getDefinitionOrSelf()->isComplete();
2546 }
2547 return isBitIntType();
2548}
2549
2551 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2552 return BT->getKind() >= BuiltinType::Bool &&
2553 BT->getKind() <= BuiltinType::Ibm128;
2554 if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2555 // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
2556 // If a body isn't seen by the time we get here, return false.
2557 //
2558 // C++0x: Enumerations are not arithmetic types. For now, just return
2559 // false for scoped enumerations since that will disable any
2560 // unwanted implicit conversions.
2561 const auto *ED = ET->getDecl();
2562 return !ED->isScoped() && ED->getDefinitionOrSelf()->isComplete();
2563 }
2564
2565 if (isOverflowBehaviorType() &&
2567 return true;
2568
2569 return isa<ComplexType>(CanonicalType) || isBitIntType();
2570}
2571
2573 if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
2574 return VT->getElementType()->isBooleanType();
2575 if (const auto *ED = getAsEnumDecl())
2576 return ED->isComplete() && ED->getIntegerType()->isBooleanType();
2577 if (const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2578 return IT->getNumBits() == 1;
2579 return isBooleanType();
2580}
2581
2583 assert(isScalarType());
2584
2585 const Type *T = CanonicalType.getTypePtr();
2586 if (const auto *BT = dyn_cast<BuiltinType>(T)) {
2587 if (BT->getKind() == BuiltinType::Bool)
2588 return STK_Bool;
2589 if (BT->getKind() == BuiltinType::NullPtr)
2590 return STK_CPointer;
2591 if (BT->isInteger())
2592 return STK_Integral;
2593 if (BT->isFloatingPoint())
2594 return STK_Floating;
2595 if (BT->isFixedPointType())
2596 return STK_FixedPoint;
2597 llvm_unreachable("unknown scalar builtin type");
2598 } else if (isa<PointerType>(T)) {
2599 return STK_CPointer;
2600 } else if (isa<BlockPointerType>(T)) {
2601 return STK_BlockPointer;
2602 } else if (isa<ObjCObjectPointerType>(T)) {
2603 return STK_ObjCObjectPointer;
2604 } else if (isa<MemberPointerType>(T)) {
2605 return STK_MemberPointer;
2606 } else if (isa<EnumType>(T)) {
2607 assert(T->castAsEnumDecl()->isComplete());
2608 return STK_Integral;
2609 } else if (const auto *CT = dyn_cast<ComplexType>(T)) {
2610 if (CT->getElementType()->isRealFloatingType())
2611 return STK_FloatingComplex;
2612 return STK_IntegralComplex;
2613 } else if (isBitIntType()) {
2614 return STK_Integral;
2615 } else if (isa<OverflowBehaviorType>(T)) {
2616 return STK_Integral;
2617 }
2618
2619 llvm_unreachable("unknown scalar type");
2620}
2621
2622/// Determines whether the type is a C++ aggregate type or C
2623/// aggregate or union type.
2624///
2625/// An aggregate type is an array or a class type (struct, union, or
2626/// class) that has no user-declared constructors, no private or
2627/// protected non-static data members, no base classes, and no virtual
2628/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type
2629/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also
2630/// includes union types.
2632 if (const auto *Record = dyn_cast<RecordType>(CanonicalType)) {
2633 if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl()))
2634 return ClassDecl->isAggregate();
2635
2636 return true;
2637 }
2638
2639 return isa<ArrayType>(CanonicalType);
2640}
2641
2642/// isConstantSizeType - Return true if this is not a variable sized type,
2643/// according to the rules of C99 6.7.5p3. It is not legal to call this on
2644/// incomplete types or dependent types.
2646 assert(!isIncompleteType() && "This doesn't make sense for incomplete types");
2647 assert(!isDependentType() && "This doesn't make sense for dependent types");
2648 // The VAT must have a size, as it is known to be complete.
2649 return !isa<VariableArrayType>(CanonicalType);
2650}
2651
2652/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1)
2653/// - a type that can describe objects, but which lacks information needed to
2654/// determine its size.
2656 if (Def)
2657 *Def = nullptr;
2658
2659 switch (CanonicalType->getTypeClass()) {
2660 default:
2661 return false;
2662 case Builtin:
2663 // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never
2664 // be completed.
2665 return isVoidType();
2666 case Enum: {
2667 auto *EnumD = castAsEnumDecl();
2668 if (Def)
2669 *Def = EnumD;
2670 return !EnumD->isComplete();
2671 }
2672 case Record: {
2673 // A tagged type (struct/union/enum/class) is incomplete if the decl is a
2674 // forward declaration, but not a full definition (C99 6.2.5p22).
2675 auto *Rec = castAsRecordDecl();
2676 if (Def)
2677 *Def = Rec;
2678 return !Rec->isCompleteDefinition();
2679 }
2680 case InjectedClassName: {
2681 auto *Rec = castAsCXXRecordDecl();
2682 if (!Rec->isBeingDefined())
2683 return false;
2684 if (Def)
2685 *Def = Rec;
2686 return true;
2687 }
2688 case ConstantArray:
2689 case VariableArray:
2690 // An array is incomplete if its element type is incomplete
2691 // (C++ [dcl.array]p1).
2692 // We don't handle dependent-sized arrays (dependent types are never treated
2693 // as incomplete).
2694 return cast<ArrayType>(CanonicalType)
2695 ->getElementType()
2696 ->isIncompleteType(Def);
2697 case IncompleteArray:
2698 // An array of unknown size is an incomplete type (C99 6.2.5p22).
2699 return true;
2700 case MemberPointer: {
2701 // Member pointers in the MS ABI have special behavior in
2702 // RequireCompleteType: they attach a MSInheritanceAttr to the CXXRecordDecl
2703 // to indicate which inheritance model to use.
2704 // The inheritance attribute might only be present on the most recent
2705 // CXXRecordDecl.
2706 const CXXRecordDecl *RD =
2707 cast<MemberPointerType>(CanonicalType)->getMostRecentCXXRecordDecl();
2708 // Member pointers with dependent class types don't get special treatment.
2709 if (!RD || RD->isDependentType())
2710 return false;
2711 ASTContext &Context = RD->getASTContext();
2712 // Member pointers not in the MS ABI don't get special treatment.
2713 if (!Context.getTargetInfo().getCXXABI().isMicrosoft())
2714 return false;
2715 // Nothing interesting to do if the inheritance attribute is already set.
2716 if (RD->hasAttr<MSInheritanceAttr>())
2717 return false;
2718 return true;
2719 }
2720 case ObjCObject:
2721 return cast<ObjCObjectType>(CanonicalType)
2722 ->getBaseType()
2723 ->isIncompleteType(Def);
2724 case ObjCInterface: {
2725 // ObjC interfaces are incomplete if they are @class, not @interface.
2727 cast<ObjCInterfaceType>(CanonicalType)->getDecl();
2728 if (Def)
2729 *Def = Interface;
2730 return !Interface->hasDefinition();
2731 }
2732 }
2733}
2734
2736 if (!isIncompleteType())
2737 return false;
2738
2739 // Forward declarations of structs, classes, enums, and unions could be later
2740 // completed in a compilation unit by providing a type definition.
2741 if (isa<TagType>(CanonicalType))
2742 return false;
2743
2744 // Other types are incompletable.
2745 //
2746 // E.g. `char[]` and `void`. The type is incomplete and no future
2747 // type declarations can make the type complete.
2748 return true;
2749}
2750
2753 return true;
2754
2755 if (const BuiltinType *BT = getAs<BuiltinType>()) {
2756 switch (BT->getKind()) {
2757 // WebAssembly reference types
2758#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2759#include "clang/Basic/WebAssemblyReferenceTypes.def"
2760 // HLSL intangible types
2761#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2762#include "clang/Basic/HLSLIntangibleTypes.def"
2763 // AMDGPU feature predicate type
2764 case BuiltinType::AMDGPUFeaturePredicate:
2765 return true;
2766 default:
2767 return false;
2768 }
2769 }
2770 return false;
2771}
2772
2774 if (const auto *BT = getAs<BuiltinType>())
2775 return BT->getKind() == BuiltinType::WasmExternRef;
2776 return false;
2777}
2778
2780 if (const auto *ATy = dyn_cast<ArrayType>(this))
2781 return ATy->getElementType().isWebAssemblyReferenceType();
2782
2783 if (const auto *PTy = dyn_cast<PointerType>(this))
2784 return PTy->getPointeeType().isWebAssemblyReferenceType();
2785
2786 return false;
2787}
2788
2790
2794
2796 if (const BuiltinType *BT = getAs<BuiltinType>()) {
2797 switch (BT->getKind()) {
2798 // SVE Types
2799#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
2800 case BuiltinType::Id: \
2801 return true;
2802#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
2803 case BuiltinType::Id: \
2804 return true;
2805#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId) \
2806 case BuiltinType::Id: \
2807 return true;
2808#include "clang/Basic/AArch64ACLETypes.def"
2809 default:
2810 return false;
2811 }
2812 }
2813 return false;
2814}
2815
2817 if (const BuiltinType *BT = getAs<BuiltinType>()) {
2818 switch (BT->getKind()) {
2819#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2820#include "clang/Basic/RISCVVTypes.def"
2821 return true;
2822 default:
2823 return false;
2824 }
2825 }
2826 return false;
2827}
2828
2830 if (const BuiltinType *BT = getAs<BuiltinType>()) {
2831 switch (BT->getKind()) {
2832 case BuiltinType::SveInt8:
2833 case BuiltinType::SveInt16:
2834 case BuiltinType::SveInt32:
2835 case BuiltinType::SveInt64:
2836 case BuiltinType::SveUint8:
2837 case BuiltinType::SveUint16:
2838 case BuiltinType::SveUint32:
2839 case BuiltinType::SveUint64:
2840 case BuiltinType::SveFloat16:
2841 case BuiltinType::SveFloat32:
2842 case BuiltinType::SveFloat64:
2843 case BuiltinType::SveBFloat16:
2844 case BuiltinType::SveBool:
2845 case BuiltinType::SveMFloat8:
2846 return true;
2847 default:
2848 return false;
2849 }
2850 }
2851 return false;
2852}
2853
2855 assert(isSizelessVectorType() && "Must be sizeless vector type");
2856 // Currently supports SVE and RVV
2858 return getSveEltType(Ctx);
2859
2861 return getRVVEltType(Ctx);
2862
2863 llvm_unreachable("Unhandled type");
2864}
2865
2867 assert(isSveVLSBuiltinType() && "unsupported type!");
2868
2869 const BuiltinType *BTy = castAs<BuiltinType>();
2870 if (BTy->getKind() == BuiltinType::SveBool)
2871 // Represent predicates as i8 rather than i1 to avoid any layout issues.
2872 // The type is bitcasted to a scalable predicate type when casting between
2873 // scalable and fixed-length vectors.
2874 return Ctx.UnsignedCharTy;
2875 else
2876 return Ctx.getBuiltinVectorTypeInfo(BTy).ElementType;
2877}
2878
2880 if (const BuiltinType *BT = getAs<BuiltinType>()) {
2881 switch (BT->getKind()) {
2882#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, \
2883 IsFP, IsBF) \
2884 case BuiltinType::Id: \
2885 return NF == 1;
2886#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls) \
2887 case BuiltinType::Id: \
2888 return true;
2889#include "clang/Basic/RISCVVTypes.def"
2890 default:
2891 return false;
2892 }
2893 }
2894 return false;
2895}
2896
2898 assert(isRVVVLSBuiltinType() && "unsupported type!");
2899
2900 const BuiltinType *BTy = castAs<BuiltinType>();
2901
2902 switch (BTy->getKind()) {
2903#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls) \
2904 case BuiltinType::Id: \
2905 return Ctx.UnsignedCharTy;
2906 default:
2907 return Ctx.getBuiltinVectorTypeInfo(BTy).ElementType;
2908#include "clang/Basic/RISCVVTypes.def"
2909 }
2910
2911 llvm_unreachable("Unhandled type");
2912}
2913
2914bool QualType::isPODType(const ASTContext &Context) const {
2915 if (Context.getLangOpts().HLSL &&
2916 getTypePtr()->isHLSLStandardLayoutRecordOrArrayOf())
2917 return true;
2918
2919 // C++11 has a more relaxed definition of POD.
2920 if (Context.getLangOpts().CPlusPlus11)
2921 return isCXX11PODType(Context);
2922
2923 return isCXX98PODType(Context);
2924}
2925
2926bool QualType::isCXX98PODType(const ASTContext &Context) const {
2927 // The compiler shouldn't query this for incomplete types, but the user might.
2928 // We return false for that case. Except for incomplete arrays of PODs, which
2929 // are PODs according to the standard.
2930 if (isNull())
2931 return false;
2932
2933 if ((*this)->isIncompleteArrayType())
2934 return Context.getBaseElementType(*this).isCXX98PODType(Context);
2935
2936 if ((*this)->isIncompleteType())
2937 return false;
2938
2940 return false;
2941
2942 QualType CanonicalType = getTypePtr()->CanonicalType;
2943
2944 // Any type that is, or contains, address discriminated data is never POD.
2945 if (Context.containsAddressDiscriminatedPointerAuth(CanonicalType))
2946 return false;
2947
2948 switch (CanonicalType->getTypeClass()) {
2949 // Everything not explicitly mentioned is not POD.
2950 default:
2951 return false;
2952 case Type::VariableArray:
2953 case Type::ConstantArray:
2954 // IncompleteArray is handled above.
2955 return Context.getBaseElementType(*this).isCXX98PODType(Context);
2956
2957 case Type::ObjCObjectPointer:
2958 case Type::BlockPointer:
2959 case Type::Builtin:
2960 case Type::Complex:
2961 case Type::Pointer:
2962 case Type::MemberPointer:
2963 case Type::Vector:
2964 case Type::ExtVector:
2965 case Type::BitInt:
2966 case Type::OverflowBehavior:
2967 return true;
2968
2969 case Type::Enum:
2970 return true;
2971
2972 case Type::Record:
2973 if (const auto *ClassDecl =
2974 dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl()))
2975 return ClassDecl->isPOD();
2976
2977 // C struct/union is POD.
2978 return true;
2979 }
2980}
2981
2982bool QualType::isTrivialType(const ASTContext &Context) const {
2983 // The compiler shouldn't query this for incomplete types, but the user might.
2984 // We return false for that case. Except for incomplete arrays of PODs, which
2985 // are PODs according to the standard.
2986 if (isNull())
2987 return false;
2988
2989 if ((*this)->isArrayType())
2990 return Context.getBaseElementType(*this).isTrivialType(Context);
2991
2992 if ((*this)->isSizelessBuiltinType())
2993 return true;
2994
2995 // Return false for incomplete types after skipping any incomplete array
2996 // types which are expressly allowed by the standard and thus our API.
2997 if ((*this)->isIncompleteType())
2998 return false;
2999
3001 return false;
3002
3003 QualType CanonicalType = getTypePtr()->CanonicalType;
3004 if (CanonicalType->isDependentType())
3005 return false;
3006
3007 // Any type that is, or contains, address discriminated data is never a
3008 // trivial type.
3009 if (Context.containsAddressDiscriminatedPointerAuth(CanonicalType))
3010 return false;
3011
3012 // C++0x [basic.types]p9:
3013 // Scalar types, trivial class types, arrays of such types, and
3014 // cv-qualified versions of these types are collectively called trivial
3015 // types.
3016
3017 // As an extension, Clang treats vector types as Scalar types.
3018 if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
3019 return true;
3020
3021 if (const auto *ClassDecl = CanonicalType->getAsCXXRecordDecl()) {
3022 // C++20 [class]p6:
3023 // A trivial class is a class that is trivially copyable, and
3024 // has one or more eligible default constructors such that each is
3025 // trivial.
3026 // FIXME: We should merge this definition of triviality into
3027 // CXXRecordDecl::isTrivial. Currently it computes the wrong thing.
3028 return ClassDecl->hasTrivialDefaultConstructor() &&
3029 !ClassDecl->hasNonTrivialDefaultConstructor() &&
3030 ClassDecl->isTriviallyCopyable();
3031 }
3032
3033 if (isa<RecordType>(CanonicalType))
3034 return true;
3035
3036 // No other types can match.
3037 return false;
3038}
3039
3041 const ASTContext &Context,
3042 bool IsCopyConstructible) {
3043 if (type->isArrayType())
3044 return isTriviallyCopyableTypeImpl(Context.getBaseElementType(type),
3045 Context, IsCopyConstructible);
3046
3047 if (type.hasNonTrivialObjCLifetime())
3048 return false;
3049
3050 // C++11 [basic.types]p9 - See Core 2094
3051 // Scalar types, trivially copyable class types, arrays of such types, and
3052 // cv-qualified versions of these types are collectively
3053 // called trivially copy constructible types.
3054
3055 QualType CanonicalType = type.getCanonicalType();
3056 if (CanonicalType->isDependentType())
3057 return false;
3058
3059 if (CanonicalType->isSizelessBuiltinType())
3060 return true;
3061
3062 // Return false for incomplete types after skipping any incomplete array types
3063 // which are expressly allowed by the standard and thus our API.
3064 if (CanonicalType->isIncompleteType())
3065 return false;
3066
3067 if (CanonicalType.hasAddressDiscriminatedPointerAuth())
3068 return false;
3069
3070 // As an extension, Clang treats vector and matrix types as Scalar types.
3071 if (CanonicalType->isScalarType() || CanonicalType->isVectorType() ||
3072 CanonicalType->isMatrixType())
3073 return true;
3074
3075 // Mfloat8 type is a special case as it not scalar, but is still trivially
3076 // copyable.
3077 if (CanonicalType->isMFloat8Type())
3078 return true;
3079
3080 if (const auto *RD = CanonicalType->getAsRecordDecl()) {
3081 if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RD)) {
3082 if (IsCopyConstructible)
3083 return ClassDecl->isTriviallyCopyConstructible();
3084 return ClassDecl->isTriviallyCopyable();
3085 }
3086 return !RD->isNonTrivialToPrimitiveCopy();
3087 }
3088 // No other types can match.
3089 return false;
3090}
3091
3093 return isTriviallyCopyableTypeImpl(*this, Context,
3094 /*IsCopyConstructible=*/false);
3095}
3096
3097// FIXME: each call will trigger a full computation, cache the result.
3099 auto CanonicalType = getCanonicalType();
3100 if (CanonicalType.hasNonTrivialObjCLifetime())
3101 return false;
3102 if (CanonicalType->isArrayType())
3103 return Context.getBaseElementType(CanonicalType)
3104 .isBitwiseCloneableType(Context);
3105
3106 if (CanonicalType->isIncompleteType())
3107 return false;
3108
3109 // Any type that is, or contains, address discriminated data is never
3110 // bitwise clonable.
3111 if (Context.containsAddressDiscriminatedPointerAuth(CanonicalType))
3112 return false;
3113
3114 const auto *RD = CanonicalType->getAsRecordDecl(); // struct/union/class
3115 if (!RD)
3116 return true;
3117
3118 if (RD->isInvalidDecl())
3119 return false;
3120
3121 // Never allow memcpy when we're adding poisoned padding bits to the struct.
3122 // Accessing these posioned bits will trigger false alarms on
3123 // SanitizeAddressFieldPadding etc.
3124 if (RD->mayInsertExtraPadding())
3125 return false;
3126
3127 for (auto *const Field : RD->fields()) {
3128 if (!Field->getType().isBitwiseCloneableType(Context))
3129 return false;
3130 }
3131
3132 if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
3133 for (auto Base : CXXRD->bases())
3134 if (!Base.getType().isBitwiseCloneableType(Context))
3135 return false;
3136 for (auto VBase : CXXRD->vbases())
3137 if (!VBase.getType().isBitwiseCloneableType(Context))
3138 return false;
3139 }
3140 return true;
3141}
3142
3144 const ASTContext &Context) const {
3145 return isTriviallyCopyableTypeImpl(*this, Context,
3146 /*IsCopyConstructible=*/true);
3147}
3148
3150 return !Context.getLangOpts().ObjCAutoRefCount &&
3151 Context.getLangOpts().ObjCWeak &&
3153}
3154
3156 const RecordDecl *RD) {
3158}
3159
3162}
3163
3166}
3167
3171
3175
3181
3183 if (const auto *OBT = getCanonicalType()->getAs<OverflowBehaviorType>())
3184 return OBT->getBehaviorKind() ==
3185 OverflowBehaviorType::OverflowBehaviorKind::Wrap;
3186
3187 return false;
3188}
3189
3191 if (const auto *OBT = getCanonicalType()->getAs<OverflowBehaviorType>())
3192 return OBT->getBehaviorKind() ==
3193 OverflowBehaviorType::OverflowBehaviorKind::Trap;
3194
3195 return false;
3196}
3197
3200 if (const auto *RD =
3201 getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
3203 return PDIK_Struct;
3204
3205 switch (getQualifiers().getObjCLifetime()) {
3207 return PDIK_ARCStrong;
3209 return PDIK_ARCWeak;
3210 default:
3211 return PDIK_Trivial;
3212 }
3213}
3214
3216 if (const auto *RD =
3217 getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
3219 return PCK_Struct;
3220
3222 switch (Qs.getObjCLifetime()) {
3224 return PCK_ARCStrong;
3226 return PCK_ARCWeak;
3227 default:
3229 return PCK_PtrAuth;
3231 }
3232}
3233
3238
3239bool Type::isLiteralType(const ASTContext &Ctx) const {
3240 if (isDependentType())
3241 return false;
3242
3243 // C++1y [basic.types]p10:
3244 // A type is a literal type if it is:
3245 // -- cv void; or
3246 if (Ctx.getLangOpts().CPlusPlus14 && isVoidType())
3247 return true;
3248
3249 // C++11 [basic.types]p10:
3250 // A type is a literal type if it is:
3251 // [...]
3252 // -- an array of literal type other than an array of runtime bound; or
3253 if (isVariableArrayType())
3254 return false;
3255 const Type *BaseTy = getBaseElementTypeUnsafe();
3256 assert(BaseTy && "NULL element type");
3257
3258 // Return false for incomplete types after skipping any incomplete array
3259 // types; those are expressly allowed by the standard and thus our API.
3260 if (BaseTy->isIncompleteType())
3261 return false;
3262
3263 // C++11 [basic.types]p10:
3264 // A type is a literal type if it is:
3265 // -- a scalar type; or
3266 // As an extension, Clang treats vector types and complex types as
3267 // literal types.
3268 if (BaseTy->isScalarType() || BaseTy->isVectorType() ||
3269 BaseTy->isAnyComplexType())
3270 return true;
3271 // Matrices with constant numbers of rows and columns are also literal types
3272 // in HLSL.
3273 if (Ctx.getLangOpts().HLSL && BaseTy->isConstantMatrixType())
3274 return true;
3275 // -- a reference type; or
3276 if (BaseTy->isReferenceType())
3277 return true;
3278 // -- a class type that has all of the following properties:
3279 if (const auto *RD = BaseTy->getAsRecordDecl()) {
3280 // -- a trivial destructor,
3281 // -- every constructor call and full-expression in the
3282 // brace-or-equal-initializers for non-static data members (if any)
3283 // is a constant expression,
3284 // -- it is an aggregate type or has at least one constexpr
3285 // constructor or constructor template that is not a copy or move
3286 // constructor, and
3287 // -- all non-static data members and base classes of literal types
3288 //
3289 // We resolve DR1361 by ignoring the second bullet.
3290 if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RD))
3291 return ClassDecl->isLiteral();
3292
3293 return true;
3294 }
3295
3296 // C++26 [basic.types]p9:
3297 // -- std::meta::info is a scalar type
3298 // C++26 [basic.types]p10:
3299 // -- a scalar type is a literal type
3300 if (isMetaInfoType())
3301 return true;
3302
3303 // We treat _Atomic T as a literal type if T is a literal type.
3304 if (const auto *AT = BaseTy->getAs<AtomicType>())
3305 return AT->getValueType()->isLiteralType(Ctx);
3306
3307 if (const auto *OBT = BaseTy->getAs<OverflowBehaviorType>())
3308 return OBT->getUnderlyingType()->isLiteralType(Ctx);
3309
3310 // If this type hasn't been deduced yet, then conservatively assume that
3311 // it'll work out to be a literal type.
3313 return true;
3314
3315 return false;
3316}
3317
3319 // C++20 [temp.param]p6:
3320 // A structural type is one of the following:
3321 // -- a scalar type; or
3322 // -- a vector type [Clang extension]; or
3323 if (isScalarType() || isVectorType())
3324 return true;
3325 // -- an lvalue reference type; or
3327 return true;
3328 // -- a literal class type [...under some conditions]
3329 if (const CXXRecordDecl *RD = getAsCXXRecordDecl())
3330 return RD->isStructural();
3331 return false;
3332}
3333
3335 if (isDependentType())
3336 return false;
3337
3338 // C++0x [basic.types]p9:
3339 // Scalar types, standard-layout class types, arrays of such types, and
3340 // cv-qualified versions of these types are collectively called
3341 // standard-layout types.
3342 const Type *BaseTy = getBaseElementTypeUnsafe();
3343 assert(BaseTy && "NULL element type");
3344
3345 // Return false for incomplete types after skipping any incomplete array
3346 // types which are expressly allowed by the standard and thus our API.
3347 if (BaseTy->isIncompleteType())
3348 return false;
3349
3350 // As an extension, Clang treats vector types as Scalar types.
3351 if (BaseTy->isScalarType() || BaseTy->isVectorType())
3352 return true;
3353 if (const auto *RD = BaseTy->getAsRecordDecl()) {
3354 if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RD);
3355 ClassDecl && !ClassDecl->isStandardLayout())
3356 return false;
3357
3358 // Default to 'true' for non-C++ class types.
3359 // FIXME: This is a bit dubious, but plain C structs should trivially meet
3360 // all the requirements of standard layout classes.
3361 return true;
3362 }
3363
3364 // No other types can match.
3365 return false;
3366}
3367
3368// This is effectively the intersection of isTrivialType and
3369// isStandardLayoutType. We implement it directly to avoid redundant
3370// conversions from a type to a CXXRecordDecl.
3371bool QualType::isCXX11PODType(const ASTContext &Context) const {
3372 const Type *ty = getTypePtr();
3373 if (ty->isDependentType())
3374 return false;
3375
3377 return false;
3378
3379 // C++11 [basic.types]p9:
3380 // Scalar types, POD classes, arrays of such types, and cv-qualified
3381 // versions of these types are collectively called trivial types.
3382 const Type *BaseTy = ty->getBaseElementTypeUnsafe();
3383 assert(BaseTy && "NULL element type");
3384
3385 if (BaseTy->isSizelessBuiltinType())
3386 return true;
3387
3388 // Return false for incomplete types after skipping any incomplete array
3389 // types which are expressly allowed by the standard and thus our API.
3390 if (BaseTy->isIncompleteType())
3391 return false;
3392
3393 // Any type that is, or contains, address discriminated data is non-POD.
3394 if (Context.containsAddressDiscriminatedPointerAuth(*this))
3395 return false;
3396
3397 // As an extension, Clang treats vector types as Scalar types.
3398 if (BaseTy->isScalarType() || BaseTy->isVectorType())
3399 return true;
3400 if (const auto *RD = BaseTy->getAsRecordDecl()) {
3401 if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RD)) {
3402 // C++11 [class]p10:
3403 // A POD struct is a non-union class that is both a trivial class [...]
3404 if (!ClassDecl->isTrivial())
3405 return false;
3406
3407 // C++11 [class]p10:
3408 // A POD struct is a non-union class that is both a trivial class and
3409 // a standard-layout class [...]
3410 if (!ClassDecl->isStandardLayout())
3411 return false;
3412
3413 // C++11 [class]p10:
3414 // A POD struct is a non-union class that is both a trivial class and
3415 // a standard-layout class, and has no non-static data members of type
3416 // non-POD struct, non-POD union (or array of such types). [...]
3417 //
3418 // We don't directly query the recursive aspect as the requirements for
3419 // both standard-layout classes and trivial classes apply recursively
3420 // already.
3421 }
3422
3423 return true;
3424 }
3425
3426 // No other types can match.
3427 return false;
3428}
3429
3430bool Type::isNothrowT() const {
3431 if (const auto *RD = getAsCXXRecordDecl()) {
3432 IdentifierInfo *II = RD->getIdentifier();
3433 if (II && II->isStr("nothrow_t") && RD->isInStdNamespace())
3434 return true;
3435 }
3436 return false;
3437}
3438
3439bool Type::isAlignValT() const {
3440 if (const auto *ET = getAsCanonical<EnumType>()) {
3441 const auto *ED = ET->getDecl();
3442 IdentifierInfo *II = ED->getIdentifier();
3443 if (II && II->isStr("align_val_t") && ED->isInStdNamespace())
3444 return true;
3445 }
3446 return false;
3447}
3448
3450 if (const auto *ET = getAsCanonical<EnumType>()) {
3451 const auto *ED = ET->getDecl();
3452 IdentifierInfo *II = ED->getIdentifier();
3453 if (II && II->isStr("byte") && ED->isInStdNamespace())
3454 return true;
3455 }
3456 return false;
3457}
3458
3460 // Note that this intentionally does not use the canonical type.
3461 switch (getTypeClass()) {
3462 case Builtin:
3463 case Record:
3464 case Enum:
3465 case Typedef:
3466 case Complex:
3467 case TypeOfExpr:
3468 case TypeOf:
3469 case TemplateTypeParm:
3470 case SubstTemplateTypeParm:
3471 case TemplateSpecialization:
3472 case DependentName:
3473 case ObjCInterface:
3474 case ObjCObject:
3475 return true;
3476 default:
3477 return false;
3478 }
3479}
3480
3482 switch (TypeSpec) {
3483 default:
3485 case TST_typename:
3487 case TST_class:
3489 case TST_struct:
3491 case TST_interface:
3493 case TST_union:
3495 case TST_enum:
3497 }
3498}
3499
3501 switch (TypeSpec) {
3502 case TST_class:
3503 return TagTypeKind::Class;
3504 case TST_struct:
3505 return TagTypeKind::Struct;
3506 case TST_interface:
3508 case TST_union:
3509 return TagTypeKind::Union;
3510 case TST_enum:
3511 return TagTypeKind::Enum;
3512 }
3513
3514 llvm_unreachable("Type specifier is not a tag type kind.");
3515}
3516
3519 switch (Kind) {
3520 case TagTypeKind::Class:
3526 case TagTypeKind::Union:
3528 case TagTypeKind::Enum:
3530 }
3531 llvm_unreachable("Unknown tag type kind.");
3532}
3533
3536 switch (Keyword) {
3538 return TagTypeKind::Class;
3540 return TagTypeKind::Struct;
3544 return TagTypeKind::Union;
3546 return TagTypeKind::Enum;
3547 case ElaboratedTypeKeyword::None: // Fall through.
3549 llvm_unreachable("Elaborated type keyword is not a tag type kind.");
3550 }
3551 llvm_unreachable("Unknown elaborated type keyword.");
3552}
3553
3555 switch (Keyword) {
3558 return false;
3564 return true;
3565 }
3566 llvm_unreachable("Unknown elaborated type keyword.");
3567}
3568
3570 switch (Keyword) {
3572 return {};
3574 return "typename";
3576 return "class";
3578 return "struct";
3580 return "__interface";
3582 return "union";
3584 return "enum";
3585 }
3586
3587 llvm_unreachable("Unknown elaborated type keyword.");
3588}
3589
3592 if (const auto *TST = dyn_cast<TemplateSpecializationType>(this))
3593 Keyword = TST->getKeyword();
3594 else if (const auto *DepName = dyn_cast<DependentNameType>(this))
3595 Keyword = DepName->getKeyword();
3596 else if (const auto *T = dyn_cast<TagType>(this))
3597 Keyword = T->getKeyword();
3598 else if (const auto *T = dyn_cast<TypedefType>(this))
3599 Keyword = T->getKeyword();
3600 else if (const auto *T = dyn_cast<UnresolvedUsingType>(this))
3601 Keyword = T->getKeyword();
3602 else if (const auto *T = dyn_cast<UsingType>(this))
3603 Keyword = T->getKeyword();
3604 else
3605 return false;
3606
3608}
3609
3610const char *Type::getTypeClassName() const {
3611 switch (TypeBits.TC) {
3612#define ABSTRACT_TYPE(Derived, Base)
3613#define TYPE(Derived, Base) \
3614 case Derived: \
3615 return #Derived;
3616#include "clang/AST/TypeNodes.inc"
3617 }
3618
3619 llvm_unreachable("Invalid type class.");
3620}
3621
3622StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
3623 switch (getKind()) {
3624 case Void:
3625 return "void";
3626 case Bool:
3627 return Policy.Bool ? "bool" : "_Bool";
3628 case Char_S:
3629 return "char";
3630 case Char_U:
3631 return "char";
3632 case SChar:
3633 return "signed char";
3634 case Short:
3635 return "short";
3636 case Int:
3637 return "int";
3638 case Long:
3639 return "long";
3640 case LongLong:
3641 return "long long";
3642 case Int128:
3643 return "__int128";
3644 case UChar:
3645 return "unsigned char";
3646 case UShort:
3647 return "unsigned short";
3648 case UInt:
3649 return "unsigned int";
3650 case ULong:
3651 return "unsigned long";
3652 case ULongLong:
3653 return "unsigned long long";
3654 case UInt128:
3655 return "unsigned __int128";
3656 case Half:
3657 return Policy.Half ? "half" : "__fp16";
3658 case BFloat16:
3659 return "__bf16";
3660 case Float:
3661 return "float";
3662 case Double:
3663 return "double";
3664 case LongDouble:
3665 return "long double";
3666 case ShortAccum:
3667 return "short _Accum";
3668 case Accum:
3669 return "_Accum";
3670 case LongAccum:
3671 return "long _Accum";
3672 case UShortAccum:
3673 return "unsigned short _Accum";
3674 case UAccum:
3675 return "unsigned _Accum";
3676 case ULongAccum:
3677 return "unsigned long _Accum";
3678 case BuiltinType::MetaInfo:
3679 return "std::meta::info";
3680 case BuiltinType::ShortFract:
3681 return "short _Fract";
3682 case BuiltinType::Fract:
3683 return "_Fract";
3684 case BuiltinType::LongFract:
3685 return "long _Fract";
3686 case BuiltinType::UShortFract:
3687 return "unsigned short _Fract";
3688 case BuiltinType::UFract:
3689 return "unsigned _Fract";
3690 case BuiltinType::ULongFract:
3691 return "unsigned long _Fract";
3692 case BuiltinType::SatShortAccum:
3693 return "_Sat short _Accum";
3694 case BuiltinType::SatAccum:
3695 return "_Sat _Accum";
3696 case BuiltinType::SatLongAccum:
3697 return "_Sat long _Accum";
3698 case BuiltinType::SatUShortAccum:
3699 return "_Sat unsigned short _Accum";
3700 case BuiltinType::SatUAccum:
3701 return "_Sat unsigned _Accum";
3702 case BuiltinType::SatULongAccum:
3703 return "_Sat unsigned long _Accum";
3704 case BuiltinType::SatShortFract:
3705 return "_Sat short _Fract";
3706 case BuiltinType::SatFract:
3707 return "_Sat _Fract";
3708 case BuiltinType::SatLongFract:
3709 return "_Sat long _Fract";
3710 case BuiltinType::SatUShortFract:
3711 return "_Sat unsigned short _Fract";
3712 case BuiltinType::SatUFract:
3713 return "_Sat unsigned _Fract";
3714 case BuiltinType::SatULongFract:
3715 return "_Sat unsigned long _Fract";
3716 case Float16:
3717 return "_Float16";
3718 case Float128:
3719 return "__float128";
3720 case Ibm128:
3721 return "__ibm128";
3722 case WChar_S:
3723 case WChar_U:
3724 return Policy.MSWChar ? "__wchar_t" : "wchar_t";
3725 case Char8:
3726 return "char8_t";
3727 case Char16:
3728 return "char16_t";
3729 case Char32:
3730 return "char32_t";
3731 case NullPtr:
3732 return Policy.NullptrTypeInNamespace ? "std::nullptr_t" : "nullptr_t";
3733 case Overload:
3734 return "<overloaded function type>";
3735 case BoundMember:
3736 return "<bound member function type>";
3737 case UnresolvedTemplate:
3738 return "<unresolved template type>";
3739 case PseudoObject:
3740 return "<pseudo-object type>";
3741 case Dependent:
3742 return "<dependent type>";
3743 case UnknownAny:
3744 return "<unknown type>";
3745 case ARCUnbridgedCast:
3746 return "<ARC unbridged cast type>";
3747 case BuiltinFn:
3748 return "<builtin fn type>";
3749 case ObjCId:
3750 return "id";
3751 case ObjCClass:
3752 return "Class";
3753 case ObjCSel:
3754 return "SEL";
3755#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3756 case Id: \
3757 return "__" #Access " " #ImgType "_t";
3758#include "clang/Basic/OpenCLImageTypes.def"
3759 case OCLSampler:
3760 return "sampler_t";
3761 case OCLEvent:
3762 return "event_t";
3763 case OCLClkEvent:
3764 return "clk_event_t";
3765 case OCLQueue:
3766 return "queue_t";
3767 case OCLReserveID:
3768 return "reserve_id_t";
3769 case IncompleteMatrixIdx:
3770 return "<incomplete matrix index type>";
3771 case ArraySection:
3772 return "<array section type>";
3773 case OMPArrayShaping:
3774 return "<OpenMP array shaping type>";
3775 case OMPIterator:
3776 return "<OpenMP iterator type>";
3777#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3778 case Id: \
3779 return #ExtType;
3780#include "clang/Basic/OpenCLExtensionTypes.def"
3781#define SVE_TYPE(Name, Id, SingletonId) \
3782 case Id: \
3783 return #Name;
3784#include "clang/Basic/AArch64ACLETypes.def"
3785#define PPC_VECTOR_TYPE(Name, Id, Size) \
3786 case Id: \
3787 return #Name;
3788#include "clang/Basic/PPCTypes.def"
3789#define RVV_TYPE(Name, Id, SingletonId) \
3790 case Id: \
3791 return Name;
3792#include "clang/Basic/RISCVVTypes.def"
3793#define WASM_TYPE(Name, Id, SingletonId) \
3794 case Id: \
3795 return Name;
3796#include "clang/Basic/WebAssemblyReferenceTypes.def"
3797#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
3798 case Id: \
3799 return Name;
3800#include "clang/Basic/AMDGPUTypes.def"
3801#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3802 case Id: \
3803 return #Name;
3804#include "clang/Basic/HLSLIntangibleTypes.def"
3805#define HLSL_PACKED_TYPE(Name, Id, SingletonId) \
3806 case Id: \
3807 return #Name;
3808#include "clang/Basic/HLSLPackedTypes.def"
3809#define SPIRV_TYPE(Name, Id, SingletonId) \
3810 case Id: \
3811 return Name;
3812#include "clang/Basic/SPIRVTypes.def"
3813 }
3814
3815 llvm_unreachable("Invalid builtin type.");
3816}
3817
3819 // We never wrap type sugar around a PackExpansionType.
3820 if (auto *PET = dyn_cast<PackExpansionType>(getTypePtr()))
3821 return PET->getPattern();
3822 return *this;
3823}
3824
3826 if (const auto *RefType = getTypePtr()->getAs<ReferenceType>())
3827 return RefType->getPointeeType();
3828
3829 // C++0x [basic.lval]:
3830 // Class prvalues can have cv-qualified types; non-class prvalues always
3831 // have cv-unqualified types.
3832 //
3833 // See also C99 6.3.2.1p2.
3834 if (!Context.getLangOpts().CPlusPlus ||
3835 (!getTypePtr()->isDependentType() && !getTypePtr()->isRecordType()))
3836 return getUnqualifiedType();
3837
3838 return *this;
3839}
3840
3842 if (const auto *FPT = getAs<FunctionProtoType>())
3843 return FPT->hasCFIUncheckedCallee();
3844 return false;
3845}
3846
3848 switch (CC) {
3849 case CC_C:
3850 return "cdecl";
3851 case CC_X86StdCall:
3852 return "stdcall";
3853 case CC_X86FastCall:
3854 return "fastcall";
3855 case CC_X86ThisCall:
3856 return "thiscall";
3857 case CC_X86Pascal:
3858 return "pascal";
3859 case CC_X86VectorCall:
3860 return "vectorcall";
3861 case CC_Win64:
3862 return "ms_abi";
3863 case CC_X86_64SysV:
3864 return "sysv_abi";
3865 case CC_X86RegCall:
3866 return "regcall";
3867 case CC_AAPCS:
3868 return "aapcs";
3869 case CC_AAPCS_VFP:
3870 return "aapcs-vfp";
3872 return "aarch64_vector_pcs";
3873 case CC_AArch64SVEPCS:
3874 return "aarch64_sve_pcs";
3875 case CC_IntelOclBicc:
3876 return "intel_ocl_bicc";
3877 case CC_DeviceKernel:
3878 return "device_kernel";
3879 case CC_Swift:
3880 return "swiftcall";
3881 case CC_SwiftAsync:
3882 return "swiftasynccall";
3883 case CC_PreserveMost:
3884 return "preserve_most";
3885 case CC_PreserveAll:
3886 return "preserve_all";
3887 case CC_M68kRTD:
3888 return "m68k_rtd";
3889 case CC_PreserveNone:
3890 return "preserve_none";
3891 // clang-format off
3892 case CC_RISCVVectorCall: return "riscv_vector_cc";
3893#define CC_VLS_CASE(ABI_VLEN) \
3894 case CC_RISCVVLSCall_##ABI_VLEN: return "riscv_vls_cc(" #ABI_VLEN ")";
3895 CC_VLS_CASE(32)
3896 CC_VLS_CASE(64)
3897 CC_VLS_CASE(128)
3898 CC_VLS_CASE(256)
3899 CC_VLS_CASE(512)
3900 CC_VLS_CASE(1024)
3901 CC_VLS_CASE(2048)
3902 CC_VLS_CASE(4096)
3903 CC_VLS_CASE(8192)
3904 CC_VLS_CASE(16384)
3905 CC_VLS_CASE(32768)
3906 CC_VLS_CASE(65536)
3907#undef CC_VLS_CASE
3908 // clang-format on
3909 }
3910
3911 llvm_unreachable("Invalid calling convention.");
3912}
3913
3920
3921FunctionProtoType::FunctionProtoType(QualType result, ArrayRef<QualType> params,
3922 QualType canonical,
3923 const ExtProtoInfo &epi)
3924 : FunctionType(FunctionProto, result, canonical, result->getDependence(),
3925 epi.ExtInfo) {
3926 FunctionTypeBits.FastTypeQuals = epi.TypeQuals.getFastQualifiers();
3927 FunctionTypeBits.RefQualifier = epi.RefQualifier;
3928 FunctionTypeBits.NumParams = params.size();
3929 assert(getNumParams() == params.size() && "NumParams overflow!");
3930 FunctionTypeBits.ExceptionSpecType = epi.ExceptionSpec.Type;
3931 FunctionTypeBits.HasExtParameterInfos = !!epi.ExtParameterInfos;
3932 FunctionTypeBits.Variadic = epi.Variadic;
3933 FunctionTypeBits.HasTrailingReturn = epi.HasTrailingReturn;
3934 FunctionTypeBits.CFIUncheckedCallee = epi.CFIUncheckedCallee;
3935
3937 FunctionTypeBits.HasExtraBitfields = true;
3938 auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
3939 ExtraBits = FunctionTypeExtraBitfields();
3940 } else {
3941 FunctionTypeBits.HasExtraBitfields = false;
3942 }
3943
3944 // Propagate any extra attribute information.
3946 auto &ExtraAttrInfo = *getTrailingObjects<FunctionTypeExtraAttributeInfo>();
3947 ExtraAttrInfo.CFISalt = epi.ExtraAttributeInfo.CFISalt;
3948
3949 // Also set the bit in FunctionTypeExtraBitfields.
3950 auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
3951 ExtraBits.HasExtraAttributeInfo = true;
3952 }
3953
3955 auto &ArmTypeAttrs = *getTrailingObjects<FunctionTypeArmAttributes>();
3956 ArmTypeAttrs = FunctionTypeArmAttributes();
3957
3958 // Also set the bit in FunctionTypeExtraBitfields
3959 auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
3960 ExtraBits.HasArmTypeAttributes = true;
3961 }
3962
3963 // Fill in the trailing argument array.
3964 auto *argSlot = getTrailingObjects<QualType>();
3965 for (unsigned i = 0; i != getNumParams(); ++i) {
3966 addDependence(params[i]->getDependence() &
3967 ~TypeDependence::VariablyModified);
3968 argSlot[i] = params[i];
3969 }
3970
3971 // Propagate the SME ACLE attributes.
3973 auto &ArmTypeAttrs = *getTrailingObjects<FunctionTypeArmAttributes>();
3975 "Not enough bits to encode SME attributes");
3976 ArmTypeAttrs.AArch64SMEAttributes = epi.AArch64SMEAttributes;
3977 }
3978
3979 // Fill in the exception type array if present.
3981 auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
3982 size_t NumExceptions = epi.ExceptionSpec.Exceptions.size();
3983 assert(NumExceptions <= 1023 && "Not enough bits to encode exceptions");
3984 ExtraBits.NumExceptionType = NumExceptions;
3985
3986 assert(hasExtraBitfields() && "missing trailing extra bitfields!");
3987 auto *exnSlot =
3988 reinterpret_cast<QualType *>(getTrailingObjects<ExceptionType>());
3989 unsigned I = 0;
3990 for (QualType ExceptionType : epi.ExceptionSpec.Exceptions) {
3991 // Note that, before C++17, a dependent exception specification does
3992 // *not* make a type dependent; it's not even part of the C++ type
3993 // system.
3995 ExceptionType->getDependence() &
3996 (TypeDependence::Instantiation | TypeDependence::UnexpandedPack));
3997
3998 exnSlot[I++] = ExceptionType;
3999 }
4000 }
4001 // Fill in the Expr * in the exception specification if present.
4003 assert(epi.ExceptionSpec.NoexceptExpr && "computed noexcept with no expr");
4006
4007 // Store the noexcept expression and context.
4008 *getTrailingObjects<Expr *>() = epi.ExceptionSpec.NoexceptExpr;
4009
4012 (TypeDependence::Instantiation | TypeDependence::UnexpandedPack));
4013 }
4014 // Fill in the FunctionDecl * in the exception specification if present.
4016 // Store the function decl from which we will resolve our
4017 // exception specification.
4018 auto **slot = getTrailingObjects<FunctionDecl *>();
4019 slot[0] = epi.ExceptionSpec.SourceDecl;
4020 slot[1] = epi.ExceptionSpec.SourceTemplate;
4021 // This exception specification doesn't make the type dependent, because
4022 // it's not instantiated as part of instantiating the type.
4023 } else if (getExceptionSpecType() == EST_Unevaluated) {
4024 // Store the function decl from which we will resolve our
4025 // exception specification.
4026 auto **slot = getTrailingObjects<FunctionDecl *>();
4027 slot[0] = epi.ExceptionSpec.SourceDecl;
4028 }
4029
4030 // If this is a canonical type, and its exception specification is dependent,
4031 // then it's a dependent type. This only happens in C++17 onwards.
4032 if (isCanonicalUnqualified()) {
4035 assert(hasDependentExceptionSpec() && "type should not be canonical");
4036 addDependence(TypeDependence::DependentInstantiation);
4037 }
4038 } else if (getCanonicalTypeInternal()->isDependentType()) {
4039 // Ask our canonical type whether our exception specification was dependent.
4040 addDependence(TypeDependence::DependentInstantiation);
4041 }
4042
4043 // Fill in the extra parameter info if present.
4044 if (epi.ExtParameterInfos) {
4045 auto *extParamInfos = getTrailingObjects<ExtParameterInfo>();
4046 for (unsigned i = 0; i != getNumParams(); ++i)
4047 extParamInfos[i] = epi.ExtParameterInfos[i];
4048 }
4049
4050 if (epi.TypeQuals.hasNonFastQualifiers()) {
4051 FunctionTypeBits.HasExtQuals = 1;
4052 *getTrailingObjects<Qualifiers>() = epi.TypeQuals;
4053 } else {
4054 FunctionTypeBits.HasExtQuals = 0;
4055 }
4056
4057 // Fill in the Ellipsis location info if present.
4058 if (epi.Variadic) {
4059 auto &EllipsisLoc = *getTrailingObjects<SourceLocation>();
4060 EllipsisLoc = epi.EllipsisLoc;
4061 }
4062
4063 if (!epi.FunctionEffects.empty()) {
4064 auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
4065 size_t EffectsCount = epi.FunctionEffects.size();
4066 ExtraBits.NumFunctionEffects = EffectsCount;
4067 assert(ExtraBits.NumFunctionEffects == EffectsCount &&
4068 "effect bitfield overflow");
4069
4070 ArrayRef<FunctionEffect> SrcFX = epi.FunctionEffects.effects();
4071 auto *DestFX = getTrailingObjects<FunctionEffect>();
4072 llvm::uninitialized_copy(SrcFX, DestFX);
4073
4074 ArrayRef<EffectConditionExpr> SrcConds = epi.FunctionEffects.conditions();
4075 if (!SrcConds.empty()) {
4076 ExtraBits.EffectsHaveConditions = true;
4077 auto *DestConds = getTrailingObjects<EffectConditionExpr>();
4078 llvm::uninitialized_copy(SrcConds, DestConds);
4079 assert(llvm::any_of(SrcConds,
4080 [](const EffectConditionExpr &EC) {
4081 if (const Expr *E = EC.getCondition())
4082 return E->isTypeDependent() ||
4083 E->isValueDependent();
4084 return false;
4085 }) &&
4086 "expected a dependent expression among the conditions");
4087 addDependence(TypeDependence::DependentInstantiation);
4088 }
4089 }
4090}
4091
4093 if (Expr *NE = getNoexceptExpr())
4094 return NE->isValueDependent();
4095 for (QualType ET : exceptions())
4096 // A pack expansion with a non-dependent pattern is still dependent,
4097 // because we don't know whether the pattern is in the exception spec
4098 // or not (that depends on whether the pack has 0 expansions).
4099 if (ET->isDependentType() || ET->getAs<PackExpansionType>())
4100 return true;
4101 return false;
4102}
4103
4105 if (Expr *NE = getNoexceptExpr())
4106 return NE->isInstantiationDependent();
4107 for (QualType ET : exceptions())
4109 return true;
4110 return false;
4111}
4112
4114 switch (getExceptionSpecType()) {
4115 case EST_Unparsed:
4116 case EST_Unevaluated:
4117 llvm_unreachable("should not call this with unresolved exception specs");
4118
4119 case EST_DynamicNone:
4120 case EST_BasicNoexcept:
4121 case EST_NoexceptTrue:
4122 case EST_NoThrow:
4123 return CT_Cannot;
4124
4125 case EST_None:
4126 case EST_MSAny:
4127 case EST_NoexceptFalse:
4128 return CT_Can;
4129
4130 case EST_Dynamic:
4131 // A dynamic exception specification is throwing unless every exception
4132 // type is an (unexpanded) pack expansion type.
4133 for (unsigned I = 0; I != getNumExceptions(); ++I)
4135 return CT_Can;
4136 return CT_Dependent;
4137
4138 case EST_Uninstantiated:
4140 return CT_Dependent;
4141 }
4142
4143 llvm_unreachable("unexpected exception specification kind");
4144}
4145
4147 for (unsigned ArgIdx = getNumParams(); ArgIdx; --ArgIdx)
4148 if (isa<PackExpansionType>(getParamType(ArgIdx - 1)))
4149 return true;
4150
4151 return false;
4152}
4153
4154void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result,
4155 const QualType *ArgTys, unsigned NumParams,
4156 const ExtProtoInfo &epi,
4157 const ASTContext &Context) {
4158 // We have to be careful not to get ambiguous profile encodings.
4159 // Note that valid type pointers are never ambiguous with anything else.
4160 //
4161 // The encoding grammar begins:
4162 // type type* bool int bool
4163 // If that final bool is true, then there is a section for the EH spec:
4164 // bool type*
4165 // This is followed by an optional "consumed argument" section of the
4166 // same length as the first type sequence:
4167 // bool*
4168 // This is followed by the ext info:
4169 // int
4170 // Finally we have a trailing return type flag (bool)
4171 // combined with AArch64 SME Attributes and extra attribute info, to save
4172 // space:
4173 // int
4174 // combined with any FunctionEffects
4175 //
4176 // There is no ambiguity between the consumed arguments and an empty EH
4177 // spec because of the leading 'bool' which unambiguously indicates
4178 // whether the following bool is the EH spec or part of the arguments.
4179
4180 ID.AddPointer(Result.getAsOpaquePtr());
4181 for (unsigned i = 0; i != NumParams; ++i)
4182 ID.AddPointer(ArgTys[i].getAsOpaquePtr());
4183 // This method is relatively performance sensitive, so as a performance
4184 // shortcut, use one AddInteger call instead of four for the next four
4185 // fields.
4186 assert(!(unsigned(epi.Variadic) & ~1) && !(unsigned(epi.RefQualifier) & ~3) &&
4187 !(unsigned(epi.ExceptionSpec.Type) & ~15) &&
4188 "Values larger than expected.");
4189 ID.AddInteger(unsigned(epi.Variadic) + (epi.RefQualifier << 1) +
4190 (epi.ExceptionSpec.Type << 3));
4191 ID.Add(epi.TypeQuals);
4192 if (epi.ExceptionSpec.Type == EST_Dynamic) {
4193 for (QualType Ex : epi.ExceptionSpec.Exceptions)
4194 ID.AddPointer(Ex.getAsOpaquePtr());
4195 } else if (epi.ExceptionSpec.Type == EST_NoexceptTrue ||
4196 epi.ExceptionSpec.Type == EST_NoexceptFalse) {
4197 // If the exception type has already been determined, we can use the
4198 // address of the expression as profiling results instead of profiling the
4199 // expression.
4200 //
4201 // This is not only an optimization but avoids an access on uninitialized
4202 // fields during the profiling.
4203 //
4204 // See clang/test/Modules/concept-specialization-deserialization.cppm for
4205 // an example.
4206 ID.AddPointer(epi.ExceptionSpec.NoexceptExpr);
4207 } else if (epi.ExceptionSpec.Type == EST_DependentNoexcept) {
4208 // getFunctionTypeInternal compares noexcept expressions after the lookup,
4209 // so the key only needs their canonical form.
4210 epi.ExceptionSpec.NoexceptExpr->Profile(ID, Context, /*Canonical=*/true);
4211 } else if (epi.ExceptionSpec.Type == EST_Uninstantiated ||
4212 epi.ExceptionSpec.Type == EST_Unevaluated) {
4213 ID.AddPointer(epi.ExceptionSpec.SourceDecl->getCanonicalDecl());
4214 }
4215 if (epi.ExtParameterInfos) {
4216 for (unsigned i = 0; i != NumParams; ++i)
4217 ID.AddInteger(epi.ExtParameterInfos[i].getOpaqueValue());
4218 }
4219
4220 epi.ExtInfo.Profile(ID);
4221 epi.ExtraAttributeInfo.Profile(ID);
4222
4223 unsigned EffectCount = epi.FunctionEffects.size();
4224 bool HasConds = !epi.FunctionEffects.Conditions.empty();
4225
4226 ID.AddInteger((EffectCount << 3) | (HasConds << 2) |
4227 (epi.AArch64SMEAttributes << 1) | epi.HasTrailingReturn);
4228 ID.AddInteger(epi.CFIUncheckedCallee);
4229
4230 for (unsigned Idx = 0; Idx != EffectCount; ++Idx) {
4231 ID.AddInteger(epi.FunctionEffects.Effects[Idx].toOpaqueInt32());
4232 if (HasConds)
4233 ID.AddPointer(epi.FunctionEffects.Conditions[Idx].getCondition());
4234 }
4235}
4236
4237void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID,
4238 const ASTContext &Ctx) {
4240 getExtProtoInfo(), Ctx);
4241}
4242
4244 : Data(D, Deref << DerefShift) {}
4245
4247 return Data.getInt() & DerefMask;
4248}
4249ValueDecl *TypeCoupledDeclRefInfo::getDecl() const { return Data.getPointer(); }
4250unsigned TypeCoupledDeclRefInfo::getInt() const { return Data.getInt(); }
4252 return Data.getOpaqueValue();
4253}
4255 const TypeCoupledDeclRefInfo &Other) const {
4256 return getOpaqueValue() == Other.getOpaqueValue();
4257}
4259 Data.setFromOpaqueValue(V);
4260}
4261
4262OverflowBehaviorType::OverflowBehaviorType(
4263 const ASTContext &Context, QualType Canon, QualType Underlying,
4264 OverflowBehaviorType::OverflowBehaviorKind Kind)
4265 : Type(OverflowBehavior, Canon, Underlying->getDependence()),
4266 UnderlyingType(Underlying), BehaviorKind(Kind), Context(Context) {}
4267
4268SplitQualType OverflowBehaviorType::getSplitUnqualifiedType() const {
4269 SplitQualType SplitUnderlying = UnderlyingType.getSplitUnqualifiedType();
4270 QualType UnqualUnderlyingTy(SplitUnderlying.Ty, 0);
4271 if (UnqualUnderlyingTy == UnderlyingType)
4272 return SplitQualType(this, Qualifiers());
4273
4274 QualType UnqualTy =
4275 Context.getOverflowBehaviorType(BehaviorKind, UnqualUnderlyingTy);
4276 return SplitQualType(UnqualTy.getTypePtr(), SplitUnderlying.Quals);
4277}
4278
4280 QualType Canon)
4281 : Type(TC, Canon, Wrapped->getDependence()), WrappedTy(Wrapped) {}
4282
4283CountAttributedType::CountAttributedType(
4284 QualType Wrapped, QualType Canon, Expr *CountExpr, bool CountInBytes,
4285 bool OrNull, ArrayRef<TypeCoupledDeclRefInfo> CoupledDecls)
4286 : BoundsAttributedType(CountAttributed, Wrapped, Canon),
4287 CountExpr(CountExpr) {
4288 CountAttributedTypeBits.NumCoupledDecls = CoupledDecls.size();
4289 CountAttributedTypeBits.CountInBytes = CountInBytes;
4290 CountAttributedTypeBits.OrNull = OrNull;
4291 // `CoupledDecls` is already allocated by the caller (Create), so it
4292 // can be retained by reference. This lets a type created by a late-parsed
4293 // attribute start out with no decls and gain them later via `complete`,
4294 // which a trailing-object array could not accommodate.
4295 Decls = CoupledDecls;
4296}
4297
4298/// Copy \p Decls into \p Ctx so a \c CountAttributedType can retain it by
4299/// reference. The node owns this allocation rather than its callers, so both
4300/// \c Create and \c complete route through here.
4304 if (Decls.empty())
4305 return {};
4306 auto *Slots = Ctx.Allocate<TypeCoupledDeclRefInfo>(Decls.size());
4307 llvm::copy(Decls, Slots);
4308 return ArrayRef(Slots, Decls.size());
4309}
4310
4312CountAttributedType::Create(const ASTContext &Ctx, QualType Wrapped,
4313 QualType Canon, Expr *CountExpr, bool CountInBytes,
4314 bool OrNull,
4315 ArrayRef<TypeCoupledDeclRefInfo> CoupledDecls) {
4316 ArrayRef<TypeCoupledDeclRefInfo> Decls =
4317 allocateCoupledDecls(Ctx, CoupledDecls);
4318 return new (Ctx, alignof(CountAttributedType)) CountAttributedType(
4319 Wrapped, Canon, CountExpr, CountInBytes, OrNull, Decls);
4320}
4321
4322void CountAttributedType::complete(
4323 const ASTContext &Ctx, Expr *E,
4324 ArrayRef<TypeCoupledDeclRefInfo> CoupledDecls) {
4325 assert(!CountExpr && "count expression is already set");
4326 assert(E && "completing with a null count expression");
4327 CountExpr = E;
4328 Decls = allocateCoupledDecls(Ctx, CoupledDecls);
4329 CountAttributedTypeBits.NumCoupledDecls = Decls.size();
4330}
4331
4332StringRef CountAttributedType::getAttributeName(bool WithMacroPrefix) const {
4333// TODO: This method isn't really ideal because it doesn't return the spelling
4334// of the attribute that was used in the user's code. This method is used for
4335// diagnostics so the fact it doesn't use the spelling of the attribute in
4336// the user's code could be confusing (#113585).
4337#define ENUMERATE_ATTRS(PREFIX) \
4338 do { \
4339 if (isCountInBytes()) { \
4340 if (isOrNull()) \
4341 return PREFIX "sized_by_or_null"; \
4342 return PREFIX "sized_by"; \
4343 } \
4344 if (isOrNull()) \
4345 return PREFIX "counted_by_or_null"; \
4346 return PREFIX "counted_by"; \
4347 } while (0)
4348
4349 if (WithMacroPrefix)
4350 ENUMERATE_ATTRS("__");
4351 else
4352 ENUMERATE_ATTRS("");
4353
4354#undef ENUMERATE_ATTRS
4355}
4356
4357TypedefType::TypedefType(TypeClass TC, ElaboratedTypeKeyword Keyword,
4358 NestedNameSpecifier Qualifier,
4359 const TypedefNameDecl *D, QualType UnderlyingType,
4360 bool HasTypeDifferentFromDecl)
4362 Keyword, TC, UnderlyingType.getCanonicalType(),
4363 toSemanticDependence(UnderlyingType->getDependence()) |
4364 (Qualifier
4365 ? toTypeDependence(Qualifier.getDependence() &
4366 ~NestedNameSpecifierDependence::Dependent)
4367 : TypeDependence{})),
4368 Decl(const_cast<TypedefNameDecl *>(D)) {
4369 if ((TypedefBits.hasQualifier = !!Qualifier))
4370 *getTrailingObjects<NestedNameSpecifier>() = Qualifier;
4371 if ((TypedefBits.hasTypeDifferentFromDecl = HasTypeDifferentFromDecl))
4372 *getTrailingObjects<QualType>() = UnderlyingType;
4373}
4374
4376 return typeMatchesDecl() ? Decl->getUnderlyingType()
4377 : *getTrailingObjects<QualType>();
4378}
4379
4380UnresolvedUsingType::UnresolvedUsingType(ElaboratedTypeKeyword Keyword,
4381 NestedNameSpecifier Qualifier,
4383 const Type *CanonicalType)
4385 Keyword, UnresolvedUsing, QualType(CanonicalType, 0),
4386 TypeDependence::DependentInstantiation |
4387 (Qualifier
4388 ? toTypeDependence(Qualifier.getDependence() &
4389 ~NestedNameSpecifierDependence::Dependent)
4390 : TypeDependence{})),
4391 Decl(const_cast<UnresolvedUsingTypenameDecl *>(D)) {
4392 if ((UnresolvedUsingBits.hasQualifier = !!Qualifier))
4393 *getTrailingObjects<NestedNameSpecifier>() = Qualifier;
4394}
4395
4396UsingType::UsingType(ElaboratedTypeKeyword Keyword,
4397 NestedNameSpecifier Qualifier, const UsingShadowDecl *D,
4398 QualType UnderlyingType)
4399 : TypeWithKeyword(Keyword, Using, UnderlyingType.getCanonicalType(),
4400 toSemanticDependence(UnderlyingType->getDependence())),
4401 D(const_cast<UsingShadowDecl *>(D)), UnderlyingType(UnderlyingType) {
4402 if ((UsingBits.hasQualifier = !!Qualifier))
4403 *getTrailingObjects() = Qualifier;
4404}
4405
4407
4409 // Step over MacroQualifiedTypes from the same macro to find the type
4410 // ultimately qualified by the macro qualifier.
4411 QualType Inner = cast<AttributedType>(getUnderlyingType())->getModifiedType();
4412 while (auto *InnerMQT = dyn_cast<MacroQualifiedType>(Inner)) {
4413 if (InnerMQT->getMacroIdentifier() != getMacroIdentifier())
4414 break;
4415 Inner = InnerMQT->getModifiedType();
4416 }
4417 return Inner;
4418}
4419
4421 TypeOfKind Kind, QualType Can)
4422 : Type(TypeOfExpr,
4423 // We have to protect against 'Can' being invalid through its
4424 // default argument.
4425 Kind == TypeOfKind::Unqualified && !Can.isNull()
4426 ? Context.getUnqualifiedArrayType(Can).getAtomicUnqualifiedType()
4427 : Can,
4429 (E->getType()->getDependence() &
4430 TypeDependence::VariablyModified)),
4431 TOExpr(E), Context(Context) {
4432 TypeOfBits.Kind = static_cast<unsigned>(Kind);
4433}
4434
4435bool TypeOfExprType::isSugared() const { return !TOExpr->isTypeDependent(); }
4436
4438 if (isSugared()) {
4441 ? Context.getUnqualifiedArrayType(QT).getAtomicUnqualifiedType()
4442 : QT;
4443 }
4444 return QualType(this, 0);
4445}
4446
4447void DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID,
4448 const ASTContext &Context, Expr *E,
4449 bool IsUnqual) {
4450 E->Profile(ID, Context, true);
4451 ID.AddBoolean(IsUnqual);
4452}
4453
4454TypeOfType::TypeOfType(const ASTContext &Context, QualType T, QualType Can,
4455 TypeOfKind Kind)
4456 : Type(TypeOf,
4457 Kind == TypeOfKind::Unqualified
4458 ? Context.getUnqualifiedArrayType(Can).getAtomicUnqualifiedType()
4459 : Can,
4460 T->getDependence()),
4461 TOType(T), Context(Context) {
4462 TypeOfBits.Kind = static_cast<unsigned>(Kind);
4463}
4464
4465QualType TypeOfType::desugar() const {
4466 QualType QT = getUnmodifiedType();
4468 ? Context.getUnqualifiedArrayType(QT).getAtomicUnqualifiedType()
4469 : QT;
4470}
4471
4472DecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can)
4473 // C++11 [temp.type]p2: "If an expression e involves a template parameter,
4474 // decltype(e) denotes a unique dependent type." Hence a decltype type is
4475 // type-dependent even if its expression is only instantiation-dependent.
4476 : Type(Decltype, can,
4477 toTypeDependence(E->getDependence()) |
4478 (E->isInstantiationDependent() ? TypeDependence::Dependent
4479 : TypeDependence::None) |
4480 (E->getType()->getDependence() &
4481 TypeDependence::VariablyModified)),
4482 E(E), UnderlyingType(underlyingType) {}
4483
4484bool DecltypeType::isSugared() const { return !E->isInstantiationDependent(); }
4485
4486QualType DecltypeType::desugar() const {
4487 if (isSugared())
4488 return getUnderlyingType();
4489
4490 return QualType(this, 0);
4491}
4492
4493DependentDecltypeType::DependentDecltypeType(Expr *E)
4494 : DecltypeType(E, QualType()) {}
4495
4496void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID,
4497 const ASTContext &Context, Expr *E) {
4498 E->Profile(ID, Context, true);
4499}
4500
4501PackIndexingType::PackIndexingType(QualType Canonical, QualType Pattern,
4502 Expr *IndexExpr, bool FullySubstituted,
4503 ArrayRef<QualType> Expansions)
4504 : Type(PackIndexing, Canonical,
4505 computeDependence(Pattern, IndexExpr, Expansions)),
4506 Pattern(Pattern), IndexExpr(IndexExpr), Size(Expansions.size()),
4507 FullySubstituted(FullySubstituted) {
4508
4509 llvm::uninitialized_copy(Expansions, getTrailingObjects());
4510}
4511
4512UnsignedOrNone PackIndexingType::getSelectedIndex() const {
4513 if (isInstantiationDependentType())
4514 return std::nullopt;
4515 // Should only be not a constant for error recovery.
4516 ConstantExpr *CE = dyn_cast<ConstantExpr>(getIndexExpr());
4517 if (!CE)
4518 return std::nullopt;
4519 auto Index = CE->getResultAsAPSInt();
4520 assert(Index.isNonNegative() && "Invalid index");
4521 return static_cast<unsigned>(Index.getExtValue());
4522}
4523
4525PackIndexingType::computeDependence(QualType Pattern, Expr *IndexExpr,
4526 ArrayRef<QualType> Expansions) {
4527 TypeDependence IndexD = toTypeDependence(IndexExpr->getDependence());
4528
4529 TypeDependence TD = IndexD | (IndexExpr->isInstantiationDependent()
4530 ? TypeDependence::DependentInstantiation
4531 : TypeDependence::None);
4532 if (Expansions.empty())
4533 TD |= Pattern->getDependence() & TypeDependence::DependentInstantiation;
4534 else
4535 for (const QualType &T : Expansions)
4536 TD |= T->getDependence();
4537
4538 if (!(IndexD & TypeDependence::UnexpandedPack))
4539 TD &= ~TypeDependence::UnexpandedPack;
4540
4541 // If the pattern does not contain an unexpended pack,
4542 // the type is still dependent, and invalid
4543 if (!Pattern->containsUnexpandedParameterPack())
4544 TD |= TypeDependence::Error | TypeDependence::DependentInstantiation;
4545
4546 return TD;
4547}
4548
4549void PackIndexingType::Profile(llvm::FoldingSetNodeID &ID,
4550 const ASTContext &Context) {
4551 Profile(ID, Context, getPattern(), getIndexExpr(), isFullySubstituted(),
4552 getExpansions());
4553}
4554
4555void PackIndexingType::Profile(llvm::FoldingSetNodeID &ID,
4556 const ASTContext &Context, QualType Pattern,
4557 Expr *E, bool FullySubstituted,
4558 ArrayRef<QualType> Expansions) {
4559
4560 E->Profile(ID, Context, true);
4561 ID.AddBoolean(FullySubstituted);
4562 if (!Expansions.empty()) {
4563 ID.AddInteger(Expansions.size());
4564 for (QualType T : Expansions)
4565 T.getCanonicalType().Profile(ID);
4566 } else {
4567 Pattern.Profile(ID);
4568 }
4569}
4570
4571UnaryTransformType::UnaryTransformType(QualType BaseType,
4572 QualType UnderlyingType, UTTKind UKind,
4573 QualType CanonicalType)
4574 : Type(UnaryTransform, CanonicalType, BaseType->getDependence()),
4575 BaseType(BaseType), UnderlyingType(UnderlyingType), UKind(UKind) {}
4576
4577TagType::TagType(TypeClass TC, ElaboratedTypeKeyword Keyword,
4578 NestedNameSpecifier Qualifier, const TagDecl *Tag,
4579 bool OwnsTag, bool ISInjected, const Type *CanonicalType)
4581 Keyword, TC, QualType(CanonicalType, 0),
4582 (Tag->isDependentType() ? TypeDependence::DependentInstantiation
4583 : TypeDependence::None) |
4584 (Qualifier
4585 ? toTypeDependence(Qualifier.getDependence() &
4586 ~NestedNameSpecifierDependence::Dependent)
4587 : TypeDependence{})),
4588 decl(const_cast<TagDecl *>(Tag)) {
4589 if ((TagTypeBits.HasQualifier = !!Qualifier))
4590 getTrailingQualifier() = Qualifier;
4591 TagTypeBits.OwnsTag = !!OwnsTag;
4592 TagTypeBits.IsInjected = ISInjected;
4593}
4594
4595void *TagType::getTrailingPointer() const {
4596 switch (getTypeClass()) {
4597 case Type::Enum:
4598 return const_cast<EnumType *>(cast<EnumType>(this) + 1);
4599 case Type::Record:
4600 return const_cast<RecordType *>(cast<RecordType>(this) + 1);
4601 case Type::InjectedClassName:
4602 return const_cast<InjectedClassNameType *>(
4603 cast<InjectedClassNameType>(this) + 1);
4604 default:
4605 llvm_unreachable("unexpected type class");
4606 }
4607}
4608
4609NestedNameSpecifier &TagType::getTrailingQualifier() const {
4610 assert(TagTypeBits.HasQualifier);
4611 return *reinterpret_cast<NestedNameSpecifier *>(llvm::alignAddr(
4612 getTrailingPointer(), llvm::Align::Of<NestedNameSpecifier *>()));
4613}
4614
4615NestedNameSpecifier TagType::getQualifier() const {
4616 return TagTypeBits.HasQualifier ? getTrailingQualifier() : std::nullopt;
4617}
4618
4619ClassTemplateDecl *TagType::getTemplateDecl() const {
4620 auto *Decl = dyn_cast<CXXRecordDecl>(decl);
4621 if (!Decl)
4622 return nullptr;
4623 if (auto *RD = dyn_cast<ClassTemplateSpecializationDecl>(Decl))
4624 return RD->getSpecializedTemplate();
4625 return Decl->getDescribedClassTemplate();
4626}
4627
4628TemplateName TagType::getTemplateName(const ASTContext &Ctx) const {
4629 auto *TD = getTemplateDecl();
4630 if (!TD)
4631 return TemplateName();
4632 if (isCanonicalUnqualified())
4633 return TemplateName(TD);
4634 return Ctx.getQualifiedTemplateName(getQualifier(), /*TemplateKeyword=*/false,
4635 TemplateName(TD));
4636}
4637
4639TagType::getTemplateArgs(const ASTContext &Ctx) const {
4640 auto *Decl = dyn_cast<CXXRecordDecl>(decl);
4641 if (!Decl)
4642 return {};
4643
4644 if (auto *RD = dyn_cast<ClassTemplateSpecializationDecl>(Decl))
4645 return RD->getTemplateArgs().asArray();
4646 if (ClassTemplateDecl *TD = Decl->getDescribedClassTemplate())
4647 return TD->getTemplateParameters()->getInjectedTemplateArgs(Ctx);
4648 return {};
4649}
4650
4651bool RecordType::hasConstFields() const {
4652 std::vector<const RecordType *> RecordTypeList;
4653 RecordTypeList.push_back(this);
4654 unsigned NextToCheckIndex = 0;
4655
4656 while (RecordTypeList.size() > NextToCheckIndex) {
4657 for (FieldDecl *FD : RecordTypeList[NextToCheckIndex]
4658 ->getDecl()
4659 ->getDefinitionOrSelf()
4660 ->fields()) {
4661 QualType FieldTy = FD->getType();
4662 if (FieldTy.isConstQualified())
4663 return true;
4664 FieldTy = FieldTy.getCanonicalType();
4665 if (const auto *FieldRecTy = FieldTy->getAsCanonical<RecordType>()) {
4666 if (!llvm::is_contained(RecordTypeList, FieldRecTy))
4667 RecordTypeList.push_back(FieldRecTy);
4668 }
4669 }
4670 ++NextToCheckIndex;
4671 }
4672 return false;
4673}
4674
4675InjectedClassNameType::InjectedClassNameType(ElaboratedTypeKeyword Keyword,
4676 NestedNameSpecifier Qualifier,
4677 const TagDecl *TD, bool IsInjected,
4678 const Type *CanonicalType)
4679 : TagType(TypeClass::InjectedClassName, Keyword, Qualifier, TD,
4680 /*OwnsTag=*/false, IsInjected, CanonicalType) {}
4681
4682AttributedType::AttributedType(QualType canon, const Attr *attr,
4683 QualType modified, QualType equivalent)
4684 : AttributedType(canon, attr->getKind(), attr, modified, equivalent) {}
4685
4686AttributedType::AttributedType(QualType canon, attr::Kind attrKind,
4687 const Attr *attr, QualType modified,
4688 QualType equivalent)
4689 : Type(Attributed, canon, equivalent->getDependence()), Attribute(attr),
4690 ModifiedType(modified), EquivalentType(equivalent) {
4691 AttributedTypeBits.AttrKind = attrKind;
4692 assert(!attr || attr->getKind() == attrKind);
4693}
4694
4695bool AttributedType::isQualifier() const {
4696 // FIXME: Generate this with TableGen.
4697 switch (getAttrKind()) {
4698 // These are type qualifiers in the traditional C sense: they annotate
4699 // something about a specific value/variable of a type. (They aren't
4700 // always part of the canonical type, though.)
4701 case attr::ObjCGC:
4702 case attr::ObjCOwnership:
4703 case attr::ObjCInertUnsafeUnretained:
4704 case attr::TypeNonNull:
4705 case attr::TypeNullable:
4706 case attr::TypeNullableResult:
4707 case attr::TypeNullUnspecified:
4708 case attr::LifetimeBound:
4709 case attr::AddressSpace:
4710 return true;
4711
4712 // All other type attributes aren't qualifiers; they rewrite the modified
4713 // type to be a semantically different type.
4714 default:
4715 return false;
4716 }
4717}
4718
4719bool AttributedType::isMSTypeSpec() const {
4720 // FIXME: Generate this with TableGen?
4721 switch (getAttrKind()) {
4722 default:
4723 return false;
4724 case attr::Ptr32:
4725 case attr::Ptr64:
4726 case attr::SPtr:
4727 case attr::UPtr:
4728 return true;
4729 }
4730 llvm_unreachable("invalid attr kind");
4731}
4732
4733bool AttributedType::isWebAssemblyFuncrefSpec() const {
4734 return getAttrKind() == attr::WebAssemblyFuncref;
4735}
4736
4737bool AttributedType::isCallingConv() const {
4738 // FIXME: Generate this with TableGen.
4739 switch (getAttrKind()) {
4740 default:
4741 return false;
4742 case attr::Pcs:
4743 case attr::CDecl:
4744 case attr::FastCall:
4745 case attr::StdCall:
4746 case attr::ThisCall:
4747 case attr::RegCall:
4748 case attr::SwiftCall:
4749 case attr::SwiftAsyncCall:
4750 case attr::VectorCall:
4751 case attr::AArch64VectorPcs:
4752 case attr::AArch64SVEPcs:
4753 case attr::DeviceKernel:
4754 case attr::Pascal:
4755 case attr::MSABI:
4756 case attr::SysVABI:
4757 case attr::IntelOclBicc:
4758 case attr::PreserveMost:
4759 case attr::PreserveAll:
4760 case attr::M68kRTD:
4761 case attr::PreserveNone:
4762 case attr::RISCVVectorCC:
4763 case attr::RISCVVLSCC:
4764 return true;
4765 }
4766 llvm_unreachable("invalid attr kind");
4767}
4768
4769IdentifierInfo *TemplateTypeParmType::getIdentifier() const {
4770 return isCanonicalUnqualified() ? nullptr : getDecl()->getIdentifier();
4771}
4772
4773SubstTemplateTypeParmType::SubstTemplateTypeParmType(QualType Replacement,
4774 Decl *AssociatedDecl,
4775 unsigned Index,
4777 bool Final)
4778 : Type(SubstTemplateTypeParm, Replacement.getCanonicalType(),
4779 Replacement->getDependence()),
4780 AssociatedDecl(AssociatedDecl) {
4781 SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType =
4782 Replacement != getCanonicalTypeInternal();
4783 if (SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType)
4784 *getTrailingObjects() = Replacement;
4785
4786 SubstTemplateTypeParmTypeBits.Index = Index;
4787 SubstTemplateTypeParmTypeBits.Final = Final;
4789 PackIndex.toInternalRepresentation();
4790 assert(AssociatedDecl != nullptr);
4791}
4792
4794SubstTemplateTypeParmType::getReplacedParameter() const {
4795 return cast<TemplateTypeParmDecl>(std::get<0>(
4796 getReplacedTemplateParameter(getAssociatedDecl(), getIndex())));
4797}
4798
4799SubstPackType::SubstPackType(TypeClass Derived, QualType Canon,
4800 const TemplateArgument &ArgPack)
4801 : Type(Derived, Canon,
4802 TypeDependence::DependentInstantiation |
4803 TypeDependence::UnexpandedPack),
4804 Arguments(ArgPack.pack_begin()) {
4805 assert(llvm::all_of(
4806 ArgPack.pack_elements(),
4807 [](auto &P) { return P.getKind() == TemplateArgument::Type; }) &&
4808 "non-type argument to SubstPackType?");
4809 SubstPackTypeBits.NumArgs = ArgPack.pack_size();
4810}
4811
4812TemplateArgument SubstPackType::getArgumentPack() const {
4813 return TemplateArgument(llvm::ArrayRef(Arguments, getNumArgs()));
4814}
4815
4816void SubstPackType::Profile(llvm::FoldingSetNodeID &ID) {
4817 Profile(ID, getArgumentPack());
4818}
4819
4820void SubstPackType::Profile(llvm::FoldingSetNodeID &ID,
4821 const TemplateArgument &ArgPack) {
4822 ID.AddInteger(ArgPack.pack_size());
4823 for (const auto &P : ArgPack.pack_elements())
4824 ID.AddPointer(P.getAsType().getAsOpaquePtr());
4825}
4826
4827SubstTemplateTypeParmPackType::SubstTemplateTypeParmPackType(
4828 QualType Canon, Decl *AssociatedDecl, unsigned Index, bool Final,
4829 const TemplateArgument &ArgPack)
4830 : SubstPackType(SubstTemplateTypeParmPack, Canon, ArgPack),
4831 AssociatedDeclAndFinal(AssociatedDecl, Final) {
4832 assert(AssociatedDecl != nullptr);
4833
4834 SubstPackTypeBits.SubstTemplTypeParmPackIndex = Index;
4835 assert(getNumArgs() == ArgPack.pack_size() &&
4836 "Parent bitfields in SubstPackType were overwritten."
4837 "Check NumSubstPackTypeBits.");
4838}
4839
4840Decl *SubstTemplateTypeParmPackType::getAssociatedDecl() const {
4841 return AssociatedDeclAndFinal.getPointer();
4842}
4843
4844bool SubstTemplateTypeParmPackType::getFinal() const {
4845 return AssociatedDeclAndFinal.getInt();
4846}
4847
4849SubstTemplateTypeParmPackType::getReplacedParameter() const {
4850 return cast<TemplateTypeParmDecl>(std::get<0>(
4851 getReplacedTemplateParameter(getAssociatedDecl(), getIndex())));
4852}
4853
4854IdentifierInfo *SubstTemplateTypeParmPackType::getIdentifier() const {
4855 return getReplacedParameter()->getIdentifier();
4856}
4857
4858void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID) {
4859 Profile(ID, getAssociatedDecl(), getIndex(), getFinal(), getArgumentPack());
4860}
4861
4862void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID,
4863 const Decl *AssociatedDecl,
4864 unsigned Index, bool Final,
4865 const TemplateArgument &ArgPack) {
4866 ID.AddPointer(AssociatedDecl);
4867 ID.AddInteger(Index);
4868 ID.AddBoolean(Final);
4869 SubstPackType::Profile(ID, ArgPack);
4870}
4871
4872SubstBuiltinTemplatePackType::SubstBuiltinTemplatePackType(
4873 QualType Canon, const TemplateArgument &ArgPack)
4874 : SubstPackType(SubstBuiltinTemplatePack, Canon, ArgPack) {}
4875
4876bool TemplateSpecializationType::anyDependentTemplateArguments(
4877 const TemplateArgumentListInfo &Args,
4878 ArrayRef<TemplateArgument> Converted) {
4879 return anyDependentTemplateArguments(Args.arguments(), Converted);
4880}
4881
4882bool TemplateSpecializationType::anyDependentTemplateArguments(
4884 for (const TemplateArgument &Arg : Converted)
4885 if (Arg.isDependent())
4886 return true;
4887 return false;
4888}
4889
4890bool TemplateSpecializationType::anyInstantiationDependentTemplateArguments(
4892 for (const TemplateArgumentLoc &ArgLoc : Args) {
4893 if (ArgLoc.getArgument().isInstantiationDependent())
4894 return true;
4895 }
4896 return false;
4897}
4898
4899static TypeDependence
4901 TypeDependence D = Underlying.isNull()
4902 ? TypeDependence::DependentInstantiation
4903 : toSemanticDependence(Underlying->getDependence());
4904 D |= toTypeDependence(T.getDependence()) & TypeDependence::UnexpandedPack;
4906 if (Underlying.isNull()) // Dependent, will produce a pack on substitution.
4907 D |= TypeDependence::UnexpandedPack;
4908 else
4909 D |= (Underlying->getDependence() & TypeDependence::UnexpandedPack);
4910 }
4911 return D;
4912}
4913
4914TemplateSpecializationType::TemplateSpecializationType(
4916 ArrayRef<TemplateArgument> Args, QualType Underlying)
4918 Underlying.isNull() ? QualType(this, 0)
4919 : Underlying.getCanonicalType(),
4921 Template(T) {
4922 TemplateSpecializationTypeBits.NumArgs = Args.size();
4923 TemplateSpecializationTypeBits.TypeAlias = IsAlias;
4924
4925 auto *TemplateArgs =
4926 const_cast<TemplateArgument *>(template_arguments().data());
4927 for (const TemplateArgument &Arg : Args) {
4928 // Update instantiation-dependent, variably-modified, and error bits.
4929 // If the canonical type exists and is non-dependent, the template
4930 // specialization type can be non-dependent even if one of the type
4931 // arguments is. Given:
4932 // template<typename T> using U = int;
4933 // U<T> is always non-dependent, irrespective of the type T.
4934 // However, U<Ts> contains an unexpanded parameter pack, even though
4935 // its expansion (and thus its desugared type) doesn't.
4936 addDependence(toTypeDependence(Arg.getDependence()) &
4937 ~TypeDependence::Dependent);
4938 if (Arg.getKind() == TemplateArgument::Type)
4939 addDependence(Arg.getAsType()->getDependence() &
4940 TypeDependence::VariablyModified);
4941 new (TemplateArgs++) TemplateArgument(Arg);
4942 }
4943
4944 // Store the aliased type after the template arguments, if this is a type
4945 // alias template specialization.
4946 if (IsAlias)
4947 *reinterpret_cast<QualType *>(TemplateArgs) = Underlying;
4948}
4949
4950QualType TemplateSpecializationType::getAliasedType() const {
4951 assert(isTypeAlias() && "not a type alias template specialization");
4952 return *reinterpret_cast<const QualType *>(template_arguments().end());
4953}
4954
4955bool clang::TemplateSpecializationType::isSugared() const {
4956 return !isDependentType() || isCurrentInstantiation() || isTypeAlias() ||
4958 isa<SubstBuiltinTemplatePackType>(*getCanonicalTypeInternal()));
4959}
4960
4961void TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
4962 const ASTContext &Ctx) {
4963 Profile(ID, getKeyword(), Template, template_arguments(),
4964 isSugared() ? desugar() : QualType(), Ctx);
4965}
4966
4967void TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
4971 QualType Underlying,
4972 const ASTContext &Context) {
4973 ID.AddInteger(llvm::to_underlying(Keyword));
4974 T.Profile(ID);
4975 Underlying.Profile(ID);
4976
4977 ID.AddInteger(Args.size());
4978 for (const TemplateArgument &Arg : Args)
4979 Arg.Profile(ID, Context);
4980}
4981
4983 QualType QT) const {
4984 if (!hasNonFastQualifiers())
4986
4987 return Context.getQualifiedType(QT, *this);
4988}
4989
4991 const Type *T) const {
4992 if (!hasNonFastQualifiers())
4993 return QualType(T, getFastQualifiers());
4994
4995 return Context.getQualifiedType(T, *this);
4996}
4997
4998void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID, QualType BaseType,
4999 ArrayRef<QualType> typeArgs,
5001 bool isKindOf) {
5002 ID.AddPointer(BaseType.getAsOpaquePtr());
5003 ID.AddInteger(typeArgs.size());
5004 for (auto typeArg : typeArgs)
5005 ID.AddPointer(typeArg.getAsOpaquePtr());
5006 ID.AddInteger(protocols.size());
5007 for (auto *proto : protocols)
5008 ID.AddPointer(proto);
5009 ID.AddBoolean(isKindOf);
5010}
5011
5012void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) {
5013 Profile(ID, getBaseType(), getTypeArgsAsWritten(),
5014 llvm::ArrayRef(qual_begin(), getNumProtocols()),
5015 isKindOfTypeAsWritten());
5016}
5017
5018namespace {
5019
5020/// The cached properties of a type.
5021class CachedProperties {
5022 Linkage L;
5023 bool local;
5024
5025public:
5026 CachedProperties(Linkage L, bool local) : L(L), local(local) {}
5027
5028 Linkage getLinkage() const { return L; }
5029 bool hasLocalOrUnnamedType() const { return local; }
5030
5031 friend CachedProperties merge(CachedProperties L, CachedProperties R) {
5032 Linkage MergedLinkage = minLinkage(L.L, R.L);
5033 return CachedProperties(MergedLinkage, L.hasLocalOrUnnamedType() ||
5034 R.hasLocalOrUnnamedType());
5035 }
5036};
5037
5038} // namespace
5039
5040static CachedProperties computeCachedProperties(const Type *T);
5041
5042namespace clang {
5043
5044/// The type-property cache. This is templated so as to be
5045/// instantiated at an internal type to prevent unnecessary symbol
5046/// leakage.
5047template <class Private> class TypePropertyCache {
5048public:
5049 static CachedProperties get(QualType T) { return get(T.getTypePtr()); }
5050
5051 static CachedProperties get(const Type *T) {
5052 ensure(T);
5053 return CachedProperties(T->TypeBits.getLinkage(),
5054 T->TypeBits.hasLocalOrUnnamedType());
5055 }
5056
5057 static void ensure(const Type *T) {
5058 // If the cache is valid, we're okay.
5059 if (T->TypeBits.isCacheValid())
5060 return;
5061
5062 // If this type is non-canonical, ask its canonical type for the
5063 // relevant information.
5064 if (!T->isCanonicalUnqualified()) {
5065 const Type *CT = T->getCanonicalTypeInternal().getTypePtr();
5066 ensure(CT);
5067 T->TypeBits.CacheValid = true;
5068 T->TypeBits.CachedLinkage = CT->TypeBits.CachedLinkage;
5069 T->TypeBits.CachedLocalOrUnnamed = CT->TypeBits.CachedLocalOrUnnamed;
5070 return;
5071 }
5072
5073 // Compute the cached properties and then set the cache.
5074 CachedProperties Result = computeCachedProperties(T);
5075 T->TypeBits.CacheValid = true;
5076 T->TypeBits.CachedLinkage = llvm::to_underlying(Result.getLinkage());
5077 T->TypeBits.CachedLocalOrUnnamed = Result.hasLocalOrUnnamedType();
5078 }
5079};
5080
5081} // namespace clang
5082
5083// Instantiate the friend template at a private class. In a
5084// reasonable implementation, these symbols will be internal.
5085// It is terrible that this is the best way to accomplish this.
5086namespace {
5087
5088class Private {};
5089
5090} // namespace
5091
5093
5094static CachedProperties computeCachedProperties(const Type *T) {
5095 switch (T->getTypeClass()) {
5096#define TYPE(Class, Base)
5097#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
5098#include "clang/AST/TypeNodes.inc"
5099 llvm_unreachable("didn't expect a non-canonical type here");
5100
5101#define TYPE(Class, Base)
5102#define DEPENDENT_TYPE(Class, Base) case Type::Class:
5103#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
5104#include "clang/AST/TypeNodes.inc"
5105 // Treat instantiation-dependent types as external.
5106 assert(T->isInstantiationDependentType());
5107 return CachedProperties(Linkage::External, false);
5108
5109 case Type::Auto:
5110 case Type::DeducedTemplateSpecialization:
5111 // Give non-deduced 'auto' types external linkage. We should only see them
5112 // here in error recovery.
5113 return CachedProperties(Linkage::External, false);
5114
5115 case Type::BitInt:
5116 case Type::Builtin:
5117 // C++ [basic.link]p8:
5118 // A type is said to have linkage if and only if:
5119 // - it is a fundamental type (3.9.1); or
5120 return CachedProperties(Linkage::External, false);
5121
5122 case Type::Record:
5123 case Type::Enum: {
5124 const auto *Tag = cast<TagType>(T)->getDecl()->getDefinitionOrSelf();
5125
5126 // C++ [basic.link]p8:
5127 // - it is a class or enumeration type that is named (or has a name
5128 // for linkage purposes (7.1.3)) and the name has linkage; or
5129 // - it is a specialization of a class template (14); or
5130 Linkage L = Tag->getLinkageInternal();
5131 bool IsLocalOrUnnamed = Tag->getDeclContext()->isFunctionOrMethod() ||
5132 !Tag->hasNameForLinkage();
5133 return CachedProperties(L, IsLocalOrUnnamed);
5134 }
5135
5136 // C++ [basic.link]p8:
5137 // - it is a compound type (3.9.2) other than a class or enumeration,
5138 // compounded exclusively from types that have linkage; or
5139 case Type::Complex:
5140 return Cache::get(cast<ComplexType>(T)->getElementType());
5141 case Type::Pointer:
5143 case Type::BlockPointer:
5145 case Type::LValueReference:
5146 case Type::RValueReference:
5148 case Type::MemberPointer: {
5149 const auto *MPT = cast<MemberPointerType>(T);
5150 CachedProperties Cls = [&] {
5151 if (MPT->isSugared())
5152 MPT = cast<MemberPointerType>(MPT->getCanonicalTypeInternal());
5153 return Cache::get(MPT->getQualifier().getAsType());
5154 }();
5155 return merge(Cls, Cache::get(MPT->getPointeeType()));
5156 }
5157 case Type::ConstantArray:
5158 case Type::IncompleteArray:
5159 case Type::VariableArray:
5160 case Type::ArrayParameter:
5161 return Cache::get(cast<ArrayType>(T)->getElementType());
5162 case Type::Vector:
5163 case Type::ExtVector:
5164 return Cache::get(cast<VectorType>(T)->getElementType());
5165 case Type::ConstantMatrix:
5166 return Cache::get(cast<ConstantMatrixType>(T)->getElementType());
5167 case Type::FunctionNoProto:
5168 return Cache::get(cast<FunctionType>(T)->getReturnType());
5169 case Type::FunctionProto: {
5170 const auto *FPT = cast<FunctionProtoType>(T);
5171 CachedProperties result = Cache::get(FPT->getReturnType());
5172 for (const auto &ai : FPT->param_types())
5173 result = merge(result, Cache::get(ai));
5174 return result;
5175 }
5176 case Type::ObjCInterface: {
5177 Linkage L = cast<ObjCInterfaceType>(T)->getDecl()->getLinkageInternal();
5178 return CachedProperties(L, false);
5179 }
5180 case Type::ObjCObject:
5181 return Cache::get(cast<ObjCObjectType>(T)->getBaseType());
5182 case Type::ObjCObjectPointer:
5184 case Type::Atomic:
5185 return Cache::get(cast<AtomicType>(T)->getValueType());
5186 case Type::Pipe:
5187 return Cache::get(cast<PipeType>(T)->getElementType());
5188 case Type::HLSLAttributedResource:
5189 return Cache::get(cast<HLSLAttributedResourceType>(T)->getWrappedType());
5190 case Type::HLSLInlineSpirv:
5191 return CachedProperties(Linkage::External, false);
5192 case Type::OverflowBehavior:
5194 }
5195
5196 llvm_unreachable("unhandled type class");
5197}
5198
5199/// Determine the linkage of this type.
5201 Cache::ensure(this);
5202 return TypeBits.getLinkage();
5203}
5204
5206 Cache::ensure(this);
5207 return TypeBits.hasLocalOrUnnamedType();
5208}
5209
5211 switch (T->getTypeClass()) {
5212#define TYPE(Class, Base)
5213#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
5214#include "clang/AST/TypeNodes.inc"
5215 llvm_unreachable("didn't expect a non-canonical type here");
5216
5217#define TYPE(Class, Base)
5218#define DEPENDENT_TYPE(Class, Base) case Type::Class:
5219#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
5220#include "clang/AST/TypeNodes.inc"
5221 // Treat instantiation-dependent types as external.
5222 assert(T->isInstantiationDependentType());
5223 return LinkageInfo::external();
5224
5225 case Type::BitInt:
5226 case Type::Builtin:
5227 return LinkageInfo::external();
5228
5229 case Type::Auto:
5230 case Type::DeducedTemplateSpecialization:
5231 return LinkageInfo::external();
5232
5233 case Type::Record:
5234 case Type::Enum:
5236 cast<TagType>(T)->getDecl()->getDefinitionOrSelf());
5237
5238 case Type::Complex:
5239 return computeTypeLinkageInfo(cast<ComplexType>(T)->getElementType());
5240 case Type::Pointer:
5242 case Type::BlockPointer:
5244 case Type::LValueReference:
5245 case Type::RValueReference:
5247 case Type::MemberPointer: {
5248 const auto *MPT = cast<MemberPointerType>(T);
5249 LinkageInfo LV;
5250 if (auto *D = MPT->getMostRecentCXXRecordDecl()) {
5252 } else {
5253 LV.merge(computeTypeLinkageInfo(MPT->getQualifier().getAsType()));
5254 }
5255 LV.merge(computeTypeLinkageInfo(MPT->getPointeeType()));
5256 return LV;
5257 }
5258 case Type::ConstantArray:
5259 case Type::IncompleteArray:
5260 case Type::VariableArray:
5261 case Type::ArrayParameter:
5262 return computeTypeLinkageInfo(cast<ArrayType>(T)->getElementType());
5263 case Type::Vector:
5264 case Type::ExtVector:
5265 return computeTypeLinkageInfo(cast<VectorType>(T)->getElementType());
5266 case Type::ConstantMatrix:
5268 cast<ConstantMatrixType>(T)->getElementType());
5269 case Type::FunctionNoProto:
5270 return computeTypeLinkageInfo(cast<FunctionType>(T)->getReturnType());
5271 case Type::FunctionProto: {
5272 const auto *FPT = cast<FunctionProtoType>(T);
5273 LinkageInfo LV = computeTypeLinkageInfo(FPT->getReturnType());
5274 for (const auto &ai : FPT->param_types())
5276 return LV;
5277 }
5278 case Type::ObjCInterface:
5280 case Type::ObjCObject:
5281 return computeTypeLinkageInfo(cast<ObjCObjectType>(T)->getBaseType());
5282 case Type::ObjCObjectPointer:
5285 case Type::Atomic:
5286 return computeTypeLinkageInfo(cast<AtomicType>(T)->getValueType());
5287 case Type::Pipe:
5288 return computeTypeLinkageInfo(cast<PipeType>(T)->getElementType());
5289 case Type::OverflowBehavior:
5292 case Type::HLSLAttributedResource:
5294 cast<HLSLAttributedResourceType>(T)->getWrappedType());
5295 case Type::HLSLInlineSpirv:
5296 return LinkageInfo::external();
5297 }
5298
5299 llvm_unreachable("unhandled type class");
5300}
5301
5303 if (!TypeBits.isCacheValid())
5304 return true;
5305
5308 .getLinkage();
5309 return L == TypeBits.getLinkage();
5310}
5311
5313 if (!T->isCanonicalUnqualified())
5314 return computeTypeLinkageInfo(T->getCanonicalTypeInternal());
5315
5317 assert(LV.getLinkage() == T->getLinkage());
5318 return LV;
5319}
5320
5324
5326 QualType Type(this, 0);
5327 while (const auto *AT = Type->getAs<AttributedType>()) {
5328 // Check whether this is an attributed type with nullability
5329 // information.
5330 if (auto Nullability = AT->getImmediateNullability())
5331 return Nullability;
5332
5333 Type = AT->getEquivalentType();
5334 }
5335 return std::nullopt;
5336}
5337
5338bool Type::canHaveNullability(bool ResultIfUnknown) const {
5340
5341 switch (type->getTypeClass()) {
5342#define NON_CANONICAL_TYPE(Class, Parent) \
5343 /* We'll only see canonical types here. */ \
5344 case Type::Class: \
5345 llvm_unreachable("non-canonical type");
5346#define TYPE(Class, Parent)
5347#include "clang/AST/TypeNodes.inc"
5348
5349 // Pointer types.
5350 case Type::Pointer:
5351 case Type::BlockPointer:
5352 case Type::MemberPointer:
5353 case Type::ObjCObjectPointer:
5354 return true;
5355
5356 // Dependent types that could instantiate to pointer types.
5357 case Type::UnresolvedUsing:
5358 case Type::TypeOfExpr:
5359 case Type::TypeOf:
5360 case Type::Decltype:
5361 case Type::PackIndexing:
5362 case Type::UnaryTransform:
5363 case Type::TemplateTypeParm:
5364 case Type::SubstTemplateTypeParmPack:
5365 case Type::SubstBuiltinTemplatePack:
5366 case Type::DependentName:
5367 case Type::Auto:
5368 return ResultIfUnknown;
5369
5370 // Dependent template specializations could instantiate to pointer types.
5371 case Type::TemplateSpecialization:
5372 // If it's a known class template, we can already check if it's nullable.
5373 if (TemplateDecl *templateDecl =
5375 ->getTemplateName()
5376 .getAsTemplateDecl())
5377 if (auto *CTD = dyn_cast<ClassTemplateDecl>(templateDecl))
5378 return llvm::any_of(
5379 CTD->redecls(), [](const RedeclarableTemplateDecl *RTD) {
5380 return RTD->getTemplatedDecl()->hasAttr<TypeNullableAttr>();
5381 });
5382 return ResultIfUnknown;
5383
5384 case Type::Builtin:
5385 switch (cast<BuiltinType>(type.getTypePtr())->getKind()) {
5386 // Signed, unsigned, and floating-point types cannot have nullability.
5387#define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
5388#define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
5389#define FLOATING_TYPE(Id, SingletonId) case BuiltinType::Id:
5390#define BUILTIN_TYPE(Id, SingletonId)
5391#include "clang/AST/BuiltinTypes.def"
5392 return false;
5393
5394 case BuiltinType::UnresolvedTemplate:
5395 // Dependent types that could instantiate to a pointer type.
5396 case BuiltinType::Dependent:
5397 case BuiltinType::Overload:
5398 case BuiltinType::BoundMember:
5399 case BuiltinType::PseudoObject:
5400 case BuiltinType::UnknownAny:
5401 case BuiltinType::ARCUnbridgedCast:
5402 return ResultIfUnknown;
5403
5404 case BuiltinType::Void:
5405 case BuiltinType::ObjCId:
5406 case BuiltinType::ObjCClass:
5407 case BuiltinType::ObjCSel:
5408#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
5409 case BuiltinType::Id:
5410#include "clang/Basic/OpenCLImageTypes.def"
5411#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) case BuiltinType::Id:
5412#include "clang/Basic/OpenCLExtensionTypes.def"
5413 case BuiltinType::OCLSampler:
5414 case BuiltinType::OCLEvent:
5415 case BuiltinType::OCLClkEvent:
5416 case BuiltinType::OCLQueue:
5417 case BuiltinType::OCLReserveID:
5418#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
5419#include "clang/Basic/AArch64ACLETypes.def"
5420#define PPC_VECTOR_TYPE(Name, Id, Size) case BuiltinType::Id:
5421#include "clang/Basic/PPCTypes.def"
5422#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
5423#include "clang/Basic/RISCVVTypes.def"
5424#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
5425#include "clang/Basic/WebAssemblyReferenceTypes.def"
5426#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) case BuiltinType::Id:
5427#include "clang/Basic/AMDGPUTypes.def"
5428#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
5429#include "clang/Basic/HLSLIntangibleTypes.def"
5430#define HLSL_PACKED_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
5431#include "clang/Basic/HLSLPackedTypes.def"
5432#define SPIRV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
5433#include "clang/Basic/SPIRVTypes.def"
5434 case BuiltinType::BuiltinFn:
5435 case BuiltinType::NullPtr:
5436 case BuiltinType::MetaInfo:
5437 case BuiltinType::IncompleteMatrixIdx:
5438 case BuiltinType::ArraySection:
5439 case BuiltinType::OMPArrayShaping:
5440 case BuiltinType::OMPIterator:
5441 return false;
5442 }
5443 llvm_unreachable("unknown builtin type");
5444
5445 case Type::Record: {
5446 const auto *RD = cast<RecordType>(type)->getDecl();
5447 // For template specializations, look only at primary template attributes.
5448 // This is a consistent regardless of whether the instantiation is known.
5449 if (const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
5450 return llvm::any_of(
5451 CTSD->getSpecializedTemplate()->redecls(),
5452 [](const RedeclarableTemplateDecl *RTD) {
5453 return RTD->getTemplatedDecl()->hasAttr<TypeNullableAttr>();
5454 });
5455 return llvm::any_of(RD->redecls(), [](const TagDecl *RD) {
5456 return RD->hasAttr<TypeNullableAttr>();
5457 });
5458 }
5459
5460 // Non-pointer types.
5461 case Type::Complex:
5462 case Type::LValueReference:
5463 case Type::RValueReference:
5464 case Type::ConstantArray:
5465 case Type::IncompleteArray:
5466 case Type::VariableArray:
5467 case Type::DependentSizedArray:
5468 case Type::DependentVector:
5469 case Type::DependentSizedExtVector:
5470 case Type::Vector:
5471 case Type::ExtVector:
5472 case Type::ConstantMatrix:
5473 case Type::DependentSizedMatrix:
5474 case Type::DependentAddressSpace:
5475 case Type::FunctionProto:
5476 case Type::FunctionNoProto:
5477 case Type::DeducedTemplateSpecialization:
5478 case Type::Enum:
5479 case Type::InjectedClassName:
5480 case Type::PackExpansion:
5481 case Type::ObjCObject:
5482 case Type::ObjCInterface:
5483 case Type::Atomic:
5484 case Type::Pipe:
5485 case Type::BitInt:
5486 case Type::DependentBitInt:
5487 case Type::ArrayParameter:
5488 case Type::HLSLAttributedResource:
5489 case Type::HLSLInlineSpirv:
5490 case Type::OverflowBehavior:
5491 return false;
5492 }
5493 llvm_unreachable("bad type kind!");
5494}
5495
5496NullabilityKindOrNone AttributedType::getImmediateNullability() const {
5497 if (getAttrKind() == attr::TypeNonNull)
5499 if (getAttrKind() == attr::TypeNullable)
5501 if (getAttrKind() == attr::TypeNullUnspecified)
5503 if (getAttrKind() == attr::TypeNullableResult)
5505 return std::nullopt;
5506}
5507
5508NullabilityKindOrNone AttributedType::stripOuterNullability(QualType &T) {
5509 QualType AttrTy = T;
5510 if (auto MacroTy = dyn_cast<MacroQualifiedType>(T))
5511 AttrTy = MacroTy->getUnderlyingType();
5512
5513 if (auto attributed = dyn_cast<AttributedType>(AttrTy)) {
5514 if (auto nullability = attributed->getImmediateNullability()) {
5515 T = attributed->getModifiedType();
5516 return nullability;
5517 }
5518 }
5519
5520 return std::nullopt;
5521}
5522
5523void AttributedType::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx,
5524 Kind attrKind, QualType modified,
5525 QualType equivalent, const Attr *attr) {
5526 ID.AddInteger(attrKind);
5527 ID.AddPointer(modified.getAsOpaquePtr());
5528 ID.AddPointer(equivalent.getAsOpaquePtr());
5529 if (attr)
5530 attr->Profile(ID, Ctx);
5531}
5532
5534 if (!isIntegralType(Ctx) || isEnumeralType())
5535 return false;
5536 return Ctx.getTypeSize(this) == Ctx.getTypeSize(Ctx.VoidPtrTy);
5537}
5538
5540 const auto *objcPtr = getAs<ObjCObjectPointerType>();
5541 if (!objcPtr)
5542 return false;
5543
5544 if (objcPtr->isObjCIdType()) {
5545 // id is always okay.
5546 return true;
5547 }
5548
5549 // Blocks are NSObjects.
5550 if (ObjCInterfaceDecl *iface = objcPtr->getInterfaceDecl()) {
5551 if (iface->getIdentifier() != ctx.getNSObjectName())
5552 return false;
5553
5554 // Continue to check qualifiers, below.
5555 } else if (objcPtr->isObjCQualifiedIdType()) {
5556 // Continue to check qualifiers, below.
5557 } else {
5558 return false;
5559 }
5560
5561 // Check protocol qualifiers.
5562 for (ObjCProtocolDecl *proto : objcPtr->quals()) {
5563 // Blocks conform to NSObject and NSCopying.
5564 if (proto->getIdentifier() != ctx.getNSObjectName() &&
5565 proto->getIdentifier() != ctx.getNSCopyingName())
5566 return false;
5567 }
5568
5569 return true;
5570}
5571
5577
5579 assert(isObjCLifetimeType() &&
5580 "cannot query implicit lifetime for non-inferrable type");
5581
5582 const Type *canon = getCanonicalTypeInternal().getTypePtr();
5583
5584 // Walk down to the base type. We don't care about qualifiers for this.
5585 while (const auto *array = dyn_cast<ArrayType>(canon))
5586 canon = array->getElementType().getTypePtr();
5587
5588 if (const auto *opt = dyn_cast<ObjCObjectPointerType>(canon)) {
5589 // Class and Class<Protocol> don't require retention.
5590 if (opt->getObjectType()->isObjCClass())
5591 return true;
5592 }
5593
5594 return false;
5595}
5596
5598 if (const auto *typedefType = getAs<TypedefType>())
5599 return typedefType->getDecl()->hasAttr<ObjCNSObjectAttr>();
5600 return false;
5601}
5602
5604 if (const auto *typedefType = getAs<TypedefType>())
5605 return typedefType->getDecl()->hasAttr<ObjCIndependentClassAttr>();
5606 return false;
5607}
5608
5613
5615 if (isObjCLifetimeType())
5616 return true;
5617 if (const auto *OPT = getAs<PointerType>())
5618 return OPT->getPointeeType()->isObjCIndirectLifetimeType();
5619 if (const auto *Ref = getAs<ReferenceType>())
5620 return Ref->getPointeeType()->isObjCIndirectLifetimeType();
5621 if (const auto *MemPtr = getAs<MemberPointerType>())
5622 return MemPtr->getPointeeType()->isObjCIndirectLifetimeType();
5623 return false;
5624}
5625
5626/// Returns true if objects of this type have lifetime semantics under
5627/// ARC.
5629 const Type *type = this;
5630 while (const ArrayType *array = type->getAsArrayTypeUnsafe())
5631 type = array->getElementType().getTypePtr();
5632 return type->isObjCRetainableType();
5633}
5634
5635/// Determine whether the given type T is a "bridgable" Objective-C type,
5636/// which is either an Objective-C object pointer type or an
5640
5641/// Determine whether the given type T is a "bridgeable" C type.
5643 const auto *Pointer = getAsCanonical<PointerType>();
5644 if (!Pointer)
5645 return false;
5646
5647 QualType Pointee = Pointer->getPointeeType();
5648 return Pointee->isVoidType() || Pointee->isRecordType();
5649}
5650
5651/// Check if the specified type is the CUDA device builtin surface type.
5653 if (const auto *RT = getAsCanonical<RecordType>())
5654 return RT->getDecl()
5655 ->getMostRecentDecl()
5656 ->hasAttr<CUDADeviceBuiltinSurfaceTypeAttr>();
5657 return false;
5658}
5659
5660/// Check if the specified type is the CUDA device builtin texture type.
5662 if (const auto *RT = getAsCanonical<RecordType>())
5663 return RT->getDecl()
5664 ->getMostRecentDecl()
5665 ->hasAttr<CUDADeviceBuiltinTextureTypeAttr>();
5666 return false;
5667}
5668
5669static bool isAMDGPUNamedBarrierTypeImpl(const Type *Ty, bool AllowWrappers) {
5670 // This query does not care about qualifiers at all.
5671 Ty = Ty->getUnqualifiedDesugaredType();
5672
5673 // Unwrap arrays.
5674 while (isa<ArrayType>(Ty))
5676
5677 if (const auto *BT = dyn_cast<BuiltinType>(Ty))
5678 return BT->getKind() == BuiltinType::AMDGPUNamedWorkgroupBarrier;
5679 if (AllowWrappers) {
5680 if (const auto *RT = dyn_cast<RecordType>(Ty))
5681 return RT->getDecl()->hasAttr<AMDGPUNamedBarrierWrapperAttr>();
5682 }
5683 return false;
5684}
5685
5687 return isAMDGPUNamedBarrierTypeImpl(this, /*AllowWrappers=*/false);
5688}
5689
5691 return isAMDGPUNamedBarrierTypeImpl(this, /*AllowWrappers=*/true);
5692}
5693
5696 return false;
5697
5698 if (const auto *ptr = getAs<PointerType>())
5699 return ptr->getPointeeType()->hasSizedVLAType();
5700 if (const auto *ref = getAs<ReferenceType>())
5701 return ref->getPointeeType()->hasSizedVLAType();
5702 if (const ArrayType *arr = getAsArrayTypeUnsafe()) {
5703 if (isa<VariableArrayType>(arr) &&
5704 cast<VariableArrayType>(arr)->getSizeExpr())
5705 return true;
5706
5707 return arr->getElementType()->hasSizedVLAType();
5708 }
5709
5710 return false;
5711}
5712
5714 return HLSLAttributedResourceType::findHandleTypeOnResource(this) != nullptr;
5715}
5716
5718 const Type *Ty = getUnqualifiedDesugaredType();
5719 if (!Ty->isArrayType())
5720 return false;
5721 while (isa<ArrayType>(Ty))
5723 return Ty->isHLSLResourceRecord();
5724}
5725
5727 const Type *Ty = getUnqualifiedDesugaredType();
5728
5729 // check if it's a builtin type first
5730 if (Ty->isBuiltinType())
5731 return Ty->isHLSLBuiltinIntangibleType();
5732
5733 // unwrap arrays
5734 while (isa<ArrayType>(Ty))
5736
5737 const RecordType *RT =
5738 dyn_cast<RecordType>(Ty->getUnqualifiedDesugaredType());
5739 if (!RT)
5740 return false;
5741
5742 CXXRecordDecl *RD = RT->getAsCXXRecordDecl();
5743 assert(RD != nullptr &&
5744 "all HLSL structs and classes should be CXXRecordDecl");
5745 assert(RD->isCompleteDefinition() && "expecting complete type");
5746 return RD->isHLSLIntangible();
5747}
5748
5750 const Type *BaseTy = getBaseElementTypeUnsafe();
5751 if (const auto *RD =
5752 dyn_cast_or_null<CXXRecordDecl>(BaseTy->getAsRecordDecl())) {
5753 if (!RD->isHLSLBuiltinRecord() && RD->isStandardLayout())
5754 return true;
5755 }
5756 return false;
5757}
5758
5759QualType::DestructionKind QualType::isDestructedTypeImpl(QualType type) {
5760 switch (type.getObjCLifetime()) {
5764 break;
5765
5769 return DK_objc_weak_lifetime;
5770 }
5771
5772 if (const auto *RD = type->getBaseElementTypeUnsafe()->getAsRecordDecl()) {
5773 if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
5774 /// Check if this is a C++ object with a non-trivial destructor.
5775 if (CXXRD->hasDefinition() && !CXXRD->hasTrivialDestructor())
5776 return DK_cxx_destructor;
5777 } else {
5778 /// Check if this is a C struct that is non-trivial to destroy or an array
5779 /// that contains such a struct.
5782 }
5783 }
5784
5785 return DK_none;
5786}
5787
5788static bool
5790 llvm::SmallPtrSetImpl<const Decl *> &Seen) {
5791 if (const auto *Arr = Context.getAsArrayType(Ty))
5792 Ty = Context.getBaseElementType(Arr);
5793
5794 if (const auto *AttrTy = Ty->getAs<AttributedType>())
5795 Ty = AttrTy->getModifiedType();
5796
5797 assert(!Ty->isIncompleteType() &&
5798 "Incomplete types cannot be evaluated for laundering");
5799
5800 const auto *Record = Ty->getAsCXXRecordDecl();
5801 if (!Record)
5802 return false;
5803
5804 // We've already checked this type, or are in the process of checking it.
5805 if (!Seen.insert(Record).second)
5806 return false;
5807
5808 if (Record->isDynamicClass())
5809 return true;
5810
5811 for (FieldDecl *F : Record->fields()) {
5812 if (requiresBuiltinLaunderImpl(Context, F->getType(), Seen))
5813 return true;
5814 }
5815 return false;
5816}
5817
5820 return requiresBuiltinLaunderImpl(Context, *this, Seen);
5821}
5822
5825 *D2 = getQualifier().getAsRecordDecl();
5826 assert(!D1 == !D2);
5827 return D1 != D2 && D1->getCanonicalDecl() != D2->getCanonicalDecl();
5828}
5829
5830void MemberPointerType::Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
5831 const NestedNameSpecifier Qualifier,
5832 const CXXRecordDecl *Cls) {
5833 ID.AddPointer(Pointee.getAsOpaquePtr());
5834 Qualifier.Profile(ID);
5835 if (Cls)
5836 ID.AddPointer(Cls->getCanonicalDecl());
5837}
5838
5839CXXRecordDecl *MemberPointerType::getCXXRecordDecl() const {
5840 return dyn_cast<MemberPointerType>(getCanonicalTypeInternal())
5841 ->getQualifier()
5842 .getAsRecordDecl();
5843}
5844
5846 auto *RD = getCXXRecordDecl();
5847 if (!RD)
5848 return nullptr;
5849 return RD->getMostRecentDecl();
5850}
5851
5853 llvm::APSInt Val, unsigned Scale) {
5854 llvm::FixedPointSemantics FXSema(Val.getBitWidth(), Scale, Val.isSigned(),
5855 /*IsSaturated=*/false,
5856 /*HasUnsignedPadding=*/false);
5857 llvm::APFixedPoint(Val, FXSema).toString(Str);
5858}
5859
5860DeducedType::DeducedType(TypeClass TC, DeducedKind DK,
5861 QualType DeducedAsTypeOrCanon)
5862 : Type(TC, /*canon=*/DK == DeducedKind::Deduced
5863 ? DeducedAsTypeOrCanon.getCanonicalType()
5864 : DeducedAsTypeOrCanon,
5866 DeducedTypeBits.Kind = llvm::to_underlying(DK);
5867 switch (DK) {
5869 break;
5871 assert(!DeducedAsTypeOrCanon.isNull() && "Deduced type cannot be null");
5872 addDependence(DeducedAsTypeOrCanon->getDependence() &
5873 ~TypeDependence::VariablyModified);
5874 DeducedAsType = DeducedAsTypeOrCanon;
5875 break;
5877 addDependence(TypeDependence::UnexpandedPack);
5878 [[fallthrough]];
5880 addDependence(TypeDependence::DependentInstantiation);
5881 break;
5882 }
5883 assert(getDeducedKind() == DK && "DeducedKind does not match the type state");
5884}
5885
5886AutoType::AutoType(DeducedKind DK, QualType DeducedAsTypeOrCanon,
5887 AutoTypeKeyword Keyword, TemplateName TypeConstraintConcept,
5888 ArrayRef<TemplateArgument> TypeConstraintArgs)
5889 : DeducedType(Auto, DK, DeducedAsTypeOrCanon) {
5890 AutoTypeBits.Keyword = llvm::to_underlying(Keyword);
5891 AutoTypeBits.NumArgs = TypeConstraintArgs.size();
5892 this->TypeConstraintConcept = TypeConstraintConcept;
5893 assert(!TypeConstraintConcept.isNull() || AutoTypeBits.NumArgs == 0);
5894 if (!TypeConstraintConcept.isNull()) {
5895 assert(TypeConstraintConcept.isConceptName() &&
5896 "type-constraint does not name a concept");
5897
5898 auto Dep = toTypeDependence(TypeConstraintConcept.getDependence());
5899
5900 auto *ArgBuffer =
5901 const_cast<TemplateArgument *>(getTypeConstraintArguments().data());
5902 for (const TemplateArgument &Arg : TypeConstraintArgs) {
5903 Dep |= toTypeDependence(Arg.getDependence());
5904 new (ArgBuffer++) TemplateArgument(Arg);
5905 }
5906 // A deduced AutoType only syntactically depends on its constraints.
5907 if (DK == DeducedKind::Deduced)
5908 Dep = toSyntacticDependence(Dep);
5909 addDependence(Dep);
5910 }
5911}
5912
5913void AutoType::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
5916 ArrayRef<TemplateArgument> Arguments) {
5917 DeducedType::Profile(ID, DK, Deduced);
5918 ID.AddInteger(llvm::to_underlying(Keyword));
5919 CD.Profile(ID);
5920 for (const TemplateArgument &Arg : Arguments)
5921 Arg.Profile(ID, Context);
5922}
5923
5924void AutoType::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
5925 Profile(ID, Context, getDeducedKind(), getDeducedType(), getKeyword(),
5926 getTypeConstraintConcept(), getTypeConstraintArguments());
5927}
5928
5930 switch (kind()) {
5931 case Kind::NonBlocking:
5932 return Kind::Blocking;
5933 case Kind::Blocking:
5934 return Kind::NonBlocking;
5936 return Kind::Allocating;
5937 case Kind::Allocating:
5938 return Kind::NonAllocating;
5939 }
5940 llvm_unreachable("unknown effect kind");
5941}
5942
5943StringRef FunctionEffect::name() const {
5944 switch (kind()) {
5945 case Kind::NonBlocking:
5946 return "nonblocking";
5948 return "nonallocating";
5949 case Kind::Blocking:
5950 return "blocking";
5951 case Kind::Allocating:
5952 return "allocating";
5953 }
5954 llvm_unreachable("unknown effect kind");
5955}
5956
5958 const Decl &Callee, FunctionEffectKindSet CalleeFX) const {
5959 switch (kind()) {
5961 case Kind::NonBlocking: {
5962 for (FunctionEffect Effect : CalleeFX) {
5963 // nonblocking/nonallocating cannot call allocating.
5964 if (Effect.kind() == Kind::Allocating)
5965 return Effect;
5966 // nonblocking cannot call blocking.
5967 if (kind() == Kind::NonBlocking && Effect.kind() == Kind::Blocking)
5968 return Effect;
5969 }
5970 return std::nullopt;
5971 }
5972
5973 case Kind::Allocating:
5974 case Kind::Blocking:
5975 assert(0 && "effectProhibitingInference with non-inferable effect kind");
5976 break;
5977 }
5978 llvm_unreachable("unknown effect kind");
5979}
5980
5982 bool Direct, FunctionEffectKindSet CalleeFX) const {
5983 switch (kind()) {
5985 case Kind::NonBlocking: {
5986 const Kind CallerKind = kind();
5987 for (FunctionEffect Effect : CalleeFX) {
5988 const Kind EK = Effect.kind();
5989 // Does callee have same or stronger constraint?
5990 if (EK == CallerKind ||
5991 (CallerKind == Kind::NonAllocating && EK == Kind::NonBlocking)) {
5992 return false; // no diagnostic
5993 }
5994 }
5995 return true; // warning
5996 }
5997 case Kind::Allocating:
5998 case Kind::Blocking:
5999 return false;
6000 }
6001 llvm_unreachable("unknown effect kind");
6002}
6003
6004// =====
6005
6007 Conflicts &Errs) {
6008 FunctionEffect::Kind NewOppositeKind = NewEC.Effect.oppositeKind();
6009 Expr *NewCondition = NewEC.Cond.getCondition();
6010
6011 // The index at which insertion will take place; default is at end
6012 // but we might find an earlier insertion point.
6013 unsigned InsertIdx = Effects.size();
6014 unsigned Idx = 0;
6015 for (const FunctionEffectWithCondition &EC : *this) {
6016 // Note about effects with conditions: They are considered distinct from
6017 // those without conditions; they are potentially unique, redundant, or
6018 // in conflict, but we can't tell which until the condition is evaluated.
6019 if (EC.Cond.getCondition() == nullptr && NewCondition == nullptr) {
6020 if (EC.Effect.kind() == NewEC.Effect.kind()) {
6021 // There is no condition, and the effect kind is already present,
6022 // so just fail to insert the new one (creating a duplicate),
6023 // and return success.
6024 return true;
6025 }
6026
6027 if (EC.Effect.kind() == NewOppositeKind) {
6028 Errs.push_back({EC, NewEC});
6029 return false;
6030 }
6031 }
6032
6033 if (NewEC.Effect.kind() < EC.Effect.kind() && InsertIdx > Idx)
6034 InsertIdx = Idx;
6035
6036 ++Idx;
6037 }
6038
6039 if (NewCondition || !Conditions.empty()) {
6040 if (Conditions.empty() && !Effects.empty())
6041 Conditions.resize(Effects.size());
6042 Conditions.insert(Conditions.begin() + InsertIdx,
6043 NewEC.Cond.getCondition());
6044 }
6045 Effects.insert(Effects.begin() + InsertIdx, NewEC.Effect);
6046 return true;
6047}
6048
6050 for (const auto &Item : Set)
6051 insert(Item, Errs);
6052 return Errs.empty();
6053}
6054
6056 FunctionEffectsRef RHS) {
6059
6060 // We could use std::set_intersection but that would require expanding the
6061 // container interface to include push_back, making it available to clients
6062 // who might fail to maintain invariants.
6063 auto IterA = LHS.begin(), EndA = LHS.end();
6064 auto IterB = RHS.begin(), EndB = RHS.end();
6065
6066 auto FEWCLess = [](const FunctionEffectWithCondition &LHS,
6067 const FunctionEffectWithCondition &RHS) {
6068 return std::tuple(LHS.Effect, uintptr_t(LHS.Cond.getCondition())) <
6069 std::tuple(RHS.Effect, uintptr_t(RHS.Cond.getCondition()));
6070 };
6071
6072 while (IterA != EndA && IterB != EndB) {
6073 FunctionEffectWithCondition A = *IterA;
6074 FunctionEffectWithCondition B = *IterB;
6075 if (FEWCLess(A, B))
6076 ++IterA;
6077 else if (FEWCLess(B, A))
6078 ++IterB;
6079 else {
6080 Result.insert(A, Errs);
6081 ++IterA;
6082 ++IterB;
6083 }
6084 }
6085
6086 // Insertion shouldn't be able to fail; that would mean both input
6087 // sets contained conflicts.
6088 assert(Errs.empty() && "conflict shouldn't be possible in getIntersection");
6089
6090 return Result;
6091}
6092
6095 Conflicts &Errs) {
6096 // Optimize for either of the two sets being empty (very common).
6097 if (LHS.empty())
6098 return FunctionEffectSet(RHS);
6099
6100 FunctionEffectSet Combined(LHS);
6101 Combined.insert(RHS, Errs);
6102 return Combined;
6103}
6104
6105namespace clang {
6106
6107raw_ostream &operator<<(raw_ostream &OS,
6108 const FunctionEffectWithCondition &CFE) {
6109 OS << CFE.Effect.name();
6110 if (Expr *E = CFE.Cond.getCondition()) {
6111 OS << '(';
6112 E->dump();
6113 OS << ')';
6114 }
6115 return OS;
6116}
6117
6118} // namespace clang
6119
6120LLVM_DUMP_METHOD void FunctionEffectsRef::dump(llvm::raw_ostream &OS) const {
6121 OS << "Effects{";
6122 llvm::interleaveComma(*this, OS);
6123 OS << "}";
6124}
6125
6126LLVM_DUMP_METHOD void FunctionEffectSet::dump(llvm::raw_ostream &OS) const {
6127 FunctionEffectsRef(*this).dump(OS);
6128}
6129
6130LLVM_DUMP_METHOD void FunctionEffectKindSet::dump(llvm::raw_ostream &OS) const {
6131 OS << "Effects{";
6132 llvm::interleaveComma(*this, OS);
6133 OS << "}";
6134}
6135
6139 assert(llvm::is_sorted(FX) && "effects should be sorted");
6140 assert((Conds.empty() || Conds.size() == FX.size()) &&
6141 "effects size should match conditions size");
6142 return FunctionEffectsRef(FX, Conds);
6143}
6144
6146 std::string Result(Effect.name().str());
6147 if (Cond.getCondition() != nullptr)
6148 Result += "(expr)";
6149 return Result;
6150}
6151
6153HLSLAttributedResourceType::computeDependence(QualType Contained,
6154 const Attributes &Attrs) {
6155 TypeDependence Deps = TypeDependence::None;
6156 if (!Contained.isNull())
6157 Deps |= Contained->getDependence();
6158 if (Attrs.SampleCountExpr)
6159 Deps |= toTypeDependence(Attrs.SampleCountExpr->getDependence());
6160 return Deps;
6161}
6162
6163HLSLAttributedResourceType::HLSLAttributedResourceType(QualType Wrapped,
6164 QualType Contained,
6165 const Attributes &Attrs)
6166 : Type(HLSLAttributedResource, QualType(),
6167 computeDependence(Contained, Attrs)),
6168 WrappedType(Wrapped), ContainedType(Contained), Attrs(Attrs) {}
6169
6170void HLSLAttributedResourceType::Profile(llvm::FoldingSetNodeID &ID,
6171 const ASTContext &Ctx,
6172 QualType Wrapped, QualType Contained,
6173 const Attributes &Attrs) {
6174 ID.AddPointer(Wrapped.getAsOpaquePtr());
6175 ID.AddPointer(Contained.getAsOpaquePtr());
6176 ID.AddInteger(static_cast<uint32_t>(Attrs.ResourceClass));
6177 ID.AddInteger(static_cast<uint32_t>(Attrs.ResourceDimension));
6178 ID.AddBoolean(Attrs.IsROV);
6179 ID.AddBoolean(Attrs.RawBuffer);
6180 ID.AddBoolean(Attrs.IsCounter);
6181 ID.AddBoolean(Attrs.IsArray);
6182 ID.AddBoolean(Attrs.SampleCountExpr != nullptr);
6183 if (Attrs.SampleCountExpr)
6184 Attrs.SampleCountExpr->Profile(ID, Ctx, /*Canonical=*/true);
6185}
6186
6187const HLSLAttributedResourceType *
6188HLSLAttributedResourceType::findHandleTypeOnResource(const Type *RT) {
6189 // If the type RT is an HLSL resource class, the first field must
6190 // be the resource handle of type HLSLAttributedResourceType
6191 const clang::Type *Ty = RT->getUnqualifiedDesugaredType();
6192 if (const RecordDecl *RD = Ty->getAsCXXRecordDecl()) {
6193 if (!RD->fields().empty()) {
6194 const auto &FirstFD = RD->fields().begin();
6195 return dyn_cast<HLSLAttributedResourceType>(
6196 FirstFD->getType().getTypePtr());
6197 }
6198 }
6199 return nullptr;
6200}
6201
6202StringRef PredefinedSugarType::getName(Kind KD) {
6203 switch (KD) {
6204 case Kind::SizeT:
6205 return "__size_t";
6206 case Kind::SignedSizeT:
6207 return "__signed_size_t";
6208 case Kind::PtrdiffT:
6209 return "__ptrdiff_t";
6210 }
6211 llvm_unreachable("unexpected kind");
6212}
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:4900
#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:4302
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:5669
static bool requiresBuiltinLaunderImpl(const ASTContext &Context, QualType Ty, llvm::SmallPtrSetImpl< const Decl * > &Seen)
Definition Type.cpp:5789
TypePropertyCache< Private > Cache
Definition Type.cpp:5092
static bool isTriviallyCopyableTypeImpl(const QualType &type, const ASTContext &Context, bool IsCopyConstructible)
Definition Type.cpp:3040
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:5094
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:926
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:971
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:4279
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:3622
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:4332
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:2137
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
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:6130
bool insert(const FunctionEffectWithCondition &NewEC, Conflicts &Errs)
Definition Type.cpp:6006
SmallVector< Conflict > Conflicts
Definition TypeBase.h:5516
static FunctionEffectSet getIntersection(FunctionEffectsRef LHS, FunctionEffectsRef RHS)
Definition Type.cpp:6055
void dump(llvm::raw_ostream &OS) const
Definition Type.cpp:6126
static FunctionEffectSet getUnion(FunctionEffectsRef LHS, FunctionEffectsRef RHS, Conflicts &Errs)
Definition Type.cpp:6093
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:5981
StringRef name() const
The description printed in diagnostics, e.g. 'nonblocking'.
Definition Type.cpp:5943
Kind oppositeKind() const
Return the opposite kind, for effects which have opposites.
Definition Type.cpp:5929
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:5957
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:6120
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:6137
iterator end() const
Definition TypeBase.h:5387
bool hasDependentExceptionSpec() const
Return whether this function has a dependent exception spec.
Definition Type.cpp:4092
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:4146
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:4237
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:4113
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:4104
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:3847
bool getCFIUncheckedCalleeAttr() const
Determine whether this is a function prototype that includes the cfi_unchecked_callee attribute.
Definition Type.cpp:3841
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:5210
LinkageInfo getTypeLinkageAndVisibility(const Type *T)
Definition Type.cpp:5312
LinkageInfo getDeclLinkageAndVisibility(const NamedDecl *D)
Definition Decl.cpp:1629
static LinkageInfo external()
Definition Visibility.h:72
Linkage getLinkage() const
Definition Visibility.h:88
void merge(LinkageInfo other)
Merge both linkage and visibility.
Definition Visibility.h:137
QualType desugar() const
Definition Type.cpp:4406
QualType getModifiedType() const
Return this attributed type's modified type with no qualifiers attached to it.
Definition Type.cpp:4408
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:5823
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:5845
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:3092
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:3176
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type.
Definition Type.cpp:3825
@ 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:3149
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:3098
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:3143
bool isTrivialType(const ASTContext &Context) const
Return true if this is a trivial type per (C++0x [basic.types]p9)
Definition Type.cpp:2982
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:3215
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:2926
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:3168
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:3190
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:3199
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:3172
QualType getNonPackExpansionType() const
Remove an outer pack expansion type (if any) from this type.
Definition Type.cpp:3818
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:3371
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:5818
bool isWrapType() const
Returns true if it is a OverflowBehaviorType of Wrap kind.
Definition Type.cpp:3182
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:2914
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:3235
@ 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:4982
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:4249
bool operator==(const TypeCoupledDeclRefInfo &Other) const
Definition Type.cpp:4254
void * getOpaqueValue() const
Definition Type.cpp:4251
TypeCoupledDeclRefInfo(ValueDecl *D=nullptr, bool Deref=false)
D is to a declaration referenced by the argument of attribute.
Definition Type.cpp:4243
unsigned getInt() const
Definition Type.cpp:4250
void setFromOpaqueValue(void *V)
Definition Type.cpp:4258
bool isSugared() const
Returns whether this type directly provides sugar.
Definition Type.cpp:4435
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:4420
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:4437
The type-property cache.
Definition Type.cpp:5047
static void ensure(const Type *T)
Definition Type.cpp:5057
static CachedProperties get(QualType T)
Definition Type.cpp:5049
static CachedProperties get(const Type *T)
Definition Type.cpp:5051
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:2789
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:5302
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:2415
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:2735
QualType getRVVEltType(const ASTContext &Ctx) const
Returns the representative type for the element of an RVV builtin type.
Definition Type.cpp:2897
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:3239
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
Definition Type.cpp:2392
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:2483
bool isIntegralOrUnscopedEnumerationType() const
Determine whether this type is an integral or unscoped enumeration type.
Definition Type.cpp:2299
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:3430
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:2645
bool isArrayType() const
Definition TypeBase.h:8914
bool isCharType() const
Definition Type.cpp:2319
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:5637
CXXRecordDecl * castAsCXXRecordDecl() const
Definition Type.h:36
bool isArithmeticType() const
Definition Type.cpp:2550
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:2795
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:5726
bool isEnumeralType() const
Definition TypeBase.h:8946
void addDependence(TypeDependence D)
Definition TypeBase.h:2436
bool isObjCNSObjectType() const
Definition Type.cpp:5597
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:2335
bool isSizelessBuiltinType() const
Definition Type.cpp:2751
bool isAMDGPUNamedBarrierTypeOrWrapper() const
Check if the type is the AMDGPU named barrier type/a RecordType of a named barrier wrapper,...
Definition Type.cpp:5690
bool isCUDADeviceBuiltinSurfaceType() const
Check if the type is the CUDA device builtin surface type.
Definition Type.cpp:5652
bool isSveVLSBuiltinType() const
Determines if this is a sizeless type supported by the 'arm_sve_vector_bits' type attribute,...
Definition Type.cpp:2829
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
Definition Type.cpp:2282
bool isElaboratedTypeSpecifier() const
Determine wither this type is a C++ elaborated-type-specifier.
Definition Type.cpp:3590
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:3439
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:5321
bool hasUnsignedIntegerRepresentation() const
Determine whether this type has an unsigned integer representation of some sort, e....
Definition Type.cpp:2504
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition Type.cpp:2355
bool isExtVectorBoolType() const
Definition TypeBase.h:8962
bool isWebAssemblyExternrefType() const
Check if this is a WebAssembly Externref Type.
Definition Type.cpp:2773
bool canHaveNullability(bool ResultIfUnknown=true) const
Determine whether the given type can have a nullability specifier applied to it, i....
Definition Type.cpp:5338
QualType getSveEltType(const ASTContext &Ctx) const
Returns the representative type for the element of an SVE builtin type.
Definition Type.cpp:2866
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:3318
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:2631
bool isCARCBridgableType() const
Determine whether the given type T is a "bridgeable" C type.
Definition Type.cpp:5642
bool isSignableIntegerType(const ASTContext &Ctx) const
Definition Type.cpp:5533
RecordDecl * castAsRecordDecl() const
Definition Type.h:48
TypeBitfields TypeBits
Definition TypeBase.h:2376
bool isChar16Type() const
Definition Type.cpp:2341
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:2582
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g....
Definition Type.cpp:2436
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:3610
bool isWebAssemblyTableType() const
Returns true if this is a WebAssembly table type: either an array of reference types,...
Definition Type.cpp:2779
@ 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:5749
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:2347
bool isStandardLayoutType() const
Test if this type is a standard-layout type.
Definition Type.cpp:3334
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:2312
bool isStdByteType() const
Definition Type.cpp:3449
UnresolvedUsingBitfields UnresolvedUsingBits
Definition TypeBase.h:2384
bool isCUDADeviceBuiltinTextureType() const
Check if the type is the CUDA device builtin texture type.
Definition Type.cpp:5661
bool isBlockCompatibleObjCPointerType(ASTContext &ctx) const
Definition Type.cpp:5539
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:5628
bool isHLSLResourceRecord() const
Definition Type.cpp:5713
EnumDecl * getAsEnumDecl() const
Retrieves the EnumDecl this type refers to.
Definition Type.h:53
bool isObjCIndirectLifetimeType() const
Definition Type.cpp:5614
bool hasUnnamedOrLocalType() const
Whether this type is or contains a local or unnamed type.
Definition Type.cpp:5205
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:5572
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:3459
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition Type.cpp:2655
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:2525
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:5686
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:2879
bool isRealFloatingType() const
Floating point categories.
Definition Type.cpp:2533
bool isRVVSizelessBuiltinType() const
Returns true for RVV scalable vector types.
Definition Type.cpp:2816
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:5200
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:2517
const ObjCObjectType * getAsObjCInterfaceType() const
Definition Type.cpp:2064
bool isWideCharType() const
Definition Type.cpp:2328
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:2460
bool isRealType() const
Definition Type.cpp:2539
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:5694
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:5578
bool isRecordType() const
Definition TypeBase.h:8942
bool isHLSLResourceRecordArray() const
Definition Type.cpp:5717
bool isObjCRetainableType() const
Definition Type.cpp:5609
bool isObjCIndependentClassType() const
Definition Type.cpp:5603
bool isUnionType() const
Definition Type.cpp:851
bool isSizelessVectorType() const
Returns true for all scalable vector types.
Definition Type.cpp:2791
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:5325
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:2854
bool isUnicodeCharacterType() const
Definition Type.cpp:2375
bool hasBooleanRepresentation() const
Determine whether this type has a boolean representation – i.e., it is a boolean type,...
Definition Type.cpp:2572
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:4375
bool typeMatchesDecl() const
Definition TypeBase.h:6400
Represents a dependent using declaration which was marked with typename.
Definition DeclCXX.h:4075
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3437
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:819
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:5555
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:555
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:5852
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:844
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)
@ Other
Other implicit parameter.
Definition Decl.h:1787
@ 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:6145
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:3569
static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag)
Converts a TagTypeKind into an elaborated type keyword.
Definition Type.cpp:3518
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition Type.cpp:3535
static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec)
Converts a type specifier (DeclSpec::TST) into a tag type kind.
Definition Type.cpp:3500
static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword)
Definition Type.cpp:3554
static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec)
Converts a type specifier (DeclSpec::TST) into an elaborated type keyword.
Definition Type.cpp:3481
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