aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/ASTUnit.cpp
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2024-04-25 15:45:16 +0800
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>2024-04-25 15:55:46 +0800
commitfe47e8ff3ae7fc8975eaade6bfa6679737c28b93 (patch)
treee2343c49c99acb6648059498708b0addd150eb67 /clang/lib/Frontend/ASTUnit.cpp
parent51f6570eba69b7030f2845e30b7973bd9ac6c522 (diff)
downloadllvm-fe47e8ff3ae7fc8975eaade6bfa6679737c28b93.zip
llvm-fe47e8ff3ae7fc8975eaade6bfa6679737c28b93.tar.gz
llvm-fe47e8ff3ae7fc8975eaade6bfa6679737c28b93.tar.bz2
[NFC] [ASTUnit] [Serialization] Transalte local decl ID to global decl ID before consuming
Discovered from https://github.com/llvm/llvm-project/commit/d86cc73bbfd9a22d9a0d498d72c9b2ee235128e9. 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.
Diffstat (limited to 'clang/lib/Frontend/ASTUnit.cpp')
-rw-r--r--clang/lib/Frontend/ASTUnit.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 2f75313e..1b93588 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -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();