Skip to content

Commit 2fe155a

Browse files
committed
OSSALifetimeCompletion: check liveness failure
This transformation is invalid without complete liveness. Add a release assert to check this. Temporarily hide the assert under -verify-lifetime-completion until the passes that use this utility are fixed to check escapes.
1 parent 7760dbc commit 2fe155a

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

lib/SIL/Utils/OSSALifetimeCompletion.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@
6161

6262
using namespace swift;
6363

64+
// FIXME: remove this option after fixing:
65+
// rdar://145994924 (Mem2Reg calls lifetime completion without checking for
66+
// pointer escapes)
67+
llvm::cl::opt<bool> VerifyLifetimeCompletion(
68+
"verify-lifetime-completion", llvm::cl::init(false),
69+
llvm::cl::desc("."));
70+
6471
static SILInstruction *endOSSALifetime(SILValue value,
6572
OSSALifetimeCompletion::LifetimeEnd end,
6673
SILBuilder &builder,
@@ -493,8 +500,16 @@ bool OSSALifetimeCompletion::analyzeAndUpdateLifetime(
493500
}
494501
};
495502
Walker walker(*this, scopedAddress, boundary, liveness);
496-
std::move(walker).walk(scopedAddress.value);
497-
503+
AddressUseKind result = walker.walk(scopedAddress.value);
504+
if (VerifyLifetimeCompletion && boundary != Boundary::Availability
505+
&& result != AddressUseKind::NonEscaping) {
506+
llvm::errs() << "Incomplete liveness for:\n" << scopedAddress.value;
507+
if (auto *escapingUse = walker.getEscapingUse()) {
508+
llvm::errs() << " escapes at:\n";
509+
escapingUse->getUser()->printInContext(llvm::errs());
510+
}
511+
ASSERT(false && "caller must check for pointer escapes");
512+
}
498513
return endLifetimeAtBoundary(scopedAddress.value, liveness, boundary,
499514
deadEndBlocks);
500515
}
@@ -524,6 +539,15 @@ bool OSSALifetimeCompletion::analyzeAndUpdateLifetime(SILValue value,
524539
}
525540
InteriorLiveness liveness(value);
526541
liveness.compute(domInfo, handleInnerScope);
542+
if (VerifyLifetimeCompletion && boundary != Boundary::Availability
543+
&& liveness.getAddressUseKind() != AddressUseKind::NonEscaping) {
544+
llvm::errs() << "Incomplete liveness for: " << value;
545+
if (auto *escapingUse = liveness.escapingUse) {
546+
llvm::errs() << " escapes at:\n";
547+
escapingUse->getUser()->printInContext(llvm::errs());
548+
}
549+
ASSERT(false && "caller must check for pointer escapes");
550+
}
527551
return endLifetimeAtBoundary(value, liveness.getLiveness(), boundary,
528552
deadEndBlocks);
529553
}

0 commit comments

Comments
 (0)