summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkira Hatanaka <ahatanaka@apple.com>2019-05-10 21:54:16 +0000
committerAkira Hatanaka <ahatanaka@apple.com>2019-05-10 21:54:16 +0000
commitb30d40eb8d46a8ffe901cd75582b74b92cb7b377 (patch)
treeeafea97e3292778095a9dd904c3ed1dfdbb1a294
parentf71afb2d0678fcd167bd8e04f523d6828f0f0295 (diff)
downloadclang-b30d40eb8d46a8ffe901cd75582b74b92cb7b377.tar.gz
[CodeGen][ObjC] Emit invoke instead of call to call `objc_release` when
necessary. Prior to r349952, clang used to call objc_msgSend when sending a release messages, emitting an invoke instruction instead of a call instruction when it was necessary to catch an exception. That changed in r349952 because runtime function objc_release is called as a nounwind function, which broke programs that were overriding the dealloc method and throwing an exception from it. This patch restores the behavior prior to r349952. rdar://problem/50253394 Differential Revision: https://reviews.llvm.org/D61803 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360474 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGObjC.cpp2
-rw-r--r--test/CodeGenObjC/convert-messages-to-runtime-calls.m11
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp
index d5906cf994..5b67565151 100644
--- a/lib/CodeGen/CGObjC.cpp
+++ b/lib/CodeGen/CGObjC.cpp
@@ -2631,7 +2631,7 @@ void CodeGenFunction::EmitObjCRelease(llvm::Value *value,
value = Builder.CreateBitCast(value, Int8PtrTy);
// Call objc_release.
- llvm::CallInst *call = EmitNounwindRuntimeCall(fn, value);
+ llvm::CallBase *call = EmitCallOrInvoke(fn, value);
if (precise == ARCImpreciseLifetime) {
call->setMetadata("clang.imprecise_release",
diff --git a/test/CodeGenObjC/convert-messages-to-runtime-calls.m b/test/CodeGenObjC/convert-messages-to-runtime-calls.m
index 39a26475ea..d1a9624932 100644
--- a/test/CodeGenObjC/convert-messages-to-runtime-calls.m
+++ b/test/CodeGenObjC/convert-messages-to-runtime-calls.m
@@ -175,3 +175,14 @@ float test_cannot_message_return_float(C *c) {
@end
+@class Ety;
+
+// CHECK-LABEL: define {{.*}}void @testException
+void testException(NSObject *a) {
+ // MSGS: {{invoke.*@objc_msgSend}}
+ // CALLS: invoke{{.*}}void @objc_release(i8* %
+ @try {
+ [a release];
+ } @catch (Ety *e) {
+ }
+}