Skip to content

Commit 3535225

Browse files
Merge pull request #84543 from nate-chandler/rdar161371112
[OwnershipDiagnosticLowering] Visit autorelease_value insts.
2 parents a1e5a06 + d844cc3 commit 3535225

File tree

2 files changed

+86
-28
lines changed

2 files changed

+86
-28
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyWrappedTypeEliminator.cpp

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -205,43 +205,44 @@ struct SILMoveOnlyWrappedTypeEliminatorVisitor
205205

206206
#define NO_UPDATE_NEEDED(CLS) \
207207
bool visit##CLS##Inst(CLS##Inst *inst) { return false; }
208-
NO_UPDATE_NEEDED(AllocStack)
208+
NO_UPDATE_NEEDED(AddressToPointer)
209209
NO_UPDATE_NEEDED(AllocBox)
210-
NO_UPDATE_NEEDED(ProjectBox)
211-
NO_UPDATE_NEEDED(DebugValue)
212-
NO_UPDATE_NEEDED(StructElementAddr)
213-
NO_UPDATE_NEEDED(TupleElementAddr)
214-
NO_UPDATE_NEEDED(UncheckedTakeEnumDataAddr)
215-
NO_UPDATE_NEEDED(DestructureTuple)
216-
NO_UPDATE_NEEDED(DestructureStruct)
217-
NO_UPDATE_NEEDED(SelectEnum)
218-
NO_UPDATE_NEEDED(MarkDependence)
219-
NO_UPDATE_NEEDED(MarkDependenceAddr)
220-
NO_UPDATE_NEEDED(DestroyAddr)
221-
NO_UPDATE_NEEDED(DeallocStack)
222-
NO_UPDATE_NEEDED(DeallocBox)
210+
NO_UPDATE_NEEDED(AllocStack)
211+
NO_UPDATE_NEEDED(AutoreleaseValue)
212+
NO_UPDATE_NEEDED(BeginAccess)
223213
NO_UPDATE_NEEDED(Branch)
224-
NO_UPDATE_NEEDED(ExplicitCopyAddr)
225-
NO_UPDATE_NEEDED(CopyAddr)
226-
NO_UPDATE_NEEDED(RefElementAddr)
214+
NO_UPDATE_NEEDED(BridgeObjectToRef)
215+
NO_UPDATE_NEEDED(Builtin)
227216
NO_UPDATE_NEEDED(CheckedCastBranch)
228-
NO_UPDATE_NEEDED(Object)
229-
NO_UPDATE_NEEDED(OpenExistentialRef)
230-
NO_UPDATE_NEEDED(OpenExistentialAddr)
231-
NO_UPDATE_NEEDED(OpenExistentialBox)
217+
NO_UPDATE_NEEDED(ClassMethod)
232218
NO_UPDATE_NEEDED(ConvertFunction)
233-
NO_UPDATE_NEEDED(RefToBridgeObject)
234-
NO_UPDATE_NEEDED(BridgeObjectToRef)
235-
NO_UPDATE_NEEDED(BeginAccess)
219+
NO_UPDATE_NEEDED(CopyAddr)
220+
NO_UPDATE_NEEDED(DeallocBox)
221+
NO_UPDATE_NEEDED(DeallocStack)
222+
NO_UPDATE_NEEDED(DebugValue)
223+
NO_UPDATE_NEEDED(DestroyAddr)
224+
NO_UPDATE_NEEDED(DestructureStruct)
225+
NO_UPDATE_NEEDED(DestructureTuple)
236226
NO_UPDATE_NEEDED(EndAccess)
237227
NO_UPDATE_NEEDED(EndCOWMutationAddr)
238-
NO_UPDATE_NEEDED(ClassMethod)
239-
NO_UPDATE_NEEDED(FixLifetime)
240-
NO_UPDATE_NEEDED(AddressToPointer)
241228
NO_UPDATE_NEEDED(ExistentialMetatype)
242-
NO_UPDATE_NEEDED(Builtin)
229+
NO_UPDATE_NEEDED(ExplicitCopyAddr)
230+
NO_UPDATE_NEEDED(FixLifetime)
243231
NO_UPDATE_NEEDED(IgnoredUse)
232+
NO_UPDATE_NEEDED(MarkDependence)
233+
NO_UPDATE_NEEDED(MarkDependenceAddr)
244234
NO_UPDATE_NEEDED(ObjCMethod)
235+
NO_UPDATE_NEEDED(Object)
236+
NO_UPDATE_NEEDED(OpenExistentialAddr)
237+
NO_UPDATE_NEEDED(OpenExistentialBox)
238+
NO_UPDATE_NEEDED(OpenExistentialRef)
239+
NO_UPDATE_NEEDED(ProjectBox)
240+
NO_UPDATE_NEEDED(RefElementAddr)
241+
NO_UPDATE_NEEDED(RefToBridgeObject)
242+
NO_UPDATE_NEEDED(SelectEnum)
243+
NO_UPDATE_NEEDED(StructElementAddr)
244+
NO_UPDATE_NEEDED(TupleElementAddr)
245+
NO_UPDATE_NEEDED(UncheckedTakeEnumDataAddr)
245246
#undef NO_UPDATE_NEEDED
246247

247248
bool eliminateIdentityCast(SingleValueInstruction *svi) {
@@ -258,6 +259,7 @@ struct SILMoveOnlyWrappedTypeEliminatorVisitor
258259
}
259260
ELIMINATE_POTENTIAL_IDENTITY_CAST(Upcast)
260261
ELIMINATE_POTENTIAL_IDENTITY_CAST(UncheckedAddrCast)
262+
ELIMINATE_POTENTIAL_IDENTITY_CAST(UncheckedRefCast)
261263
ELIMINATE_POTENTIAL_IDENTITY_CAST(UnconditionalCheckedCast)
262264
#undef ELIMINATE_POTENTIAL_IDENTITY_CAST
263265
// We handle apply sites by just inserting a convert_function that converts
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
// RUN: %target-swift-frontend \
4+
// RUN: %t/Library.swift \
5+
// RUN: -enable-experimental-feature Lifetimes \
6+
// RUN: -sil-verify-all \
7+
// RUN: -verify \
8+
// RUN: -emit-sil \
9+
// RUN: -import-objc-header %t/Header.h \
10+
// RUN: > /dev/null
11+
12+
// REQUIRES: objc_interop
13+
14+
// REQUIRES: swift_feature_Lifetimes
15+
16+
//--- Header.h
17+
18+
@import Foundation;
19+
20+
@interface Foo : NSObject
21+
@property (nonatomic, readwrite) NSInteger length;
22+
- (const unichar *)_fastCharacterContents NS_RETURNS_INNER_POINTER;
23+
@end
24+
25+
//--- Library.swift
26+
27+
extension Foo {
28+
var utf16Span: Span<UInt16>? {
29+
@_lifetime(borrow self)
30+
borrowing get {
31+
// FIXME: This error shouldn't be here.
32+
guard let ptr = self._fastCharacterContents() else { // expected-error{{copy of noncopyable typed value}}
33+
return nil
34+
}
35+
let length = self.length
36+
let buffer = UnsafeBufferPointer(start: ptr, count: length)
37+
let span = unsafe Span<UInt16>(_unsafeElements: buffer)
38+
return _overrideLifetime(span, borrowing: self)
39+
}
40+
}
41+
}
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)