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