From b76db237b8c2080137f9dc3362712432f3150ff1 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Fri, 23 Apr 2010 19:12:32 +0000 Subject: [PATCH] NeXT/EH: When generating the rethrow code for a finally block, make sure to chain outwards when inside a nested exception scope. - A real test for this is going into LLVM test-suite. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102204 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGObjCMac.cpp | 14 ++++++++++++-- test/CodeGenObjC/exceptions.m | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test/CodeGenObjC/exceptions.m diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index e8c0805630..421136ba47 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -5772,9 +5772,19 @@ CGObjCNonFragileABIMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, // Branch around the rethrow code. CGF.EmitBranch(FinallyEnd); + // Generate the rethrow code, taking care to use an invoke if we are in a + // nested exception scope. CGF.EmitBlock(FinallyRethrow); - CGF.Builder.CreateCall(ObjCTypes.getUnwindResumeOrRethrowFn(), - CGF.Builder.CreateLoad(RethrowPtr)); + if (PrevLandingPad) { + llvm::BasicBlock *Cont = CGF.createBasicBlock("invoke.cont"); + CGF.Builder.CreateInvoke(ObjCTypes.getUnwindResumeOrRethrowFn(), + Cont, PrevLandingPad, + CGF.Builder.CreateLoad(RethrowPtr)); + CGF.EmitBlock(Cont); + } else { + CGF.Builder.CreateCall(ObjCTypes.getUnwindResumeOrRethrowFn(), + CGF.Builder.CreateLoad(RethrowPtr)); + } CGF.Builder.CreateUnreachable(); CGF.EmitBlock(FinallyEnd); diff --git a/test/CodeGenObjC/exceptions.m b/test/CodeGenObjC/exceptions.m new file mode 100644 index 0000000000..a74dee95dd --- /dev/null +++ b/test/CodeGenObjC/exceptions.m @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o %t %s +// +// [irgen] [eh] Exception code built with clang (x86_64) crashes + +// Just check that we don't emit any dead blocks. +// +// RUN: grep 'No predecessors' %t | count 0 + +@interface NSArray @end +void f0() { + @try { + @try { + @throw @"a"; + } @catch(NSArray *e) { + } + } @catch (id e) { + } +} -- 2.40.0