It seems straightforward to implement, if it just needs to be functionally correct.<br><br>I have another question about setjmp/longjmp. When the following program is compiled and run with argument 10 (./a.out 10), should it print 10 or 23? I am asking this question because it prints 23 when compiled with gcc and prints 10 when compiled with clang. If it is supposed to return 23, it seems to me that saving and clobbering registers is not enough to guarantee correctness of the compiled program.     <br>
<br>#include <stdio.h><br>#include <stdlib.h><br>#include <setjmp.h><br><br>jmp_buf buf;<br><br>void __attribute__((noinline))<br>sub2 (void)<br>{<br>  longjmp (buf, 1);<br>}<br><br>int<br>main (int argc, char** argv)<br>
{<br>  int n = atoi(argv[1]), r;<br><br>  if ((r = setjmp (buf)))<br>    {<br>      printf("n = %d\n", n);<br>      return 0;<br>    }<br><br>    n += 13;<br>    sub2 ();<br><br>  return n;<br>}<br><br><br><div class="gmail_quote">
On Tue, Apr 12, 2011 at 5:51 PM, John McCall <span dir="ltr"><<a href="mailto:rjmccall@apple.com" target="_blank">rjmccall@apple.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div>On Apr 12, 2011, at 3:15 PM, Jim Grosbach wrote:<br>
> If you want an automated method, then using the source code re-writer interfaces in clang is probably a reasonable starting place. Just modifying the source code manually is probably easier, though, to be honest.<br>




><br>
> As a moderate caveat to all of this, there are some bits of code out there that use these builtins that are very tightly coupled to the compiler (the Linux kernel used to do this, I think, and maybe still does). Those sorts of situations are unlikely to be solved satisfactorily by moving to library calls (performance reasons, usually). The appropriate solution there will be very situation specific and will likely involve refactoring the implementations in question to some degree.<br>




<br>
</div>Are these intrinsics really prohibitively difficult to implement?  I'm not suggesting that you (or anyone else) particularly needs to do them, but is there more to them than clobbering all registers and then lowering to a quick series of instructions which save/restore the current IP, SP, and (maybe?) FP?  Something seems very wrong if rewriting a custom refactoring tool to turn builtin_setjmp/longjmp into library calls could possibly be simpler than just adding support for these intrinsics to one or two more targets.<br>




<font color="#888888"><br>
John.<br>
</font></blockquote></div><br>