[PATCH] D57797: Variable auto-init: fix __block initialization

JF Bastien via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 5 17:03:28 PST 2019


jfb created this revision.
jfb added reviewers: rjmccall, pcc, kcc.
Herald added subscribers: cfe-commits, dexonsmith, jkorous.
Herald added a project: clang.

Automatic initialization [1] of __block variables was happening too late, which
caused self-init usage to crash, such as here:

typedef struct XYZ { void (^block)(); } *xyz_t;

  __attribute__((noinline))
  xyz_t create(void (^block)()) {
    xyz_t myself = malloc(sizeof(struct XYZ));
    myself->block = block;
    return myself;
  }
  int main() {
    __block xyz_t captured = create(^(){ (void)captured; });
  }

This type of code shouldn't be broken by variable auto-init, even if it's
sketchy.

This change moves some GEP generation to earlier to ensure that this
initialization occurs at the right time, hence the extra few tests being
modified.

[1] With -ftrivial-auto-var-init=pattern

rdar://problem/47798396


Repository:
  rC Clang

https://reviews.llvm.org/D57797

Files:
  lib/CodeGen/CGDecl.cpp
  test/CodeGenCXX/trivial-auto-var-init.cpp
  test/CodeGenObjC/arc-blocks.m
  test/CodeGenObjC/blocks-2.m
  test/CodeGenObjC/blocks.m
  test/CodeGenObjCXX/arc-blocks.mm

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57797.185447.patch
Type: text/x-patch
Size: 10326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190206/44e1818c/attachment.bin>


More information about the cfe-commits mailing list