[PATCH] D32210: [Sema][ObjC] Add support for attribute "noescape"

Adam Kemp via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 19 09:25:25 PDT 2017


TheRealAdamKemp added inline comments.


================
Comment at: include/clang/Basic/AttrDocs.td:122
+* Cannot be returned from a function
+* Cannot be captured by a block
+* Cannot be assigned to a variable
----------------
This may be too restrictive in some cases. Consider this:

```
typedef void (^BlockTy)();
void nonescapingFunc(__attribute__((noescape)) BlockTy);

void callerFunc(__attribute__((noescape)) BlockTy block) {
  nonescapingFunc(^{ block(); });
}
```

It sounds like the above code would give an error, but the capturing block is also nonescaping, which means it should be allowed. This is a useful pattern, and disallowing it would make these attributes very cumbersome.

The code could also be written like this:

```
typedef void (^BlockTy)();
void nonescapingFunc(__attribute__((noescape)) BlockTy);

void callerFunc(__attribute__((noescape)) BlockTy block) {
  BlockTy wrapBlock = ^{
    block();
  };
  nonescapingFunc(wrapBlock);
}
```

Again, I would expect that to not give an error or at least be able to decorate the declaration of `wrapBlock` to indicate that it is also nonescaping (can this attribute be applied to locals or only function arguments?).


https://reviews.llvm.org/D32210





More information about the cfe-commits mailing list