[PATCH] D61803: [CodeGen][ObjC] Emit invoke instead of call to call `objc_release` when necessary.
This revision was automatically updated to reflect the committed changes. Closed by commit rL360474: [CodeGen][ObjC] Emit invoke instead of call to call `objc_release` when (authored by ahatanak, committed by ). Herald added a project: LLVM. Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D61803?vs=199081=199090#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D61803/new/ https://reviews.llvm.org/D61803 Files: cfe/trunk/lib/CodeGen/CGObjC.cpp cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m Index: cfe/trunk/lib/CodeGen/CGObjC.cpp === --- cfe/trunk/lib/CodeGen/CGObjC.cpp +++ cfe/trunk/lib/CodeGen/CGObjC.cpp @@ -2631,7 +2631,7 @@ 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", Index: cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m === --- cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m +++ cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m @@ -175,3 +175,14 @@ @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) { + } +} Index: cfe/trunk/lib/CodeGen/CGObjC.cpp === --- cfe/trunk/lib/CodeGen/CGObjC.cpp +++ cfe/trunk/lib/CodeGen/CGObjC.cpp @@ -2631,7 +2631,7 @@ 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", Index: cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m === --- cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m +++ cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m @@ -175,3 +175,14 @@ @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) { + } +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D61803: [CodeGen][ObjC] Emit invoke instead of call to call `objc_release` when necessary.
erik.pilkington accepted this revision. erik.pilkington added a comment. This revision is now accepted and ready to land. LGTM, thanks! Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D61803/new/ https://reviews.llvm.org/D61803 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D61803: [CodeGen][ObjC] Emit invoke instead of call to call `objc_release` when necessary.
ahatanak updated this revision to Diff 199081. ahatanak marked an inline comment as done. ahatanak added a comment. Just call `EmitCallOrInvoke`. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D61803/new/ https://reviews.llvm.org/D61803 Files: lib/CodeGen/CGObjC.cpp test/CodeGenObjC/convert-messages-to-runtime-calls.m Index: test/CodeGenObjC/convert-messages-to-runtime-calls.m === --- test/CodeGenObjC/convert-messages-to-runtime-calls.m +++ test/CodeGenObjC/convert-messages-to-runtime-calls.m @@ -175,3 +175,14 @@ @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) { + } +} Index: lib/CodeGen/CGObjC.cpp === --- lib/CodeGen/CGObjC.cpp +++ lib/CodeGen/CGObjC.cpp @@ -2631,7 +2631,7 @@ 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", Index: test/CodeGenObjC/convert-messages-to-runtime-calls.m === --- test/CodeGenObjC/convert-messages-to-runtime-calls.m +++ test/CodeGenObjC/convert-messages-to-runtime-calls.m @@ -175,3 +175,14 @@ @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) { + } +} Index: lib/CodeGen/CGObjC.cpp === --- lib/CodeGen/CGObjC.cpp +++ lib/CodeGen/CGObjC.cpp @@ -2631,7 +2631,7 @@ 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", ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D61803: [CodeGen][ObjC] Emit invoke instead of call to call `objc_release` when necessary.
erik.pilkington added inline comments. Comment at: lib/CodeGen/CGObjC.cpp:2634-2646 + ASTContext = getContext(); + const ImplicitParamDecl *paramDecl = + ImplicitParamDecl::Create(Ctx, nullptr, SourceLocation(), nullptr, +Ctx.VoidPtrTy, ImplicitParamDecl::Other); + FunctionArgList funcArgs; + funcArgs.push_back(paramDecl); + const CGFunctionInfo = Can't you just write `EmitCallOrInvoke(fn, value)`? See what we do in `emitObjCValueOperation`, which can handle this case. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D61803/new/ https://reviews.llvm.org/D61803 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D61803: [CodeGen][ObjC] Emit invoke instead of call to call `objc_release` when necessary.
ahatanak created this revision. ahatanak added reviewers: pete, rjmccall. ahatanak added a project: clang. Herald added subscribers: dexonsmith, jkorous. 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 Repository: rC Clang https://reviews.llvm.org/D61803 Files: lib/CodeGen/CGObjC.cpp test/CodeGenObjC/convert-messages-to-runtime-calls.m Index: test/CodeGenObjC/convert-messages-to-runtime-calls.m === --- test/CodeGenObjC/convert-messages-to-runtime-calls.m +++ test/CodeGenObjC/convert-messages-to-runtime-calls.m @@ -175,3 +175,14 @@ @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) { + } +} Index: lib/CodeGen/CGObjC.cpp === --- lib/CodeGen/CGObjC.cpp +++ lib/CodeGen/CGObjC.cpp @@ -2631,7 +2631,19 @@ value = Builder.CreateBitCast(value, Int8PtrTy); // Call objc_release. - llvm::CallInst *call = EmitNounwindRuntimeCall(fn, value); + ASTContext = getContext(); + const ImplicitParamDecl *paramDecl = + ImplicitParamDecl::Create(Ctx, nullptr, SourceLocation(), nullptr, +Ctx.VoidPtrTy, ImplicitParamDecl::Other); + FunctionArgList funcArgs; + funcArgs.push_back(paramDecl); + const CGFunctionInfo = + CGM.getTypes().arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, funcArgs); + CallArgList args; + args.add(RValue::get(value), Ctx.VoidPtrTy); + llvm::CallBase *call; + EmitCall(fnInfo, CGCallee::forDirect(cast(fn.getCallee())), + ReturnValueSlot(), args, ); if (precise == ARCImpreciseLifetime) { call->setMetadata("clang.imprecise_release", Index: test/CodeGenObjC/convert-messages-to-runtime-calls.m === --- test/CodeGenObjC/convert-messages-to-runtime-calls.m +++ test/CodeGenObjC/convert-messages-to-runtime-calls.m @@ -175,3 +175,14 @@ @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) { + } +} Index: lib/CodeGen/CGObjC.cpp === --- lib/CodeGen/CGObjC.cpp +++ lib/CodeGen/CGObjC.cpp @@ -2631,7 +2631,19 @@ value = Builder.CreateBitCast(value, Int8PtrTy); // Call objc_release. - llvm::CallInst *call = EmitNounwindRuntimeCall(fn, value); + ASTContext = getContext(); + const ImplicitParamDecl *paramDecl = + ImplicitParamDecl::Create(Ctx, nullptr, SourceLocation(), nullptr, +Ctx.VoidPtrTy, ImplicitParamDecl::Other); + FunctionArgList funcArgs; + funcArgs.push_back(paramDecl); + const CGFunctionInfo = + CGM.getTypes().arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, funcArgs); + CallArgList args; + args.add(RValue::get(value), Ctx.VoidPtrTy); + llvm::CallBase *call; + EmitCall(fnInfo, CGCallee::forDirect(cast(fn.getCallee())), + ReturnValueSlot(), args, ); if (precise == ARCImpreciseLifetime) { call->setMetadata("clang.imprecise_release", ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits