diff options
Diffstat (limited to 'clang/lib/AST/ASTContext.cpp')
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 106 |
1 files changed, 72 insertions, 34 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 2d85d72e5b8a..008b703d4c1a 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -2286,8 +2286,8 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { Align = toBits(Layout.getAlignment()); break; } - case Type::ExtInt: { - const auto *EIT = cast<ExtIntType>(T); + case Type::BitInt: { + const auto *EIT = cast<BitIntType>(T); Align = std::min(static_cast<unsigned>(std::max( getCharWidth(), llvm::PowerOf2Ceil(EIT->getNumBits()))), @@ -2349,6 +2349,9 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { case Type::ObjCTypeParam: return getTypeInfo(cast<ObjCTypeParamType>(T)->desugar().getTypePtr()); + case Type::Using: + return getTypeInfo(cast<UsingType>(T)->desugar().getTypePtr()); + case Type::Typedef: { const TypedefNameDecl *Typedef = cast<TypedefType>(T)->getDecl(); TypeInfo Info = getTypeInfo(Typedef->getUnderlyingType().getTypePtr()); @@ -3569,8 +3572,8 @@ QualType ASTContext::getVariableArrayDecayedType(QualType type) const { case Type::Auto: case Type::DeducedTemplateSpecialization: case Type::PackExpansion: - case Type::ExtInt: - case Type::DependentExtInt: + case Type::BitInt: + case Type::DependentBitInt: llvm_unreachable("type should never be variably-modified"); // These types can be variably-modified but should never need to @@ -4482,34 +4485,34 @@ QualType ASTContext::getWritePipeType(QualType T) const { return getPipeType(T, false); } -QualType ASTContext::getExtIntType(bool IsUnsigned, unsigned NumBits) const { +QualType ASTContext::getBitIntType(bool IsUnsigned, unsigned NumBits) const { llvm::FoldingSetNodeID ID; - ExtIntType::Profile(ID, IsUnsigned, NumBits); + BitIntType::Profile(ID, IsUnsigned, NumBits); void *InsertPos = nullptr; - if (ExtIntType *EIT = ExtIntTypes.FindNodeOrInsertPos(ID, InsertPos)) + if (BitIntType *EIT = BitIntTypes.FindNodeOrInsertPos(ID, InsertPos)) return QualType(EIT, 0); - auto *New = new (*this, TypeAlignment) ExtIntType(IsUnsigned, NumBits); - ExtIntTypes.InsertNode(New, InsertPos); + auto *New = new (*this, TypeAlignment) BitIntType(IsUnsigned, NumBits); + BitIntTypes.InsertNode(New, InsertPos); Types.push_back(New); return QualType(New, 0); } -QualType ASTContext::getDependentExtIntType(bool IsUnsigned, +QualType ASTContext::getDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr) const { assert(NumBitsExpr->isInstantiationDependent() && "Only good for dependent"); llvm::FoldingSetNodeID ID; - DependentExtIntType::Profile(ID, *this, IsUnsigned, NumBitsExpr); + DependentBitIntType::Profile(ID, *this, IsUnsigned, NumBitsExpr); void *InsertPos = nullptr; - if (DependentExtIntType *Existing = - DependentExtIntTypes.FindNodeOrInsertPos(ID, InsertPos)) + if (DependentBitIntType *Existing = + DependentBitIntTypes.FindNodeOrInsertPos(ID, InsertPos)) return QualType(Existing, 0); auto *New = new (*this, TypeAlignment) - DependentExtIntType(*this, IsUnsigned, NumBitsExpr); - DependentExtIntTypes.InsertNode(New, InsertPos); + DependentBitIntType(*this, IsUnsigned, NumBitsExpr); + DependentBitIntTypes.InsertNode(New, InsertPos); Types.push_back(New); return QualType(New, 0); @@ -4568,9 +4571,7 @@ QualType ASTContext::getTypeDeclTypeSlow(const TypeDecl *Decl) const { assert(Enum->isFirstDecl() && "enum has previous declaration"); return getEnumType(Enum); } else if (const auto *Using = dyn_cast<UnresolvedUsingTypenameDecl>(Decl)) { - Type *newType = new (*this, TypeAlignment) UnresolvedUsingType(Using); - Decl->TypeForDecl = newType; - Types.push_back(newType); + return getUnresolvedUsingType(Using); } else llvm_unreachable("TypeDecl without a type?"); @@ -4593,6 +4594,27 @@ QualType ASTContext::getTypedefType(const TypedefNameDecl *Decl, return QualType(newType, 0); } +QualType ASTContext::getUsingType(const UsingShadowDecl *Found, + QualType Underlying) const { + llvm::FoldingSetNodeID ID; + UsingType::Profile(ID, Found); + + void *InsertPos = nullptr; + UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos); + if (T) + return QualType(T, 0); + + assert(!Underlying.hasLocalQualifiers()); + assert(Underlying == getTypeDeclType(cast<TypeDecl>(Found->getTargetDecl()))); + QualType Canon = Underlying.getCanonicalType(); + + UsingType *NewType = + new (*this, TypeAlignment) UsingType(Found, Underlying, Canon); + Types.push_back(NewType); + UsingTypes.InsertNode(NewType, InsertPos); + return QualType(NewType, 0); +} + QualType ASTContext::getRecordType(const RecordDecl *Decl) const { if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); @@ -4619,6 +4641,22 @@ QualType ASTContext::getEnumType(const EnumDecl *Decl) const { return QualType(newType, 0); } +QualType ASTContext::getUnresolvedUsingType( + const UnresolvedUsingTypenameDecl *Decl) const { + if (Decl->TypeForDecl) + return QualType(Decl->TypeForDecl, 0); + + if (const UnresolvedUsingTypenameDecl *CanonicalDecl = + Decl->getCanonicalDecl()) + if (CanonicalDecl->TypeForDecl) + return QualType(Decl->TypeForDecl = CanonicalDecl->TypeForDecl, 0); + + Type *newType = new (*this, TypeAlignment) UnresolvedUsingType(Decl); + Decl->TypeForDecl = newType; + Types.push_back(newType); + return QualType(newType, 0); +} + QualType ASTContext::getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType) { @@ -6444,7 +6482,7 @@ unsigned ASTContext::getIntegerRank(const Type *T) const { // Results in this 'losing' to any type of the same size, but winning if // larger. - if (const auto *EIT = dyn_cast<ExtIntType>(T)) + if (const auto *EIT = dyn_cast<BitIntType>(T)) return 0 + (EIT->getNumBits() << 3); switch (cast<BuiltinType>(T)->getKind()) { @@ -7885,7 +7923,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string &S, return; case Type::Pipe: - case Type::ExtInt: + case Type::BitInt: #define ABSTRACT_TYPE(KIND, BASE) #define TYPE(KIND, BASE) #define DEPENDENT_TYPE(KIND, BASE) \ @@ -9234,7 +9272,7 @@ void getIntersectionOfProtocols(ASTContext &Context, // Remove any implied protocols from the list of inherited protocols. if (!ImpliedProtocols.empty()) { llvm::erase_if(IntersectionSet, [&](ObjCProtocolDecl *proto) -> bool { - return ImpliedProtocols.count(proto) > 0; + return ImpliedProtocols.contains(proto); }); } @@ -10101,12 +10139,12 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, assert(LHS != RHS && "Equivalent pipe types should have already been handled!"); return {}; - case Type::ExtInt: { - // Merge two ext-int types, while trying to preserve typedef info. - bool LHSUnsigned = LHS->castAs<ExtIntType>()->isUnsigned(); - bool RHSUnsigned = RHS->castAs<ExtIntType>()->isUnsigned(); - unsigned LHSBits = LHS->castAs<ExtIntType>()->getNumBits(); - unsigned RHSBits = RHS->castAs<ExtIntType>()->getNumBits(); + case Type::BitInt: { + // Merge two bit-precise int types, while trying to preserve typedef info. + bool LHSUnsigned = LHS->castAs<BitIntType>()->isUnsigned(); + bool RHSUnsigned = RHS->castAs<BitIntType>()->isUnsigned(); + unsigned LHSBits = LHS->castAs<BitIntType>()->getNumBits(); + unsigned RHSBits = RHS->castAs<BitIntType>()->getNumBits(); // Like unsigned/int, shouldn't have a type if they don't match. if (LHSUnsigned != RHSUnsigned) @@ -10256,7 +10294,7 @@ unsigned ASTContext::getIntWidth(QualType T) const { T = ET->getDecl()->getIntegerType(); if (T->isBooleanType()) return 1; - if(const auto *EIT = T->getAs<ExtIntType>()) + if (const auto *EIT = T->getAs<BitIntType>()) return EIT->getNumBits(); // For builtin types, just use the standard type sizing method return (unsigned)getTypeSize(T); @@ -10271,9 +10309,9 @@ QualType ASTContext::getCorrespondingUnsignedType(QualType T) const { return getVectorType(getCorrespondingUnsignedType(VTy->getElementType()), VTy->getNumElements(), VTy->getVectorKind()); - // For _ExtInt, return an unsigned _ExtInt with same width. - if (const auto *EITy = T->getAs<ExtIntType>()) - return getExtIntType(/*IsUnsigned=*/true, EITy->getNumBits()); + // For _BitInt, return an unsigned _BitInt with same width. + if (const auto *EITy = T->getAs<BitIntType>()) + return getBitIntType(/*IsUnsigned=*/true, EITy->getNumBits()); // For enums, get the underlying integer type of the enum, and let the general // integer type signchanging code handle it. @@ -10339,9 +10377,9 @@ QualType ASTContext::getCorrespondingSignedType(QualType T) const { return getVectorType(getCorrespondingSignedType(VTy->getElementType()), VTy->getNumElements(), VTy->getVectorKind()); - // For _ExtInt, return a signed _ExtInt with same width. - if (const auto *EITy = T->getAs<ExtIntType>()) - return getExtIntType(/*IsUnsigned=*/false, EITy->getNumBits()); + // For _BitInt, return a signed _BitInt with same width. + if (const auto *EITy = T->getAs<BitIntType>()) + return getBitIntType(/*IsUnsigned=*/false, EITy->getNumBits()); // For enums, get the underlying integer type of the enum, and let the general // integer type signchanging code handle it. |