diff options
author | Akira Hatanaka <ahatanaka@apple.com> | 2018-07-26 16:51:21 +0000 |
---|---|---|
committer | Akira Hatanaka <ahatanaka@apple.com> | 2018-07-26 16:51:21 +0000 |
commit | cb6a933c9bd010f06b0ae50893afb3f821bd5fe0 (patch) | |
tree | a8d4d01d376436d9211d8ae6d7c213b42770854b /clang/lib/CodeGen/CGDecl.cpp | |
parent | 6fcc7d703b571f456f662a0be1ec6f449d55fdb9 (diff) | |
download | llvm-cb6a933c9bd010f06b0ae50893afb3f821bd5fe0.zip llvm-cb6a933c9bd010f06b0ae50893afb3f821bd5fe0.tar.gz llvm-cb6a933c9bd010f06b0ae50893afb3f821bd5fe0.tar.bz2 |
[CodeGen][ObjC] Make block copy/dispose helper functions exception-safe.
When an exception is thrown in a block copy helper function, captured
objects that have previously been copied should be destructed or
released. Similarly, captured objects that are yet to be released should
be released when an exception is thrown in a dispose helper function.
rdar://problem/42410255
Differential Revision: https://reviews.llvm.org/D49718
llvm-svn: 338041
Diffstat (limited to 'clang/lib/CodeGen/CGDecl.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index d1df5b3..57b2fba 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -1710,9 +1710,15 @@ void CodeGenFunction::EmitAutoVarCleanups(const AutoVarEmission &emission) { } // If this is a block variable, call _Block_object_destroy - // (on the unforwarded address). - if (emission.IsByRef) - enterByrefCleanup(emission); + // (on the unforwarded address). Don't enter this cleanup if we're in pure-GC + // mode. + if (emission.IsByRef && CGM.getLangOpts().getGC() != LangOptions::GCOnly) { + BlockFieldFlags Flags = BLOCK_FIELD_IS_BYREF; + if (emission.Variable->getType().isObjCGCWeak()) + Flags |= BLOCK_FIELD_IS_WEAK; + enterByrefCleanup(NormalAndEHCleanup, emission.Addr, Flags, + /*LoadBlockVarAddr*/ false); + } } CodeGenFunction::Destroyer * |