r227668 - [modules] When we try to complete the redeclaration chain for a class template
Richard Smith
richard-llvm at metafoo.co.uk
Fri Jan 30 19:04:56 PST 2015
Author: rsmith
Date: Fri Jan 30 21:04:55 2015
New Revision: 227668
URL: http://llvm.org/viewvc/llvm-project?rev=227668&view=rev
Log:
[modules] When we try to complete the redeclaration chain for a class template
specialization, pull in any lazy specializations of the class template.
Added:
cfe/trunk/test/Modules/Inputs/merge-template-members/
cfe/trunk/test/Modules/Inputs/merge-template-members/def.h
cfe/trunk/test/Modules/Inputs/merge-template-members/module.modulemap
cfe/trunk/test/Modules/Inputs/merge-template-members/update.h
cfe/trunk/test/Modules/merge-template-members.cpp
Modified:
cfe/trunk/include/clang/AST/DeclTemplate.h
cfe/trunk/lib/Serialization/ASTReader.cpp
Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=227668&r1=227667&r2=227668&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Fri Jan 30 21:04:55 2015
@@ -788,9 +788,6 @@ protected:
friend class FunctionDecl;
- /// \brief Load any lazily-loaded specializations from the external source.
- void LoadLazySpecializations() const;
-
/// \brief Retrieve the set of function template specializations of this
/// function template.
llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> &
@@ -804,6 +801,9 @@ protected:
void *InsertPos);
public:
+ /// \brief Load any lazily-loaded specializations from the external source.
+ void LoadLazySpecializations() const;
+
/// Get the underlying function declaration of the template.
FunctionDecl *getTemplatedDecl() const {
return static_cast<FunctionDecl*>(TemplatedDecl);
@@ -1827,9 +1827,6 @@ protected:
uint32_t *LazySpecializations;
};
- /// \brief Load any lazily-loaded specializations from the external source.
- void LoadLazySpecializations() const;
-
/// \brief Retrieve the set of specializations of this class template.
llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
getSpecializations() const;
@@ -1851,6 +1848,9 @@ protected:
}
public:
+ /// \brief Load any lazily-loaded specializations from the external source.
+ void LoadLazySpecializations() const;
+
/// \brief Get the underlying class declarations of the template.
CXXRecordDecl *getTemplatedDecl() const {
return static_cast<CXXRecordDecl *>(TemplatedDecl);
@@ -2662,9 +2662,6 @@ protected:
uint32_t *LazySpecializations;
};
- /// \brief Load any lazily-loaded specializations from the external source.
- void LoadLazySpecializations() const;
-
/// \brief Retrieve the set of specializations of this variable template.
llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
getSpecializations() const;
@@ -2686,6 +2683,9 @@ protected:
}
public:
+ /// \brief Load any lazily-loaded specializations from the external source.
+ void LoadLazySpecializations() const;
+
/// \brief Get the underlying variable declarations of the template.
VarDecl *getTemplatedDecl() const {
return static_cast<VarDecl *>(TemplatedDecl);
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=227668&r1=227667&r2=227668&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Jan 30 21:04:55 2015
@@ -6081,6 +6081,12 @@ Decl *ASTReader::GetExternalDecl(uint32_
return GetDecl(ID);
}
+template<typename TemplateSpecializationDecl>
+static void completeRedeclChainForTemplateSpecialization(Decl *D) {
+ if (auto *TSD = dyn_cast<TemplateSpecializationDecl>(D))
+ TSD->getSpecializedTemplate()->LoadLazySpecializations();
+}
+
void ASTReader::CompleteRedeclChain(const Decl *D) {
if (NumCurrentElementsDeserializing) {
// We arrange to not care about the complete redeclaration chain while we're
@@ -6114,6 +6120,15 @@ void ASTReader::CompleteRedeclChain(cons
D->getDeclContext()->decls_begin();
}
}
+
+ if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D))
+ CTSD->getSpecializedTemplate()->LoadLazySpecializations();
+ if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D))
+ VTSD->getSpecializedTemplate()->LoadLazySpecializations();
+ if (auto *FD = dyn_cast<FunctionDecl>(D)) {
+ if (auto *Template = FD->getPrimaryTemplate())
+ Template->LoadLazySpecializations();
+ }
}
uint64_t ASTReader::readCXXBaseSpecifiers(ModuleFile &M,
Added: cfe/trunk/test/Modules/Inputs/merge-template-members/def.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-template-members/def.h?rev=227668&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-template-members/def.h (added)
+++ cfe/trunk/test/Modules/Inputs/merge-template-members/def.h Fri Jan 30 21:04:55 2015
@@ -0,0 +1,2 @@
+template<typename> struct A { int n; };
+template<typename> struct B { typedef A<void> C; };
Added: cfe/trunk/test/Modules/Inputs/merge-template-members/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-template-members/module.modulemap?rev=227668&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-template-members/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/merge-template-members/module.modulemap Fri Jan 30 21:04:55 2015
@@ -0,0 +1,2 @@
+module def { header "def.h" export * }
+module update { header "update.h" export * }
Added: cfe/trunk/test/Modules/Inputs/merge-template-members/update.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-template-members/update.h?rev=227668&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-template-members/update.h (added)
+++ cfe/trunk/test/Modules/Inputs/merge-template-members/update.h Fri Jan 30 21:04:55 2015
@@ -0,0 +1,2 @@
+#include "def.h"
+B<int>::C use1;
Added: cfe/trunk/test/Modules/merge-template-members.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/merge-template-members.cpp?rev=227668&view=auto
==============================================================================
--- cfe/trunk/test/Modules/merge-template-members.cpp (added)
+++ cfe/trunk/test/Modules/merge-template-members.cpp Fri Jan 30 21:04:55 2015
@@ -0,0 +1,10 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/merge-template-members -verify %s
+// expected-no-diagnostics
+
+template<typename> struct A { int n; };
+template<typename> struct B { typedef A<void> C; };
+template class B<int>;
+
+#include "update.h"
+B<int>::C use2;
More information about the cfe-commits
mailing list