diff --git a/a.out b/a.out new file mode 100755 index 0000000000000..f3921876e2c1f Binary files /dev/null and b/a.out differ diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 7cb93f3c5b050..c4e1bc112fe2a 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -50,7 +50,7 @@ static bool isDeclWithinFunction(const Decl *D) { return false; } -template +template static bool SubstQualifier(Sema &SemaRef, const DeclT *OldDecl, DeclT *NewDecl, const MultiLevelTemplateArgumentList &TemplateArgs) { if (!OldDecl->getQualifierLoc()) @@ -65,9 +65,8 @@ static bool SubstQualifier(Sema &SemaRef, const DeclT *OldDecl, DeclT *NewDecl, ? NewDecl->getLexicalDeclContext() : OldDecl->getLexicalDeclContext())); - NestedNameSpecifierLoc NewQualifierLoc - = SemaRef.SubstNestedNameSpecifierLoc(OldDecl->getQualifierLoc(), - TemplateArgs); + NestedNameSpecifierLoc NewQualifierLoc = SemaRef.SubstNestedNameSpecifierLoc( + OldDecl->getQualifierLoc(), TemplateArgs); if (!NewQualifierLoc) return true; @@ -121,8 +120,7 @@ static void instantiateDependentAlignedAttr( SmallVector Unexpanded; if (Aligned->isAlignmentExpr()) - S.collectUnexpandedParameterPacks(Aligned->getAlignmentExpr(), - Unexpanded); + S.collectUnexpandedParameterPacks(Aligned->getAlignmentExpr(), Unexpanded); else S.collectUnexpandedParameterPacks(Aligned->getAlignmentType()->getTypeLoc(), Unexpanded); @@ -262,8 +260,8 @@ static void sharedInstantiateConstructorDestructorAttr( } static Expr *instantiateDependentFunctionAttrCondition( - Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, - const Attr *A, Expr *OldCond, const Decl *Tmpl, FunctionDecl *New) { + Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const Attr *A, + Expr *OldCond, const Decl *Tmpl, FunctionDecl *New) { Expr *Cond = nullptr; { Sema::ContextRAII SwitchContext(S, New); @@ -400,7 +398,7 @@ static void instantiateOMPDeclareSimdDeclAttr( Simdlen = Subst(E); if (Attr.uniforms_size() > 0) { - for(auto *E : Attr.uniforms()) { + for (auto *E : Attr.uniforms()) { ExprResult Inst = Subst(E); if (Inst.isInvalid()) continue; @@ -1080,9 +1078,10 @@ static bool isRelevantAttr(Sema &S, const Decl *D, const Attr *A) { const FunctionDecl *FD = dyn_cast(D); switch (BA->getID()) { case Builtin::BIforward: - // Do not treat 'std::forward' as a builtin if it takes an rvalue reference - // type and returns an lvalue reference type. The library implementation - // will produce an error in this case; don't get in its way. + // Do not treat 'std::forward' as a builtin if it takes an rvalue + // reference type and returns an lvalue reference type. The library + // implementation will produce an error in this case; don't get in its + // way. if (FD && FD->getNumParams() >= 1 && FD->getParamDecl(0)->getType()->isRValueReferenceType() && FD->getReturnType()->isLValueReferenceType()) { @@ -1154,8 +1153,7 @@ void Sema::InstantiateAttrsForDecl( } } -static Sema::RetainOwnershipKind -attrToRetainOwnershipKind(const Attr *A) { +static Sema::RetainOwnershipKind attrToRetainOwnershipKind(const Attr *A) { switch (A->getKind()) { case clang::attr::CFConsumed: return Sema::RetainOwnershipKind::CF; @@ -1189,7 +1187,8 @@ void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, } if (const auto *AssumeAligned = dyn_cast(TmplAttr)) { - instantiateDependentAssumeAlignedAttr(*this, TemplateArgs, AssumeAligned, New); + instantiateDependentAssumeAlignedAttr(*this, TemplateArgs, AssumeAligned, + New); continue; } @@ -1370,7 +1369,7 @@ void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, if (const auto *SYCLIntelMaxConcurrency = dyn_cast(TmplAttr)) { instantiateSYCLIntelMaxConcurrencyAttr(*this, TemplateArgs, - SYCLIntelMaxConcurrency, New); + SYCLIntelMaxConcurrency, New); } if (const auto *SYCLIntelInitiationInterval = dyn_cast(TmplAttr)) { @@ -1546,7 +1545,7 @@ void Sema::InstantiateDefaultCtorDefaultArgs(CXXConstructorDecl *Ctor) { return; for (unsigned I = 0; I != NumParams; ++I) { (void)CheckCXXDefaultArgExpr(Attr->getLocation(), Ctor, - Ctor->getParamDecl(I)); + Ctor->getParamDecl(I)); CleanupVarDeclMarking(); } } @@ -1555,7 +1554,7 @@ void Sema::InstantiateDefaultCtorDefaultArgs(CXXConstructorDecl *Ctor) { /// instantiation. If this finds a previous declaration, then the previous /// declaration of the instantiation of D should be an instantiation of the /// result of this function. -template +template static DeclT *getPreviousDeclForInstantiation(DeclT *D) { DeclT *Result = D->getPreviousDecl(); @@ -1583,8 +1582,7 @@ Decl *TemplateDeclInstantiator::VisitHLSLRootSignatureDecl( llvm_unreachable("HLSL root signature declarations cannot be instantiated"); } -Decl * -TemplateDeclInstantiator::VisitPragmaCommentDecl(PragmaCommentDecl *D) { +Decl *TemplateDeclInstantiator::VisitPragmaCommentDecl(PragmaCommentDecl *D) { llvm_unreachable("pragma comment cannot be instantiated"); } @@ -1593,8 +1591,7 @@ Decl *TemplateDeclInstantiator::VisitPragmaDetectMismatchDecl( llvm_unreachable("pragma comment cannot be instantiated"); } -Decl * -TemplateDeclInstantiator::VisitExternCContextDecl(ExternCContextDecl *D) { +Decl *TemplateDeclInstantiator::VisitExternCContextDecl(ExternCContextDecl *D) { llvm_unreachable("extern \"C\" context cannot be instantiated"); } @@ -1612,8 +1609,7 @@ Decl *TemplateDeclInstantiator::VisitTemplateParamObjectDecl( llvm_unreachable("template parameter objects cannot be instantiated"); } -Decl * -TemplateDeclInstantiator::VisitLabelDecl(LabelDecl *D) { +Decl *TemplateDeclInstantiator::VisitLabelDecl(LabelDecl *D) { LabelDecl *Inst = LabelDecl::Create(SemaRef.Context, Owner, D->getLocation(), D->getIdentifier()); SemaRef.InstantiateAttrs(TemplateArgs, D, Inst, LateAttrs, StartingScope); @@ -1621,8 +1617,7 @@ TemplateDeclInstantiator::VisitLabelDecl(LabelDecl *D) { return Inst; } -Decl * -TemplateDeclInstantiator::VisitNamespaceDecl(NamespaceDecl *D) { +Decl *TemplateDeclInstantiator::VisitNamespaceDecl(NamespaceDecl *D) { llvm_unreachable("Namespaces cannot be instantiated"); } @@ -1984,16 +1979,11 @@ Decl *TemplateDeclInstantiator::VisitOpenACCRoutineDecl(OpenACCRoutineDecl *D) { return Res.getSingleDecl(); } -Decl * -TemplateDeclInstantiator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { - NamespaceAliasDecl *Inst - = NamespaceAliasDecl::Create(SemaRef.Context, Owner, - D->getNamespaceLoc(), - D->getAliasLoc(), - D->getIdentifier(), - D->getQualifierLoc(), - D->getTargetNameLoc(), - D->getNamespace()); +Decl *TemplateDeclInstantiator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { + NamespaceAliasDecl *Inst = NamespaceAliasDecl::Create( + SemaRef.Context, Owner, D->getNamespaceLoc(), D->getAliasLoc(), + D->getIdentifier(), D->getQualifierLoc(), D->getTargetNameLoc(), + D->getNamespace()); Owner->addDecl(Inst); return Inst; } @@ -2056,8 +2046,8 @@ Decl *TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D, } if (TypedefNameDecl *Prev = getPreviousDeclForInstantiation(D)) { - NamedDecl *InstPrev = SemaRef.FindInstantiatedDecl(D->getLocation(), Prev, - TemplateArgs); + NamedDecl *InstPrev = + SemaRef.FindInstantiatedDecl(D->getLocation(), Prev, TemplateArgs); if (!InstPrev) return nullptr; @@ -2127,12 +2117,12 @@ Decl *TemplateDeclInstantiator::InstantiateTypeAliasTemplateDecl( } TypeAliasDecl *AliasInst = cast_or_null( - InstantiateTypedefNameDecl(Pattern, /*IsTypeAlias=*/true)); + InstantiateTypedefNameDecl(Pattern, /*IsTypeAlias=*/true)); if (!AliasInst) return nullptr; - TypeAliasTemplateDecl *Inst - = TypeAliasTemplateDecl::Create(SemaRef.Context, Owner, D->getLocation(), + TypeAliasTemplateDecl *Inst = + TypeAliasTemplateDecl::Create(SemaRef.Context, Owner, D->getLocation(), D->getDeclName(), InstParams, AliasInst); AliasInst->setDescribedAliasTemplate(Inst); if (PrevAliasTemplate) @@ -2167,7 +2157,7 @@ Decl *TemplateDeclInstantiator::VisitBindingDecl(BindingDecl *D) { Decl *TemplateDeclInstantiator::VisitDecompositionDecl(DecompositionDecl *D) { // Transform the bindings first. // The transformed DD will have all of the concrete BindingDecls. - SmallVector NewBindings; + SmallVector NewBindings; BindingDecl *OldBindingPack = nullptr; for (auto *OldBD : D->bindings()) { Expr *BindingExpr = OldBD->getBinding(); @@ -2178,7 +2168,7 @@ Decl *TemplateDeclInstantiator::VisitDecompositionDecl(DecompositionDecl *D) { } NewBindings.push_back(cast(VisitBindingDecl(OldBD))); } - ArrayRef NewBindingArray = NewBindings; + ArrayRef NewBindingArray = NewBindings; auto *NewDD = cast_if_present( VisitVarDecl(D, /*InstantiatingVarTemplate=*/false, &NewBindingArray)); @@ -2209,9 +2199,10 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) { return VisitVarDecl(D, /*InstantiatingVarTemplate=*/false); } -Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D, - bool InstantiatingVarTemplate, - ArrayRef *Bindings) { +Decl * +TemplateDeclInstantiator::VisitVarDecl(VarDecl *D, + bool InstantiatingVarTemplate, + ArrayRef *Bindings) { // Do substitution on the type of the declaration TypeSourceInfo *TSI = SemaRef.SubstType( @@ -2314,8 +2305,9 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D, } } if (const auto *SYCLDevice = Var->getAttr()) { - if (!SemaRef.SYCL().isTypeDecoratedWithDeclAttribute( - Var->getType())) + if (!SemaRef.SYCL() + .isTypeDecoratedWithDeclAttribute( + Var->getType())) SemaRef.Diag(SYCLDevice->getLoc(), diag::err_sycl_attribute_not_device_global) << SYCLDevice; @@ -2333,8 +2325,8 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D, } Decl *TemplateDeclInstantiator::VisitAccessSpecDecl(AccessSpecDecl *D) { - AccessSpecDecl* AD - = AccessSpecDecl::Create(SemaRef.Context, D->getAccess(), Owner, + AccessSpecDecl *AD = + AccessSpecDecl::Create(SemaRef.Context, D->getAccess(), Owner, D->getAccessSpecifierLoc(), D->getColonLoc()); Owner->addHiddenDecl(AD); return AD; @@ -2373,8 +2365,7 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) { EnterExpressionEvaluationContext Unevaluated( SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); - ExprResult InstantiatedBitWidth - = SemaRef.SubstExpr(BitWidth, TemplateArgs); + ExprResult InstantiatedBitWidth = SemaRef.SubstExpr(BitWidth, TemplateArgs); if (InstantiatedBitWidth.isInvalid()) { Invalid = true; BitWidth = nullptr; @@ -2403,7 +2394,8 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) { // Keep track of where this decl came from. SemaRef.Context.setInstantiatedFromUnnamedFieldDecl(Field, D); } - if (CXXRecordDecl *Parent= dyn_cast(Field->getDeclContext())) { + if (CXXRecordDecl *Parent = + dyn_cast(Field->getDeclContext())) { if (Parent->isAnonymousStructOrUnion() && Parent->getRedeclContext()->isFunctionOrMethod()) SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Field); @@ -2433,7 +2425,7 @@ Decl *TemplateDeclInstantiator::VisitMSPropertyDecl(MSPropertyDecl *D) { if (TSI->getType()->isVariablyModifiedType()) { SemaRef.Diag(D->getLocation(), diag::err_property_is_variably_modified) - << D; + << D; Invalid = true; } else if (TSI->getType()->isInstantiationDependentType()) { TSI = SemaRef.SubstType(TSI, TemplateArgs, D->getLocation(), @@ -2461,8 +2453,7 @@ Decl *TemplateDeclInstantiator::VisitMSPropertyDecl(MSPropertyDecl *D) { TSI->getType(), TSI, D->getBeginLoc(), D->getGetterId(), D->getSetterId()); - SemaRef.InstantiateAttrs(TemplateArgs, D, Property, LateAttrs, - StartingScope); + SemaRef.InstantiateAttrs(TemplateArgs, D, Property, LateAttrs, StartingScope); if (Invalid) Property->setInvalidDecl(); @@ -2475,19 +2466,19 @@ Decl *TemplateDeclInstantiator::VisitMSPropertyDecl(MSPropertyDecl *D) { Decl *TemplateDeclInstantiator::VisitIndirectFieldDecl(IndirectFieldDecl *D) { NamedDecl **NamedChain = - new (SemaRef.Context)NamedDecl*[D->getChainingSize()]; + new (SemaRef.Context) NamedDecl *[D->getChainingSize()]; int i = 0; for (auto *PI : D->chain()) { - NamedDecl *Next = SemaRef.FindInstantiatedDecl(D->getLocation(), PI, - TemplateArgs); + NamedDecl *Next = + SemaRef.FindInstantiatedDecl(D->getLocation(), PI, TemplateArgs); if (!Next) return nullptr; NamedChain[i++] = Next; } - QualType T = cast(NamedChain[i-1])->getType(); + QualType T = cast(NamedChain[i - 1])->getType(); IndirectFieldDecl *IndirectField = IndirectFieldDecl::Create( SemaRef.Context, Owner, D->getLocation(), D->getIdentifier(), T, {NamedChain, D->getChainingSize()}); @@ -2575,11 +2566,12 @@ Decl *TemplateDeclInstantiator::VisitFriendDecl(FriendDecl *D) { // objects, with the most important detail being that the target // decl should almost certainly not be placed in Owner. Decl *NewND = Visit(ND); - if (!NewND) return nullptr; + if (!NewND) + return nullptr; FriendDecl *FD = - FriendDecl::Create(SemaRef.Context, Owner, D->getLocation(), - cast(NewND), D->getFriendLoc()); + FriendDecl::Create(SemaRef.Context, Owner, D->getLocation(), + cast(NewND), D->getFriendLoc()); FD->setAccess(AS_public); FD->setUnsupportedFriend(D->isUnsupportedFriend()); Owner->addDecl(FD); @@ -2593,8 +2585,8 @@ Decl *TemplateDeclInstantiator::VisitStaticAssertDecl(StaticAssertDecl *D) { EnterExpressionEvaluationContext Unevaluated( SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); - ExprResult InstantiatedAssertExpr - = SemaRef.SubstExpr(AssertExpr, TemplateArgs); + ExprResult InstantiatedAssertExpr = + SemaRef.SubstExpr(AssertExpr, TemplateArgs); if (InstantiatedAssertExpr.isInvalid()) return nullptr; @@ -2612,9 +2604,9 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) { EnumDecl *PrevDecl = nullptr; if (EnumDecl *PatternPrev = getPreviousDeclForInstantiation(D)) { NamedDecl *Prev = SemaRef.FindInstantiatedDecl(D->getLocation(), - PatternPrev, - TemplateArgs); - if (!Prev) return nullptr; + PatternPrev, TemplateArgs); + if (!Prev) + return nullptr; PrevDecl = cast(Prev); } @@ -2628,8 +2620,8 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) { // has been explicitly set by the user. Perform substitution on it before // moving on. SourceLocation UnderlyingLoc = TI->getTypeLoc().getBeginLoc(); - TypeSourceInfo *NewTI = SemaRef.SubstType(TI, TemplateArgs, UnderlyingLoc, - DeclarationName()); + TypeSourceInfo *NewTI = + SemaRef.SubstType(TI, TemplateArgs, UnderlyingLoc, DeclarationName()); if (!NewTI || SemaRef.CheckEnumUnderlyingType(NewTI)) Enum->setIntegerType(SemaRef.Context.IntTy); else { @@ -2657,8 +2649,8 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) { ? SemaRef.Context.getPromotedIntegerType(UnderlyingType) : UnderlyingType); } else { - assert(!D->getIntegerType()->isDependentType() - && "Dependent type without type source info"); + assert(!D->getIntegerType()->isDependentType() && + "Dependent type without type source info"); Enum->setIntegerType(D->getIntegerType()); } } @@ -2677,7 +2669,8 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) { // If it did, mark the new tag as being associated with that typedef. if (TypedefNameDecl *TND = SemaRef.Context.getTypedefNameForUnnamedTagDecl(D)) SemaRef.Context.addTypedefNameForUnnamedTagDecl(Enum, TND); - if (SubstQualifier(D, Enum)) return nullptr; + if (SubstQualifier(D, Enum)) + return nullptr; Owner->addDecl(Enum); EnumDecl *Def = D->getDefinition(); @@ -2687,9 +2680,8 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) { // declarations. if (TypeSourceInfo *TI = Def->getIntegerTypeSourceInfo()) { SourceLocation UnderlyingLoc = TI->getTypeLoc().getBeginLoc(); - QualType DefnUnderlying = - SemaRef.SubstType(TI->getType(), TemplateArgs, - UnderlyingLoc, DeclarationName()); + QualType DefnUnderlying = SemaRef.SubstType( + TI->getType(), TemplateArgs, UnderlyingLoc, DeclarationName()); SemaRef.CheckEnumRedeclaration(Def->getLocation(), Def->isScoped(), DefnUnderlying, /*IsFixed=*/true, Enum); } @@ -2715,14 +2707,14 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) { return Enum; } -void TemplateDeclInstantiator::InstantiateEnumDefinition( - EnumDecl *Enum, EnumDecl *Pattern) { +void TemplateDeclInstantiator::InstantiateEnumDefinition(EnumDecl *Enum, + EnumDecl *Pattern) { Enum->startDefinition(); // Update the location to refer to the definition. Enum->setLocation(Pattern->getLocation()); - SmallVector Enumerators; + SmallVector Enumerators; EnumConstantDecl *LastEnumConst = nullptr; for (auto *EC : Pattern->enumerators()) { @@ -2743,10 +2735,9 @@ void TemplateDeclInstantiator::InstantiateEnumDefinition( isInvalid = true; } - EnumConstantDecl *EnumConst - = SemaRef.CheckEnumConstant(Enum, LastEnumConst, - EC->getLocation(), EC->getIdentifier(), - Value.get()); + EnumConstantDecl *EnumConst = + SemaRef.CheckEnumConstant(Enum, LastEnumConst, EC->getLocation(), + EC->getIdentifier(), Value.get()); if (isInvalid) { if (EnumConst) @@ -2802,8 +2793,8 @@ Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) { // the new declaration in the appropriate context. NestedNameSpecifierLoc QualifierLoc = Pattern->getQualifierLoc(); if (QualifierLoc) { - QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc, - TemplateArgs); + QualifierLoc = + SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc, TemplateArgs); if (!QualifierLoc) return nullptr; } @@ -2830,11 +2821,11 @@ Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) { CXXScopeSpec SS; SS.Adopt(QualifierLoc); DC = SemaRef.computeDeclContext(SS); - if (!DC) return nullptr; + if (!DC) + return nullptr; } else { - DC = SemaRef.FindInstantiatedContext(Pattern->getLocation(), - Pattern->getDeclContext(), - TemplateArgs); + DC = SemaRef.FindInstantiatedContext( + Pattern->getLocation(), Pattern->getDeclContext(), TemplateArgs); } // Look for a previous declaration of the template in the owning @@ -2865,10 +2856,10 @@ Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) { RecordInst->setQualifierInfo(QualifierLoc); SemaRef.InstantiateAttrsForDecl(TemplateArgs, Pattern, RecordInst, LateAttrs, - StartingScope); + StartingScope); - ClassTemplateDecl *Inst - = ClassTemplateDecl::Create(SemaRef.Context, DC, D->getLocation(), + ClassTemplateDecl *Inst = + ClassTemplateDecl::Create(SemaRef.Context, DC, D->getLocation(), D->getIdentifier(), InstParams, RecordInst); RecordInst->setDescribedClassTemplate(Inst); @@ -2940,25 +2931,24 @@ Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) { return Inst; } -Decl * -TemplateDeclInstantiator::VisitClassTemplatePartialSpecializationDecl( - ClassTemplatePartialSpecializationDecl *D) { +Decl *TemplateDeclInstantiator::VisitClassTemplatePartialSpecializationDecl( + ClassTemplatePartialSpecializationDecl *D) { ClassTemplateDecl *ClassTemplate = D->getSpecializedTemplate(); // Lookup the already-instantiated declaration in the instantiation // of the class template and return that. - DeclContext::lookup_result Found - = Owner->lookup(ClassTemplate->getDeclName()); + DeclContext::lookup_result Found = + Owner->lookup(ClassTemplate->getDeclName()); if (Found.empty()) return nullptr; - ClassTemplateDecl *InstClassTemplate - = dyn_cast(Found.front()); + ClassTemplateDecl *InstClassTemplate = + dyn_cast(Found.front()); if (!InstClassTemplate) return nullptr; - if (ClassTemplatePartialSpecializationDecl *Result - = InstClassTemplate->findPartialSpecInstantiatedFromMember(D)) + if (ClassTemplatePartialSpecializationDecl *Result = + InstClassTemplate->findPartialSpecInstantiatedFromMember(D)) return Result; return InstantiateClassTemplatePartialSpecialization(InstClassTemplate, D); @@ -2988,13 +2978,14 @@ Decl *TemplateDeclInstantiator::VisitVarTemplateDecl(VarTemplateDecl *D) { VarDecl *VarInst = cast_or_null(VisitVarDecl(Pattern, /*InstantiatingVarTemplate=*/true)); - if (!VarInst) return nullptr; + if (!VarInst) + return nullptr; DeclContext *DC = Owner; - VarTemplateDecl *Inst = VarTemplateDecl::Create( - SemaRef.Context, DC, D->getLocation(), D->getIdentifier(), InstParams, - VarInst); + VarTemplateDecl *Inst = + VarTemplateDecl::Create(SemaRef.Context, DC, D->getLocation(), + D->getIdentifier(), InstParams, VarInst); VarInst->setDescribedVarTemplate(Inst); Inst->setPreviousDecl(PrevVarTemplate); @@ -3061,20 +3052,19 @@ TemplateDeclInstantiator::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { FunctionDecl *Instantiated = nullptr; if (CXXMethodDecl *DMethod = dyn_cast(D->getTemplatedDecl())) - Instantiated = cast_or_null(VisitCXXMethodDecl(DMethod, - InstParams)); + Instantiated = + cast_or_null(VisitCXXMethodDecl(DMethod, InstParams)); else - Instantiated = cast_or_null(VisitFunctionDecl( - D->getTemplatedDecl(), - InstParams)); + Instantiated = cast_or_null( + VisitFunctionDecl(D->getTemplatedDecl(), InstParams)); if (!Instantiated) return nullptr; // Link the instantiated function template declaration to the function // template from which it was instantiated. - FunctionTemplateDecl *InstTemplate - = Instantiated->getDescribedFunctionTemplate(); + FunctionTemplateDecl *InstTemplate = + Instantiated->getDescribedFunctionTemplate(); InstTemplate->setAccess(D->getAccess()); assert(InstTemplate && "VisitFunctionDecl/CXXMethodDecl didn't create a template!"); @@ -3102,9 +3092,9 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) { CXXRecordDecl *PrevDecl = nullptr; if (CXXRecordDecl *PatternPrev = getPreviousDeclForInstantiation(D)) { NamedDecl *Prev = SemaRef.FindInstantiatedDecl(D->getLocation(), - PatternPrev, - TemplateArgs); - if (!Prev) return nullptr; + PatternPrev, TemplateArgs); + if (!Prev) + return nullptr; PrevDecl = cast(Prev); } @@ -3127,7 +3117,7 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) { return nullptr; SemaRef.InstantiateAttrsForDecl(TemplateArgs, D, Record, LateAttrs, - StartingScope); + StartingScope); // FIXME: Check against AS_none is an ugly hack to work around the issue that // the tag decls introduced by friend class declarations don't have an access @@ -3203,10 +3193,9 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) { static QualType adjustFunctionTypeForInstantiation(ASTContext &Context, FunctionDecl *D, TypeSourceInfo *TInfo) { - const FunctionProtoType *OrigFunc - = D->getType()->castAs(); - const FunctionProtoType *NewFunc - = TInfo->getType()->castAs(); + const FunctionProtoType *OrigFunc = D->getType()->castAs(); + const FunctionProtoType *NewFunc = + TInfo->getType()->castAs(); if (OrigFunc->getExtInfo() == NewFunc->getExtInfo()) return TInfo->getType(); @@ -3250,18 +3239,18 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl( ArrayRef Innermost = TemplateArgs.getInnermost(); void *InsertPos = nullptr; - FunctionDecl *SpecFunc - = FunctionTemplate->findSpecialization(Innermost, InsertPos); + FunctionDecl *SpecFunc = + FunctionTemplate->findSpecialization(Innermost, InsertPos); // If we already have a function template specialization, return it. if (SpecFunc) return SpecFunc; } - bool MergeWithParentScope = (TemplateParams != nullptr) || - Owner->isFunctionOrMethod() || - !(isa(Owner) && - cast(Owner)->isDefinedOutsideFunctionOrMethod()); + bool MergeWithParentScope = + (TemplateParams != nullptr) || Owner->isFunctionOrMethod() || + !(isa(Owner) && + cast(Owner)->isDefinedOutsideFunctionOrMethod()); LocalInstantiationScope Scope(SemaRef, MergeWithParentScope); ExplicitSpecifier InstantiatedExplicitSpecifier; @@ -3297,8 +3286,8 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl( NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc(); if (QualifierLoc) { - QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc, - TemplateArgs); + QualifierLoc = + SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc, TemplateArgs); if (!QualifierLoc) return nullptr; } @@ -3316,14 +3305,15 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl( CXXScopeSpec SS; SS.Adopt(QualifierLoc); DC = SemaRef.computeDeclContext(SS); - if (!DC) return nullptr; + if (!DC) + return nullptr; } else { DC = SemaRef.FindInstantiatedContext(D->getLocation(), D->getDeclContext(), TemplateArgs); } - DeclarationNameInfo NameInfo - = SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs); + DeclarationNameInfo NameInfo = + SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs); if (FunctionRewriteKind != RewriteKind::None) adjustForRewrite(FunctionRewriteKind, D, T, TInfo, NameInfo); @@ -3362,8 +3352,7 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl( if (!isFriend && D->isOutOfLine() && !D->isLocalExternDecl()) { assert(D->getDeclContext()->isFileContext()); LexicalDC = D->getDeclContext(); - } - else if (D->isLocalExternDecl()) { + } else if (D->isLocalExternDecl()) { LexicalDC = SemaRef.CurContext; } @@ -3396,27 +3385,26 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl( // which means substituting int for T, but leaving "f" as a friend function // template. // Build the function template itself. - FunctionTemplate = FunctionTemplateDecl::Create(SemaRef.Context, DC, - Function->getLocation(), - Function->getDeclName(), - TemplateParams, Function); + FunctionTemplate = FunctionTemplateDecl::Create( + SemaRef.Context, DC, Function->getLocation(), Function->getDeclName(), + TemplateParams, Function); Function->setDescribedFunctionTemplate(FunctionTemplate); FunctionTemplate->setLexicalDeclContext(LexicalDC); if (isFriend && D->isThisDeclarationADefinition()) { FunctionTemplate->setInstantiatedFromMemberTemplate( - D->getDescribedFunctionTemplate()); + D->getDescribedFunctionTemplate()); } } else if (FunctionTemplate && SemaRef.CodeSynthesisContexts.back().Kind != Sema::CodeSynthesisContext::BuildingDeductionGuides) { // Record this function template specialization. ArrayRef Innermost = TemplateArgs.getInnermost(); - Function->setFunctionTemplateSpecialization(FunctionTemplate, - TemplateArgumentList::CreateCopy(SemaRef.Context, - Innermost), - /*InsertPos=*/nullptr); + Function->setFunctionTemplateSpecialization( + FunctionTemplate, + TemplateArgumentList::CreateCopy(SemaRef.Context, Innermost), + /*InsertPos=*/nullptr); } else if (FunctionRewriteKind == RewriteKind::None) { if (isFriend && D->isThisDeclarationADefinition()) { // Do not connect the friend to the template unless it's actually a @@ -3492,8 +3480,7 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl( ExplicitArgs)) return nullptr; - if (SemaRef.CheckFunctionTemplateSpecialization(Function, - &ExplicitArgs, + if (SemaRef.CheckFunctionTemplateSpecialization(Function, &ExplicitArgs, Previous)) Function->setInvalidDecl(); @@ -3515,8 +3502,8 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl( // effect this has is to remove declarations found in inline namespaces // for friend declarations with unqualified names. if (isFriend && !QualifierLoc) { - SemaRef.FilterLookupForScope(Previous, DC, /*Scope=*/ nullptr, - /*ConsiderLinkage=*/ true, + SemaRef.FilterLookupForScope(Previous, DC, /*Scope=*/nullptr, + /*ConsiderLinkage=*/true, QualifierLoc.hasQualifier()); } } @@ -3538,14 +3525,15 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl( for (ParmVarDecl *PVD : Function->parameters()) { if (!PVD->hasDefaultArg()) continue; - if (SemaRef.SubstDefaultArgument(D->getInnerLocStart(), PVD, TemplateArgs)) { + if (SemaRef.SubstDefaultArgument(D->getInnerLocStart(), PVD, + TemplateArgs)) { // If substitution fails, the default argument is set to a // RecoveryExpr that wraps the uninstantiated default argument so // that downstream diagnostics are omitted. Expr *UninstExpr = PVD->getUninstantiatedDefaultArg(); ExprResult ErrorResult = SemaRef.CreateRecoveryExpr( - UninstExpr->getBeginLoc(), UninstExpr->getEndLoc(), - { UninstExpr }, UninstExpr->getType()); + UninstExpr->getBeginLoc(), UninstExpr->getEndLoc(), {UninstExpr}, + UninstExpr->getType()); if (ErrorResult.isUsable()) PVD->setDefaultArg(ErrorResult.get()); } @@ -3573,7 +3561,8 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl( // instantiation. // FIXME: If this is a friend function template definition, we should check // to see if any specializations have been used. - if (isFriend && D->isThisDeclarationADefinition() && Function->isUsed(false)) { + if (isFriend && D->isThisDeclarationADefinition() && + Function->isUsed(false)) { if (MemberSpecializationInfo *MSInfo = Function->getMemberSpecializationInfo()) { if (MSInfo->getPointOfInstantiation().isInvalid()) { @@ -3618,8 +3607,8 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl( ArrayRef Innermost = TemplateArgs.getInnermost(); void *InsertPos = nullptr; - FunctionDecl *SpecFunc - = FunctionTemplate->findSpecialization(Innermost, InsertPos); + FunctionDecl *SpecFunc = + FunctionTemplate->findSpecialization(Innermost, InsertPos); // If we already have a function template specialization, return it. if (SpecFunc) @@ -3632,9 +3621,10 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl( else isFriend = (D->getFriendObjectKind() != Decl::FOK_None); - bool MergeWithParentScope = (TemplateParams != nullptr) || - !(isa(Owner) && - cast(Owner)->isDefinedOutsideFunctionOrMethod()); + bool MergeWithParentScope = + (TemplateParams != nullptr) || + !(isa(Owner) && + cast(Owner)->isDefinedOutsideFunctionOrMethod()); LocalInstantiationScope Scope(SemaRef, MergeWithParentScope); Sema::LambdaScopeForCallOperatorInstantiationRAII LambdaScope( @@ -3712,8 +3702,8 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl( NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc(); if (QualifierLoc) { - QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc, - TemplateArgs); + QualifierLoc = + SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc, TemplateArgs); if (!QualifierLoc) return nullptr; } @@ -3729,17 +3719,17 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl( return nullptr; } else { DC = SemaRef.FindInstantiatedContext(D->getLocation(), - D->getDeclContext(), - TemplateArgs); + D->getDeclContext(), TemplateArgs); } - if (!DC) return nullptr; + if (!DC) + return nullptr; } CXXRecordDecl *Record = cast(DC); AssociatedConstraint TrailingRequiresClause = D->getTrailingRequiresClause(); - DeclarationNameInfo NameInfo - = SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs); + DeclarationNameInfo NameInfo = + SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs); if (FunctionRewriteKind != RewriteKind::None) adjustForRewrite(FunctionRewriteKind, D, T, TInfo, NameInfo); @@ -3800,10 +3790,9 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl( // We are instantiating the member template "f" within X, which means // substituting int for T, but leaving "f" as a member function template. // Build the function template itself. - FunctionTemplate = FunctionTemplateDecl::Create(SemaRef.Context, Record, - Method->getLocation(), - Method->getDeclName(), - TemplateParams, Method); + FunctionTemplate = FunctionTemplateDecl::Create( + SemaRef.Context, Record, Method->getLocation(), Method->getDeclName(), + TemplateParams, Method); if (isFriend) { FunctionTemplate->setLexicalDeclContext(Owner); FunctionTemplate->setObjectOfFriendDecl(); @@ -3813,10 +3802,10 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl( } else if (FunctionTemplate) { // Record this function template specialization. ArrayRef Innermost = TemplateArgs.getInnermost(); - Method->setFunctionTemplateSpecialization(FunctionTemplate, - TemplateArgumentList::CreateCopy(SemaRef.Context, - Innermost), - /*InsertPos=*/nullptr); + Method->setFunctionTemplateSpecialization( + FunctionTemplate, + TemplateArgumentList::CreateCopy(SemaRef.Context, Innermost), + /*InsertPos=*/nullptr); } else if (!isFriend && FunctionRewriteKind == RewriteKind::None) { // Record that this is an instantiation of a member function. Method->setInstantiationOfMemberFunction(D, TSK_ImplicitInstantiation); @@ -3889,8 +3878,7 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl( ExplicitArgs)) return nullptr; - if (SemaRef.CheckFunctionTemplateSpecialization(Method, - &ExplicitArgs, + if (SemaRef.CheckFunctionTemplateSpecialization(Method, &ExplicitArgs, Previous)) Method->setInvalidDecl(); @@ -3931,8 +3919,8 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl( // that downstream diagnostics are omitted. Expr *UninstExpr = Params[P]->getUninstantiatedDefaultArg(); ExprResult ErrorResult = SemaRef.CreateRecoveryExpr( - UninstExpr->getBeginLoc(), UninstExpr->getEndLoc(), - { UninstExpr }, UninstExpr->getType()); + UninstExpr->getBeginLoc(), UninstExpr->getEndLoc(), {UninstExpr}, + UninstExpr->getType()); if (ErrorResult.isUsable()) Params[P]->setDefaultArg(ErrorResult.get()); } @@ -3993,11 +3981,11 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl( if (FunctionTemplate) { // do nothing - // Don't hide a (potentially) valid declaration with an invalid one. + // Don't hide a (potentially) valid declaration with an invalid one. } else if (Method->isInvalidDecl() && !Previous.empty()) { // do nothing - // Otherwise, check access to friends and make them visible. + // Otherwise, check access to friends and make them visible. } else if (isFriend) { // We only need to re-check access for methods which we didn't // manage to match during parsing. @@ -4006,9 +3994,9 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl( Record->makeDeclVisibleInContext(Method); - // Otherwise, add the declaration. We don't need to do this for - // class-scope specializations because we'll have matched them with - // the appropriate template. + // Otherwise, add the declaration. We don't need to do this for + // class-scope specializations because we'll have matched them with + // the appropriate template. } else { Owner->addDecl(Method); } @@ -4048,8 +4036,8 @@ Decl *TemplateDeclInstantiator::VisitParmVarDecl(ParmVarDecl *D) { /*ExpectParameterPack=*/false); } -Decl *TemplateDeclInstantiator::VisitTemplateTypeParmDecl( - TemplateTypeParmDecl *D) { +Decl * +TemplateDeclInstantiator::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { assert(D->getTypeForDecl()->isTemplateTypeParmType()); UnsignedOrNone NumExpanded = std::nullopt; @@ -4116,7 +4104,7 @@ Decl *TemplateDeclInstantiator::VisitTemplateTypeParmDecl( } Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl( - NonTypeTemplateParmDecl *D) { + NonTypeTemplateParmDecl *D) { // Substitute into the type of the non-type template parameter. TypeLoc TL = D->getTypeSourceInfo()->getTypeLoc(); SmallVector ExpandedParameterPackTypesAsWritten; @@ -4199,9 +4187,8 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl( // We cannot fully expand the pack expansion now, so substitute into the // pattern and create a new pack expansion type. Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, std::nullopt); - TypeSourceInfo *NewPattern = SemaRef.SubstType(Pattern, TemplateArgs, - D->getLocation(), - D->getDeclName()); + TypeSourceInfo *NewPattern = SemaRef.SubstType( + Pattern, TemplateArgs, D->getLocation(), D->getDeclName()); if (!NewPattern) return nullptr; @@ -4279,8 +4266,7 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl( } static void collectUnexpandedParameterPacks( - Sema &S, - TemplateParameterList *Params, + Sema &S, TemplateParameterList *Params, SmallVectorImpl &Unexpanded) { for (const auto &P : *Params) { if (P->isTemplateParameterPack()) @@ -4294,13 +4280,12 @@ static void collectUnexpandedParameterPacks( } } -Decl * -TemplateDeclInstantiator::VisitTemplateTemplateParmDecl( - TemplateTemplateParmDecl *D) { +Decl *TemplateDeclInstantiator::VisitTemplateTemplateParmDecl( + TemplateTemplateParmDecl *D) { // Instantiate the template parameter list of the template template parameter. TemplateParameterList *TempParams = D->getTemplateParameters(); TemplateParameterList *InstParams; - SmallVector ExpandedParams; + SmallVector ExpandedParams; bool IsExpandedParameterPack = false; @@ -4309,11 +4294,11 @@ TemplateDeclInstantiator::VisitTemplateTemplateParmDecl( // expansion of template parameters. Substitute into each of the expanded // parameters. ExpandedParams.reserve(D->getNumExpansionTemplateParameters()); - for (unsigned I = 0, N = D->getNumExpansionTemplateParameters(); - I != N; ++I) { + for (unsigned I = 0, N = D->getNumExpansionTemplateParameters(); I != N; + ++I) { LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true); TemplateParameterList *Expansion = - SubstTemplateParams(D->getExpansionTemplateParameters(I)); + SubstTemplateParams(D->getExpansionTemplateParameters(I)); if (!Expansion) return nullptr; ExpandedParams.push_back(Expansion); @@ -4413,13 +4398,10 @@ Decl *TemplateDeclInstantiator::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { // Using directives are never dependent (and never contain any types or // expressions), so they require no explicit instantiation work. - UsingDirectiveDecl *Inst - = UsingDirectiveDecl::Create(SemaRef.Context, Owner, D->getLocation(), - D->getNamespaceKeyLocation(), - D->getQualifierLoc(), - D->getIdentLocation(), - D->getNominatedNamespace(), - D->getCommonAncestor()); + UsingDirectiveDecl *Inst = UsingDirectiveDecl::Create( + SemaRef.Context, Owner, D->getLocation(), D->getNamespaceKeyLocation(), + D->getQualifierLoc(), D->getIdentLocation(), D->getNominatedNamespace(), + D->getCommonAncestor()); // Add the using directive to its declaration context // only if this is not a function or method. @@ -4486,9 +4468,8 @@ Decl *TemplateDeclInstantiator::VisitUsingDecl(UsingDecl *D) { // template struct t; // Here, in using s1::f1, s1 refers to t::s1; // we need to substitute for t::s1. - NestedNameSpecifierLoc QualifierLoc - = SemaRef.SubstNestedNameSpecifierLoc(D->getQualifierLoc(), - TemplateArgs); + NestedNameSpecifierLoc QualifierLoc = + SemaRef.SubstNestedNameSpecifierLoc(D->getQualifierLoc(), TemplateArgs); if (!QualifierLoc) return nullptr; @@ -4507,11 +4488,9 @@ Decl *TemplateDeclInstantiator::VisitUsingDecl(UsingDecl *D) { LookupResult Prev(SemaRef, NameInfo, Sema::LookupUsingDeclName, RedeclarationKind::ForVisibleRedeclaration); - UsingDecl *NewUD = UsingDecl::Create(SemaRef.Context, Owner, - D->getUsingLoc(), - QualifierLoc, - NameInfo, - D->hasTypename()); + UsingDecl *NewUD = + UsingDecl::Create(SemaRef.Context, Owner, D->getUsingLoc(), QualifierLoc, + NameInfo, D->hasTypename()); CXXScopeSpec SS; SS.Adopt(QualifierLoc); @@ -4520,9 +4499,8 @@ Decl *TemplateDeclInstantiator::VisitUsingDecl(UsingDecl *D) { SemaRef.LookupQualifiedName(Prev, Owner); // Check for invalid redeclarations. - if (SemaRef.CheckUsingDeclRedeclaration(D->getUsingLoc(), - D->hasTypename(), SS, - D->getLocation(), Prev)) + if (SemaRef.CheckUsingDeclRedeclaration(D->getUsingLoc(), D->hasTypename(), + SS, D->getLocation(), Prev)) NewUD->setInvalidDecl(); } @@ -4637,7 +4615,7 @@ Decl *TemplateDeclInstantiator::instantiateUnresolvedUsingDecl( } // Instantiate the slices of this pack and build a UsingPackDecl. - SmallVector Expansions; + SmallVector Expansions; for (unsigned I = 0; I != *NumExpansions; ++I) { Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, I); Decl *Slice = instantiateUnresolvedUsingDecl(D, true); @@ -4659,17 +4637,16 @@ Decl *TemplateDeclInstantiator::instantiateUnresolvedUsingDecl( UnresolvedUsingTypenameDecl *TD = dyn_cast(D); SourceLocation TypenameLoc = TD ? TD->getTypenameLoc() : SourceLocation(); - NestedNameSpecifierLoc QualifierLoc - = SemaRef.SubstNestedNameSpecifierLoc(D->getQualifierLoc(), - TemplateArgs); + NestedNameSpecifierLoc QualifierLoc = + SemaRef.SubstNestedNameSpecifierLoc(D->getQualifierLoc(), TemplateArgs); if (!QualifierLoc) return nullptr; CXXScopeSpec SS; SS.Adopt(QualifierLoc); - DeclarationNameInfo NameInfo - = SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs); + DeclarationNameInfo NameInfo = + SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs); // Produce a pack expansion only if we're not instantiating a particular // slice of a pack expansion. @@ -4708,7 +4685,7 @@ Decl *TemplateDeclInstantiator::VisitUnresolvedUsingIfExistsDecl( } Decl *TemplateDeclInstantiator::VisitUsingPackDecl(UsingPackDecl *D) { - SmallVector Expansions; + SmallVector Expansions; for (auto *UD : D->expansions()) { if (NamedDecl *NewUD = SemaRef.FindInstantiatedDecl(D->getLocation(), UD, TemplateArgs)) @@ -4723,8 +4700,8 @@ Decl *TemplateDeclInstantiator::VisitUsingPackDecl(UsingPackDecl *D) { return NewD; } -Decl *TemplateDeclInstantiator::VisitOMPThreadPrivateDecl( - OMPThreadPrivateDecl *D) { +Decl * +TemplateDeclInstantiator::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { SmallVector Vars; for (auto *I : D->varlist()) { Expr *Var = SemaRef.SubstExpr(I, TemplateArgs).get(); @@ -5000,8 +4977,7 @@ Decl *TemplateDeclInstantiator::VisitRecordDecl(RecordDecl *D) { llvm_unreachable("There are only CXXRecordDecls in C++"); } -Decl * -TemplateDeclInstantiator::VisitClassTemplateSpecializationDecl( +Decl *TemplateDeclInstantiator::VisitClassTemplateSpecializationDecl( ClassTemplateSpecializationDecl *D) { // As a MS extension, we permit class-scope explicit specialization // of member class templates. @@ -5050,13 +5026,10 @@ TemplateDeclInstantiator::VisitClassTemplateSpecializationDecl( // Check whether we've already seen a conflicting instantiation of this // declaration (for instance, if there was a prior implicit instantiation). bool Ignored; - if (PrevDecl && - SemaRef.CheckSpecializationInstantiationRedecl(D->getLocation(), - D->getSpecializationKind(), - PrevDecl, - PrevDecl->getSpecializationKind(), - PrevDecl->getPointOfInstantiation(), - Ignored)) + if (PrevDecl && SemaRef.CheckSpecializationInstantiationRedecl( + D->getLocation(), D->getSpecializationKind(), PrevDecl, + PrevDecl->getSpecializationKind(), + PrevDecl->getPointOfInstantiation(), Ignored)) return nullptr; // If PrevDecl was a definition and D is also a definition, diagnose. @@ -5214,17 +5187,16 @@ TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl( return Var; } -Decl *TemplateDeclInstantiator::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) { +Decl * +TemplateDeclInstantiator::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) { llvm_unreachable("@defs is not supported in Objective-C++"); } Decl *TemplateDeclInstantiator::VisitFriendTemplateDecl(FriendTemplateDecl *D) { // FIXME: We need to be able to instantiate FriendTemplateDecls. unsigned DiagID = SemaRef.getDiagnostics().getCustomDiagID( - DiagnosticsEngine::Error, - "cannot instantiate %0 yet"); - SemaRef.Diag(D->getLocation(), DiagID) - << D->getDeclKindName(); + DiagnosticsEngine::Error, "cannot instantiate %0 yet"); + SemaRef.Diag(D->getLocation(), DiagID) << D->getDeclKindName(); return nullptr; } @@ -5255,9 +5227,8 @@ Decl *Sema::SubstDecl(Decl *D, DeclContext *Owner, return nullptr; Decl *SubstD; - runWithSufficientStackSpace(D->getLocation(), [&] { - SubstD = Instantiator.Visit(D); - }); + runWithSufficientStackSpace(D->getLocation(), + [&] { SubstD = Instantiator.Visit(D); }); return SubstD; } @@ -5357,10 +5328,9 @@ TemplateDeclInstantiator::SubstTemplateParams(TemplateParameterList *L) { Expr *InstRequiresClause = L->getRequiresClause(); - TemplateParameterList *InstL - = TemplateParameterList::Create(SemaRef.Context, L->getTemplateLoc(), - L->getLAngleLoc(), Params, - L->getRAngleLoc(), InstRequiresClause); + TemplateParameterList *InstL = TemplateParameterList::Create( + SemaRef.Context, L->getTemplateLoc(), L->getLAngleLoc(), Params, + L->getRAngleLoc(), InstRequiresClause); return InstL; } @@ -5386,8 +5356,8 @@ Sema::SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner, /// NULL to indicate an error. ClassTemplatePartialSpecializationDecl * TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization( - ClassTemplateDecl *ClassTemplate, - ClassTemplatePartialSpecializationDecl *PartialSpec) { + ClassTemplateDecl *ClassTemplate, + ClassTemplatePartialSpecializationDecl *PartialSpec) { // Create a local instantiation scope for this class template partial // specialization, which will contain the instantiations of the template // parameters. @@ -5402,8 +5372,8 @@ TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization( // Substitute into the template arguments of the class template partial // specialization. - const ASTTemplateArgumentListInfo *TemplArgInfo - = PartialSpec->getTemplateArgsAsWritten(); + const ASTTemplateArgumentListInfo *TemplArgInfo = + PartialSpec->getTemplateArgsAsWritten(); TemplateArgumentListInfo InstTemplateArgs(TemplArgInfo->LAngleLoc, TemplArgInfo->RAngleLoc); if (SemaRef.SubstTemplateArguments(TemplArgInfo->arguments(), TemplateArgs, @@ -5512,8 +5482,8 @@ TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization( // Substitute into the template arguments of the variable template partial // specialization. - const ASTTemplateArgumentListInfo *TemplArgInfo - = PartialSpec->getTemplateArgsAsWritten(); + const ASTTemplateArgumentListInfo *TemplArgInfo = + PartialSpec->getTemplateArgsAsWritten(); TemplateArgumentListInfo InstTemplateArgs(TemplArgInfo->LAngleLoc, TemplArgInfo->RAngleLoc); if (SemaRef.SubstTemplateArguments(TemplArgInfo->arguments(), TemplateArgs, @@ -5606,9 +5576,8 @@ TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization( return InstPartialSpec; } -TypeSourceInfo* -TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D, - SmallVectorImpl &Params) { +TypeSourceInfo *TemplateDeclInstantiator::SubstFunctionType( + FunctionDecl *D, SmallVectorImpl &Params) { TypeSourceInfo *OldTInfo = D->getTypeSourceInfo(); assert(OldTInfo && "substituting function without type source info"); assert(Params.empty() && "parameter vector is non-empty at start"); @@ -5643,9 +5612,8 @@ TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D, UnsignedOrNone NumArgumentsInExpansion = std::nullopt; if (OldParam->isParameterPack()) - NumArgumentsInExpansion = - SemaRef.getNumArgumentsInExpansion(OldParam->getType(), - TemplateArgs); + NumArgumentsInExpansion = SemaRef.getNumArgumentsInExpansion( + OldParam->getType(), TemplateArgs); if (!NumArgumentsInExpansion) { // Simple case: normal parameter, or a parameter pack that's // instantiated to a (still-dependent) parameter pack. @@ -5903,9 +5871,8 @@ void Sema::InstantiateExceptionSpec(SourceLocation PointOfInstantiation, /// declaration (New) from the corresponding fields of its template (Tmpl). /// /// \returns true if there was an error -bool -TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, - FunctionDecl *Tmpl) { +bool TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, + FunctionDecl *Tmpl) { New->setImplicit(Tmpl->isImplicit()); // Forward the mangling number from the template to the instantiated decl. @@ -5958,8 +5925,8 @@ TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, NewEST = EST_Unevaluated; // Mark the function has having an uninstantiated exception specification. - const FunctionProtoType *NewProto - = New->getType()->getAs(); + const FunctionProtoType *NewProto = + New->getType()->getAs(); assert(NewProto && "Template instantiation without function prototype?"); EPI = NewProto->getExtProtoInfo(); EPI.ExceptionSpec.Type = NewEST; @@ -5977,8 +5944,8 @@ TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, const FunctionDecl *Definition = Tmpl; Tmpl->isDefined(Definition); - SemaRef.InstantiateAttrs(TemplateArgs, Definition, New, - LateAttrs, StartingScope); + SemaRef.InstantiateAttrs(TemplateArgs, Definition, New, LateAttrs, + StartingScope); return false; } @@ -5988,9 +5955,8 @@ TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, /// (Tmpl). /// /// \returns true if there was an error -bool -TemplateDeclInstantiator::InitMethodInstantiation(CXXMethodDecl *New, - CXXMethodDecl *Tmpl) { +bool TemplateDeclInstantiator::InitMethodInstantiation(CXXMethodDecl *New, + CXXMethodDecl *Tmpl) { if (InitFunctionInstantiation(New, Tmpl)) return true; @@ -6050,8 +6016,7 @@ FunctionDecl *Sema::InstantiateFunctionDeclaration( } void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, - FunctionDecl *Function, - bool Recursive, + FunctionDecl *Function, bool Recursive, bool DefinitionRequired, bool AtEndOfTU) { if (Function->isInvalidDecl() || isa(Function)) @@ -6081,7 +6046,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, // instantiated friend declaration, attach the instantiated body to the // corresponding declaration of the function. assert(ExistingDefn->isThisDeclarationInstantiatedFromAFriendDefinition()); - Function = const_cast(ExistingDefn); + Function = const_cast(ExistingDefn); } #ifndef NDEBUG @@ -6154,8 +6119,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, } // Postpone late parsed template instantiations. - if (PatternDecl->isLateTemplateParsed() && - !LateTemplateParser) { + if (PatternDecl->isLateTemplateParsed() && !LateTemplateParser) { Function->setInstantiationIsPending(true); LateParsedInstantiations.push_back( std::make_pair(Function, PointOfInstantiation)); @@ -6188,8 +6152,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, // Call the LateTemplateParser callback if there is a need to late parse // a templated function definition. - if (!Pattern && PatternDecl->isLateTemplateParsed() && - LateTemplateParser) { + if (!Pattern && PatternDecl->isLateTemplateParsed() && LateTemplateParser) { // FIXME: Optimize to allow individual templates to be deserialized. if (PatternDecl->isFromASTFile()) ExternalSource->ReadLateParsedTemplates(LateParsedTemplateMap); @@ -6595,8 +6558,7 @@ void Sema::BuildVariableInstantiation( VarDecl *NewVar, VarDecl *OldVar, const MultiLevelTemplateArgumentList &TemplateArgs, LateInstantiatedAttrVec *LateAttrs, DeclContext *Owner, - LocalInstantiationScope *StartingScope, - bool InstantiatingVarTemplate, + LocalInstantiationScope *StartingScope, bool InstantiatingVarTemplate, VarTemplateSpecializationDecl *PrevDeclForVarTemplateSpecialization) { // Instantiating a partial specialization to produce a partial // specialization. @@ -6647,7 +6609,8 @@ void Sema::BuildVariableInstantiation( if (NewVar->isLocalExternDecl() && OldVar->getPreviousDecl() && (!OldVar->getPreviousDecl()->getDeclContext()->isDependentContext() || - OldVar->getPreviousDecl()->getDeclContext()==OldVar->getDeclContext())) { + OldVar->getPreviousDecl()->getDeclContext() == + OldVar->getDeclContext())) { // We have a previous declaration. Use that one, so we merge with the // right type. if (NamedDecl *NewPrev = FindInstantiatedDecl( @@ -6798,7 +6761,8 @@ void Sema::InstantiateVariableInitializer( void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, VarDecl *Var, bool Recursive, - bool DefinitionRequired, bool AtEndOfTU) { + bool DefinitionRequired, + bool AtEndOfTU) { if (Var->isInvalidDecl()) return; @@ -6886,8 +6850,7 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, // Warn about missing definition at the end of translation unit. if (AtEndOfTU && !getDiagnostics().hasErrorOccurred() && !getSourceManager().isInSystemHeader(PatternDecl->getBeginLoc())) { - Diag(PointOfInstantiation, diag::warn_var_template_missing) - << Var; + Diag(PointOfInstantiation, diag::warn_var_template_missing) << Var; Diag(PatternDecl->getLocation(), diag::note_forward_template_decl); if (getLangOpts().CPlusPlus11) Diag(PointOfInstantiation, diag::note_inst_declaration_hint) << Var; @@ -6900,9 +6863,9 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, // definitions should be visible within this instantiation. // FIXME: Produce diagnostics when Var->getInstantiatedFromStaticDataMember(). if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Var, - /*InstantiatedFromMember*/false, + /*InstantiatedFromMember*/ false, PatternDecl, Def, TSK, - /*Complain*/DefinitionRequired)) + /*Complain*/ DefinitionRequired)) return; // C++11 [temp.explicit]p10: @@ -6976,8 +6939,8 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, // provided inside the class. InstantiateVariableInitializer(Var, Def, TemplateArgs); } else if (!VarSpec) { - Var = cast_or_null(SubstDecl(Def, Var->getDeclContext(), - TemplateArgs)); + Var = cast_or_null( + SubstDecl(Def, Var->getDeclContext(), TemplateArgs)); } else if (Var->isStaticDataMember() && Var->getLexicalDeclContext()->isRecord()) { // We need to instantiate the definition of a static data member template, @@ -7005,10 +6968,10 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, VTSD->setTemplateArgsAsWritten(TemplateArgInfo); llvm::PointerUnion PatternPtr = - VarSpec->getSpecializedTemplateOrPartial(); + VarTemplatePartialSpecializationDecl *> + PatternPtr = VarSpec->getSpecializedTemplateOrPartial(); if (VarTemplatePartialSpecializationDecl *Partial = - PatternPtr.dyn_cast()) + PatternPtr.dyn_cast()) cast(Var)->setInstantiationOf( Partial, &VarSpec->getTemplateInstantiationArgs()); @@ -7037,12 +7000,11 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, GlobalInstantiations.perform(); } -void -Sema::InstantiateMemInitializers(CXXConstructorDecl *New, - const CXXConstructorDecl *Tmpl, - const MultiLevelTemplateArgumentList &TemplateArgs) { +void Sema::InstantiateMemInitializers( + CXXConstructorDecl *New, const CXXConstructorDecl *Tmpl, + const MultiLevelTemplateArgumentList &TemplateArgs) { - SmallVector NewInits; + SmallVector NewInits; bool AnyErrors = Tmpl->isInvalidDecl(); // Instantiate all the initializers. @@ -7086,20 +7048,18 @@ Sema::InstantiateMemInitializers(CXXConstructorDecl *New, } // Instantiate the base type. - TypeSourceInfo *BaseTInfo = SubstType(Init->getTypeSourceInfo(), - TemplateArgs, - Init->getSourceLocation(), - New->getDeclName()); + TypeSourceInfo *BaseTInfo = + SubstType(Init->getTypeSourceInfo(), TemplateArgs, + Init->getSourceLocation(), New->getDeclName()); if (!BaseTInfo) { AnyErrors = true; break; } // Build the initializer. - MemInitResult NewInit = BuildBaseInitializer(BaseTInfo->getType(), - BaseTInfo, TempInit.get(), - New->getParent(), - SourceLocation()); + MemInitResult NewInit = BuildBaseInitializer( + BaseTInfo->getType(), BaseTInfo, TempInit.get(), New->getParent(), + SourceLocation()); if (NewInit.isInvalid()) { AnyErrors = true; break; @@ -7121,10 +7081,9 @@ Sema::InstantiateMemInitializers(CXXConstructorDecl *New, MemInitResult NewInit; if (Init->isDelegatingInitializer() || Init->isBaseInitializer()) { - TypeSourceInfo *TInfo = SubstType(Init->getTypeSourceInfo(), - TemplateArgs, - Init->getSourceLocation(), - New->getDeclName()); + TypeSourceInfo *TInfo = + SubstType(Init->getTypeSourceInfo(), TemplateArgs, + Init->getSourceLocation(), New->getDeclName()); if (!TInfo) { AnyErrors = true; New->setInvalidDecl(); @@ -7135,13 +7094,12 @@ Sema::InstantiateMemInitializers(CXXConstructorDecl *New, NewInit = BuildBaseInitializer(TInfo->getType(), TInfo, TempInit.get(), New->getParent(), EllipsisLoc); else - NewInit = BuildDelegatingInitializer(TInfo, TempInit.get(), - cast(CurContext->getParent())); + NewInit = BuildDelegatingInitializer( + TInfo, TempInit.get(), + cast(CurContext->getParent())); } else if (Init->isMemberInitializer()) { FieldDecl *Member = cast_or_null(FindInstantiatedDecl( - Init->getMemberLocation(), - Init->getMember(), - TemplateArgs)); + Init->getMemberLocation(), Init->getMember(), TemplateArgs)); if (!Member) { AnyErrors = true; New->setInvalidDecl(); @@ -7151,10 +7109,9 @@ Sema::InstantiateMemInitializers(CXXConstructorDecl *New, NewInit = BuildMemberInitializer(Member, TempInit.get(), Init->getSourceLocation()); } else if (Init->isIndirectMemberInitializer()) { - IndirectFieldDecl *IndirectMember = - cast_or_null(FindInstantiatedDecl( - Init->getMemberLocation(), - Init->getIndirectMember(), TemplateArgs)); + IndirectFieldDecl *IndirectMember = cast_or_null( + FindInstantiatedDecl(Init->getMemberLocation(), + Init->getIndirectMember(), TemplateArgs)); if (!IndirectMember) { AnyErrors = true; @@ -7177,9 +7134,7 @@ Sema::InstantiateMemInitializers(CXXConstructorDecl *New, // Assign all the initializers to the new constructor. ActOnMemInitializers(New, /*FIXME: ColonLoc */ - SourceLocation(), - NewInits, - AnyErrors); + SourceLocation(), NewInits, AnyErrors); } // TODO: this could be templated if the various decl types used the @@ -7190,7 +7145,8 @@ static bool isInstantiationOf(ClassTemplateDecl *Pattern, do { Instance = Instance->getCanonicalDecl(); - if (Pattern == Instance) return true; + if (Pattern == Instance) + return true; Instance = Instance->getInstantiatedFromMemberTemplate(); } while (Instance); @@ -7203,7 +7159,8 @@ static bool isInstantiationOf(FunctionTemplateDecl *Pattern, do { Instance = Instance->getCanonicalDecl(); - if (Pattern == Instance) return true; + if (Pattern == Instance) + return true; Instance = Instance->getInstantiatedFromMemberTemplate(); } while (Instance); @@ -7213,11 +7170,11 @@ static bool isInstantiationOf(FunctionTemplateDecl *Pattern, static bool isInstantiationOf(ClassTemplatePartialSpecializationDecl *Pattern, ClassTemplatePartialSpecializationDecl *Instance) { - Pattern - = cast(Pattern->getCanonicalDecl()); + Pattern = + cast(Pattern->getCanonicalDecl()); do { Instance = cast( - Instance->getCanonicalDecl()); + Instance->getCanonicalDecl()); if (Pattern == Instance) return true; Instance = Instance->getInstantiatedFromMember(); @@ -7226,39 +7183,39 @@ isInstantiationOf(ClassTemplatePartialSpecializationDecl *Pattern, return false; } -static bool isInstantiationOf(CXXRecordDecl *Pattern, - CXXRecordDecl *Instance) { +static bool isInstantiationOf(CXXRecordDecl *Pattern, CXXRecordDecl *Instance) { Pattern = Pattern->getCanonicalDecl(); do { Instance = Instance->getCanonicalDecl(); - if (Pattern == Instance) return true; + if (Pattern == Instance) + return true; Instance = Instance->getInstantiatedFromMemberClass(); } while (Instance); return false; } -static bool isInstantiationOf(FunctionDecl *Pattern, - FunctionDecl *Instance) { +static bool isInstantiationOf(FunctionDecl *Pattern, FunctionDecl *Instance) { Pattern = Pattern->getCanonicalDecl(); do { Instance = Instance->getCanonicalDecl(); - if (Pattern == Instance) return true; + if (Pattern == Instance) + return true; Instance = Instance->getInstantiatedFromMemberFunction(); } while (Instance); return false; } -static bool isInstantiationOf(EnumDecl *Pattern, - EnumDecl *Instance) { +static bool isInstantiationOf(EnumDecl *Pattern, EnumDecl *Instance) { Pattern = Pattern->getCanonicalDecl(); do { Instance = Instance->getCanonicalDecl(); - if (Pattern == Instance) return true; + if (Pattern == Instance) + return true; Instance = Instance->getInstantiatedFromMemberEnum(); } while (Instance); @@ -7266,8 +7223,7 @@ static bool isInstantiationOf(EnumDecl *Pattern, } static bool isInstantiationOf(UsingShadowDecl *Pattern, - UsingShadowDecl *Instance, - ASTContext &C) { + UsingShadowDecl *Instance, ASTContext &C) { return declaresSameEntity(C.getInstantiatedFromUsingShadowDecl(Instance), Pattern); } @@ -7277,7 +7233,7 @@ static bool isInstantiationOf(UsingDecl *Pattern, UsingDecl *Instance, return declaresSameEntity(C.getInstantiatedFromUsingDecl(Instance), Pattern); } -template +template static bool isInstantiationOfUnresolvedUsingDecl(T *Pattern, Decl *Other, ASTContext &Ctx) { // An unresolved using declaration can instantiate to an unresolved using @@ -7312,7 +7268,8 @@ static bool isInstantiationOfStaticDataMember(VarDecl *Pattern, do { Instance = Instance->getCanonicalDecl(); - if (Pattern == Instance) return true; + if (Pattern == Instance) + return true; Instance = Instance->getInstantiatedFromStaticDataMember(); } while (Instance); @@ -7373,9 +7330,8 @@ static bool isInstantiationOf(ASTContext &Ctx, NamedDecl *D, Decl *Other) { D->getDeclName() == cast(Other)->getDeclName(); } -template -static NamedDecl *findInstantiationOf(ASTContext &Ctx, - NamedDecl *D, +template +static NamedDecl *findInstantiationOf(ASTContext &Ctx, NamedDecl *D, ForwardIterator first, ForwardIterator last) { for (; first != last; ++first) @@ -7385,12 +7341,14 @@ static NamedDecl *findInstantiationOf(ASTContext &Ctx, return nullptr; } -DeclContext *Sema::FindInstantiatedContext(SourceLocation Loc, DeclContext* DC, - const MultiLevelTemplateArgumentList &TemplateArgs) { +DeclContext *Sema::FindInstantiatedContext( + SourceLocation Loc, DeclContext *DC, + const MultiLevelTemplateArgumentList &TemplateArgs) { if (NamedDecl *D = dyn_cast(DC)) { - Decl* ID = FindInstantiatedDecl(Loc, D, TemplateArgs, true); + Decl *ID = FindInstantiatedDecl(Loc, D, TemplateArgs, true); return cast_or_null(ID); - } else return DC; + } else + return DC; } /// Determine whether the given context is dependent on template parameters at @@ -7407,9 +7365,10 @@ static bool isDependentContextAtLevel(DeclContext *DC, unsigned Level) { return cast(DC)->getTemplateDepth() > Level; } -NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, - const MultiLevelTemplateArgumentList &TemplateArgs, - bool FindingInstantiatedContext) { +NamedDecl * +Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, + const MultiLevelTemplateArgumentList &TemplateArgs, + bool FindingInstantiatedContext) { DeclContext *ParentDC = D->getDeclContext(); // Determine whether our parent context depends on any of the template // arguments we're currently substituting. @@ -7535,8 +7494,8 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, if (CXXRecordDecl *InstRecord = dyn_cast(DC)) { // Check whether we're in the process of instantiating a class template // specialization of the template we're mapping. - if (ClassTemplateSpecializationDecl *InstSpec - = dyn_cast(InstRecord)){ + if (ClassTemplateSpecializationDecl *InstSpec = + dyn_cast(InstRecord)) { ClassTemplateDecl *SpecTemplate = InstSpec->getSpecializedTemplate(); if (ClassTemplate && isInstantiationOf(ClassTemplate, SpecTemplate)) return InstRecord; @@ -7562,7 +7521,7 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, // Convert the arguments to an "as-written" list. TemplateArgumentListInfo Args(Loc, Loc); for (TemplateArgument Arg : TemplateArgs.getInnermost().take_front( - TD->getTemplateParameters()->size())) { + TD->getTemplateParameters()->size())) { ArrayRef Unpacked(Arg); if (Arg.getKind() == TemplateArgument::Pack) Unpacked = Arg.pack_elements(); @@ -7605,8 +7564,9 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, usesPartialOrExplicitSpecialization( Loc, cast(SubstRecord))) { Diag(Loc, diag::err_specialization_not_primary_template) - << T << (SubstRecord->getTemplateSpecializationKind() == - TSK_ExplicitSpecialization); + << T + << (SubstRecord->getTemplateSpecializationKind() == + TSK_ExplicitSpecialization); return nullptr; } DC = SubstRecord; @@ -7670,8 +7630,7 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, // - unnamed class/struct/union/enum within a template // // FIXME: Find a better way to find these instantiations! - Result = findInstantiationOf(Context, D, - ParentDC->decls_begin(), + Result = findInstantiationOf(Context, D, ParentDC->decls_begin(), ParentDC->decls_end()); } @@ -7698,13 +7657,13 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, // but can't be found in the instantiation. This can happen if an // unscoped enumeration member is explicitly specialized. EnumDecl *Enum = cast(ED->getLexicalDeclContext()); - EnumDecl *Spec = cast(FindInstantiatedDecl(Loc, Enum, - TemplateArgs)); + EnumDecl *Spec = + cast(FindInstantiatedDecl(Loc, Enum, TemplateArgs)); assert(Spec->getTemplateSpecializationKind() == - TSK_ExplicitSpecialization); + TSK_ExplicitSpecialization); Diag(Loc, diag::err_enumerator_does_not_exist) - << D->getDeclName() - << Context.getTypeDeclType(cast(Spec->getDeclContext())); + << D->getDeclName() + << Context.getTypeDeclType(cast(Spec->getDeclContext())); Diag(Spec->getLocation(), diag::note_enum_specialized_here) << Context.getCanonicalTagType(Spec); } else { @@ -7733,9 +7692,33 @@ static void processFunctionInstantiation(Sema &S, FD->setInstantiationIsPending(false); } +static std::unique_ptr createSYCLMangleContext(ASTContext &Ctx) { + // For SYCL offload compilation (CUDA/HIP), always use device mangling context + // to ensure consistent kernel name mangling across compilation units. + // Device lambda numbering is tracked globally via + // DeviceLambdaManglingNumbers, which provides stable numbering even for + // shared libraries compiled separately. This solves both cross-ABI scenarios + // (Microsoft host + Itanium device) and same-ABI scenarios (Itanium host + + // Itanium device) where separate compilation would otherwise produce + // different lambda numbers. + const TargetInfo *AuxTarget = Ctx.getAuxTargetInfo(); + if (AuxTarget) { + return std::unique_ptr( + Ctx.createDeviceMangleContext(*AuxTarget)); + } + // No offload target: use standard mangling + return std::unique_ptr(Ctx.createMangleContext()); +} + void Sema::PerformPendingInstantiations(bool LocalOnly, bool AtEndOfTU) { + // For SYCL compilation (both host and device), use device-aware mangle + // context to ensure consistent kernel name mangling across different + // backends (CUDA/HIP) and between host and device compilations. std::unique_ptr MangleCtx( - getASTContext().createMangleContext()); + (LangOpts.SYCLIsHost || LangOpts.SYCLIsDevice) + ? createSYCLMangleContext(getASTContext()) + : std::unique_ptr( + getASTContext().createMangleContext())); std::deque DelayedImplicitInstantiations; while (!PendingLocalImplicitInstantiations.empty() || (!LocalOnly && !PendingInstantiations.empty())) { @@ -7798,7 +7781,7 @@ void Sema::PerformPendingInstantiations(bool LocalOnly, bool AtEndOfTU) { llvm_unreachable("Cannot instantitiate an undeclared specialization."); case TSK_ExplicitInstantiationDeclaration: case TSK_ExplicitSpecialization: - continue; // No longer need to instantiate this type. + continue; // No longer need to instantiate this type. case TSK_ExplicitInstantiationDefinition: // We only need an instantiation if the pending instantiation *is* the // explicit instantiation. @@ -7824,8 +7807,9 @@ void Sema::PerformPendingInstantiations(bool LocalOnly, bool AtEndOfTU) { PendingInstantiations.swap(DelayedImplicitInstantiations); } -void Sema::PerformDependentDiagnostics(const DeclContext *Pattern, - const MultiLevelTemplateArgumentList &TemplateArgs) { +void Sema::PerformDependentDiagnostics( + const DeclContext *Pattern, + const MultiLevelTemplateArgumentList &TemplateArgs) { for (auto *DD : Pattern->ddiags()) { switch (DD->getKind()) { case DependentDiagnostic::Access: diff --git a/string_test_executable b/string_test_executable new file mode 100755 index 0000000000000..0f00331fd55cc Binary files /dev/null and b/string_test_executable differ diff --git a/sycl/test-e2e/IntermediateLib/multi_lib_app.cpp b/sycl/test-e2e/IntermediateLib/multi_lib_app.cpp index 09f572ba05201..247093b1c9580 100644 --- a/sycl/test-e2e/IntermediateLib/multi_lib_app.cpp +++ b/sycl/test-e2e/IntermediateLib/multi_lib_app.cpp @@ -1,6 +1,3 @@ -// UNSUPPORTED: cuda || hip -// UNSUPPORTED-TRACKER: CMPLRLLVM-69415 - // DEFINE: %{fPIC_flag} = %if windows %{%} %else %{-fPIC%} // DEFINE: %{shared_lib_ext} = %if windows %{dll%} %else %{so%}