Skip to content

Commit eea57a0

Browse files
[SR-7263] Ensure caller alive after optimization
1 parent 4664bc6 commit eea57a0

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#import <Foundation/Foundation.h>
2+
3+
@interface Foo: NSObject
4+
5+
- (CFTypeRef _Nonnull)bar;
6+
- (CFTypeRef _Nullable)nullabar;
7+
8+
@end
9+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#import "objc_implicit_inner_pointer.h"
2+
3+
@implementation Foo {
4+
CFTypeRef _bar;
5+
}
6+
7+
- (id)init {
8+
_bar = (__bridge_retained CFTypeRef)[[NSNumber alloc] initWithInt:1234567891];
9+
return self;
10+
}
11+
12+
- (CFTypeRef)bar {
13+
return _bar;
14+
}
15+
16+
- (CFTypeRef)nullabar {
17+
return _bar;
18+
}
19+
20+
- (void)dealloc {
21+
printf("%s", __FUNCTION__);
22+
23+
if (_bar)
24+
CFRelease(_bar);
25+
}
26+
27+
@end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-clang -fobjc-arc %S/Inputs/objc_implicit_inner_pointer/objc_implicit_inner_pointer.m -c -o %t/objc_implicit_inner_pointer.o
3+
// RUN: %target-build-swift %s -import-objc-header %S/Inputs/objc_implicit_inner_pointer/objc_implicit_inner_pointer.h %t/objc_implicit_inner_pointer.o -o %t/main
4+
// RUN: %target-run %t/main | %FileCheck %s
5+
6+
// REQUIRES: executable_test
7+
// REQUIRES: objc_interop
8+
9+
do {
10+
// The lifetime of Foo() currently gets extended using autorelease.
11+
autoreleasepool {
12+
let x = Foo().bar().takeUnretainedValue()
13+
print(x) // CHECK: 1234567891
14+
} // CHECK: -[Foo dealloc]
15+
16+
autoreleasepool {
17+
let y = Foo().nullabar()!.takeUnretainedValue()
18+
print(y) // CHECK: 1234567891
19+
} // CHECK: -[Foo dealloc]
20+
}
21+

0 commit comments

Comments
 (0)