Skip to content

Commit dc73b5a

Browse files
authored
Merge pull request #65864 from gottesmm/pr-cfee502eb154203b1fda427c5ce8d64de2158c85
[move-only] Fix a thinko where we are treating inout convention as a consuming use instead of liveness use.
2 parents 290ede8 + a4fcdd8 commit dc73b5a

File tree

5 files changed

+20
-41
lines changed

5 files changed

+20
-41
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ static bool memInstMustConsume(Operand *memOper) {
433433
return false;
434434
ApplySite applySite(pai);
435435
auto convention = applySite.getArgumentConvention(*memOper);
436-
return convention.isInoutConvention();
436+
return !convention.isInoutConvention();
437437
}
438438
case SILInstructionKind::DestroyAddrInst:
439439
return true;
@@ -1802,8 +1802,9 @@ bool GatherUsesVisitor::visitUse(Operand *op) {
18021802
}
18031803

18041804
if (auto *pas = dyn_cast<PartialApplyInst>(user)) {
1805-
if (pas->isOnStack()) {
1806-
LLVM_DEBUG(llvm::dbgs() << "Found on stack partial apply!\n");
1805+
if (pas->isOnStack() ||
1806+
ApplySite(pas).getArgumentConvention(*op).isInoutConvention()) {
1807+
LLVM_DEBUG(llvm::dbgs() << "Found on stack partial apply or inout usage!\n");
18071808
// On-stack partial applications and their final consumes are always a
18081809
// liveness use of their captures.
18091810
auto leafRange = TypeTreeLeafTypeRange::get(op->get(), getRootAddress());

test/SILGen/moveonly_escaping_closure.swift

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,8 @@ func testConsumingEscapeClosureCaptureLet(_ f: consuming @escaping () -> ()) {
607607
// CHECK: } // end sil function '$s16moveonly_closure29testGlobalClosureCaptureInOutyyAA9SingleEltVzFyycfU_'
608608
var globalClosureCaptureInOut: () -> () = {}
609609
func testGlobalClosureCaptureInOut(_ x: inout SingleElt) {
610-
// expected-error @-1 {{'x' consumed but not reinitialized before end of function}}
611-
// expected-note @-2 {{'x' is declared 'inout'}}
610+
// expected-note @-1 {{'x' is declared 'inout'}}
612611
globalClosureCaptureInOut = { // expected-error {{escaping closure captures 'inout' parameter 'x'}}
613-
// expected-note @-1 {{consuming use here}}
614612
borrowVal(x) // expected-note {{captured here}}
615613
consumeVal(x) // expected-note {{captured here}}
616614
consumeVal(x) // expected-note {{captured here}}
@@ -652,9 +650,7 @@ func testGlobalClosureCaptureInOut(_ x: inout SingleElt) {
652650
// CHECK: } // end sil function '$s16moveonly_closure31testLocalLetClosureCaptureInOutyyAA9SingleEltVzFyycfU_'
653651
func testLocalLetClosureCaptureInOut(_ x: inout SingleElt) {
654652
// expected-note @-1 {{'x' is declared 'inout'}}
655-
// expected-error @-2 {{'x' consumed but not reinitialized before end of function}}
656653
let f = { // expected-error {{escaping closure captures 'inout' parameter 'x'}}
657-
// expected-note @-1 {{consuming use here}}
658654
borrowVal(x) // expected-note {{captured here}}
659655
consumeVal(x) // expected-note {{captured here}}
660656
consumeVal(x) // expected-note {{captured here}}
@@ -700,10 +696,8 @@ func testLocalLetClosureCaptureInOut(_ x: inout SingleElt) {
700696
// CHECK: apply {{%.*}}([[LOADED_READ]], [[LOADED_TAKE]])
701697
// CHECK: } // end sil function '$s16moveonly_closure31testLocalVarClosureCaptureInOutyyAA9SingleEltVzFyycfU_'
702698
func testLocalVarClosureCaptureInOut(_ x: inout SingleElt) {
703-
// expected-error @-1 {{'x' consumed but not reinitialized before end of function}}
704-
// expected-note @-2 {{'x' is declared 'inout'}}
705-
var f = { // expected-note {{consuming use here}}
706-
// expected-error @-1 {{escaping closure captures 'inout' parameter 'x'}}
699+
// expected-note @-1 {{'x' is declared 'inout'}}
700+
var f = { // expected-error {{escaping closure captures 'inout' parameter 'x'}}
707701
borrowVal(x) // expected-note {{captured here}}
708702
consumeVal(x) // expected-note {{captured here}}
709703
consumeVal(x) // expected-note {{captured here}}
@@ -750,10 +744,8 @@ func testLocalVarClosureCaptureInOut(_ x: inout SingleElt) {
750744
// CHECK: apply {{%.*}}([[LOADED_READ]], [[LOADED_TAKE]])
751745
// CHECK: } // end sil function '$s16moveonly_closure026testInOutVarClosureCapturedE0yyyycz_AA9SingleEltVztFyycfU_'
752746
func testInOutVarClosureCaptureInOut(_ f: inout () -> (), _ x: inout SingleElt) {
753-
// expected-error @-1 {{'x' consumed but not reinitialized before end of function}}
754-
// expected-note @-2 {{'x' is declared 'inout'}}
747+
// expected-note @-1 {{'x' is declared 'inout'}}
755748
f = { // expected-error {{escaping closure captures 'inout' parameter 'x'}}
756-
// expected-note @-1 {{consuming use here}}
757749
borrowVal(x) // expected-note {{captured here}}
758750
consumeVal(x) // expected-note {{captured here}}
759751
consumeVal(x) // expected-note {{captured here}}
@@ -805,9 +797,7 @@ func testInOutVarClosureCaptureInOut(_ f: inout () -> (), _ x: inout SingleElt)
805797
// CHECK: } // end sil function '$s16moveonly_closure38testConsumingEscapeClosureCaptureInOutyyyycn_AA9SingleEltVztFyycfU_'
806798
func testConsumingEscapeClosureCaptureInOut(_ f: consuming @escaping () -> (), _ x: inout SingleElt) {
807799
// expected-note @-1 {{'x' is declared 'inout'}}
808-
// expected-error @-2 {{'x' consumed but not reinitialized before end of function}}
809800
f = { // expected-error {{escaping closure captures 'inout' parameter 'x'}}
810-
// expected-note @-1 {{consuming use here}}
811801
borrowVal(x) // expected-note {{captured here}}
812802
consumeVal(x) // expected-note {{captured here}}
813803
consumeVal(x) // expected-note {{captured here}}

test/SILOptimizer/moveonly_addresschecker_diagnostics.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,9 +3116,8 @@ public func closureCaptureClassUseAfterConsumeError() {
31163116
}
31173117

31183118
public func closureCaptureClassArgUseAfterConsume(_ x2: inout Klass) {
3119-
// expected-error @-1 {{'x2' consumed but not reinitialized before end of function}}
3120-
// expected-note @-2 {{'x2' is declared 'inout'}}
3121-
let f = { // expected-note {{consuming use here}}
3119+
// expected-note @-1 {{'x2' is declared 'inout'}}
3120+
let f = {
31223121
// expected-error @-1 {{escaping closure captures 'inout' parameter 'x2'}}
31233122
borrowVal(x2) // expected-note {{captured here}}
31243123
consumeVal(x2) // expected-note {{captured here}}
@@ -3230,12 +3229,10 @@ public func closureAndDeferCaptureClassUseAfterConsume3() {
32303229
}
32313230

32323231
public func closureAndDeferCaptureClassArgUseAfterConsume(_ x2: inout Klass) {
3233-
// expected-error @-1 {{'x2' consumed but not reinitialized before end of function}}
3234-
// expected-error @-2 {{'x2' consumed in closure but not reinitialized before end of closure}}
3235-
// expected-error @-3 {{'x2' consumed more than once}}
3236-
// expected-note @-4 {{'x2' is declared 'inout'}}
3232+
// expected-error @-1 {{'x2' consumed in closure but not reinitialized before end of closure}}
3233+
// expected-error @-2 {{'x2' consumed more than once}}
3234+
// expected-note @-3 {{'x2' is declared 'inout'}}
32373235
let f = { // expected-error {{escaping closure captures 'inout' parameter 'x2'}}
3238-
// expected-note @-1 {{consuming use here}}
32393236
defer { // expected-note {{captured indirectly by this call}}
32403237
borrowVal(x2) // expected-note {{captured here}}
32413238
consumeVal(x2) // expected-note {{captured here}}
@@ -3280,11 +3277,9 @@ public func closureAndClosureCaptureClassUseAfterConsume2() {
32803277

32813278

32823279
public func closureAndClosureCaptureClassArgUseAfterConsume(_ x2: inout Klass) {
3283-
// expected-error @-1 {{'x2' consumed but not reinitialized before end of function}}
3280+
// expected-note @-1 {{'x2' is declared 'inout'}}
32843281
// expected-note @-2 {{'x2' is declared 'inout'}}
3285-
// expected-note @-3 {{'x2' is declared 'inout'}}
32863282
let f = { // expected-error {{escaping closure captures 'inout' parameter 'x2'}}
3287-
// expected-note @-1 {{consuming use here}}
32883283
let g = { // expected-error {{escaping closure captures 'inout' parameter 'x2'}}
32893284
// expected-note @-1 {{captured indirectly by this call}}
32903285
borrowVal(x2)

test/SILOptimizer/moveonly_objectchecker_diagnostics.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,9 +2787,7 @@ public func closureCaptureClassUseAfterConsume1(_ x: borrowing Klass) { // expec
27872787

27882788
public func closureCaptureClassUseAfterConsume2(_ x2: inout Klass) {
27892789
// expected-note @-1 {{'x2' is declared 'inout'}}
2790-
// expected-error @-2 {{'x2' consumed but not reinitialized before end of function}}
27912790
let f = { // expected-error {{escaping closure captures 'inout' parameter 'x2'}}
2792-
// expected-note @-1 {{consuming use here}}
27932791
borrowVal(x2) // expected-note {{captured here}}
27942792
consumeVal(x2) // expected-note {{captured here}}
27952793
consumeVal(x2) // expected-note {{captured here}}

test/SILOptimizer/moveonly_trivial_addresschecker_diagnostics.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,9 +1227,8 @@ public func closureCaptureClassUseAfterConsumeError() {
12271227
}
12281228

12291229
public func closureCaptureClassArgUseAfterConsume(_ x2: inout NonTrivialStruct) {
1230-
// expected-error @-1 {{'x2' consumed but not reinitialized before end of function}}
1231-
// expected-note @-2 {{'x2' is declared 'inout'}}
1232-
let f = { // expected-note {{consuming use here}}
1230+
// expected-note @-1 {{'x2' is declared 'inout'}}
1231+
let f = {
12331232
// expected-error @-1 {{escaping closure captures 'inout' parameter 'x2'}}
12341233
borrowVal(x2) // expected-note {{captured here}}
12351234
consumeVal(x2) // expected-note {{captured here}}
@@ -1341,12 +1340,10 @@ public func closureAndDeferCaptureClassUseAfterConsume3() {
13411340
}
13421341

13431342
public func closureAndDeferCaptureClassArgUseAfterConsume(_ x2: inout NonTrivialStruct) {
1344-
// expected-error @-1 {{'x2' consumed but not reinitialized before end of function}}
1345-
// expected-error @-2 {{'x2' consumed in closure but not reinitialized before end of closure}}
1346-
// expected-error @-3 {{'x2' consumed more than once}}
1347-
// expected-note @-4 {{'x2' is declared 'inout'}}
1343+
// expected-error @-1 {{'x2' consumed in closure but not reinitialized before end of closure}}
1344+
// expected-error @-2 {{'x2' consumed more than once}}
1345+
// expected-note @-3 {{'x2' is declared 'inout'}}
13481346
let f = { // expected-error {{escaping closure captures 'inout' parameter 'x2'}}
1349-
// expected-note @-1 {{consuming use here}}
13501347
defer { // expected-note {{captured indirectly by this call}}
13511348
borrowVal(x2) // expected-note {{captured here}}
13521349
consumeVal(x2) // expected-note {{captured here}}
@@ -1391,11 +1388,9 @@ public func closureAndClosureCaptureClassUseAfterConsume2() {
13911388

13921389

13931390
public func closureAndClosureCaptureClassArgUseAfterConsume(_ x2: inout NonTrivialStruct) {
1394-
// expected-error @-1 {{'x2' consumed but not reinitialized before end of function}}
1391+
// expected-note @-1 {{'x2' is declared 'inout'}}
13951392
// expected-note @-2 {{'x2' is declared 'inout'}}
1396-
// expected-note @-3 {{'x2' is declared 'inout'}}
13971393
let f = { // expected-error {{escaping closure captures 'inout' parameter 'x2'}}
1398-
// expected-note @-1 {{consuming use here}}
13991394
let g = { // expected-error {{escaping closure captures 'inout' parameter 'x2'}}
14001395
// expected-note @-1 {{captured indirectly by this call}}
14011396
borrowVal(x2)

0 commit comments

Comments
 (0)