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