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