Author: Richard Smith Date: 2022-04-19T14:48:42-07:00 New Revision: 63814be4fa23ef9b36cf2d14388c7f6ba591d3b6
URL: https://github.com/llvm/llvm-project/commit/63814be4fa23ef9b36cf2d14388c7f6ba591d3b6 DIFF: https://github.com/llvm/llvm-project/commit/63814be4fa23ef9b36cf2d14388c7f6ba591d3b6.diff LOG: [modules] Merge variable template specializations. Added: Modified: clang/lib/Serialization/ASTReaderDecl.cpp clang/test/Modules/Inputs/merge-template-specializations/a.h clang/test/Modules/Inputs/merge-template-specializations/b.h clang/test/Modules/Inputs/merge-template-specializations/c.h clang/test/Modules/merge-template-specializations.cpp Removed: ################################################################################ diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 43aacdeda9987..9e0c3d558323f 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -2382,13 +2382,17 @@ ASTDeclReader::VisitVarTemplateSpecializationDeclImpl( if (writtenAsCanonicalDecl) { auto *CanonPattern = readDeclAs<VarTemplateDecl>(); if (D->isCanonicalDecl()) { // It's kept in the folding set. - // FIXME: If it's already present, merge it. + VarTemplateSpecializationDecl *CanonSpec; if (auto *Partial = dyn_cast<VarTemplatePartialSpecializationDecl>(D)) { - CanonPattern->getCommonPtr()->PartialSpecializations - .GetOrInsertNode(Partial); + CanonSpec = CanonPattern->getCommonPtr() + ->PartialSpecializations.GetOrInsertNode(Partial); } else { - CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); + CanonSpec = + CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); } + // If we already have a matching specialization, merge it. + if (CanonSpec != D) + mergeRedeclarable<VarDecl>(D, CanonSpec, Redecl); } } diff --git a/clang/test/Modules/Inputs/merge-template-specializations/a.h b/clang/test/Modules/Inputs/merge-template-specializations/a.h index fb05647c0aa93..00426af2b1d59 100644 --- a/clang/test/Modules/Inputs/merge-template-specializations/a.h +++ b/clang/test/Modules/Inputs/merge-template-specializations/a.h @@ -1 +1,3 @@ template<unsigned> class SmallString {}; + +template<int> int var_template = 0; diff --git a/clang/test/Modules/Inputs/merge-template-specializations/b.h b/clang/test/Modules/Inputs/merge-template-specializations/b.h index 96ce2bb1d8d6a..89d0e36d6c964 100644 --- a/clang/test/Modules/Inputs/merge-template-specializations/b.h +++ b/clang/test/Modules/Inputs/merge-template-specializations/b.h @@ -1,2 +1,4 @@ #include "a.h" void f(SmallString<256>&); + +template<typename T> void use_var_template(decltype(T() + var_template<0>)) {} diff --git a/clang/test/Modules/Inputs/merge-template-specializations/c.h b/clang/test/Modules/Inputs/merge-template-specializations/c.h index 100463a2f7f28..44fe4925d7c2d 100644 --- a/clang/test/Modules/Inputs/merge-template-specializations/c.h +++ b/clang/test/Modules/Inputs/merge-template-specializations/c.h @@ -1,3 +1,6 @@ #include "a.h" struct X { SmallString<256> ss; }; + +template<typename T> void use_var_template(decltype(T() + var_template<0>)); + #include "b.h" diff --git a/clang/test/Modules/merge-template-specializations.cpp b/clang/test/Modules/merge-template-specializations.cpp index 25db93fbbb206..1f8e68a2e925a 100644 --- a/clang/test/Modules/merge-template-specializations.cpp +++ b/clang/test/Modules/merge-template-specializations.cpp @@ -3,3 +3,7 @@ // expected-no-diagnostics #include "c.h" X x; + +void test_var_template() { + use_var_template<int>(0); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits