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