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;
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;
}
} 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;