[haiku-development] Re: Use of virtual to silence "may be clobbered by longjmp"

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Thu, 25 Feb 2016 18:20:56 +0100

On 25.02.2016 17:42, Michael David Crawford wrote:

I'm working at silencing build warnings.  I figure this is a good way
to become familiar with the code base.

GCC warned that a variable "might be clobbered by 'longjmp' or
'vfork'".  That's the first time I've ever seen that.  The problem has
to do with that registers are restored by the setjmp that occurs after
longjmp.

It worked to declare that variable virtual.  Somehow I find that
unsatisfying.  My objective in declaring it virtual was to get the
variable stored on the stack rather than in a register.

I assume you mean "volatile".

I agree that this is not a satisfying solution, though I don't have a better solution. In the JPEGTranslator case one would think that rephrasing the code "if (setjmp(...) != 0) return ...;" should do the trick, since the compiler could infer that the variable won't be used after a longjmp(), but at least gcc 2 doesn't.

There are more warnings just like this in PNGTranslator.c.  When I
declare the variables virtual, it leads to fatal errors because some
of these variables are passed to subroutines whose arguments are not
declared virtual.

I could declare the arguments virtual but again this strikes me as
unsatisfying.  Is there something better I could do?

Assuming that those are pointer variables, you might have declared them incorrectly. E.g. "volatile int* foo" declares the location the pointer refers to volatile, while "int* volatile foo" would declare the pointer variable itself volatile. Only the latter can be assigned to "int*".

CU, Ingo


Other related posts: