Distinguish `__block` variables that are captured by escaping blocks
authorAkira Hatanaka <ahatanaka@apple.com>
Mon, 1 Oct 2018 21:51:28 +0000 (21:51 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Mon, 1 Oct 2018 21:51:28 +0000 (21:51 +0000)
commit8e57b07f668528fa4ed893093342ba8d899a1556
tree02696f84b64c2a199178a3e9044b33e87f411e30
parent7a6966ec27d9ca1507eedaf1ee487dfab14478d0
Distinguish `__block` variables that are captured by escaping blocks
from those that aren't.

This patch changes the way __block variables that aren't captured by
escaping blocks are handled:

- Since non-escaping blocks on the stack never get copied to the heap
  (see https://reviews.llvm.org/D49303), Sema shouldn't error out when
  the type of a non-escaping __block variable doesn't have an accessible
  copy constructor.

- IRGen doesn't have to use the specialized byref structure (see
  https://clang.llvm.org/docs/Block-ABI-Apple.html#id8) for a
  non-escaping __block variable anymore. Instead IRGen can emit the
  variable as a normal variable and copy the reference to the block
  literal. Byref copy/dispose helpers aren't needed either.

This reapplies r343518 after fixing a use-after-free bug in function
Sema::ActOnBlockStmtExpr where the BlockScopeInfo was dereferenced after
it was popped and deleted.

rdar://problem/39352313

Differential Revision: https://reviews.llvm.org/D51564

llvm-svn: 343542
30 files changed:
clang/include/clang/AST/Decl.h
clang/include/clang/Sema/ScopeInfo.h
clang/lib/AST/Decl.cpp
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/CodeGen/CGClass.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Sema/ScopeInfo.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/test/CodeGen/block-byref-aggr.c
clang/test/CodeGen/blocks-seq.c
clang/test/CodeGen/exceptions.c
clang/test/CodeGen/personality.c
clang/test/CodeGenCXX/block-capture.cpp
clang/test/CodeGenCXX/blocks.cpp
clang/test/CodeGenCXX/debug-info-blocks.cpp
clang/test/CodeGenCXX/noescape.cpp
clang/test/CodeGenObjC/arc-no-arc-exceptions.m
clang/test/CodeGenObjC/arc-unoptimized-byref-var.m
clang/test/CodeGenObjC/blocks-1.m
clang/test/CodeGenObjC/noescape.m
clang/test/CodeGenObjCXX/arc-blocks.mm
clang/test/PCH/block-helpers.cpp
clang/test/SemaObjCXX/blocks.mm
clang/test/SemaObjCXX/noescape.mm