diff --git a/lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp b/lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp index f9f091113b54b..0d3b4b5ae5b95 100644 --- a/lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp +++ b/lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp @@ -434,10 +434,23 @@ void TypeTreeLeafTypeRange::constructFilteredProjections( callback) { auto *fn = insertPt->getFunction(); SILType type = value->getType(); - auto loc = - (insertPt->getLoc().getKind() != SILLocation::ArtificialUnreachableKind) - ? insertPt->getLoc() - : RegularLocation::getAutoGeneratedLocation(); + + // Create a debug location appropriate for synthesizing projection + // instructions that satisfy `SILInstruction::verifyDebugInfo`, while + // trying to preserve debug info when it's valid to do so. + auto projectionLocFrom = [](SILInstruction *orig) -> SILLocation { + auto loc = orig->getLoc(); + switch (loc.getKind()) { + case SILLocation::ReturnKind: + case SILLocation::ImplicitReturnKind: + case SILLocation::ArtificialUnreachableKind: + return RegularLocation::getDebugOnlyLocation(loc, orig->getModule()); + + default: + return loc; + } + }; + SILLocation loc = projectionLocFrom(insertPt); PRUNED_LIVENESS_LOG(llvm::dbgs() << "ConstructFilteredProjection. Bv: " << filterBitVector << '\n');