Skip to content

Commit 7539947

Browse files
committed
[Serialization] Check for anchoring VarDecl when serializing PDB
An invalid PDB may have no anchoring VarDecl when allowing errors, make sure not to crash in that case.
1 parent 6240435 commit 7539947

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2029,8 +2029,10 @@ void Serializer::writePatternBindingInitializer(PatternBindingDecl *binding,
20292029
StringRef initStr;
20302030
SmallString<128> scratch;
20312031
auto varDecl = binding->getAnchoringVarDecl(bindingIndex);
2032+
assert((varDecl || allowCompilerErrors()) &&
2033+
"Serializing PDB without anchoring VarDecl");
20322034
if (binding->hasInitStringRepresentation(bindingIndex) &&
2033-
varDecl->isInitExposedToClients()) {
2035+
varDecl && varDecl->isInitExposedToClients()) {
20342036
initStr = binding->getInitStringRepresentation(bindingIndex, scratch);
20352037
}
20362038

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// -parse-as-library added so that the PDB isn't added to a TopLevelCodeDecl,
4+
// which isn't serialized at all
5+
// RUN: %target-swift-frontend -emit-module -o %t/errors.swiftmodule -module-name errors -experimental-allow-module-with-compiler-errors -parse-as-library %s
6+
7+
let self = 1

0 commit comments

Comments
 (0)