diff options
author | Akira Hatanaka <ahatanaka@apple.com> | 2018-09-08 20:03:00 +0000 |
---|---|---|
committer | Akira Hatanaka <ahatanaka@apple.com> | 2018-09-08 20:03:00 +0000 |
commit | 2e00b98027b51ee5bfb88a4daea8b78bf9a01e62 (patch) | |
tree | f3d7abea73167f1aae4c974d890ed608e5c41e7f /clang/test/SemaObjCXX | |
parent | 7af5e333e7f9ae0a74d86c81babd99006c12a83b (diff) | |
download | bcm5719-llvm-2e00b98027b51ee5bfb88a4daea8b78bf9a01e62.tar.gz bcm5719-llvm-2e00b98027b51ee5bfb88a4daea8b78bf9a01e62.zip |
Distinguish `__block` variables that are captured by escaping blocks
from those that aren't.
This patch changes the way __block variables that aren't captured by
escaping blocks are handled:
- Since non-escaping blocks on the stack never get copied to the heap
(see https://reviews.llvm.org/D49303), Sema shouldn't error out when
the type of a non-escaping __block variable doesn't have an accessible
copy constructor.
- IRGen doesn't have to use the specialized byref structure (see
https://clang.llvm.org/docs/Block-ABI-Apple.html#id8) for a
non-escaping __block variable anymore. Instead IRGen can emit the
variable as a normal variable and copy the reference to the block
literal. Byref copy/dispose helpers aren't needed either.
rdar://problem/39352313
Differential Revision: https://reviews.llvm.org/D51564
llvm-svn: 341754
Diffstat (limited to 'clang/test/SemaObjCXX')
-rw-r--r-- | clang/test/SemaObjCXX/blocks.mm | 8 | ||||
-rw-r--r-- | clang/test/SemaObjCXX/noescape.mm | 25 |
2 files changed, 32 insertions, 1 deletions
diff --git a/clang/test/SemaObjCXX/blocks.mm b/clang/test/SemaObjCXX/blocks.mm index bdd5538e92b..5f735241720 100644 --- a/clang/test/SemaObjCXX/blocks.mm +++ b/clang/test/SemaObjCXX/blocks.mm @@ -76,21 +76,27 @@ namespace N1 { } // Make sure we successfully instantiate the copy constructor of a -// __block variable's type. +// __block variable's type when the variable is captured by an escaping block. namespace N2 { template <int n> struct A { A() {} A(const A &other) { int invalid[-n]; // expected-error 2 {{array with a negative size}} } + void m() {} }; + typedef void (^BlockFnTy)(); + void func(BlockFnTy); + void test1() { __block A<1> x; // expected-note {{requested here}} + func(^{ x.m(); }); } template <int n> void test2() { __block A<n> x; // expected-note {{requested here}} + func(^{ x.m(); }); } template void test2<2>(); } diff --git a/clang/test/SemaObjCXX/noescape.mm b/clang/test/SemaObjCXX/noescape.mm index 9432a3a48a0..efa2a76d668 100644 --- a/clang/test/SemaObjCXX/noescape.mm +++ b/clang/test/SemaObjCXX/noescape.mm @@ -8,6 +8,7 @@ struct S { void m(); }; +void escapingFunc0(BlockTy); void noescapeFunc0(id, __attribute__((noescape)) BlockTy); void noescapeFunc1(id, [[clang::noescape]] BlockTy); void noescapeFunc2(__attribute__((noescape)) int *); // expected-note {{previous declaration is here}} @@ -127,3 +128,27 @@ __attribute__((objc_root_class)) -(void) m1:(int*) p { } @end + +struct S6 { + S6(); + S6(const S6 &) = delete; // expected-note 3 {{'S6' has been explicitly marked deleted here}} + int f; +}; + +void test1() { + id a; + // __block variables that are not captured by escaping blocks don't + // necessitate having accessible copy constructors. + __block S6 b0; + __block S6 b1; // expected-error {{call to deleted constructor of 'S6'}} + __block S6 b2; // expected-error {{call to deleted constructor of 'S6'}} + __block S6 b3; // expected-error {{call to deleted constructor of 'S6'}} + + noescapeFunc0(a, ^{ (void)b0; }); + escapingFunc0(^{ (void)b1; }); + { + noescapeFunc0(a, ^{ (void)b0; (void)b1; }); + } + noescapeFunc0(a, ^{ escapingFunc0(^{ (void)b2; }); }); + escapingFunc0(^{ noescapeFunc0(a, ^{ (void)b3; }); }); +} |