Skip to content

Commit 67fb56d

Browse files
committed
Swift: workaround an internal crash coming from Swift 5.7.1
1 parent f618d53 commit 67fb56d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

swift/extractor/infra/SwiftDispatcher.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ class SwiftDispatcher {
215215
// Emits a Location TRAP entry and attaches it to a `Locatable` trap label
216216
template <typename Locatable>
217217
void attachLocation(Locatable* locatable, TrapLabel<LocatableTag> locatableLabel) {
218+
// Swift 5.7.1 causing a crash when the Swift compiler uses .back() of and empty
219+
// getPatternList() when getting the source location.
220+
// So far this only observed with the entities coming from precompiled modules, so they
221+
// should not have locations anyway.
222+
if constexpr (std::is_base_of<swift::Decl, Locatable>::value) {
223+
if (auto* decl = llvm::dyn_cast<swift::PatternBindingDecl>(locatable)) {
224+
if (decl->getPatternList().empty()) {
225+
return;
226+
}
227+
}
228+
}
218229
attachLocation(locatable->getStartLoc(), locatable->getEndLoc(), locatableLabel);
219230
}
220231

0 commit comments

Comments
 (0)