setjmp/longjmp

Chris Torek chris at mimsy.UUCP
Sat Apr 29 03:54:49 AEST 1989


In article <1989Apr27.165319.23986 at utzoo.uucp> henry at utzoo.uucp
(Henry Spencer) writes:
>... in the general case [getting variables right after setjmp/longjmp is]
>very hard.

It is not *that* hard.  It does inhibit some optimisation:

>... a very clever compiler can change save/restore conventions when
>it notices the setjmp() ....

This is a reasonable approach.  setjmp/longjmp are rare enough that I
doubt it will slow things much.

	... compiler code for function call ...
	if (function is setjmp || function is longjmp ||
	    setjmp is called previously in this function) {
		for (all active registers)
			if (register is used only to hold function address)
				/* do nothing */;
			else
				store the register and mark it invalid;
	}
	... generate the call itself ...
	if (function is longjmp)
		reachable = FALSE;	/* all variables are now dead */

(here `previously' means `is reachable via a flow path that might have
run before this function call is reached'---the call can appear below
if there is a loop label above this call.)  setjmp and longjmp
themselves then need not save or restore any registers.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.std.c mailing list