diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/AST/ASTContext.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/AST/ASTContext.cpp | 223 |
1 files changed, 147 insertions, 76 deletions
diff --git a/contrib/llvm-project/clang/lib/AST/ASTContext.cpp b/contrib/llvm-project/clang/lib/AST/ASTContext.cpp index e4b3827b8714..682b71a3d686 100644 --- a/contrib/llvm-project/clang/lib/AST/ASTContext.cpp +++ b/contrib/llvm-project/clang/lib/AST/ASTContext.cpp @@ -739,8 +739,8 @@ canonicalizeImmediatelyDeclaredConstraint(const ASTContext &C, Expr *IDC, // template<typename... T> concept C = true; // template<C<int> T> struct S; -> constraint is C<{T, int}> NewConverted.push_back(ConstrainedType); - for (auto &Arg : OldConverted.front().pack_elements().drop_front(1)) - NewConverted.push_back(Arg); + llvm::append_range(NewConverted, + OldConverted.front().pack_elements().drop_front(1)); TemplateArgument NewPack(NewConverted); NewConverted.clear(); @@ -752,8 +752,7 @@ canonicalizeImmediatelyDeclaredConstraint(const ASTContext &C, Expr *IDC, "Unexpected first argument kind for immediately-declared " "constraint"); NewConverted.push_back(ConstrainedType); - for (auto &Arg : OldConverted.drop_front(1)) - NewConverted.push_back(Arg); + llvm::append_range(NewConverted, OldConverted.drop_front(1)); } Expr *NewIDC = ConceptSpecializationExpr::Create( C, CSE->getNamedConcept(), NewConverted, nullptr, @@ -888,7 +887,7 @@ ASTContext::getCanonicalTemplateTemplateParmDecl( TargetCXXABI::Kind ASTContext::getCXXABIKind() const { auto Kind = getTargetInfo().getCXXABI().getKind(); - return getLangOpts().CXXABI.getValueOr(Kind); + return getLangOpts().CXXABI.value_or(Kind); } CXXABI *ASTContext::createCXXABI(const TargetInfo &T) { @@ -973,7 +972,8 @@ static bool isAddrSpaceMapManglingEnabled(const TargetInfo &TI, ASTContext::ASTContext(LangOptions &LOpts, SourceManager &SM, IdentifierTable &idents, SelectorTable &sels, Builtin::Context &builtins, TranslationUnitKind TUKind) - : ConstantArrayTypes(this_()), FunctionProtoTypes(this_()), + : ConstantArrayTypes(this_(), ConstantArrayTypesLog2InitSize), + FunctionProtoTypes(this_(), FunctionProtoTypesLog2InitSize), TemplateSpecializationTypes(this_()), DependentTemplateSpecializationTypes(this_()), AutoTypes(this_()), SubstTemplateTemplateParmPacks(this_()), @@ -1707,8 +1707,17 @@ const llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const { case BuiltinType::BFloat16: return Target->getBFloat16Format(); case BuiltinType::Float16: - case BuiltinType::Half: return Target->getHalfFormat(); + case BuiltinType::Half: + // For HLSL, when the native half type is disabled, half will be treat as + // float. + if (getLangOpts().HLSL) + if (getLangOpts().NativeHalfType) + return Target->getHalfFormat(); + else + return Target->getFloatFormat(); + else + return Target->getHalfFormat(); case BuiltinType::Float: return Target->getFloatFormat(); case BuiltinType::Double: return Target->getDoubleFormat(); case BuiltinType::Ibm128: @@ -1981,8 +1990,11 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { case Type::Vector: { const auto *VT = cast<VectorType>(T); TypeInfo EltInfo = getTypeInfo(VT->getElementType()); - Width = EltInfo.Width * VT->getNumElements(); - Align = Width; + Width = VT->isExtVectorBoolType() ? VT->getNumElements() + : EltInfo.Width * VT->getNumElements(); + // Enforce at least byte alignment. + Align = std::max<unsigned>(8, Width); + // If the alignment is not a power of 2, round up to the next power of 2. // This happens for non-power-of-2 length vectors. if (Align & (Align-1)) { @@ -2115,8 +2127,10 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { Align = Target->getLongFractAlign(); break; case BuiltinType::BFloat16: - Width = Target->getBFloat16Width(); - Align = Target->getBFloat16Align(); + if (Target->hasBFloat16Type()) { + Width = Target->getBFloat16Width(); + Align = Target->getBFloat16Align(); + } break; case BuiltinType::Float16: case BuiltinType::Half: @@ -2376,6 +2390,10 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { return getTypeInfo( cast<AttributedType>(T)->getEquivalentType().getTypePtr()); + case Type::BTFTagAttributed: + return getTypeInfo( + cast<BTFTagAttributedType>(T)->getWrappedType().getTypePtr()); + case Type::Atomic: { // Start with the base type information. TypeInfo Info = getTypeInfo(cast<AtomicType>(T)->getValueType()); @@ -2593,8 +2611,7 @@ void ASTContext::DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, if (const ObjCInterfaceDecl *SuperClass = OI->getSuperClass()) DeepCollectObjCIvars(SuperClass, false, Ivars); if (!leafClass) { - for (const auto *I : OI->ivars()) - Ivars.push_back(I); + llvm::append_range(Ivars, OI->ivars()); } else { auto *IDecl = const_cast<ObjCInterfaceDecl *>(OI); for (const ObjCIvarDecl *Iv = IDecl->all_declared_ivar_begin(); Iv; @@ -2676,7 +2693,11 @@ getSubobjectSizeInBits(const FieldDecl *Field, const ASTContext &Context) { if (!RD->isUnion()) return structHasUniqueObjectRepresentations(Context, RD); } - if (!Field->getType()->isReferenceType() && + + // A _BitInt type may not be unique if it has padding bits + // but if it is a bitfield the padding bits are not used. + bool IsBitIntType = Field->getType()->isBitIntType(); + if (!Field->getType()->isReferenceType() && !IsBitIntType && !Context.hasUniqueObjectRepresentations(Field->getType())) return llvm::None; @@ -2684,9 +2705,17 @@ getSubobjectSizeInBits(const FieldDecl *Field, const ASTContext &Context) { Context.toBits(Context.getTypeSizeInChars(Field->getType())); if (Field->isBitField()) { int64_t BitfieldSize = Field->getBitWidthValue(Context); - if (BitfieldSize > FieldSizeInBits) + if (IsBitIntType) { + if ((unsigned)BitfieldSize > + cast<BitIntType>(Field->getType())->getNumBits()) + return llvm::None; + } else if (BitfieldSize > FieldSizeInBits) { return llvm::None; + } FieldSizeInBits = BitfieldSize; + } else if (IsBitIntType && + !Context.hasUniqueObjectRepresentations(Field->getType())) { + return llvm::None; } return FieldSizeInBits; } @@ -2784,8 +2813,13 @@ bool ASTContext::hasUniqueObjectRepresentations(QualType Ty) const { return false; // All integrals and enums are unique. - if (Ty->isIntegralOrEnumerationType()) + if (Ty->isIntegralOrEnumerationType()) { + // Except _BitInt types that have padding bits. + if (const auto *BIT = dyn_cast<BitIntType>(Ty)) + return getTypeSize(BIT) == BIT->getNumBits(); + return true; + } // All other pointers are unique. if (Ty->isPointerType()) @@ -2808,8 +2842,7 @@ bool ASTContext::hasUniqueObjectRepresentations(QualType Ty) const { Optional<int64_t> StructSize = structHasUniqueObjectRepresentations(*this, Record); - return StructSize && - StructSize.getValue() == static_cast<int64_t>(getTypeSize(Ty)); + return StructSize && *StructSize == static_cast<int64_t>(getTypeSize(Ty)); } // FIXME: More cases to handle here (list by rsmith): @@ -4233,6 +4266,13 @@ static bool isCanonicalResultType(QualType T) { QualType ASTContext::getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const { + // FIXME: This assertion cannot be enabled (yet) because the ObjC rewriter + // functionality creates a function without a prototype regardless of + // language mode (so it makes them even in C++). Once the rewriter has been + // fixed, this assertion can be enabled again. + //assert(!LangOpts.requiresStrictPrototypes() && + // "strict prototypes are disabled"); + // Unique functions, to guarantee there is only one function of a particular // structure. llvm::FoldingSetNodeID ID; @@ -4436,8 +4476,7 @@ QualType ASTContext::getFunctionTypeInternal( QualType, SourceLocation, FunctionType::FunctionTypeExtraBitfields, FunctionType::ExceptionType, Expr *, FunctionDecl *, FunctionProtoType::ExtParameterInfo, Qualifiers>( - NumArgs, EPI.Variadic, - FunctionProtoType::hasExtraBitfields(EPI.ExceptionSpec.Type), + NumArgs, EPI.Variadic, EPI.requiresFunctionProtoTypeExtraBitfields(), ESH.NumExceptionType, ESH.NumExprPtr, ESH.NumFunctionDeclPtr, EPI.ExtParameterInfos ? NumArgs : 0, EPI.TypeQuals.hasNonFastQualifiers() ? 1 : 0); @@ -4682,6 +4721,26 @@ QualType ASTContext::getAttributedType(attr::Kind attrKind, return QualType(type, 0); } +QualType ASTContext::getBTFTagAttributedType(const BTFTypeTagAttr *BTFAttr, + QualType Wrapped) { + llvm::FoldingSetNodeID ID; + BTFTagAttributedType::Profile(ID, Wrapped, BTFAttr); + + void *InsertPos = nullptr; + BTFTagAttributedType *Ty = + BTFTagAttributedTypes.FindNodeOrInsertPos(ID, InsertPos); + if (Ty) + return QualType(Ty, 0); + + QualType Canon = getCanonicalType(Wrapped); + Ty = new (*this, TypeAlignment) BTFTagAttributedType(Canon, Wrapped, BTFAttr); + + Types.push_back(Ty); + BTFTagAttributedTypes.InsertNode(Ty, InsertPos); + + return QualType(Ty, 0); +} + /// Retrieve a substitution-result type. QualType ASTContext::getSubstTemplateTypeParmType(const TemplateTypeParmType *Parm, @@ -4826,11 +4885,10 @@ ASTContext::getTemplateSpecializationType(TemplateName Template, "No dependent template names here!"); // Look through qualified template names. if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) - Template = TemplateName(QTN->getTemplateDecl()); + Template = QTN->getUnderlyingTemplate(); bool IsTypeAlias = - Template.getAsTemplateDecl() && - isa<TypeAliasTemplateDecl>(Template.getAsTemplateDecl()); + isa_and_nonnull<TypeAliasTemplateDecl>(Template.getAsTemplateDecl()); QualType CanonType; if (!Underlying.isNull()) CanonType = getCanonicalType(Underlying); @@ -4882,7 +4940,7 @@ QualType ASTContext::getCanonicalTemplateSpecializationType( // Look through qualified template names. if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) - Template = TemplateName(QTN->getTemplateDecl()); + Template = TemplateName(QTN->getUnderlyingTemplate()); // Build the canonical template specialization type. TemplateName CanonTemplate = getCanonicalTemplateName(Template); @@ -6099,6 +6157,9 @@ ASTContext::getNameForTemplate(TemplateName Name, return DeclarationNameInfo(subst->getParameterPack()->getDeclName(), NameLoc); } + case TemplateName::UsingTemplate: + return DeclarationNameInfo(Name.getAsUsingShadowDecl()->getDeclName(), + NameLoc); } llvm_unreachable("bad template name kind!"); @@ -6107,6 +6168,7 @@ ASTContext::getNameForTemplate(TemplateName Name, TemplateName ASTContext::getCanonicalTemplateName(const TemplateName &Name) const { switch (Name.getKind()) { + case TemplateName::UsingTemplate: case TemplateName::QualifiedTemplate: case TemplateName::Template: { TemplateDecl *Template = Name.getAsTemplateDecl(); @@ -6797,41 +6859,6 @@ static FloatingRank getFloatingRank(QualType T) { } } -/// getFloatingTypeOfSizeWithinDomain - Returns a real floating -/// point or a complex type (based on typeDomain/typeSize). -/// 'typeDomain' is a real floating point or complex type. -/// 'typeSize' is a real floating point or complex type. -QualType ASTContext::getFloatingTypeOfSizeWithinDomain(QualType Size, - QualType Domain) const { - FloatingRank EltRank = getFloatingRank(Size); - if (Domain->isComplexType()) { - switch (EltRank) { - case BFloat16Rank: llvm_unreachable("Complex bfloat16 is not supported"); - case Float16Rank: - case HalfRank: llvm_unreachable("Complex half is not supported"); - case Ibm128Rank: return getComplexType(Ibm128Ty); - case FloatRank: return getComplexType(FloatTy); - case DoubleRank: return getComplexType(DoubleTy); - case LongDoubleRank: return getComplexType(LongDoubleTy); - case Float128Rank: return getComplexType(Float128Ty); - } - } - - assert(Domain->isRealFloatingType() && "Unknown domain!"); - switch (EltRank) { - case Float16Rank: return HalfTy; - case BFloat16Rank: return BFloat16Ty; - case HalfRank: return HalfTy; - case FloatRank: return FloatTy; - case DoubleRank: return DoubleTy; - case LongDoubleRank: return LongDoubleTy; - case Float128Rank: return Float128Ty; - case Ibm128Rank: - return Ibm128Ty; - } - llvm_unreachable("getFloatingRank(): illegal value for rank"); -} - /// getFloatingTypeOrder - Compare the rank of the two specified floating /// point types, ignoring the domain of the type (i.e. 'double' == /// '_Complex double'). If LHS > RHS, return 1. If LHS == RHS, return 0. If @@ -8976,10 +9003,9 @@ TemplateName ASTContext::getAssumedTemplateName(DeclarationName Name) const { /// Retrieve the template name that represents a qualified /// template name such as \c std::vector. -TemplateName -ASTContext::getQualifiedTemplateName(NestedNameSpecifier *NNS, - bool TemplateKeyword, - TemplateDecl *Template) const { +TemplateName ASTContext::getQualifiedTemplateName(NestedNameSpecifier *NNS, + bool TemplateKeyword, + TemplateName Template) const { assert(NNS && "Missing nested-name-specifier in qualified template name"); // FIXME: Canonicalization? @@ -10294,7 +10320,16 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, if (RHS->isObjCIdType() && LHS->isBlockPointerType()) return RHS; } - + // Allow __auto_type to match anything; it merges to the type with more + // information. + if (const auto *AT = LHS->getAs<AutoType>()) { + if (!AT->isDeduced() && AT->isGNUAutoType()) + return RHS; + } + if (const auto *AT = RHS->getAs<AutoType>()) { + if (!AT->isDeduced() && AT->isGNUAutoType()) + return LHS; + } return {}; } @@ -11231,7 +11266,7 @@ QualType ASTContext::GetBuiltinType(unsigned Id, // We really shouldn't be making a no-proto type here. - if (ArgTypes.empty() && Variadic && !getLangOpts().CPlusPlus) + if (ArgTypes.empty() && Variadic && !getLangOpts().requiresStrictPrototypes()) return getFunctionNoProtoType(ResType, EI); FunctionProtoType::ExtProtoInfo EPI; @@ -11328,7 +11363,7 @@ static GVALinkage adjustGVALinkageForAttributes(const ASTContext &Context, // name between the host and device compilation which is the same for the // same compilation unit whereas different among different compilation // units. - if (Context.shouldExternalizeStaticVar(D)) + if (Context.shouldExternalize(D)) return GVA_StrongExternal; } return L; @@ -11683,9 +11718,11 @@ MangleContext *ASTContext::createDeviceMangleContext(const TargetInfo &T) { if (const auto *RD = dyn_cast<CXXRecordDecl>(ND)) return RD->getDeviceLambdaManglingNumber(); return llvm::None; - }); + }, + /*IsAux=*/true); case TargetCXXABI::Microsoft: - return MicrosoftMangleContext::create(*this, getDiagnostics()); + return MicrosoftMangleContext::create(*this, getDiagnostics(), + /*IsAux=*/true); } llvm_unreachable("Unsupported ABI"); } @@ -11729,6 +11766,8 @@ QualType ASTContext::getRealTypeForBitwidth(unsigned DestWidth, FloatModeKind Ty = getTargetInfo().getRealTypeByWidth(DestWidth, ExplicitType); switch (Ty) { + case FloatModeKind::Half: + return HalfTy; case FloatModeKind::Float: return FloatTy; case FloatModeKind::Double: @@ -11751,9 +11790,19 @@ void ASTContext::setManglingNumber(const NamedDecl *ND, unsigned Number) { MangleNumbers[ND] = Number; } -unsigned ASTContext::getManglingNumber(const NamedDecl *ND) const { +unsigned ASTContext::getManglingNumber(const NamedDecl *ND, + bool ForAuxTarget) const { auto I = MangleNumbers.find(ND); - return I != MangleNumbers.end() ? I->second : 1; + unsigned Res = I != MangleNumbers.end() ? I->second : 1; + // CUDA/HIP host compilation encodes host and device mangling numbers + // as lower and upper half of 32 bit integer. + if (LangOpts.CUDA && !LangOpts.CUDAIsDevice) { + Res = ForAuxTarget ? Res >> 16 : Res & 0xFFFF; + } else { + assert(!ForAuxTarget && "Only CUDA/HIP host compilation supports mangling " + "number for aux target"); + } + return Res > 1 ? Res : 1; } void ASTContext::setStaticLocalNumber(const VarDecl *VD, unsigned Number) { @@ -11852,7 +11901,7 @@ ASTContext::getPredefinedStringLiteralFromCache(StringRef Key) const { StringLiteral *&Result = StringLiteralCache[Key]; if (!Result) Result = StringLiteral::Create( - *this, Key, StringLiteral::Ascii, + *this, Key, StringLiteral::Ordinary, /*Pascal*/ false, getStringLiteralArrayType(CharTy, Key.size()), SourceLocation()); return Result; @@ -11875,6 +11924,23 @@ ASTContext::getMSGuidDecl(MSGuidDecl::Parts Parts) const { return New; } +UnnamedGlobalConstantDecl * +ASTContext::getUnnamedGlobalConstantDecl(QualType Ty, + const APValue &APVal) const { + llvm::FoldingSetNodeID ID; + UnnamedGlobalConstantDecl::Profile(ID, Ty, APVal); + + void *InsertPos; + if (UnnamedGlobalConstantDecl *Existing = + UnnamedGlobalConstantDecls.FindNodeOrInsertPos(ID, InsertPos)) + return Existing; + + UnnamedGlobalConstantDecl *New = + UnnamedGlobalConstantDecl::Create(*this, Ty, APVal); + UnnamedGlobalConstantDecls.InsertNode(New, InsertPos); + return New; +} + TemplateParamObjectDecl * ASTContext::getTemplateParamObjectDecl(QualType T, const APValue &V) const { assert(T->isRecordType() && "template param object of unexpected type"); @@ -11956,8 +12022,13 @@ uint64_t ASTContext::getTargetNullPointerValue(QualType QT) const { } unsigned ASTContext::getTargetAddressSpace(QualType T) const { - return T->isFunctionType() ? getTargetInfo().getProgramAddressSpace() - : getTargetAddressSpace(T.getQualifiers()); + // Return the address space for the type. If the type is a + // function type without an address space qualifier, the + // program address space is used. Otherwise, the target picks + // the best address space based on the type information + return T->isFunctionType() && !T.hasAddressSpace() + ? getTargetInfo().getProgramAddressSpace() + : getTargetAddressSpace(T.getQualifiers()); } unsigned ASTContext::getTargetAddressSpace(Qualifiers Q) const { @@ -12255,7 +12326,7 @@ operator<<(const StreamingDiagnostic &DB, return DB << "a prior #pragma section"; } -bool ASTContext::mayExternalizeStaticVar(const Decl *D) const { +bool ASTContext::mayExternalize(const Decl *D) const { bool IsStaticVar = isa<VarDecl>(D) && cast<VarDecl>(D)->getStorageClass() == SC_Static; bool IsExplicitDeviceVar = (D->hasAttr<CUDADeviceAttr>() && @@ -12272,8 +12343,8 @@ bool ASTContext::mayExternalizeStaticVar(const Decl *D) const { GVA_Internal); } -bool ASTContext::shouldExternalizeStaticVar(const Decl *D) const { - return mayExternalizeStaticVar(D) && +bool ASTContext::shouldExternalize(const Decl *D) const { + return mayExternalize(D) && (D->hasAttr<HIPManagedAttr>() || D->hasAttr<CUDAGlobalAttr>() || CUDADeviceVarODRUsedByHost.count(cast<VarDecl>(D))); } |