1// RUN: %clang_cc1 -emit-llvm -fblocks -fobjc-arc -g -triple x86_64-apple-darwin10 %s -o - | FileCheck %s
2
3// Legend: EXP = Return expression, RET = ret instruction
4
5// CHECK: define {{.*}}testNoSideEffect
6// CHECK: call void @objc_storeStrong{{.*}}
7// CHECK: call void @objc_storeStrong{{.*}} !dbg ![[RET1:[0-9]+]]
8// CHECK: ret {{.*}} !dbg ![[RET1]]
9
10// CHECK: define {{.*}}testNoCleanup
11// CHECK: ret {{.*}} !dbg ![[RET2:[0-9]+]]
12
13// CHECK: define {{.*}}testSideEffect
14// CHECK: @objc_msgSend{{.*}} !dbg ![[MSG3:[0-9]+]]
15// CHECK: ret {{.*}} !dbg ![[RET3:[0-9]+]]
16
17// CHECK: define {{.*}}testMultiline
18// CHECK: @objc_msgSend{{.*}} !dbg ![[MSG4:[0-9]+]]
19// CHECK: load{{.*}} !dbg ![[EXP4:[0-9]+]]
20// CHECK: ret {{.*}} !dbg ![[RET4:[0-9]+]]
21
22// CHECK: define {{.*}}testVoid
23// CHECK: call void @objc_storeStrong{{.*}}
24// CHECK: call void @objc_storeStrong{{.*}} !dbg ![[RET5:[0-9]+]]
25// CHECK: ret {{.*}} !dbg ![[RET5]]
26
27// CHECK: define {{.*}}testVoidNoReturn
28// CHECK: @objc_msgSend{{.*}} !dbg ![[MSG6:[0-9]+]]
29// CHECK: ret {{.*}} !dbg ![[RET6:[0-9]+]]
30
31// CHECK: define {{.*}}testNoCleanupSideEffect
32// CHECK: @objc_msgSend{{.*}} !dbg ![[MSG7:[0-9]+]]
33// CHECK: ret {{.*}} !dbg ![[RET7:[0-9]+]]
34
35// CHECK: define {{.*}}testCleanupVoid
36// CHECK: icmp ne {{.*}}!dbg ![[SKIP1:[0-9]+]]
37// CHECK: store i32 0, i32* {{.*}}, !dbg ![[RET8:[0-9]+]]
38// CHECK: @objc_storeStrong{{.*}}, !dbg ![[ARC8:[0-9]+]]
39// CHECK: ret {{.*}} !dbg ![[RET8]]
40
41typedef signed char BOOL;
42
43@interface NSObject
44+ (id)alloc;
45- (id)init;
46- (id)retain;
47@end
48
49@class NSString;
50
51@interface AppDelegate : NSObject
52
53@end
54
55@implementation AppDelegate : NSObject
56
57// CHECK: ![[TESTNOSIDEEFFECT:.*]] = {{.*}}[ DW_TAG_subprogram ] [line [[@LINE+1]]] [local] [def] [-[AppDelegate testNoSideEffect:]]
58- (int)testNoSideEffect:(NSString *)foo {
59  int x = 1;
60  return 1; // Return expression
61  // CHECK: ![[RET1]] = !MDLocation(line: [[@LINE+1]], scope: ![[TESTNOSIDEEFFECT]])
62}           // Cleanup + Ret
63
64- (int)testNoCleanup {
65  // CHECK: ![[RET2]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
66  return 1;
67}
68
69- (int)testSideEffect:(NSString *)foo {
70  // CHECK: ![[MSG3]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
71  return [self testNoSideEffect :foo];
72  // CHECK: ![[RET3]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
73}
74
75- (int)testMultiline:(NSString *)foo {
76  // CHECK: ![[MSG4]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
77  int r = [self testSideEffect :foo];
78  // CHECK: ![[EXP4]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
79  return r;
80  // CHECK: ![[RET4]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
81}
82
83- (void)testVoid:(NSString *)foo {
84  return;
85  // CHECK: ![[RET5]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
86}
87
88- (void)testVoidNoReturn:(NSString *)foo {
89  // CHECK: ![[MSG6]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
90  [self testVoid :foo];
91  // CHECK: ![[RET6]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
92}
93
94- (int)testNoCleanupSideEffect {
95  // CHECK: ![[MSG7]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
96  [self testVoid :@"foo"];
97  // CHECK: ![[RET7]] = !MDLocation(line: [[@LINE+1]], scope: !{{.*}})
98  return 1;
99}
100
101- (void)testCleanupVoid:(BOOL)skip withDelegate: (AppDelegate *) delegate {
102  static BOOL skip_all;
103  // CHECK: ![[SKIP1]] = !MDLocation(line: [[@LINE+1]], scope:
104  if (!skip_all) {
105    if (!skip) {
106      return;
107    }
108    NSString *s = @"bar";
109    if (!skip) {
110      [delegate testVoid :s];
111    }
112  }
113  // CHECK: ![[RET8]] = !MDLocation(line: [[@LINE+2]], scope:
114  // CHECK: ![[ARC8]] = !MDLocation(line: [[@LINE+1]], scope:
115}
116
117
118@end
119
120
121int main(int argc, const char** argv) {
122  AppDelegate *o = [[AppDelegate alloc] init];
123  return [o testMultiline :@"foo"];
124}
125