Author: Erich Keane Date: 2022-03-01T08:31:51-08:00 New Revision: c601377b23767ede02fe5bbe880c05d420b53250
URL: https://github.com/llvm/llvm-project/commit/c601377b23767ede02fe5bbe880c05d420b53250 DIFF: https://github.com/llvm/llvm-project/commit/c601377b23767ede02fe5bbe880c05d420b53250.diff LOG: [NFC]Promote addInstantiatedParametersToScope to a private Sema function This is used a few places in SemaTeplateInstantiateDecl, but is going to be useful in SemaConcept.cpp as well. This patch switches it to be a private function in Sema. Differential Revision: https://reviews.llvm.org/D120729 Added: Modified: clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaTemplateInstantiateDecl.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 0840f3a6cdb71..d905db93ccfff 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -6935,6 +6935,14 @@ class Sema final { llvm::ContextualFoldingSet<ConstraintSatisfaction, const ASTContext &> SatisfactionCache; + /// Introduce the instantiated function parameters into the local + /// instantiation scope, and set the parameter names to those used + /// in the template. + bool addInstantiatedParametersToScope( + FunctionDecl *Function, const FunctionDecl *PatternDecl, + LocalInstantiationScope &Scope, + const MultiLevelTemplateArgumentList &TemplateArgs); + public: const NormalizedConstraint * getNormalizedAssociatedConstraints( diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 237886c906a5b..49fe11d3fa6df 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -4377,10 +4377,10 @@ TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D, /// Introduce the instantiated function parameters into the local /// instantiation scope, and set the parameter names to those used /// in the template. -static bool addInstantiatedParametersToScope(Sema &S, FunctionDecl *Function, - const FunctionDecl *PatternDecl, - LocalInstantiationScope &Scope, - const MultiLevelTemplateArgumentList &TemplateArgs) { +bool Sema::addInstantiatedParametersToScope( + FunctionDecl *Function, const FunctionDecl *PatternDecl, + LocalInstantiationScope &Scope, + const MultiLevelTemplateArgumentList &TemplateArgs) { unsigned FParamIdx = 0; for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I) { const ParmVarDecl *PatternParam = PatternDecl->getParamDecl(I); @@ -4396,9 +4396,9 @@ static bool addInstantiatedParametersToScope(Sema &S, FunctionDecl *Function, // it's instantiation-dependent. // FIXME: Updating the type to work around this is at best fragile. if (!PatternDecl->getType()->isDependentType()) { - QualType T = S.SubstType(PatternParam->getType(), TemplateArgs, - FunctionParam->getLocation(), - FunctionParam->getDeclName()); + QualType T = SubstType(PatternParam->getType(), TemplateArgs, + FunctionParam->getLocation(), + FunctionParam->getDeclName()); if (T.isNull()) return true; FunctionParam->setType(T); @@ -4411,8 +4411,8 @@ static bool addInstantiatedParametersToScope(Sema &S, FunctionDecl *Function, // Expand the parameter pack. Scope.MakeInstantiatedLocalArgPack(PatternParam); - Optional<unsigned> NumArgumentsInExpansion - = S.getNumArgumentsInExpansion(PatternParam->getType(), TemplateArgs); + Optional<unsigned> NumArgumentsInExpansion = + getNumArgumentsInExpansion(PatternParam->getType(), TemplateArgs); if (NumArgumentsInExpansion) { QualType PatternType = PatternParam->getType()->castAs<PackExpansionType>()->getPattern(); @@ -4420,10 +4420,10 @@ static bool addInstantiatedParametersToScope(Sema &S, FunctionDecl *Function, ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx); FunctionParam->setDeclName(PatternParam->getDeclName()); if (!PatternDecl->getType()->isDependentType()) { - Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, Arg); - QualType T = S.SubstType(PatternType, TemplateArgs, - FunctionParam->getLocation(), - FunctionParam->getDeclName()); + Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, Arg); + QualType T = + SubstType(PatternType, TemplateArgs, FunctionParam->getLocation(), + FunctionParam->getDeclName()); if (T.isNull()) return true; FunctionParam->setType(T); @@ -4487,8 +4487,7 @@ bool Sema::InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD, FunctionDecl *Pattern = FD->getTemplateInstantiationPattern( /*ForDefinition*/ false); - if (addInstantiatedParametersToScope(*this, FD, Pattern, Local, - TemplateArgs)) + if (addInstantiatedParametersToScope(FD, Pattern, Local, TemplateArgs)) return true; runWithSufficientStackSpace(CallLoc, [&] { @@ -4561,8 +4560,7 @@ void Sema::InstantiateExceptionSpec(SourceLocation PointOfInstantiation, // we don't store enough information to map back to the friend declaration in // the template. FunctionDecl *Template = Proto->getExceptionSpecTemplate(); - if (addInstantiatedParametersToScope(*this, Decl, Template, Scope, - TemplateArgs)) { + if (addInstantiatedParametersToScope(Decl, Template, Scope, TemplateArgs)) { UpdateExceptionSpec(Decl, EST_None); return; } @@ -4603,8 +4601,7 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints( MultiLevelTemplateArgumentList MLTAL( *Decl->getTemplateSpecializationArgs()); if (addInstantiatedParametersToScope( - *this, Decl, Decl->getPrimaryTemplate()->getTemplatedDecl(), - Scope, MLTAL)) + Decl, Decl->getPrimaryTemplate()->getTemplatedDecl(), Scope, MLTAL)) return true; } Qualifiers ThisQuals; @@ -5050,7 +5047,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, // PushDeclContext because we don't have a scope. Sema::ContextRAII savedContext(*this, Function); - if (addInstantiatedParametersToScope(*this, Function, PatternDecl, Scope, + if (addInstantiatedParametersToScope(Function, PatternDecl, Scope, TemplateArgs)) return; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits