From e55497cd0482688c4cf72406ba91ce67a8135aa8 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 24 Aug 2003 13:06:10 +0000 Subject: [PATCH] Implement support for the unwind intrinsic in the CBE git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8116 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/CBackend/CBackend.cpp | 13 +++++++++++++ lib/Target/CBackend/Writer.cpp | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 4bc354bdee1..7f2b14d3277 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -1137,6 +1137,19 @@ void CWriter::visitCallInst(CallInst &I) { writeOperand(I.getOperand(2)); Out << ")"; return; + + case LLVMIntrinsic::unwind: + // The unwind intrinsic calls a control flow transfer out of the current + // function, unwinding the stack until a caller who used the invoke + // instruction is found. In this context, we code generated the invoke + // instruction to add an entry to the top of the jmpbuf_list. Thus, + // here we just have to longjmp to the specified handler. + Out << "if (__llvm_jmpbuf_list == 0) { /* llvm.unwind */\n" + << " printf(\"throw found with no handler!\\n\"); abort();\n" + << " }\n" + << " longjmp(__llvm_jmpbuf_list->buf, 1)"; + return; + case LLVMIntrinsic::setjmp: case LLVMIntrinsic::sigsetjmp: diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp index 4bc354bdee1..7f2b14d3277 100644 --- a/lib/Target/CBackend/Writer.cpp +++ b/lib/Target/CBackend/Writer.cpp @@ -1137,6 +1137,19 @@ void CWriter::visitCallInst(CallInst &I) { writeOperand(I.getOperand(2)); Out << ")"; return; + + case LLVMIntrinsic::unwind: + // The unwind intrinsic calls a control flow transfer out of the current + // function, unwinding the stack until a caller who used the invoke + // instruction is found. In this context, we code generated the invoke + // instruction to add an entry to the top of the jmpbuf_list. Thus, + // here we just have to longjmp to the specified handler. + Out << "if (__llvm_jmpbuf_list == 0) { /* llvm.unwind */\n" + << " printf(\"throw found with no handler!\\n\"); abort();\n" + << " }\n" + << " longjmp(__llvm_jmpbuf_list->buf, 1)"; + return; + case LLVMIntrinsic::setjmp: case LLVMIntrinsic::sigsetjmp: -- 2.34.1