That said, they are designed for internal use by the compiler for exception handling. Calling them directly like this is very much not recommended. Using the system library setjmp()/longjmp() functions is preferred.
-Jim
> _______________________________________________
> LLVM Developers mailing list
> LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
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.
Regards,
Jim
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.
John.
> int
> main (int argc, char** argv)
> {
> int n = atoi(argv[1]), r;
>
> if ((r = setjmp (buf)))
> {
> printf("n = %d\n", n);
> return 0;
> }
Non-volatile local variables are not preserved by setjmp(), so this program can print whatever it wants.
/jakob
Neither output is wrong.
C99 7.13.2.1p3:
All accessible objects have values, and all other components of the
abstract machine212)
have state, as of the time the longjmp function was called, except
that the values of
objects of automatic storage duration that are local to the function
containing the
invocation of the corresponding setjmp macro that do not have
volatile-qualified type
and have been changed between the setjmp invocation and longjmp call are
indeterminate.
-Eli
On Apr 13, 2011, at 9:51 AM, Akira Hatanaka wrote:
> int
> main (int argc, char** argv)
> {
> int n = atoi(argv[1]), r;
>
> if ((r = setjmp (buf)))
> {
> printf("n = %d\n", n);
> return 0;
> }
/jakob
> When I compile and run the following program, is it expected that global
> variable gi2 will be incremented twice? It seems that the code generated with
> clang and llc increments it only once (line 37-43 of attached file).
try marking gi2 volatile.
Ciao, Duncan.
-Jim
> <f.s>_______________________________________________
-Jim
Why is longjmp converted into calls to the builtin then?
See PR 8765.
Joerg
I'm not aware of any diagnostic regarding them. Off the top of my head, adding one, especially when using something like the -pedantic option, sounds perfectly reasonable. The CFE guys would have a better handle on that aspect of things.
-Jim
> On Wed, Apr 27, 2011 at 03:55:53PM -0700, Jim Grosbach wrote:
>> The builtins are for internal compiler use in the context of SjLj
>> exception handling. Any other use, including any direct calls of the
>> builtins in user code, are a bad idea with no guaranteed behaviour.
>> That they're exposed at all is, again, for historical purposes. Don't use them.
>
> Why is longjmp converted into calls to the builtin then?
> See PR 8765.
Hi Joerg,
If I follow what's happing in PR8765 correctly, it's a bit different. setjmp/longjmp calls are never lowered to the builtin EH intrinsics. Unfortunately, "builtin" is a bit of an overloaded term. :( Something else is recognizing the "setjmp" name as special and is doing something with it (e.g., SelectionDAGISel checks for it as well as a few other "returns twice" functions).
-Jim
Yes, this is not about using them for exception handling.
> Unfortunately, "builtin" is a bit of an overloaded term. :( Something
> else is recognizing the "setjmp" name as special and is doing something
> with it (e.g., SelectionDAGISel checks for it as well as a few other
> "returns twice" functions).
I suppose this is the normal common library name detection logic. Point
of my inquire in this context is whether the mapping to the builtin
gives anything over just applying the "returns twice" attribute.
Doing only the latter would not have issues with the external name
mangling.
Joerg