Skip to content

Commit 0d54d9f

Browse files
committed
[MoveOnlyAddressChecker] Exclusivity handles DEs.
Switch to the areUsesWithinBoundary API which takes dead-ends into account. rdar://131960619
1 parent 0350023 commit 0d54d9f

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerTester.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class MoveOnlyAddressCheckerTesterPass : public SILFunctionTransform {
9090
auto *dominanceAnalysis = getAnalysis<DominanceAnalysis>();
9191
DominanceInfo *domTree = dominanceAnalysis->get(fn);
9292
auto *poa = getAnalysis<PostOrderAnalysis>();
93+
auto *deba = getAnalysis<DeadEndBlocksAnalysis>();
9394

9495
DiagnosticEmitter diagnosticEmitter(fn);
9596
llvm::SmallSetVector<MarkUnresolvedNonCopyableValueInst *, 32>
@@ -108,8 +109,8 @@ class MoveOnlyAddressCheckerTesterPass : public SILFunctionTransform {
108109
LLVM_DEBUG(llvm::dbgs() << "No move introducers found?!\n");
109110
} else {
110111
borrowtodestructure::IntervalMapAllocator allocator;
111-
MoveOnlyAddressChecker checker{getFunction(), diagnosticEmitter,
112-
allocator, domTree, poa};
112+
MoveOnlyAddressChecker checker{
113+
getFunction(), diagnosticEmitter, allocator, domTree, deba, poa};
113114
madeChange = checker.completeLifetimes();
114115
madeChange |= checker.check(moveIntroducersToProcess);
115116
}

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,8 @@ struct MoveOnlyAddressCheckerPImpl {
14771477
/// Information about destroys that we use when inserting destroys.
14781478
ConsumeInfo consumes;
14791479

1480+
DeadEndBlocksAnalysis *deba;
1481+
14801482
/// PostOrderAnalysis used by the BorrowToDestructureTransform.
14811483
PostOrderAnalysis *poa;
14821484

@@ -1486,10 +1488,11 @@ struct MoveOnlyAddressCheckerPImpl {
14861488
MoveOnlyAddressCheckerPImpl(
14871489
SILFunction *fn, DiagnosticEmitter &diagnosticEmitter,
14881490
DominanceInfo *domTree, PostOrderAnalysis *poa,
1491+
DeadEndBlocksAnalysis *deba,
14891492
borrowtodestructure::IntervalMapAllocator &allocator)
14901493
: fn(fn), deleter(), canonicalizer(fn, domTree, deleter),
14911494
addressUseState(domTree), diagnosticEmitter(diagnosticEmitter),
1492-
poa(poa), allocator(allocator) {
1495+
deba(deba), poa(poa), allocator(allocator) {
14931496
deleter.setCallbacks(std::move(
14941497
InstModCallbacks().onDelete([&](SILInstruction *instToDelete) {
14951498
if (auto *mvi =
@@ -2049,7 +2052,9 @@ struct GatherUsesVisitor : public TransitiveAddressWalker<GatherUsesVisitor> {
20492052
liveness->initializeDef(bai);
20502053
liveness->computeSimple();
20512054
for (auto *consumingUse : li->getConsumingUses()) {
2052-
if (!liveness->isWithinBoundary(consumingUse->getUser())) {
2055+
if (!liveness->areUsesWithinBoundary(
2056+
{consumingUse},
2057+
moveChecker.deba->get(consumingUse->getFunction()))) {
20532058
diagnosticEmitter.emitAddressExclusivityHazardDiagnostic(
20542059
markedValue, consumingUse->getUser());
20552060
emittedError = true;
@@ -3980,7 +3985,7 @@ bool MoveOnlyAddressChecker::check(
39803985
&moveIntroducersToProcess) {
39813986
assert(moveIntroducersToProcess.size() &&
39823987
"Must have checks to process to call this function");
3983-
MoveOnlyAddressCheckerPImpl pimpl(fn, diagnosticEmitter, domTree, poa,
3988+
MoveOnlyAddressCheckerPImpl pimpl(fn, diagnosticEmitter, domTree, poa, deba,
39843989
allocator);
39853990

39863991
#ifndef NDEBUG

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
namespace swift {
1919

2020
class PostOrderAnalysis;
21+
class DeadEndBlocksAnalysis;
2122

2223
namespace siloptimizer {
2324

@@ -38,6 +39,7 @@ struct MoveOnlyAddressChecker {
3839
DiagnosticEmitter &diagnosticEmitter;
3940
borrowtodestructure::IntervalMapAllocator &allocator;
4041
DominanceInfo *domTree;
42+
DeadEndBlocksAnalysis *deba;
4143
PostOrderAnalysis *poa;
4244

4345
/// \returns true if we changed the IR. To see if we emitted a diagnostic, use

lib/SILOptimizer/Mandatory/MoveOnlyChecker.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ struct MoveOnlyChecker {
7878
DiagnosticEmitter diagnosticEmitter;
7979
SILFunction *fn;
8080
DominanceInfo *domTree;
81+
DeadEndBlocksAnalysis *deba;
8182
PostOrderAnalysis *poa;
8283
bool madeChange = false;
8384
borrowtodestructure::IntervalMapAllocator allocator;
8485

8586
MoveOnlyChecker(SILFunction *fn, DominanceInfo *domTree,
86-
PostOrderAnalysis *poa)
87-
: diagnosticEmitter(fn), fn(fn), domTree(domTree), poa(poa) {
88-
}
87+
DeadEndBlocksAnalysis *deba, PostOrderAnalysis *poa)
88+
: diagnosticEmitter(fn), fn(fn), domTree(domTree), deba(deba), poa(poa) {}
8989

9090
void checkObjects();
9191
void completeObjectLifetimes(ArrayRef<MarkUnresolvedNonCopyableValueInst *>);
@@ -203,8 +203,8 @@ void MoveOnlyChecker::checkAddresses() {
203203
return;
204204
}
205205

206-
MoveOnlyAddressChecker checker{fn, diagnosticEmitter, allocator, domTree,
207-
poa};
206+
MoveOnlyAddressChecker checker{
207+
fn, diagnosticEmitter, allocator, domTree, deba, poa};
208208
madeChange |= checker.completeLifetimes();
209209
madeChange |= checker.check(moveIntroducersToProcess);
210210
}
@@ -256,9 +256,9 @@ class MoveOnlyCheckerPass : public SILFunctionTransform {
256256
LLVM_DEBUG(llvm::dbgs()
257257
<< "===> MoveOnly Checker. Visiting: " << fn->getName() << '\n');
258258

259-
MoveOnlyChecker checker(
260-
fn, getAnalysis<DominanceAnalysis>()->get(fn),
261-
getAnalysis<PostOrderAnalysis>());
259+
MoveOnlyChecker checker(fn, getAnalysis<DominanceAnalysis>()->get(fn),
260+
getAnalysis<DeadEndBlocksAnalysis>(),
261+
getAnalysis<PostOrderAnalysis>());
262262

263263
checker.checkObjects();
264264
checker.checkAddresses();

test/SILOptimizer/moveonly_addresschecker.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,14 @@ func testAssertLikeUseDifferentBits() {
3535
}
3636
}
3737
}
38+
39+
// issue #75312
40+
struct S
41+
{
42+
@usableFromInline
43+
init(utf8:consuming [UInt8])
44+
{
45+
utf8.withUnsafeBufferPointer { _ in }
46+
fatalError()
47+
}
48+
}

0 commit comments

Comments
 (0)