Skip to content

[MoveOnlyAddressChecker] Exclusivity handles DeadEnds. #75404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}