| 1 |
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -emit-llvm -disable-llvm-passes -O3 -fblocks -fobjc-arc -fobjc-runtime-has-weak -std=c++11 -o - %s | FileCheck %s |
| 2 |
|
| 3 |
void test0(id x) { |
| 4 |
extern void test0_helper(id (^)(void)); |
| 5 |
test0_helper([=]() { return x; }); |
| 6 |
// CHECK-LABEL: define internal noundef ptr @___Z5test0P11objc_object_block_invoke |
| 7 |
// CHECK: [[T0:%.*]] = call noundef ptr @"_ZZ5test0P11objc_objectENK3$_0clEv"{{.*}} [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ] |
| 8 |
// CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use(ptr [[T0]]) |
| 9 |
// CHECK-NEXT: [[T2:%.*]] = tail call ptr @llvm.objc.autoreleaseReturnValue(ptr [[T0]]) |
| 10 |
// CHECK-NEXT: ret ptr [[T2]] |
| 11 |
} |
| 12 |
|
| 13 |
// Check that the delegating block invoke function doesn't destruct the Weak |
| 14 |
// object that is passed. |
| 15 |
|
| 16 |
// CHECK-LABEL: define internal void @___Z8testWeakv_block_invoke( |
| 17 |
// CHECK: call void @"_ZZ8testWeakvENK3$_0clE4Weak"( |
| 18 |
// CHECK-NEXT: ret void |
| 19 |
|
| 20 |
// CHECK-LABEL: define internal void @"_ZZ8testWeakvENK3$_0clE4Weak"( |
| 21 |
// CHECK: call void @_ZN4WeakD1Ev( |
| 22 |
// CHECK-NEXT: ret void |
| 23 |
|
| 24 |
id test1_rv; |
| 25 |
|
| 26 |
void test1() { |
| 27 |
extern void test1_helper(id (*)(void)); |
| 28 |
test1_helper([](){ return test1_rv; }); |
| 29 |
// CHECK-LABEL: define internal noundef ptr @"_ZZ5test1vEN3$_08__invokeEv" |
| 30 |
// CHECK: [[T0:%.*]] = call noundef ptr @"_ZZ5test1vENK3$_0clEv"{{.*}} [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ] |
| 31 |
// CHECK-NEXT: call void (...) @llvm.objc.clang.arc.noop.use(ptr [[T0]]) |
| 32 |
// CHECK-NEXT: [[T2:%.*]] = tail call ptr @llvm.objc.autoreleaseReturnValue(ptr [[T0]]) |
| 33 |
// CHECK-NEXT: ret ptr [[T2]] |
| 34 |
} |
| 35 |
|
| 36 |
struct Weak { |
| 37 |
__weak id x; |
| 38 |
}; |
| 39 |
|
| 40 |
void testWeak() { |
| 41 |
extern void testWeak_helper(void (^)(Weak)); |
| 42 |
testWeak_helper([](Weak){}); |
| 43 |
} |