aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Stellard <tstellar@redhat.com>2020-11-25 16:38:08 -0800
committerTom Stellard <tstellar@redhat.com>2020-11-25 16:38:08 -0800
commitd8e8ae195a2581bea454317c4c4eabf0943d1e6d (patch)
treed3187ecb6d939eba2adaf327147af80355adcead
parent[AArch64][GlobalISel] Handle rtcGPR64RegClassID in AArch64RegisterBankInfo::g... (diff)
downloadllvm-project-d8e8ae195a2581bea454317c4c4eabf0943d1e6d.tar.gz
llvm-project-d8e8ae195a2581bea454317c4c4eabf0943d1e6d.tar.bz2
llvm-project-d8e8ae195a2581bea454317c4c4eabf0943d1e6d.zip
Revert "[SemaTemplate] Stop passing insertion position around during VarTemplate instantiation"
This reverts commit 8ac709578067f77a7036fe50610277516fa36d50. This commit changes the public API of clang, so it needs to be reworked.
-rw-r--r--clang/include/clang/Sema/Sema.h2
-rw-r--r--clang/include/clang/Sema/Template.h2
-rw-r--r--clang/lib/Sema/SemaTemplate.cpp2
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiateDecl.cpp23
-rw-r--r--clang/test/SemaTemplate/instantiate-var-template.cpp7
5 files changed, 16 insertions, 20 deletions
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 7a7722559397..6f7ad8076718 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9123,7 +9123,7 @@ public:
const TemplateArgumentList &TemplateArgList,
const TemplateArgumentListInfo &TemplateArgsInfo,
SmallVectorImpl<TemplateArgument> &Converted,
- SourceLocation PointOfInstantiation,
+ SourceLocation PointOfInstantiation, void *InsertPos,
LateInstantiatedAttrVec *LateAttrs = nullptr,
LocalInstantiationScope *StartingScope = nullptr);
VarTemplateSpecializationDecl *CompleteVarTemplateSpecializationDecl(
diff --git a/clang/include/clang/Sema/Template.h b/clang/include/clang/Sema/Template.h
index 0dcaf565591b..91d175fdd050 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -600,7 +600,7 @@ enum class TemplateSubstitutionKind : char {
TagDecl *NewDecl);
Decl *VisitVarTemplateSpecializationDecl(
- VarTemplateDecl *VarTemplate, VarDecl *FromVar,
+ VarTemplateDecl *VarTemplate, VarDecl *FromVar, void *InsertPos,
const TemplateArgumentListInfo &TemplateArgsInfo,
ArrayRef<TemplateArgument> Converted,
VarTemplateSpecializationDecl *PrevDecl = nullptr);
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index ddae944a48f3..c05ed0b14e3e 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4471,7 +4471,7 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, SourceLocation TemplateLoc,
// FIXME: LateAttrs et al.?
VarTemplateSpecializationDecl *Decl = BuildVarTemplateInstantiation(
Template, InstantiationPattern, *InstantiationArgs, TemplateArgs,
- Converted, TemplateNameLoc /*, LateAttrs, StartingScope*/);
+ Converted, TemplateNameLoc, InsertPos /*, LateAttrs, StartingScope*/);
if (!Decl)
return true;
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 903785a2be42..baec13ba627c 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3602,11 +3602,11 @@ Decl *TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl(
return nullptr;
return VisitVarTemplateSpecializationDecl(
- InstVarTemplate, D, VarTemplateArgsInfo, Converted, PrevDecl);
+ InstVarTemplate, D, InsertPos, VarTemplateArgsInfo, Converted, PrevDecl);
}
Decl *TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl(
- VarTemplateDecl *VarTemplate, VarDecl *D,
+ VarTemplateDecl *VarTemplate, VarDecl *D, void *InsertPos,
const TemplateArgumentListInfo &TemplateArgsInfo,
ArrayRef<TemplateArgument> Converted,
VarTemplateSpecializationDecl *PrevDecl) {
@@ -3629,11 +3629,8 @@ Decl *TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl(
SemaRef.Context, Owner, D->getInnerLocStart(), D->getLocation(),
VarTemplate, DI->getType(), DI, D->getStorageClass(), Converted);
Var->setTemplateArgsInfo(TemplateArgsInfo);
- if (!PrevDecl) {
- void *InsertPos = nullptr;
- VarTemplate->findSpecialization(Converted, InsertPos);
+ if (InsertPos)
VarTemplate->AddSpecialization(Var, InsertPos);
- }
if (SemaRef.getLangOpts().OpenCL)
SemaRef.deduceOpenCLAddressSpace(Var);
@@ -4842,7 +4839,7 @@ VarTemplateSpecializationDecl *Sema::BuildVarTemplateInstantiation(
const TemplateArgumentList &TemplateArgList,
const TemplateArgumentListInfo &TemplateArgsInfo,
SmallVectorImpl<TemplateArgument> &Converted,
- SourceLocation PointOfInstantiation,
+ SourceLocation PointOfInstantiation, void *InsertPos,
LateInstantiatedAttrVec *LateAttrs,
LocalInstantiationScope *StartingScope) {
if (FromVar->isInvalidDecl())
@@ -4881,7 +4878,7 @@ VarTemplateSpecializationDecl *Sema::BuildVarTemplateInstantiation(
return cast_or_null<VarTemplateSpecializationDecl>(
Instantiator.VisitVarTemplateSpecializationDecl(
- VarTemplate, FromVar, TemplateArgsInfo, Converted));
+ VarTemplate, FromVar, InsertPos, TemplateArgsInfo, Converted));
}
/// Instantiates a variable template specialization by completing it
@@ -5313,8 +5310,8 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation,
TemplateDeclInstantiator Instantiator(*this, Var->getDeclContext(),
TemplateArgs);
Var = cast_or_null<VarDecl>(Instantiator.VisitVarTemplateSpecializationDecl(
- VarSpec->getSpecializedTemplate(), Def, VarSpec->getTemplateArgsInfo(),
- VarSpec->getTemplateArgs().asArray(), VarSpec));
+ VarSpec->getSpecializedTemplate(), Def, nullptr,
+ VarSpec->getTemplateArgsInfo(), VarSpec->getTemplateArgs().asArray()));
if (Var) {
llvm::PointerUnion<VarTemplateDecl *,
VarTemplatePartialSpecializationDecl *> PatternPtr =
@@ -5324,6 +5321,12 @@ 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 a24b205da596..b7b83e4afdd5 100644
--- a/clang/test/SemaTemplate/instantiate-var-template.cpp
+++ b/clang/test/SemaTemplate/instantiate-var-template.cpp
@@ -40,10 +40,3 @@ 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>;
-}