blob: b04fa008b275bc60345b3530899f5f533a8dc766 [file] [log] [blame]
John McCall34fdee32010-10-06 18:56:43 +00001// We run this twice, once as Objective-C and once as Objective-C++.
John McCall260611a2012-06-20 06:18:46 +00002// RUN: %clang_cc1 %s -emit-llvm -o - -fobjc-gc -fblocks -fexceptions -triple i386-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 | FileCheck %s
3// 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
Daniel Dunbare2265342009-05-23 02:49:02 +00004
Daniel Dunbare2265342009-05-23 02:49:02 +00005
John McCall34fdee32010-10-06 18:56:43 +00006// CHECK: define i8* @{{.*}}test0
Fariborz Jahanian4904bf42012-06-26 16:06:38 +00007// CHECK: define internal void @{{.*}}_block_invoke(
John McCall34fdee32010-10-06 18:56:43 +00008// CHECK: call i8* @objc_assign_strongCast(
9// CHECK-NEXT: ret void
10id test0(id x) {
Daniel Dunbare2265342009-05-23 02:49:02 +000011 __block id result;
12 ^{ result = x; }();
13 return result;
14}
John McCall34fdee32010-10-06 18:56:43 +000015
16// <rdar://problem/8224178>: cleanup __block variables on EH path
17// CHECK: define void @{{.*}}test1
18void test1() {
19 extern void test1_help(void (^x)(void));
20
21 // CHECK: [[N:%.*]] = alloca [[N_T:%.*]], align 8
22 // CHECK: [[T0:%.*]] = getelementptr inbounds [[N_T]]* [[N]], i32 0, i32 4
Daniel Dunbar09c0fab2010-10-07 20:14:30 +000023 // CHECK-NEXT: store double 1.000000e+{{0?}}01, double* [[T0]], align 8
John McCall34fdee32010-10-06 18:56:43 +000024 __block double n = 10;
25
26 // CHECK: invoke void @{{.*}}test1_help
27 test1_help(^{ n = 20; });
28
John McCall0d3c9852011-02-18 02:58:31 +000029 // CHECK: [[T1:%.*]] = bitcast [[N_T]]* [[N]] to i8*
John McCall34fdee32010-10-06 18:56:43 +000030 // CHECK-NEXT: call void @_Block_object_dispose(i8* [[T1]], i32 8)
31 // CHECK-NEXT: ret void
32
Bill Wendling285cfd82011-09-19 20:31:14 +000033 // CHECK: landingpad { i8*, i32 } personality
34 // CHECK-NEXT: cleanup
John McCall0d3c9852011-02-18 02:58:31 +000035 // CHECK: [[T1:%.*]] = bitcast [[N_T]]* [[N]] to i8*
John McCall34fdee32010-10-06 18:56:43 +000036 // CHECK-NEXT: call void @_Block_object_dispose(i8* [[T1]], i32 8)
Bill Wendling285cfd82011-09-19 20:31:14 +000037 // CHECK: resume { i8*, i32 }
John McCall34fdee32010-10-06 18:56:43 +000038}