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