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

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 22 12:00:03 PDT 2021


ahatanak created this revision.
ahatanak added reviewers: rjmccall, erik.pilkington.
ahatanak added a project: clang.
ahatanak requested review of this revision.

In the following example, the block passed to the function is marked as `noescape`, which is incorrect as the `noescape` attribute applies to the reference:

  typedef void (^BlockTy)();
   __block S6 b5;
  void noescapeFuncRefParam1(__attribute__((noescape)) BlockTy &&);
  noescapeFuncRefParam1(^{ (void)b5; });

This partially fixes PR50043.

rdar://77030453


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101097

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaObjCXX/noescape.mm


Index: clang/test/SemaObjCXX/noescape.mm
===================================================================
--- clang/test/SemaObjCXX/noescape.mm
+++ clang/test/SemaObjCXX/noescape.mm
@@ -131,7 +131,7 @@
 
 struct S6 {
   S6();
-  S6(const S6 &) = delete; // expected-note 3 {{'S6' has been explicitly marked deleted here}}
+  S6(const S6 &) = delete; // expected-note 5 {{'S6' has been explicitly marked deleted here}}
   int f;
 };
 
@@ -143,6 +143,8 @@
   __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'}}
+  __block S6 b4; // expected-error {{call to deleted constructor of 'S6'}}
+  __block S6 b5; // expected-error {{call to deleted constructor of 'S6'}}
 
   noescapeFunc0(a, ^{ (void)b0; });
   escapingFunc0(^{ (void)b1; });
@@ -151,4 +153,14 @@
   }
   noescapeFunc0(a, ^{ escapingFunc0(^{ (void)b2; }); });
   escapingFunc0(^{ noescapeFunc0(a, ^{ (void)b3; }); });
+
+  void noescapeFuncRefParam0(__attribute__((noescape)) const BlockTy &);
+  noescapeFuncRefParam0(^{
+    (void)b4;
+  });
+
+  void noescapeFuncRefParam1(__attribute__((noescape)) BlockTy &&);
+  noescapeFuncRefParam1(^{
+    (void)b5;
+  });
 }
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5911,7 +5911,8 @@
                (!Param || !Param->hasAttr<CFConsumedAttr>()))
         CFAudited = true;
 
-      if (Proto->getExtParameterInfo(i).isNoEscape())
+      if (Proto->getExtParameterInfo(i).isNoEscape() &&
+          !ProtoArgType->isReferenceType())
         if (auto *BE = dyn_cast<BlockExpr>(Arg->IgnoreParenNoopCasts(Context)))
           BE->getBlockDecl()->setDoesNotEscape();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101097.339742.patch
Type: text/x-patch
Size: 1874 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210422/8767cab2/attachment.bin>


More information about the cfe-commits mailing list