[llvm-dev] Help with LLVM exceptions
Justin Mann via llvm-dev
llvm-dev at lists.llvm.org
Wed Feb 15 22:03:51 PST 2017
I am trying to use LLVM 3.9 exceptions in my language. I have modeled the
IL using C++ as the reference. My IL works correctly when the exception is
thrown in the same function catching the exception, but fails when it needs
to unwind. I am running the code using JIT.
Is there a doc, that explains this is in more detail. I have already read
through:
http://llvm.org/docs/ExceptionHandling.html
http://blog.llvm.org/2011/11/llvm-30-exception-handling-redesign.html
https://llvm.org/svn/llvm-project/llvm/trunk/examples/ExceptionDemo/ExceptionDemo.cpp
Here is my IL:
; ModuleID = 'sj'
source_filename = "sj"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
@sjExceptionType = constant { i32 } { i32 999 }
@_ZTIPv = external constant i8*
@0 = private unnamed_addr constant [24 x i8] c"CAUGHT EXCEPTION global\00"
; Function Attrs: nounwind readnone
declare i32 @llvm.eh.typeid.for(i8*) #0
define void @global() personality i8* bitcast (i32 (...)*
@__gxx_personality_v0 to i8*) {
entry:
br label %body
body: ; preds = %entry
invoke void @foo()
to label %0 unwind label %catch
; <label>:0: ; preds = %body
ret void
catch: ; preds = %body
%1 = landingpad { i8*, i32 }
catch i8* bitcast (i8** @_ZTIPv to i8*)
%2 = extractvalue { i8*, i32 } %1, 0
%3 = extractvalue { i8*, i32 } %1, 1
%4 = call i8* @__cxa_begin_catch(i8* %2)
%5 = sext i32 %3 to i64
call void @debugFunction(i8* getelementptr inbounds ([24 x i8], [24 x
i8]* @0, i32 0, i32 0), i8* %4, i64 %5)
call void @throwException()
call void @__cxa_end_catch()
ret void
}
declare i32 @__gxx_personality_v0(...)
define private void @foo() {
entry:
br label %body
body: ; preds = %entry
call void @raiseException(i64 1)
ret void
}
; Function Attrs: noreturn
declare void @raiseException(i64) #1
declare i8* @__cxa_begin_catch(i8*)
declare void @debugFunction(i8*, i8*, i64)
declare void @throwException()
declare void @__cxa_end_catch()
attributes #0 = { nounwind readnone }
attributes #1 = { noreturn }
---
throwException is being linked from C, here is the code:
extern "C" void raiseException(int64_t type) {
auto t = new SJException();
throw (void*)t;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170215/67dd76fe/attachment.html>
More information about the llvm-dev
mailing list