r360474 - [CodeGen][ObjC] Emit invoke instead of call to call `objc_release` when
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Fri May 10 14:54:16 PDT 2019
Author: ahatanak
Date: Fri May 10 14:54:16 2019
New Revision: 360474
URL: http://llvm.org/viewvc/llvm-project?rev=360474&view=rev
Log:
[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
Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=360474&r1=360473&r2=360474&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Fri May 10 14:54:16 2019
@@ -2631,7 +2631,7 @@ void CodeGenFunction::EmitObjCRelease(ll
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",
Modified: cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m?rev=360474&r1=360473&r2=360474&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m (original)
+++ cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m Fri May 10 14:54:16 2019
@@ -175,3 +175,14 @@ float test_cannot_message_return_float(C
@end
+ at 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) {
+ }
+}
More information about the cfe-commits
mailing list