1// RUN: %clang_cc1 -fobjc-exceptions -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result
2// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-exceptions -fblocks -fsyntax-only -x objective-c %s > %t
3// RUN: diff %t %s.result
4
5#define nil 0
6
7typedef int BOOL;
8
9id IhaveSideEffect();
10
11@protocol NSObject
12- (BOOL)isEqual:(id)object;
13- (id)retain;
14- (oneway void)release;
15@end
16
17@interface NSObject <NSObject> {}
18@end
19
20@interface Foo : NSObject {
21  id bar;
22}
23@property (retain) id bar;
24-(void)test:(id)obj;
25@end
26
27@implementation Foo
28
29@synthesize bar;
30
31-(void)test:(id)obj {
32  id x = self.bar;
33  [x retain];
34  self.bar = obj;
35  // do stuff with x;
36  [x release];
37
38  [IhaveSideEffect() release];
39
40  [x release], x = 0;
41
42  @try {
43  } @finally {
44    [x release];
45  }
46}
47
48@end
49
50void func(Foo *p) {
51  [p release];
52  (([p release]));
53}
54
55@interface Baz {
56	id <NSObject> _foo;
57}
58@end
59
60@implementation Baz
61- (void) dealloc {
62  [_foo release];
63}
64@end
65
66void block_test(Foo *p) {
67  id (^B)() = ^() {
68    if (p) {
69      id (^IB)() = ^() {
70        id bar = [p retain];
71	      [p release];
72        return bar;
73      };
74      IB();
75    }
76    return [p retain];
77  };
78}
79
80#define RELEASE_MACRO(x) [x release]
81#define RELEASE_MACRO2(x) RELEASE_MACRO(x)
82
83void test2(id p) {
84  RELEASE_MACRO(p);
85  RELEASE_MACRO2(p);
86}
87
88@implementation Foo2
89
90static id internal_var = 0;
91
92+ (void)setIt:(id)newone {
93    if (internal_var != newone) {
94        [internal_var release];
95        internal_var = [newone retain];
96    }
97}
98@end
99