This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Warnings around setjmp *with* volatile.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]