This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Warnings around setjmp *with* volatile.
- From: Daniel Jacobowitz <drow at mvista dot com>
- To: Robert Vazan <robertvazan at host dot sk>
- Cc: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 13 Sep 2002 12:23:38 -0400
- Subject: Re: Warnings around setjmp *with* volatile.
- References: <3D822674.32503.1F62F49@localhost>
On Fri, Sep 13, 2002 at 05:55:00PM +0200, Robert Vazan wrote:
> Hello,
>
> I am getting nasty warnings about clobbered variables despite I've
> defined them as volatile. The warning pops up when the variable is
> modified, but only in some cases. For example:
> format = "B"; /* no warning */
> ++format; /* warning! */
> Now who would ever think that longjmp() can be called inside pointer
> incrementing? Even if some signal or something I don't use can call
> longjmp(), volatile should guarantee that writing to variable is
> consistent.
> I am using setjmp like exceptions, so there are quite many such
> warnings in my program. If this specific warning could be turned off
> somehow (for example by listing message code and passing it to some
> switch).
>
> static jmp_buf buf;
> static void test(void)
> {
> volatile char *format = "A";
>
> if(!setjmp(buf))
> {
> ++format;
> if(*format)
> printf("Boo!\n");
> }
> }
>
> warning: variable `format' might be clobbered by `longjmp' or `vfork'
>
> [I am not subscribed, please cc me your reply]
The problem is that, when you longjmp() back the _pointer_ might be
clobbered. You've declared the pointed-to data as volatile, not the
pointer. You need something like "char * volatile format = ".
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer