[PATCH] D101097: [Sema] Don't set BlockDecl's DoesNotEscape bit If the block is being passed to a function taking a reference parameter

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 22 21:59:23 PDT 2021


rjmccall added inline comments.


================
Comment at: clang/lib/Sema/SemaExpr.cpp:5917
         if (auto *BE = dyn_cast<BlockExpr>(Arg->IgnoreParenNoopCasts(Context)))
           BE->getBlockDecl()->setDoesNotEscape();
 
----------------
We need to be checking that the parameter type is a block pointer type.  A parameter of a type like `id` or `void*` does not have the enhanced semantics of `noescape` for blocks.

The inevitable weird C++ test case is:

```
struct NoescapeCtor {
  NoescapeCtor(__attribute__((noescape)) void (^)());
};
struct EscapeCtor {
  EscapeCtor(void (^)());
};

void helper1(NoescapeCtor a);
void test1() { helper1(^{}); } // <- should be noescape

void helper2(NoescapeCtor &&a);
void test2() { helper2(^{}); } // <- should be noescape

void helper3(__attribute__((noescape)) EscapeCtor &&a);
void test3() { helper3(^{}); } // <- should not be noescape
```

You should probably also test that calls to function templates behave according to the instantiated type of the parameter.  I expect that that should just fall out from this implementation, which I think only triggers on non-dependent calls.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101097/new/

https://reviews.llvm.org/D101097



More information about the cfe-commits mailing list