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