Skip to content

Commit 5045371

Browse files
committed
AddressLowering: Allow lowering of begin_borrow [lexical] with no lexical address producers
1 parent 00dc5ff commit 5045371

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,21 +2760,16 @@ void UseRewriter::visitBeginBorrowInst(BeginBorrowInst *borrow) {
27602760
assert(use == getProjectedDefOperand(borrow));
27612761

27622762
// Mark the value as rewritten and use the operand's storage.
2763-
auto address = pass.valueStorageMap.getStorage(use->get()).storageAddress;
2764-
markRewritten(borrow, address);
2763+
auto storageAddr = pass.valueStorageMap.getStorage(use->get()).storageAddress;
2764+
markRewritten(borrow, storageAddr);
27652765

27662766
// Borrows are irrelevant unless they are marked lexical.
27672767
if (borrow->isLexical()) {
2768-
if (auto *allocStack = dyn_cast<AllocStackInst>(address)) {
2768+
if (auto *allocStack = dyn_cast<AllocStackInst>(storageAddr)) {
27692769
allocStack->setIsLexical();
27702770
return;
27712771
}
2772-
// Function arguments are inherently lexical.
2773-
if (isa<SILFunctionArgument>(address))
2774-
return;
2775-
2776-
SWIFT_ASSERT_ONLY(address->dump());
2777-
llvm_unreachable("^^^ unknown lexical address producer");
2772+
return;
27782773
}
27792774
}
27802775

test/SILGen/opaque_values_silgen.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ func propOfLValue(_ x: Error) -> String {
156156
// HECK: [[LOAD:%.*]] = load [copy] %{{.*}} : $*T
157157
// HECK: return [[LOAD]] : $T
158158
// CHECK-LABEL: } // end sil function '$s20opaque_values_silgen7lastValyxxd_tlF'
159-
func lastVal<T>(_ rest: T...) -> T {
160-
var minValue: T
159+
func lastVal<T>(_ initial: T, _ rest: T...) -> T {
160+
var minValue = initial
161161
for value in rest {
162162
minValue = value
163163
}
@@ -399,7 +399,7 @@ func testEmptyReturnClosure() {
399399
// CHECK: bb1(%{{.*}} : @guaranteed $C):
400400
// CHECK: bb2(%{{.*}} : @guaranteed $AnyObject):
401401
// CHECK-LABEL: } // end sil function
402-
func testCastClassToAnyObject(_ c: C) -> AnyObject {
402+
func testCastClassToAnyObject(_ c: C) {
403403
switch (c) {
404404
case let x as AnyObject:
405405
_ = x
@@ -412,7 +412,7 @@ func testCastClassToAnyObject(_ c: C) -> AnyObject {
412412
// CHECK: [[CP:%.*]] = copy_value %0 : $AnyObject
413413
// CHECK: checked_cast_br [[CP]] : $AnyObject to C, bb1, bb2
414414
// CHECK-LABEL: } // end sil function '$s20opaque_values_silgen24testCastAnyObjectToClassyAA1CCyXlF'
415-
func testCastAnyObjectToClass(_ o: AnyObject) -> C {
415+
func testCastAnyObjectToClass(_ o: AnyObject) {
416416
switch (o) {
417417
case let x as C:
418418
_ = x
@@ -427,7 +427,7 @@ func testCastAnyObjectToClass(_ o: AnyObject) -> C {
427427
// CHECK: [[CP:%.*]] = copy_value %0 : $T
428428
// CHECK: checked_cast_br [[CP]] : $T to C, bb1, bb2
429429
// CHECK-LABEL: } // end sil function '$s20opaque_values_silgen024testCastClassArchetypeToF0yAA1CCxRlzClF'
430-
func testCastClassArchetypeToClass<T : AnyObject>(_ o: T) -> C {
430+
func testCastClassArchetypeToClass<T : AnyObject>(_ o: T) {
431431
switch (o) {
432432
case let x as C:
433433
_ = x
@@ -438,7 +438,10 @@ func testCastClassArchetypeToClass<T : AnyObject>(_ o: T) -> C {
438438
}
439439

440440
class TestGeneric<T> {
441-
init() {}
441+
init(_ _generic:T, _ _borrowedGeneric:T) {
442+
generic = _generic
443+
borrowedGeneric = _borrowedGeneric
444+
}
442445

443446
var generic: T
444447
@_borrowed

0 commit comments

Comments
 (0)