Skip to content

Commit fe47e8f

Browse files
committed
[NFC] [ASTUnit] [Serialization] Transalte local decl ID to global decl ID before consuming
Discovered from d86cc73. 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.
1 parent 51f6570 commit fe47e8f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

clang/lib/Frontend/ASTUnit.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,13 +1467,12 @@ void ASTUnit::RealizeTopLevelDeclsFromPreamble() {
14671467

14681468
std::vector<Decl *> Resolved;
14691469
Resolved.reserve(TopLevelDeclsInPreamble.size());
1470-
ExternalASTSource &Source = *getASTContext().getExternalSource();
1470+
// The module file of the preamble.
1471+
serialization::ModuleFile &MF = Reader->getModuleManager().getPrimaryModule();
14711472
for (const auto TopLevelDecl : TopLevelDeclsInPreamble) {
14721473
// Resolve the declaration ID to an actual declaration, possibly
14731474
// deserializing the declaration in the process.
1474-
//
1475-
// FIMXE: We shouldn't convert a LocalDeclID to GlobalDeclID directly.
1476-
if (Decl *D = Source.GetExternalDecl(GlobalDeclID(TopLevelDecl.get())))
1475+
if (Decl *D = Reader->GetDecl(Reader->getGlobalDeclID(MF, TopLevelDecl)))
14771476
Resolved.push_back(D);
14781477
}
14791478
TopLevelDeclsInPreamble.clear();

0 commit comments

Comments
 (0)