Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!samsung!think.com!snorkelwacker.mit.edu!apple!vsi1!daver!bungi.com!news From: ian@sibyl.eleceng.ua.oz.au Newsgroups: comp.sys.nsc.32k Subject: Bug in minix library setjmp.s; lots of GNU tools diffs available Message-ID: <9102071534.5947@munnari.oz.au> Date: 6 Feb 91 22:21:46 GMT References: <<9102060029.AA11466@cs.hut.fi>> Sender: news@daver.bungi.com Lines: 52 Approved: news@daver.bungi.com Jyrki Kuoppala writes: - When porting emacs to pc532-Minix, I noticed there's a bug in the - setjmp library routine - it doesn't save registers r3-r7 (and f4-f7) - which I think it should do. - Here's the test program: - - #include - #include - - jmp_buf env; - void foo() - { - register int b = 2; - fprintf (stderr, "b = %d\n", b); - } - - void bar() - { - register int c = 3; - fprintf (stderr, "c = %d\n", 3); - longjmp(env, 1); - } - - main() - { - register int a = 1; - foo(); - if (setjmp (env)) - fprintf (stderr, "a = %d\n", a); - else { - bar(); - } - } - - It outputs: - - b = 2 - c = 3 - a = 1 - - when everything is OK, but - - b = 2 - c = 3 - a = 3 I believe in ANSI C, there is no requirement to save registers in setjump. Variables which have to be accessed after the setjump should be marked volatile. Yes, some people have said that is ugly and nor the way it should be done, but I pretty sure, that is the way it is! Ian