From 3eb288f92e81710929f16f124d24cde87f747c3f Mon Sep 17 00:00:00 2001 From: Nate Chandler Date: Mon, 22 Jul 2024 13:26:08 -0700 Subject: [PATCH] [MoveOnlyAddressChecker] Exclusivity handles DEs. Switch to the areUsesWithinBoundary API which takes dead-ends into account. rdar://131960619 --- .../Mandatory/MoveOnlyAddressCheckerUtils.cpp | 11 ++++++++--- test/SILOptimizer/moveonly_addresschecker.swift | 11 +++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp b/lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp index 1a0b3e9773444..c05de26c15c65 100644 --- a/lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp +++ b/lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp @@ -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; @@ -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 = @@ -2049,7 +2052,9 @@ struct GatherUsesVisitor : public TransitiveAddressWalker { 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; @@ -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; diff --git a/test/SILOptimizer/moveonly_addresschecker.swift b/test/SILOptimizer/moveonly_addresschecker.swift index 8752373ccf3f9..491f028e8ae50 100644 --- a/test/SILOptimizer/moveonly_addresschecker.swift +++ b/test/SILOptimizer/moveonly_addresschecker.swift @@ -35,3 +35,14 @@ func testAssertLikeUseDifferentBits() { } } } + +// issue #75312 +struct S +{ + @usableFromInline + init(utf8:consuming [UInt8]) + { + utf8.withUnsafeBufferPointer { _ in } + fatalError() + } +}