Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % clang -v
- Apple LLVM version 5.0 (clang-500.2.75) (based on LLVM 3.3svn)
- Target: x86_64-apple-darwin12.4.0
- Thread model: posix
- % cat testARC.m
- #import <Foundation/Foundation.h>
- static BOOL gSomeValue;
- static BOOL DoSomeCheck(void)
- {
- return gSomeValue;
- }
- @interface Scoped : NSObject
- @end
- @implementation Scoped
- - (instancetype)init
- {
- self = [super init];
- NSLog(@"%s %@", __func__, self);
- return self;
- }
- - (void)dealloc
- {
- NSLog(@"%s %@", __func__, self);
- }
- @end
- int main(int argc, char **argv)
- {
- gSomeValue = YES;
- {
- __attribute__((objc_precise_lifetime)) Scoped *scoped = [[Scoped alloc] init];
- NSLog(@"At the end of first block");
- }
- {
- __attribute__((objc_precise_lifetime)) Scoped *scoped = DoSomeCheck() ? [[Scoped alloc] init] : nil;
- NSLog(@"At the end of second block");
- }
- {
- Scoped *scopeMe = DoSomeCheck() ? [[Scoped alloc] init] : nil;
- __attribute__((objc_precise_lifetime)) Scoped *scoped = scopeMe;
- NSLog(@"At the end of third block");
- }
- }
- % clang -fobjc-arc -O0 -o testARC-dbg ./testARC.m
- % clang -fobjc-arc -Os -o testARC-opt ./testARC.m
- % ./testARC-dbg
- 2013-11-01 16:53:27.387 testARC-dbg[85843:707] -[Scoped init] <Scoped: 0x7f9102c081c0>
- 2013-11-01 16:53:27.389 testARC-dbg[85843:707] At the end of first block
- 2013-11-01 16:53:27.389 testARC-dbg[85843:707] -[Scoped dealloc] <Scoped: 0x7f9102c081c0>
- 2013-11-01 16:53:27.390 testARC-dbg[85843:707] -[Scoped init] <Scoped: 0x7f9103b009d0>
- 2013-11-01 16:53:27.390 testARC-dbg[85843:707] At the end of second block
- 2013-11-01 16:53:27.390 testARC-dbg[85843:707] -[Scoped dealloc] <Scoped: 0x7f9103b009d0>
- 2013-11-01 16:53:27.391 testARC-dbg[85843:707] -[Scoped init] <Scoped: 0x7f9102c02b40>
- 2013-11-01 16:53:27.408 testARC-dbg[85843:707] At the end of third block
- 2013-11-01 16:53:27.412 testARC-dbg[85843:707] -[Scoped dealloc] <Scoped: 0x7f9102c02b40>
- % ./testARC-opt
- 2013-11-01 16:53:13.479 testARC-opt[85825:707] -[Scoped init] <Scoped: 0x7ff758c081a0>
- 2013-11-01 16:53:13.484 testARC-opt[85825:707] At the end of first block
- 2013-11-01 16:53:13.485 testARC-opt[85825:707] -[Scoped dealloc] <Scoped: 0x7ff758c081a0>
- 2013-11-01 16:53:13.486 testARC-opt[85825:707] -[Scoped init] <Scoped: 0x7ff759b00470>
- 2013-11-01 16:53:13.486 testARC-opt[85825:707] -[Scoped dealloc] <Scoped: 0x7ff759b00470>
- 2013-11-01 16:53:13.487 testARC-opt[85825:707] At the end of second block
- 2013-11-01 16:53:13.489 testARC-opt[85825:707] -[Scoped init] <Scoped: 0x7ff759900140>
- 2013-11-01 16:53:13.489 testARC-opt[85825:707] At the end of third block
- 2013-11-01 16:53:13.490 testARC-opt[85825:707] -[Scoped dealloc] <Scoped: 0x7ff759900140>
Advertisement
Add Comment
Please, Sign In to add comment