mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #23627 from akyrtzi/fix-bad-deserial-49336277
[Serialization] Fix bad tagging of deserialized decls that can result in failed member lookups
This commit is contained in:
@@ -3753,35 +3753,35 @@ public:
|
||||
|
||||
Expected<Decl *>
|
||||
ModuleFile::getDeclChecked(DeclID DID) {
|
||||
// Tag every deserialized ValueDecl coming out of getDeclChecked with its ID.
|
||||
if (DID == 0)
|
||||
return nullptr;
|
||||
|
||||
assert(DID <= Decls.size() && "invalid decl ID");
|
||||
auto &declOrOffset = Decls[DID-1];
|
||||
|
||||
if (declOrOffset.isComplete())
|
||||
return declOrOffset;
|
||||
if (!declOrOffset.isComplete()) {
|
||||
++NumDeclsLoaded;
|
||||
BCOffsetRAII restoreOffset(DeclTypeCursor);
|
||||
DeclTypeCursor.JumpToBit(declOrOffset);
|
||||
|
||||
++NumDeclsLoaded;
|
||||
BCOffsetRAII restoreOffset(DeclTypeCursor);
|
||||
DeclTypeCursor.JumpToBit(declOrOffset);
|
||||
ModuleFile::DeserializingEntityRAII deserializingEntity(*this);
|
||||
Expected<Decl *> deserialized =
|
||||
DeclDeserializer(*this, declOrOffset).getDeclCheckedImpl();
|
||||
if (!deserialized)
|
||||
return deserialized;
|
||||
}
|
||||
|
||||
SWIFT_DEFER {
|
||||
if (!declOrOffset.isComplete())
|
||||
return;
|
||||
if (auto *IDC = dyn_cast_or_null<IterableDeclContext>(declOrOffset.get())) {
|
||||
// Only set the DeclID on the returned Decl if it's one that was loaded
|
||||
// and _wasn't_ one that had its DeclID set elsewhere (a followed XREF).
|
||||
if (IDC->wasDeserialized() &&
|
||||
static_cast<uint32_t>(IDC->getDeclID()) == 0) {
|
||||
IDC->setDeclID(DID);
|
||||
}
|
||||
// Tag every deserialized ValueDecl coming out of getDeclChecked with its ID.
|
||||
assert(declOrOffset.isComplete());
|
||||
if (auto *IDC = dyn_cast_or_null<IterableDeclContext>(declOrOffset.get())) {
|
||||
// Only set the DeclID on the returned Decl if it's one that was loaded
|
||||
// and _wasn't_ one that had its DeclID set elsewhere (a followed XREF).
|
||||
if (IDC->wasDeserialized() &&
|
||||
static_cast<uint32_t>(IDC->getDeclID()) == 0) {
|
||||
IDC->setDeclID(DID);
|
||||
}
|
||||
};
|
||||
|
||||
ModuleFile::DeserializingEntityRAII deserializingEntity(*this);
|
||||
return DeclDeserializer(*this, declOrOffset).getDeclCheckedImpl();
|
||||
}
|
||||
return declOrOffset;
|
||||
}
|
||||
|
||||
llvm::Error DeclDeserializer::deserializeDeclAttributes() {
|
||||
|
||||
Reference in New Issue
Block a user