Skip to content

Commit e421305

Browse files
committed
Ban multiple returns in borrow accessors returning values as well
1 parent 90e3d1c commit e421305

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

lib/SILGen/SILGenStmt.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -782,11 +782,11 @@ void SILGenFunction::emitReturnExpr(SILLocation branchLoc,
782782
diag::borrow_accessor_not_a_projection_note);
783783
return;
784784
}
785-
// Address type phis are banned in SIL.
786-
// For now diagnose multiple return statements in such cases.
787-
// TODO: Support multiple epilog blocks in SILGen and SILOptimizer.
788-
if (F.getConventions().hasGuaranteedAddressResult() &&
789-
!ReturnDest.getBlock()->getPredecessorBlocks().empty()) {
785+
// For now diagnose multiple return statements in borrow/mutate accessors.
786+
// We need additional support for this.
787+
// 1. Address phis are banned in SIL.
788+
// 2. borrowed from is not inserted in SILGenCleanup.
789+
if (!ReturnDest.getBlock()->getPredecessorBlocks().empty()) {
790790
diagnose(getASTContext(), ret->getStartLoc(),
791791
diag::invalid_multiple_return_borrow_accessor);
792792
return;

test/SILGen/borrow_accessor.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public struct Wrapper {
104104
if Int.random(in: 1..<100) == 0 {
105105
return _k
106106
}
107-
return _k
107+
return _k // expected-error{{multiple return statements in borrow accessors are not yet supported}}
108108
}
109109
}
110110

@@ -401,18 +401,18 @@ func nctest() {
401401
// CHECK: return [[REG7]]
402402
// CHECK: }
403403

404-
// CHECK: sil hidden [ossa] @$s15borrow_accessor7WrapperV8if_klassAA5KlassCvb : $@convention(method) (@guaranteed Wrapper) -> @guaranteed Klass {
405-
// CHECK: bb0([[REG0:%.*]] : @guaranteed $Wrapper):
406-
// CHECK: cond_br {{.*}}, bb1, bb2
407-
// CHECK: bb1:
408-
// CHECK: [[EX1:%.*]] = struct_extract [[REG0]], #Wrapper._k
409-
// CHECK: br bb3([[EX1]])
410-
// CHECK: bb2:
411-
// CHECK: [[EX2:%.*]] = struct_extract [[REG0]], #Wrapper._k
412-
// CHECK: br bb3([[EX2]])
413-
// CHECK: bb3([[PHI:%.*]] : @guaranteed $Klass):
414-
// CHECK: return [[PHI]]
415-
// CHECK: }
404+
// TODO-CHECK: sil hidden [ossa] @$s15borrow_accessor7WrapperV8if_klassAA5KlassCvb : $@convention(method) (@guaranteed Wrapper) -> @guaranteed Klass {
405+
// TODO-CHECK: bb0([[REG0:%.*]] : @guaranteed $Wrapper):
406+
// TODO-CHECK: cond_br {{.*}}, bb1, bb2
407+
// TODO-CHECK: bb1:
408+
// TODO-CHECK: [[EX1:%.*]] = struct_extract [[REG0]], #Wrapper._k
409+
// TODO-CHECK: br bb3([[EX1]])
410+
// TODO-CHECK: bb2:
411+
// TODO-CHECK: [[EX2:%.*]] = struct_extract [[REG0]], #Wrapper._k
412+
// TODO-CHECK: br bb3([[EX2]])
413+
// TODO-CHECK: bb3([[PHI:%.*]] : @guaranteed $Klass):
414+
// TODO-CHECK: return [[PHI]]
415+
// TODO-CHECK: }
416416

417417
// CHECK: sil [ossa] @$s15borrow_accessor10GenWrapperV4propxvb : $@convention(method) <T> (@in_guaranteed GenWrapper<T>) -> @guaranteed_addr T {
418418
// CHECK: bb0([[REG0:%.*]] : $*GenWrapper<T>):

0 commit comments

Comments
 (0)