Commit cdd6a278 authored by Akira Hatanaka's avatar Akira Hatanaka
Browse files

[ObjC] Copy a block to the heap if it is passed as a variadic argument

Call maybeExtendBlockObject in DefaultVariadicArgumentPromotion so that
the block is copied to the heap when it is passed as a variadic argument
to any calls, not only to C function calls.

rdar://problem/64201532
parent 01ddb2a7
......@@ -964,6 +964,11 @@ ExprResult Sema::DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT,
ExprResult ExprRes = DefaultArgumentPromotion(E);
if (ExprRes.isInvalid())
return ExprError();
// Copy blocks to the heap.
if (ExprRes.get()->getType()->isBlockPointerType())
maybeExtendBlockObject(ExprRes);
E = ExprRes.get();
 
// Diagnostics regarding non-POD argument types are
......@@ -5941,9 +5946,6 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc, FunctionDecl *FDecl,
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());
}
}
......
......@@ -747,5 +747,18 @@ id test22(int c, id x) {
return c ? test22_0() : ({ id (^b)(void) = ^{ return x; }; test22_1(); b(); });
}
@interface Test23
-(void)m:(int)i, ...;
@end
// CHECK-COMMON-LABEL: define void @test23(
// CHECK-COMMON: %[[V9:.*]] = call i8* @llvm.objc.retainBlock(
// CHECK-COMMON: %[[V10:.*]] = bitcast i8* %[[V9]] to void ()*
// CHECK-COMMON: call void (i8*, i8*, i32, ...) bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i32, ...)*)(i8* %{{.*}}, i8* %{{.*}}, i32 123, void ()* %[[V10]])
void test23(id x, Test23 *t) {
[t m:123, ^{ (void)x; }];
}
// CHECK: attributes [[NUW]] = { nounwind }
// CHECK-UNOPT: attributes [[NUW]] = { nounwind }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment