Skip to content

Commit 7cbd1c1

Browse files
Merge pull request #75408 from nate-chandler/cherrypick/release/6.0/rdar131960619
6.0: [MoveOnlyAddressChecker] Exclusivity handles DeadEnds.
2 parents 5e56b25 + 69b48ec commit 7cbd1c1

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerTester.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class MoveOnlyAddressCheckerTesterPass : public SILFunctionTransform {
8989
auto *dominanceAnalysis = getAnalysis<DominanceAnalysis>();
9090
DominanceInfo *domTree = dominanceAnalysis->get(fn);
9191
auto *poa = getAnalysis<PostOrderAnalysis>();
92+
auto *deadEndBlocksAnalysis = getAnalysis<DeadEndBlocksAnalysis>();
9293

9394
DiagnosticEmitter diagnosticEmitter(fn);
9495
llvm::SmallSetVector<MarkUnresolvedNonCopyableValueInst *, 32>
@@ -108,7 +109,8 @@ class MoveOnlyAddressCheckerTesterPass : public SILFunctionTransform {
108109
} else {
109110
borrowtodestructure::IntervalMapAllocator allocator;
110111
MoveOnlyAddressChecker checker{getFunction(), diagnosticEmitter,
111-
allocator, domTree, poa};
112+
allocator, domTree,
113+
poa, deadEndBlocksAnalysis};
112114
madeChange = checker.completeLifetimes();
113115
madeChange |= checker.check(moveIntroducersToProcess);
114116
}

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp

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

1476+
DeadEndBlocksAnalysis *deba;
1477+
14761478
/// PostOrderAnalysis used by the BorrowToDestructureTransform.
14771479
PostOrderAnalysis *poa;
14781480

@@ -1482,10 +1484,11 @@ struct MoveOnlyAddressCheckerPImpl {
14821484
MoveOnlyAddressCheckerPImpl(
14831485
SILFunction *fn, DiagnosticEmitter &diagnosticEmitter,
14841486
DominanceInfo *domTree, PostOrderAnalysis *poa,
1487+
DeadEndBlocksAnalysis *deba,
14851488
borrowtodestructure::IntervalMapAllocator &allocator)
14861489
: fn(fn), deleter(), canonicalizer(fn, domTree, deleter),
14871490
addressUseState(domTree), diagnosticEmitter(diagnosticEmitter),
1488-
poa(poa), allocator(allocator) {
1491+
deba(deba), poa(poa), allocator(allocator) {
14891492
deleter.setCallbacks(std::move(
14901493
InstModCallbacks().onDelete([&](SILInstruction *instToDelete) {
14911494
if (auto *mvi =
@@ -2045,7 +2048,9 @@ struct GatherUsesVisitor : public TransitiveAddressWalker<GatherUsesVisitor> {
20452048
liveness->initializeDef(bai);
20462049
liveness->computeSimple();
20472050
for (auto *consumingUse : li->getConsumingUses()) {
2048-
if (!liveness->isWithinBoundary(consumingUse->getUser())) {
2051+
if (!liveness->areUsesWithinBoundary(
2052+
{consumingUse},
2053+
moveChecker.deba->get(consumingUse->getFunction()))) {
20492054
diagnosticEmitter.emitAddressExclusivityHazardDiagnostic(
20502055
markedValue, consumingUse->getUser());
20512056
emittedError = true;
@@ -3976,7 +3981,7 @@ bool MoveOnlyAddressChecker::check(
39763981
assert(moveIntroducersToProcess.size() &&
39773982
"Must have checks to process to call this function");
39783983
MoveOnlyAddressCheckerPImpl pimpl(fn, diagnosticEmitter, domTree, poa,
3979-
allocator);
3984+
deadEndBlocksAnalysis, allocator);
39803985

39813986
#ifndef NDEBUG
39823987
static uint64_t numProcessed = 0;

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

@@ -39,6 +40,7 @@ struct MoveOnlyAddressChecker {
3940
borrowtodestructure::IntervalMapAllocator &allocator;
4041
DominanceInfo *domTree;
4142
PostOrderAnalysis *poa;
43+
DeadEndBlocksAnalysis *deadEndBlocksAnalysis;
4244

4345
/// \returns true if we changed the IR. To see if we emitted a diagnostic, use
4446
/// \p diagnosticEmitter.getDiagnosticCount().

lib/SILOptimizer/Mandatory/MoveOnlyChecker.cpp

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

8485
MoveOnlyChecker(SILFunction *fn, DominanceInfo *domTree,
85-
PostOrderAnalysis *poa)
86-
: diagnosticEmitter(fn), fn(fn), domTree(domTree), poa(poa) {
87-
}
86+
PostOrderAnalysis *poa, DeadEndBlocksAnalysis *deba)
87+
: diagnosticEmitter(fn), fn(fn), domTree(domTree), poa(poa), deba(deba) {}
8888

8989
void checkObjects();
9090
void completeObjectLifetimes(ArrayRef<MarkUnresolvedNonCopyableValueInst *>);
@@ -200,8 +200,8 @@ void MoveOnlyChecker::checkAddresses() {
200200
return;
201201
}
202202

203-
MoveOnlyAddressChecker checker{fn, diagnosticEmitter, allocator, domTree,
204-
poa};
203+
MoveOnlyAddressChecker checker{
204+
fn, diagnosticEmitter, allocator, domTree, poa, deba};
205205
madeChange |= checker.completeLifetimes();
206206
madeChange |= checker.check(moveIntroducersToProcess);
207207
}
@@ -253,9 +253,9 @@ class MoveOnlyCheckerPass : public SILFunctionTransform {
253253
LLVM_DEBUG(llvm::dbgs()
254254
<< "===> MoveOnly Checker. Visiting: " << fn->getName() << '\n');
255255

256-
MoveOnlyChecker checker(
257-
fn, getAnalysis<DominanceAnalysis>()->get(fn),
258-
getAnalysis<PostOrderAnalysis>());
256+
MoveOnlyChecker checker(fn, getAnalysis<DominanceAnalysis>()->get(fn),
257+
getAnalysis<PostOrderAnalysis>(),
258+
getAnalysis<DeadEndBlocksAnalysis>());
259259

260260
checker.checkObjects();
261261
checker.checkAddresses();

test/SILOptimizer/moveonly_addresschecker.swift

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

0 commit comments

Comments
 (0)