I'm at the stage where I'd like to try implementing exception handling for my little language.
First off, I had a lot of difficulty understanding the documentation on exception handling until I went and started looking at the source code for libstdc++, in particular the definitions of __cxa_eh_globals and the functions that use it. I did not realize, until reading that code, that the exception pointer is stored using thread-local data.
It seems to me that it ought to be possible to write a "pure" LLVM exception implementation that does not depend on the C++ libraries, however I'm not at all sure how to go about doing this.
Also, I wonder if thread local data is really the best way to go. If you have a language that has the ability to inspect a caller's stack frame (a capability which is needed anyway for generating a stack trace), you could pre-allocate space for the exception pointer in the stack frame containing the 'catch' block, and store it there as part of the process of walking up the stack. I guess you would use llvm.frameaddress to look at each stack frame in turn, although I'm unsure how you would 'mark' a stack frame to indicate whether or not it had a catch-handler block and where to store the exception. Can you even assume anything about the structure of a frame?
In any case, I'm looking for any hints or advice as to where to start on this. Or even advice on whether this is a good idea or not.
-- Talin