xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenObjC/autorelease.m (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fobjc-runtime=macosx-10.7 -fexceptions -fobjc-exceptions -o - %s | FileCheck %s
2*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -emit-llvm -fobjc-runtime=macosx-10.7 -fexceptions -fobjc-exceptions -o - %s | FileCheck %s
3*f4a2713aSLionel Sambuc// rdar://8881826
4*f4a2713aSLionel Sambuc// rdar://9412038
5*f4a2713aSLionel Sambuc
6*f4a2713aSLionel Sambuc@interface I
7*f4a2713aSLionel Sambuc{
8*f4a2713aSLionel Sambuc  id ivar;
9*f4a2713aSLionel Sambuc}
10*f4a2713aSLionel Sambuc- (id) Meth;
11*f4a2713aSLionel Sambuc+ (id) MyAlloc;;
12*f4a2713aSLionel Sambuc@end
13*f4a2713aSLionel Sambuc
14*f4a2713aSLionel Sambuc@implementation I
15*f4a2713aSLionel Sambuc- (id) Meth {
16*f4a2713aSLionel Sambuc   @autoreleasepool {
17*f4a2713aSLionel Sambuc      id p = [I MyAlloc];
18*f4a2713aSLionel Sambuc      if (!p)
19*f4a2713aSLionel Sambuc        return ivar;
20*f4a2713aSLionel Sambuc   }
21*f4a2713aSLionel Sambuc  return 0;
22*f4a2713aSLionel Sambuc}
23*f4a2713aSLionel Sambuc+ (id) MyAlloc {
24*f4a2713aSLionel Sambuc    return 0;
25*f4a2713aSLionel Sambuc}
26*f4a2713aSLionel Sambuc@end
27*f4a2713aSLionel Sambuc
28*f4a2713aSLionel Sambuc// CHECK: call i8* @objc_autoreleasePoolPush
29*f4a2713aSLionel Sambuc// CHECK: [[T:%.*]] = load i8** [[A:%.*]]
30*f4a2713aSLionel Sambuc// CHECK: call void @objc_autoreleasePoolPop
31*f4a2713aSLionel Sambuc
32*f4a2713aSLionel Sambuc// rdar://13660038
33*f4a2713aSLionel Sambucint tryTo(int (*f)(void)) {
34*f4a2713aSLionel Sambuc  @try {
35*f4a2713aSLionel Sambuc    @autoreleasepool {
36*f4a2713aSLionel Sambuc      return f();
37*f4a2713aSLionel Sambuc    }
38*f4a2713aSLionel Sambuc  } @catch (...) {
39*f4a2713aSLionel Sambuc    return 0;
40*f4a2713aSLionel Sambuc  }
41*f4a2713aSLionel Sambuc}
42*f4a2713aSLionel Sambuc// CHECK-LABEL:    define i32 @tryTo(i32 ()*
43*f4a2713aSLionel Sambuc// CHECK:      [[RET:%.*]] = alloca i32,
44*f4a2713aSLionel Sambuc// CHECK:      [[T0:%.*]] = call i8* @objc_autoreleasePoolPush()
45*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = load i32 ()** {{%.*}},
46*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = invoke i32 [[T1]]()
47*f4a2713aSLionel Sambuc// CHECK:      store i32 [[T2]], i32* [[RET]]
48*f4a2713aSLionel Sambuc// CHECK:      invoke void @objc_autoreleasePoolPop(i8* [[T0]])
49*f4a2713aSLionel Sambuc// CHECK:      landingpad { i8*, i32 } personality
50*f4a2713aSLionel Sambuc// CHECK-NEXT:   catch i8* null
51*f4a2713aSLionel Sambuc// CHECK:      call i8* @objc_begin_catch
52*f4a2713aSLionel Sambuc// CHECK-NEXT: store i32 0, i32* [[RET]]
53*f4a2713aSLionel Sambuc// CHECK:      call void @objc_end_catch()
54