Skip to content

Commit d844cc3

Browse files
committed
[ODL] Visit unchecked_ref_cast insts.
Eliminate them if they're just identity casts.
1 parent d0cd8ac commit d844cc3

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyWrappedTypeEliminator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ struct SILMoveOnlyWrappedTypeEliminatorVisitor
259259
}
260260
ELIMINATE_POTENTIAL_IDENTITY_CAST(Upcast)
261261
ELIMINATE_POTENTIAL_IDENTITY_CAST(UncheckedAddrCast)
262+
ELIMINATE_POTENTIAL_IDENTITY_CAST(UncheckedRefCast)
262263
ELIMINATE_POTENTIAL_IDENTITY_CAST(UnconditionalCheckedCast)
263264
#undef ELIMINATE_POTENTIAL_IDENTITY_CAST
264265
// We handle apply sites by just inserting a convert_function that converts

validation-test/SILOptimizer/rdar161371112.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,18 @@ extension Foo {
3939
}
4040
}
4141
}
42+
43+
extension NSString {
44+
var utf16Span: Span<UInt16>? {
45+
@_lifetime(borrow self)
46+
borrowing get { // expected-error{{'self' is borrowed and cannot be consumed}}
47+
guard let ptr = CFStringGetCharactersPtr(self) else { // expected-note{{consumed here}}
48+
return nil
49+
}
50+
let length = self.length
51+
let buffer = UnsafeBufferPointer(start: ptr, count: length)
52+
let span = unsafe Span<UInt16>(_unsafeElements: buffer)
53+
return _overrideLifetime(span, borrowing: self)
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)