diff options
author | 2020-10-12 15:58:52 -0700 | |
---|---|---|
committer | 2020-12-14 16:56:27 -0500 | |
commit | fc23bc9b30bff900cb279318e8e60050688606f9 (patch) | |
tree | db58b59a3d5fe42f466c0df96527a7bf63fa9a1d | |
parent | [X86] Fix crash with i64 bitreverse on 32-bit targets with XOP. (diff) | |
download | llvm-project-fc23bc9b30bff900cb279318e8e60050688606f9.tar.gz llvm-project-fc23bc9b30bff900cb279318e8e60050688606f9.tar.bz2 llvm-project-fc23bc9b30bff900cb279318e8e60050688606f9.zip |
[SemaTemplate] Stop passing insertion position around during VarTemplate instantiation
They can get stale at use time because of updates from other recursive
specializations. Instead, rely on the existence of previous declarations to add
the specialization.
Differential Revision: https://reviews.llvm.org/D87853
(cherry picked from commit cffb0dd54d41d8e249d2009467c4beb5b681ba26)
This is a re-commit of 8ac709578067f77a7036fe50610277516fa36d50 with
some modifications to avoid changing the clang API.
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 13 | ||||
-rw-r--r-- | clang/test/SemaTemplate/instantiate-var-template.cpp | 7 |
2 files changed, 12 insertions, 8 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index baec13ba627c..7e6efe6105bf 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3629,8 +3629,11 @@ Decl *TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl( SemaRef.Context, Owner, D->getInnerLocStart(), D->getLocation(), VarTemplate, DI->getType(), DI, D->getStorageClass(), Converted); Var->setTemplateArgsInfo(TemplateArgsInfo); - if (InsertPos) + if (!PrevDecl) { + void *InsertPos = nullptr; + VarTemplate->findSpecialization(Converted, InsertPos); VarTemplate->AddSpecialization(Var, InsertPos); + } if (SemaRef.getLangOpts().OpenCL) SemaRef.deduceOpenCLAddressSpace(Var); @@ -5311,7 +5314,7 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, TemplateArgs); Var = cast_or_null<VarDecl>(Instantiator.VisitVarTemplateSpecializationDecl( VarSpec->getSpecializedTemplate(), Def, nullptr, - VarSpec->getTemplateArgsInfo(), VarSpec->getTemplateArgs().asArray())); + VarSpec->getTemplateArgsInfo(), VarSpec->getTemplateArgs().asArray(), VarSpec)); if (Var) { llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *> PatternPtr = @@ -5321,12 +5324,6 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, cast<VarTemplateSpecializationDecl>(Var)->setInstantiationOf( Partial, &VarSpec->getTemplateInstantiationArgs()); - // Merge the definition with the declaration. - LookupResult R(*this, Var->getDeclName(), Var->getLocation(), - LookupOrdinaryName, forRedeclarationInCurContext()); - R.addDecl(OldVar); - MergeVarDecl(Var, R); - // Attach the initializer. InstantiateVariableInitializer(Var, Def, TemplateArgs); } diff --git a/clang/test/SemaTemplate/instantiate-var-template.cpp b/clang/test/SemaTemplate/instantiate-var-template.cpp index b7b83e4afdd5..a24b205da596 100644 --- a/clang/test/SemaTemplate/instantiate-var-template.cpp +++ b/clang/test/SemaTemplate/instantiate-var-template.cpp @@ -40,3 +40,10 @@ namespace PR24483 { template<typename... T> A<T...> models; template<> struct B models<>; // expected-error {{incomplete type 'struct B'}} expected-note {{forward declaration}} } + +namespace InvalidInsertPos { + template<typename T, int N> T v; + template<int N> decltype(v<int, N-1>) v<int, N>; + template<> int v<int, 0>; + int k = v<int, 500>; +} |