<br><br><div class="gmail_quote">On Sun, Sep 26, 2010 at 4:19 AM, Renato Golin <span dir="ltr"><<a href="mailto:rengolin@systemcall.org">rengolin@systemcall.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On 25 September 2010 23:46, Nathan Jeffords <<a href="mailto:blunted2night@gmail.com">blunted2night@gmail.com</a>> wrote:<br>
> catch:<br>
>   %v = ptrtoint i8 * %x to i32<br>
>   %r = icmp eq i32 %v, 255<br>
>   br i1 %r, label %bad, label %worse<br>
> bad:<br>
>   ret i32 -1<br>
> worse:<br>
>   ret i32 -2<br>
> }<br>
<br>
</div>If I understood correctly, you're trying to pass the clean-up flag<br>
through %x directly on the invoke call. But later avoid the<br>
eh.exception call, assuming that was in %x.<br>
<br>
The problem is that you're mixing two concepts: The exception<br>
structure contains information about the object that was thrown and<br>
not a "good" number. That's the role of the clean-up flag (in case the<br>
catch blocks can't deal with the exception) or the landing pads (that<br>
should reflect the return values the user asked for in their<br>
programs).<br>
<br>
It's the users role to tell what's good and what's not (return values<br>
included). the only thing you (compiler) can do is to explode<br>
prematurely in case you can't properly catch the error (ie. throw<br>
inside throw, throw inside delete, etc).<br></blockquote><div><br></div><div>The argument to the unwind instruction is always an i8* pointer, which in the case of dwarf exception handling would be the allocated exception object. I did cheat for the example, but this also demonstrates that an arbitrary value could be passed if using an LLVM specific exception handling implementation like the setjmp/longjmp version provided by the LowerInvoke pass.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
If that's the case, your implementation will not work for dwarf<br>
exceptions, and I wouldn't recommend having an *invoke* syntax for<br>
each type of exception handling mechanism.<br>
<br>
Other question: why are you passing untyped %x? I haven't seen any<br>
untyped variable in LLVM, so far, and I think it's good to be<br>
redundant in this case. That alone would have caught the mistake. If<br>
you need an i32 (for your bad/worse comparison), throwing i8* would<br>
have hinted that you crossed the concepts.<br>
<br></blockquote><div><br></div><div>The syntax for the invoke instruction is a little misleading. %x is a value that is being generated by the instruction, not passed to is. It is no different in that regard as to say '%x = call @eh.exception ...'. Since you don't specify the type in that type of assignment, I chose not to here either.</div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
On a side note...<br>
<br>
Exception handling was designed by the devil himself. Part of the flow<br>
control is designed by the user (try/catch blocks, throw<br>
specifications), part of it is designed by the compiler, in exception<br>
tables (specific unwinding instructions and types), and part by the<br>
library writers (unwinding and personality routines). All that,<br>
decided in three different time frames, by three different kinds of<br>
developers, have to communicate perfectly in run time.<br>
<br>
It'd be very difficult for the compiler to optimize automatically<br>
without breaking run-time assumptions. All of that is controlled by<br>
different ABIs, that make sure all three universes are talking the<br>
same language. You can't change one without changing all the others...<br>
<br></blockquote><div><br></div><div>I agree; this change is not attempting to change how exception handling works, just provide a small change in how it is represented in the IR to make it more direct. Especially for users not using gcc/dwarf exception handling (I hope to attempt an SEH implementation)</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
To be honest, I'm still surprised that it actually works at all! ;)<br>
<font color="#888888"><br>
--<br>
cheers,<br>
--renato<br>
<br>
<a href="http://systemcall.org/" target="_blank">http://systemcall.org/</a><br>
<br>
Reclaim your digital rights, eliminate DRM, learn more at<br>
<a href="http://www.defectivebydesign.org/what_is_drm" target="_blank">http://www.defectivebydesign.org/what_is_drm</a><br>
</font></blockquote></div><br><div>Thanks for the feedback</div><div><br></div><div>-Nathan</div>