Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!snorkelwacker.mit.edu!apple!vsi1!daver!bungi.com!news From: ian@sibyl.eleceng.ua.oz.au Newsgroups: comp.sys.nsc.32k Subject: Re: Bug in minix setjmp.s or gcc ? Message-ID: <9102101615.11494@munnari.oz.au> Date: 10 Feb 91 15:41:08 GMT References: <<9102100521.AA14965@cs.hut.fi>> Sender: news@daver.bungi.com Lines: 45 Approved: news@daver.bungi.com Jyrki Kuoppala writes: > Matti Aarnio writes: > > A way to force GCC to do this (normally GCC just ignores register > >keyword and uses own heuristics!) is to take address of variable. > > Or to declare it volatile, or to use -traditional (with -traditional > gcc puts variables in stack by default in functions calling setjmp). > But this wouldn't have helped (I did try emacs with -traditional). > > It crashed in a bit different place than without -traditional, but > crashed anyway. > > The result of the emacs crash was that a subroutine clobbered > arguments in the caller routine - and the caller routine didn't call > setjmp(). Like this: > > int foo (x, y) > int x; > int y; > { > int count = x - y; /* the compiler put this in a register > variable like r5; say count is 5 */ > /* do various things, not using r5 */ > fprintf (stderr, "Done various things, count = %d\n, count", count); > /* count is 5 here */ > bar(); /* call bar() */ > fprintf (stderr, "Done bar(), count = %d\n, count", count); > /* Oh wow, count is a wild number like 846378 here ! */ > baz(count); /* crash in baz() because of r5 (count) is bogus */ > } How does this work? Bar calls longjump so it never gets to execute baz. If it crashes in baz it must have longjumped there. Are you sure you are a) setting the jumpbuf properly b) not over writting it and c) restoring the stack properly from the stack. If you have mangled the stack, a debugger trace back will be very misleading. Regarding ansi standard conformance, the main thing is that your program should not rely on register variables of automatic variables (unless declared volatile). If you want to make setjump save and restore registers so obsolete programs will compile, well go ahead, but since obsolete programs can be made to work with -traditional, I see no real point in putting extra overhead in setjump. Ian