diff --git a/lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp b/lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp index 6722a24cda2db..7cf8faed89c79 100644 --- a/lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp +++ b/lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp @@ -441,10 +441,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');