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