[NFC] [ASTUnit] [Serialization] Transalte local decl ID to global decl ID before consuming
Discovered from
d86cc73bbf
.
There is a potential issue of using DeclID in ASTUnit. ASTUnit may
record the declaration ID from ASTWriter. And after loading the
preamble, the ASTUnit may consume the recorded declaration ID directly
in ExternalASTSource. This is not good. According to the design, all
local declaration ID consumed in ASTReader need to be translated by
`ASTReader::getGlobaldeclID()`.
This will be problematic if we changed the encodings of declaration IDs or if we
make preamble to work more complexly.
This commit is contained in:
parent
51f6570eba
commit
fe47e8ff3a
@ -1467,13 +1467,12 @@ void ASTUnit::RealizeTopLevelDeclsFromPreamble() {
|
||||
|
||||
std::vector<Decl *> Resolved;
|
||||
Resolved.reserve(TopLevelDeclsInPreamble.size());
|
||||
ExternalASTSource &Source = *getASTContext().getExternalSource();
|
||||
// The module file of the preamble.
|
||||
serialization::ModuleFile &MF = Reader->getModuleManager().getPrimaryModule();
|
||||
for (const auto TopLevelDecl : TopLevelDeclsInPreamble) {
|
||||
// Resolve the declaration ID to an actual declaration, possibly
|
||||
// deserializing the declaration in the process.
|
||||
//
|
||||
// FIMXE: We shouldn't convert a LocalDeclID to GlobalDeclID directly.
|
||||
if (Decl *D = Source.GetExternalDecl(GlobalDeclID(TopLevelDecl.get())))
|
||||
if (Decl *D = Reader->GetDecl(Reader->getGlobalDeclID(MF, TopLevelDecl)))
|
||||
Resolved.push_back(D);
|
||||
}
|
||||
TopLevelDeclsInPreamble.clear();
|
||||
|
Loading…
x
Reference in New Issue
Block a user