Skip to content

Commit 69a5a3d

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 462ce05 commit 69a5a3d

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
@@ -2084,8 +2084,10 @@ void Serializer::writePatternBindingInitializer(PatternBindingDecl *binding,
20842084
StringRef initStr;
20852085
SmallString<128> scratch;
20862086
auto varDecl = binding->getAnchoringVarDecl(bindingIndex);
2087+
assert((varDecl || allowCompilerErrors()) &&
2088+
"Serializing PDB without anchoring VarDecl");
20872089
if (binding->hasInitStringRepresentation(bindingIndex) &&
2088-
varDecl->isInitExposedToClients()) {
2090+
varDecl && varDecl->isInitExposedToClients()) {
20892091
initStr = binding->getInitStringRepresentation(bindingIndex, scratch);
20902092
}
20912093

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)