diff options
author | Akira Hatanaka <ahatanaka@apple.com> | 2019-02-27 18:17:16 +0000 |
---|---|---|
committer | Akira Hatanaka <ahatanaka@apple.com> | 2019-02-27 18:17:16 +0000 |
commit | c5792aa90fa45a1842f190c146f19e2c71ea6fbd (patch) | |
tree | 3b0e58ac909124579b2391ffd93e404edea8dc6e /clang/lib/Sema/SemaDecl.cpp | |
parent | 69bec61998c702f790cf5c9f17a3a4a086bd5804 (diff) | |
download | bcm5719-llvm-c5792aa90fa45a1842f190c146f19e2c71ea6fbd.tar.gz bcm5719-llvm-c5792aa90fa45a1842f190c146f19e2c71ea6fbd.zip |
Avoid needlessly copying a block to the heap when a block literal
initializes a local auto variable or is assigned to a local auto
variable that is declared in the scope that introduced the block
literal.
rdar://problem/13289333
https://reviews.llvm.org/D58514
llvm-svn: 355012
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index cbef0e2bb46..2078caa0bb9 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -11257,6 +11257,11 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) { << Culprit->getSourceRange(); } } + + if (auto *E = dyn_cast<ExprWithCleanups>(Init)) + if (auto *BE = dyn_cast<BlockExpr>(E->getSubExpr()->IgnoreParens())) + if (VDecl->hasLocalStorage()) + BE->getBlockDecl()->setCanAvoidCopyToHeap(); } else if (VDecl->isStaticDataMember() && !VDecl->isInline() && VDecl->getLexicalDeclContext()->isRecord()) { // This is an in-class initialization for a static data member, e.g., |