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