Skip to content

Commit c5a22e1

Browse files
authored
Merge pull request #28911 from xymus/rdar58022345
[Serialization] Recover from deserializing an enum from a missing module
2 parents 2317733 + a4cf567 commit c5a22e1

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,14 +1889,25 @@ DeclContext *ModuleFile::getLocalDeclContext(LocalDeclContextID DCID) {
18891889
}
18901890

18911891
DeclContext *ModuleFile::getDeclContext(DeclContextID DCID) {
1892+
auto deserialized = getDeclContextChecked(DCID);
1893+
if (!deserialized) {
1894+
fatal(deserialized.takeError());
1895+
}
1896+
return deserialized.get();
1897+
}
1898+
1899+
Expected<DeclContext *> ModuleFile::getDeclContextChecked(DeclContextID DCID) {
18921900
if (!DCID)
18931901
return FileContext;
18941902

18951903
if (Optional<LocalDeclContextID> contextID = DCID.getAsLocalDeclContextID())
18961904
return getLocalDeclContext(contextID.getValue());
18971905

1898-
auto D = getDecl(DCID.getAsDeclID().getValue());
1906+
auto deserialized = getDeclChecked(DCID.getAsDeclID().getValue());
1907+
if (!deserialized)
1908+
return deserialized.takeError();
18991909

1910+
auto D = deserialized.get();
19001911
if (auto GTD = dyn_cast<GenericTypeDecl>(D))
19011912
return GTD;
19021913
if (auto ED = dyn_cast<ExtensionDecl>(D))
@@ -3501,7 +3512,6 @@ class DeclDeserializer {
35013512
numConformances, numInherited,
35023513
rawInheritedAndDependencyIDs);
35033514

3504-
auto DC = MF.getDeclContext(contextID);
35053515
if (declOrOffset.isComplete())
35063516
return declOrOffset;
35073517

@@ -3515,6 +3525,11 @@ class DeclDeserializer {
35153525
}
35163526
}
35173527

3528+
auto DCOrError = MF.getDeclContextChecked(contextID);
3529+
if (!DCOrError)
3530+
return DCOrError.takeError();
3531+
auto DC = DCOrError.get();
3532+
35183533
auto genericParams = MF.maybeReadGenericParams(DC);
35193534
if (declOrOffset.isComplete())
35203535
return declOrOffset;

lib/Serialization/ModuleFile.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,11 @@ class ModuleFile
913913
/// Returns the decl context with the given ID, deserializing it if needed.
914914
DeclContext *getDeclContext(serialization::DeclContextID DID);
915915

916+
/// Returns the decl context with the given ID, deserializing it if needed,
917+
/// or the first error.
918+
llvm::Expected<DeclContext *>
919+
getDeclContextChecked(serialization::DeclContextID DCID);
920+
916921
/// Returns the local decl context with the given ID, deserializing it if needed.
917922
DeclContext *getLocalDeclContext(serialization::LocalDeclContextID DID);
918923

0 commit comments

Comments
 (0)