[modules] When instantiating the contents of an imported CXXRecordDecl, we can

emit lexical contents for a declaration for another module. Track which module
those contents came from, and ensure that we only grab the lexical contents
from a single such instantiation.

llvm-svn: 244682
This commit is contained in:
Richard Smith 2015-08-11 22:00:24 +00:00
parent c6f0468937
commit 9c9173dcc8
5 changed files with 22 additions and 7 deletions

View File

@ -499,7 +499,8 @@ private:
typedef ArrayRef<llvm::support::unaligned_uint32_t> LexicalContents;
/// \brief Map from a DeclContext to its lexical contents.
llvm::DenseMap<const DeclContext*, LexicalContents> LexicalDecls;
llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>>
LexicalDecls;
/// \brief Map from the TU to its lexical contents from each module file.
std::vector<std::pair<ModuleFile*, LexicalContents>> TULexicalDecls;

View File

@ -975,11 +975,18 @@ bool ASTReader::ReadLexicalDeclContextStorage(ModuleFile &M,
assert(!isa<TranslationUnitDecl>(DC) &&
"expected a TU_UPDATE_LEXICAL record for TU");
// FIXME: Once we remove RewriteDecl, assert that we didn't already have
// lexical decls for this context.
LexicalDecls[DC] = llvm::makeArrayRef(
reinterpret_cast<const llvm::support::unaligned_uint32_t *>(Blob.data()),
Blob.size() / 4);
// If we are handling a C++ class template instantiation, we can see multiple
// lexical updates for the same record. It's important that we select only one
// of them, so that field numbering works properly. Just pick the first one we
// see.
auto &Lex = LexicalDecls[DC];
if (!Lex.first) {
Lex = std::make_pair(
&M, llvm::makeArrayRef(
reinterpret_cast<const llvm::support::unaligned_uint32_t *>(
Blob.data()),
Blob.size() / 4));
}
DC->setHasExternalLexicalStorage(true);
return false;
}
@ -6253,7 +6260,7 @@ void ASTReader::FindExternalLexicalDecls(
} else {
auto I = LexicalDecls.find(DC);
if (I != LexicalDecls.end())
Visit(getOwningModuleFile(cast<Decl>(DC)), I->second);
Visit(I->second.first, I->second.second);
}
++NumLexicalDeclContextsRead;

View File

@ -38,6 +38,10 @@ int defineListDoubleRight() {
return ld.size;
}
inline void defineListLongRight() {
List<long> ll;
}
template<typename T> struct MergePatternDecl;
void outOfLineInlineUseRightF(void (OutOfLineInline<int>::*)() = &OutOfLineInline<int>::f);

View File

@ -10,6 +10,7 @@ public:
};
extern List<double> *instantiateListDoubleDeclaration;
extern List<long> *instantiateListLongDeclaration;
namespace A {
class Y {

View File

@ -28,6 +28,8 @@ void testTemplateClasses() {
N::Set<char> set_char;
set_char.insert('A');
static_assert(sizeof(List<long>) == sizeof(List<short>), "");
List<double> list_double;
list_double.push_back(0.0);
}