[PATCH] D71431: Call objc_retainBlock before passing a block as a variadic argument
Akira Hatanaka via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 12 12:48:55 PST 2019
ahatanak created this revision.
ahatanak added reviewers: rjmccall, arphaman.
ahatanak added a project: clang.
Herald added subscribers: ributzka, dexonsmith, jkorous.
Copy the block to the heap before passing it to the callee in case the block escapes in the callee.
rdar://problem/55683462
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D71431
Files:
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGenObjC/arc-blocks.m
Index: clang/test/CodeGenObjC/arc-blocks.m
===================================================================
--- clang/test/CodeGenObjC/arc-blocks.m
+++ clang/test/CodeGenObjC/arc-blocks.m
@@ -730,5 +730,15 @@
test20_callee(^{ (void)x; });
}
+// CHECK-LABEL: define void @test21(
+// CHECK: %[[V6:.*]] = call i8* @llvm.objc.retainBlock(
+// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to void ()*
+// CHECK: call void (i32, ...) @test21_callee(i32 1, void ()* %[[V7]]),
+
+void test21_callee(int n, ...);
+void test21(id x) {
+ test21_callee(1, ^{ (void)x; });
+}
+
// CHECK: attributes [[NUW]] = { nounwind }
// CHECK-UNOPT: attributes [[NUW]] = { nounwind }
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5247,6 +5247,9 @@
for (Expr *A : Args.slice(ArgIx)) {
ExprResult Arg = DefaultVariadicArgumentPromotion(A, CallType, FDecl);
Invalid |= Arg.isInvalid();
+ // Copy blocks to the heap.
+ if (A->getType()->isBlockPointerType())
+ maybeExtendBlockObject(Arg);
AllArgs.push_back(Arg.get());
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71431.233669.patch
Type: text/x-patch
Size: 1197 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191212/de610393/attachment.bin>
More information about the cfe-commits
mailing list