[llvm-bugs] [Bug 50043] New: [ObjC ARC][Objc block][noescape][rvalue] Objects captured by objc blocks get destructed before the block invocation
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Apr 20 11:08:06 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=50043
Bug ID: 50043
Summary: [ObjC ARC][Objc block][noescape][rvalue] Objects
captured by objc blocks get destructed before the
block invocation
Product: clang
Version: trunk
Hardware: Macintosh
OS: MacOS X
Status: NEW
Severity: release blocker
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: xiaoranxu.nju at gmail.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
When -fobjc-arc is enabled, if a block is passed as an argument to a function
whose corresponding parameter type is && rvalue and attributed as noescape, the
object captured by the block can get destructed before the block invocation.
The following code example demonstrates the issue.
#import <Foundation/Foundation.h>
template<typename Func>
void callTemplateBlock(__attribute__((noescape)) Func &&func) {
func();
}
static void test(){
NSString* str = @"test";
NSLog(@"before the block: %d", (int)str.length);
return callTemplateBlock( ^void(){
NSLog(@"inside the block:%d", (int)str.length);
});
}
$ clang++ -isysroot path_to_SDK ./main.mm -fobjc-link-runtime -fobjc-arc
# ./a.out
before the block: 4
inside the block:0
It looks the codegen assumes the block doesn't capture any value in this
scenario (noescape + rvalue + ARC). Removing the noescape attribute, or
replacing the Func && type to the concrete block type, or removing -fobjc-arc,
doesn't repro the issue.
This change may be related: https://reviews.llvm.org/D81624
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210420/e12b09a3/attachment.html>
More information about the llvm-bugs
mailing list