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 ![[ARC1:[0-9]+]] 8 // CHECK: ret {{.*}} !dbg ![[RET1:[0-9]+]] 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 ![[ARC5:[0-9]+]] 25 // CHECK: ret {{.*}} !dbg ![[RET5:[0-9]+]] 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 41 typedef 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 // CHECK: ![[ARC1]] = metadata !{i32 [[@LINE+1]], i32 0, metadata ![[TESTNOSIDEEFFECT]], null} 61 return 1; // Return expression 62 // CHECK: ![[RET1]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null} 63 } // Cleanup + Ret 64 65 - (int)testNoCleanup { 66 // CHECK: ![[RET2]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null} 67 return 1; 68 } 69 70 - (int)testSideEffect:(NSString *)foo { 71 // CHECK: ![[MSG3]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null} 72 return [self testNoSideEffect :foo]; 73 // CHECK: ![[RET3]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null} 74 } 75 76 - (int)testMultiline:(NSString *)foo { 77 // CHECK: ![[MSG4]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null} 78 int r = [self testSideEffect :foo]; 79 // CHECK: ![[EXP4]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null} 80 return r; 81 // CHECK: ![[RET4]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null} 82 } 83 84 - (void)testVoid:(NSString *)foo { 85 // CHECK: ![[ARC5]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null} 86 return; 87 // CHECK: ![[RET5]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null} 88 } 89 90 - (void)testVoidNoReturn:(NSString *)foo { 91 // CHECK: ![[MSG6]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null} 92 [self testVoid :foo]; 93 // CHECK: ![[RET6]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null} 94 } 95 96 - (int)testNoCleanupSideEffect { 97 // CHECK: ![[MSG7]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null} 98 [self testVoid :@"foo"]; 99 // CHECK: ![[RET7]] = metadata !{i32 [[@LINE+1]], i32 0, metadata !{{.*}}, null} 100 return 1; 101 } 102 103 - (void)testCleanupVoid:(BOOL)skip withDelegate: (AppDelegate *) delegate { 104 static BOOL skip_all; 105 // CHECK: ![[SKIP1]] = metadata !{i32 [[@LINE+1]], i32 0, 106 if (!skip_all) { 107 if (!skip) { 108 return; 109 } 110 NSString *s = @"bar"; 111 if (!skip) { 112 [delegate testVoid :s]; 113 } 114 } 115 // CHECK: ![[RET8]] = metadata !{i32 [[@LINE+2]], i32 0, 116 // CHECK: ![[ARC8]] = metadata !{i32 [[@LINE+1]], i32 0, 117 } 118 119 120 @end 121 122 123 int main(int argc, const char** argv) { 124 AppDelegate *o = [[AppDelegate alloc] init]; 125 return [o testMultiline :@"foo"]; 126 } 127