From fd06bb1eeb7978649f19d54711e89e645883b977 Mon Sep 17 00:00:00 2001 From: Kavon Farvardin Date: Fri, 24 Oct 2025 11:57:34 -0700 Subject: [PATCH] DebugInfo: fix FSPL SILLocation assertion issue We were reusing the SILLocation from return instructions to generate projections to ultimately destroy values. This fix improves on what we were doing before, by converting the insertion point's SILLocation into a RegularLocation _without dropping_ the source location. If the SILLocation was tied to an ASTNode, it'll carry over the line location for this new regular location. Otherwise, it'll fallback to the prior strategy of producing a line 0 autogenerated location. resolves rdar://163281183 --- .../Utils/FieldSensitivePrunedLiveness.cpp | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) 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');