Skip to content

Commit d5cc01d

Browse files
committed
Serialization: Don't fail out of loadNamedMembers()
This cleanup exposed a problem with deserialization recovery and property wrappers. If deserializing a property backed by a wrapper failed, the lazy member lookup would fail, but subsequently a loadAllMembers() call would still load the property. This behavior is actually incorrect, because silently dropping a stored property of a @Frozen struct can result in miscompiles. I've filed rdar://59403542 and rdar://59403617 to track fixing this. In the meantime, I've tweaked the logic a bit to preserve the old behavior.
1 parent 07c8b1b commit d5cc01d

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,14 +2831,10 @@ class DeclDeserializer {
28312831
if (numBackingProperties > 0) {
28322832
auto backingDecl = MF.getDeclChecked(backingPropertyIDs[0]);
28332833
if (!backingDecl) {
2834-
if (numBackingProperties > 1 &&
2835-
backingDecl.errorIsA<XRefNonLoadedModuleError>()) {
2836-
// A property wrapper defined behind an implementation-only import
2837-
// is safe to drop when it can't be deserialized.
2838-
// rdar://problem/56599179
2839-
consumeError(backingDecl.takeError());
2840-
} else
2841-
return backingDecl.takeError();
2834+
// FIXME: This is actually wrong. We can't just drop stored properties
2835+
// willy-nilly if the struct is @frozen.
2836+
consumeError(backingDecl.takeError());
2837+
return var;
28422838
}
28432839

28442840
VarDecl *backingVar = cast<VarDecl>(backingDecl.get());

lib/Serialization/ModuleFile.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2399,7 +2399,7 @@ ModuleFile::loadNamedMembers(const IterableDeclContext *IDC, DeclBaseName N,
23992399
fatalIfUnexpected(DeclMemberTablesCursor.advance());
24002400
if (entry.Kind != llvm::BitstreamEntry::Record) {
24012401
fatal();
2402-
return None;
2402+
return results;
24032403
}
24042404
SmallVector<uint64_t, 64> scratch;
24052405
StringRef blobData;
@@ -2424,10 +2424,6 @@ ModuleFile::loadNamedMembers(const IterableDeclContext *IDC, DeclBaseName N,
24242424
if (!getContext().LangOpts.EnableDeserializationRecovery)
24252425
fatal(mem.takeError());
24262426
consumeError(mem.takeError());
2427-
2428-
// Treat this as a cache-miss to the caller and let them attempt
2429-
// to refill through the normal loadAllMembers() path.
2430-
return None;
24312427
}
24322428
}
24332429
}

0 commit comments

Comments
 (0)