[PATCH] D51564: Distinguish `__block` variables that are captured by escaping blocks from those that aren't

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 5 11:15:39 PDT 2018


rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM.



================
Comment at: include/clang/AST/Decl.h:977
+
+    unsigned EscapingByref : 1;
   };
----------------
ahatanak wrote:
> rjmccall wrote:
> > This doesn't actually seem to be initialized anywhere.
> VarDecl's constructor in Decl.cpp initializes it to false.
> 
> ```
>   AllBits = 0;
>   VarDeclBits.SClass = SC;
>   // Everything else is implicitly initialized to false.
> ```
I see, thanks.


================
Comment at: lib/CodeGen/CGBlocks.cpp:497
+  return VD->isNonEscapingByref() ?
+         CGF.getContext().getLValueReferenceType(VD->getType()) : VD->getType();
 }
----------------
ahatanak wrote:
> rjmccall wrote:
> > Do you need to worry about the variable already having a reference type?
> Yes, I found out that the previous patch didn't handle `__block` variables with reference types correctly and caused assertion failures. To fix this, I made changes in computeBlockInfo so that the `__block` qualifier is ignored if the variable already has a reference type (I'm treating `__block T&` as `T&` ). There are no changes to this function.
Oh, I see.  And that can be done unconditionally because of course the reference is never reseated.  Makes sense.


Repository:
  rC Clang

https://reviews.llvm.org/D51564





More information about the cfe-commits mailing list