Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* gcc compiler warning
@ 1998-02-23  8:07 Jim. Shipman
  0 siblings, 0 replies; 3+ messages in thread
From: Jim. Shipman @ 1998-02-23  8:07 UTC (permalink / raw)


I've got a program which gets the following warnings when I compile with
-Wall.  Can anyone tell me what this is trying to say?  How would these
varibles get "clobbered"?  How can I prevent this?

This is on Alpha 164LX with linux 4.2
-------------------------------------
function `gpi_EvaluateGeneration':
gpi.c:336: warning: variable `i' might
be clobbered by `longjmp' or `vfork'
gpi.c:340: warning: variable `fit_sum'
might be clobbered by `longjmp' or `vfork'
gpi.c:372: warning: variable
`value' might be clobbered by `longjmp' or
`vfork'
-------------------------------------
Thanks,
Jim

-- 
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gcc compiler warning
@ 1998-02-23 14:37 Przemek Klosowski
  1998-02-24  0:31 ` Richard Henderson
  0 siblings, 1 reply; 3+ messages in thread
From: Przemek Klosowski @ 1998-02-23 14:37 UTC (permalink / raw)


I've got a program which gets the following warnings when I compile with
   -Wall.  Can anyone tell me what this is trying to say?  How would these
   varibles get "clobbered"?  How can I prevent this?

   function `gpi_EvaluateGeneration':
   gpi.c:336: warning: variable `i' might    be clobbered by `longjmp' or `vfork'

Register-based local variables are not guaranteed to be preserved
across longjump (and also I guess vfork); in other words if you do
setjmp, and then longjmp to it, you aren't guaranteed to see the
values of register-based local variables as they were at time of
setjmp; this is because setjmp/longjmp save/restore the stack only.

-- 
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gcc compiler warning
  1998-02-23 14:37 gcc compiler warning Przemek Klosowski
@ 1998-02-24  0:31 ` Richard Henderson
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Henderson @ 1998-02-24  0:31 UTC (permalink / raw)


On Mon, Feb 23, 1998 at 09:37:14AM -0500, Przemek Klosowski wrote:
> Register-based local variables are not guaranteed to be preserved
> across longjump (and also I guess vfork); in other words if you do
> setjmp, and then longjmp to it, you aren't guaranteed to see the
> values of register-based local variables as they were at time of
> setjmp; this is because setjmp/longjmp save/restore the stack only.

No, the real problem is that longjmp _does_ restore the call-saved
registers to the contents they had at setjmp, when what is wanted
is a real stack-unwind as is possible when the language supports
exceptions.  So in

	jmp_buf buf;
	register int i = 1;

	if (setjmp(buf))
		printf("%d\n", i);
	else
	{
		i = 10;
		longjmp(buf, 1);
	}

if i is allocated to a call-saved register, you get 1, if not, 
you get 10.  The warning reminds you that that the only way to
get consistent results is to declare i volatile.  In which case
you get 10.

r~

-- 
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-02-24  0:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-02-23 14:37 gcc compiler warning Przemek Klosowski
1998-02-24  0:31 ` Richard Henderson
  -- strict thread matches above, loose matches on Subject: below --
1998-02-23  8:07 Jim. Shipman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox