Skip to content

Commit

Permalink
Merge pull request #75404 from nate-chandler/rdar131960619
Browse files Browse the repository at this point in the history
[MoveOnlyAddressChecker] Exclusivity handles DeadEnds.
  • Loading branch information
nate-chandler authored Jul 23, 2024
2 parents 111bc46 + 3eb288f commit cc8af17
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,8 @@ struct MoveOnlyAddressCheckerPImpl {
/// Information about destroys that we use when inserting destroys.
ConsumeInfo consumes;

DeadEndBlocksAnalysis *deba;

/// PostOrderAnalysis used by the BorrowToDestructureTransform.
PostOrderAnalysis *poa;

Expand All @@ -1486,10 +1488,11 @@ struct MoveOnlyAddressCheckerPImpl {
MoveOnlyAddressCheckerPImpl(
SILFunction *fn, DiagnosticEmitter &diagnosticEmitter,
DominanceInfo *domTree, PostOrderAnalysis *poa,
DeadEndBlocksAnalysis *deba,
borrowtodestructure::IntervalMapAllocator &allocator)
: fn(fn), deleter(), canonicalizer(fn, domTree, deleter),
addressUseState(domTree), diagnosticEmitter(diagnosticEmitter),
poa(poa), allocator(allocator) {
deba(deba), poa(poa), allocator(allocator) {
deleter.setCallbacks(std::move(
InstModCallbacks().onDelete([&](SILInstruction *instToDelete) {
if (auto *mvi =
Expand Down Expand Up @@ -2049,7 +2052,9 @@ struct GatherUsesVisitor : public TransitiveAddressWalker<GatherUsesVisitor> {
liveness->initializeDef(bai);
liveness->computeSimple();
for (auto *consumingUse : li->getConsumingUses()) {
if (!liveness->isWithinBoundary(consumingUse->getUser())) {
if (!liveness->areUsesWithinBoundary(
{consumingUse},
moveChecker.deba->get(consumingUse->getFunction()))) {
diagnosticEmitter.emitAddressExclusivityHazardDiagnostic(
markedValue, consumingUse->getUser());
emittedError = true;
Expand Down Expand Up @@ -3981,7 +3986,7 @@ bool MoveOnlyAddressChecker::check(
assert(moveIntroducersToProcess.size() &&
"Must have checks to process to call this function");
MoveOnlyAddressCheckerPImpl pimpl(fn, diagnosticEmitter, domTree, poa,
allocator);
deadEndBlocksAnalysis, allocator);

#ifndef NDEBUG
static uint64_t numProcessed = 0;
Expand Down
11 changes: 11 additions & 0 deletions test/SILOptimizer/moveonly_addresschecker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,14 @@ func testAssertLikeUseDifferentBits() {
}
}
}

// issue #75312
struct S
{
@usableFromInline
init(utf8:consuming [UInt8])
{
utf8.withUnsafeBufferPointer { _ in }
fatalError()
}
}

0 comments on commit cc8af17

Please sign in to comment.