xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenObjC/blocks-2.m (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// We run this twice, once as Objective-C and once as Objective-C++.
2*f4a2713aSLionel Sambuc// RUN: %clang_cc1 %s -emit-llvm -o - -fobjc-gc -fblocks -fexceptions -triple i386-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 | FileCheck %s
3*f4a2713aSLionel Sambuc// RUN: %clang_cc1 %s -emit-llvm -o - -fobjc-gc -fblocks -fexceptions -triple i386-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 -x objective-c++ | FileCheck %s
4*f4a2713aSLionel Sambuc
5*f4a2713aSLionel Sambuc
6*f4a2713aSLionel Sambuc// CHECK: define i8* @{{.*}}test0
7*f4a2713aSLionel Sambuc// CHECK: define internal void @{{.*}}_block_invoke(
8*f4a2713aSLionel Sambuc// CHECK:      call i8* @objc_assign_strongCast(
9*f4a2713aSLionel Sambuc// CHECK-NEXT: ret void
10*f4a2713aSLionel Sambucid test0(id x) {
11*f4a2713aSLionel Sambuc  __block id result;
12*f4a2713aSLionel Sambuc  ^{ result = x; }();
13*f4a2713aSLionel Sambuc  return result;
14*f4a2713aSLionel Sambuc}
15*f4a2713aSLionel Sambuc
16*f4a2713aSLionel Sambuc// <rdar://problem/8224178>: cleanup __block variables on EH path
17*f4a2713aSLionel Sambuc// CHECK: define void @{{.*}}test1
18*f4a2713aSLionel Sambucvoid test1() {
19*f4a2713aSLionel Sambuc  extern void test1_help(void (^x)(void));
20*f4a2713aSLionel Sambuc
21*f4a2713aSLionel Sambuc  // CHECK:      [[N:%.*]] = alloca [[N_T:%.*]], align 8
22*f4a2713aSLionel Sambuc  // CHECK:      [[T0:%.*]] = getelementptr inbounds [[N_T]]* [[N]], i32 0, i32 4
23*f4a2713aSLionel Sambuc  // CHECK-NEXT: store double 1.000000e+{{0?}}01, double* [[T0]], align 8
24*f4a2713aSLionel Sambuc  __block double n = 10;
25*f4a2713aSLionel Sambuc
26*f4a2713aSLionel Sambuc  // CHECK:      invoke void @{{.*}}test1_help
27*f4a2713aSLionel Sambuc  test1_help(^{ n = 20; });
28*f4a2713aSLionel Sambuc
29*f4a2713aSLionel Sambuc  // CHECK:      [[T1:%.*]] = bitcast [[N_T]]* [[N]] to i8*
30*f4a2713aSLionel Sambuc  // CHECK-NEXT: call void @_Block_object_dispose(i8* [[T1]], i32 8)
31*f4a2713aSLionel Sambuc  // CHECK-NEXT: ret void
32*f4a2713aSLionel Sambuc
33*f4a2713aSLionel Sambuc  // CHECK:      landingpad { i8*, i32 } personality
34*f4a2713aSLionel Sambuc  // CHECK-NEXT:   cleanup
35*f4a2713aSLionel Sambuc  // CHECK:      [[T1:%.*]] = bitcast [[N_T]]* [[N]] to i8*
36*f4a2713aSLionel Sambuc  // CHECK-NEXT: call void @_Block_object_dispose(i8* [[T1]], i32 8)
37*f4a2713aSLionel Sambuc  // CHECK:      resume { i8*, i32 }
38*f4a2713aSLionel Sambuc}
39