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]

Re: erroneous "clobbering" warning when using setjmp() (reproducible, w/ small source)


> I found this strange, and investigated. I'm including a (very short,
> 50 lines) C program that illustrates the bug clearly, as well as the
> .i and .s files you ask for on the gcc homepage.

Thanks for your bug report. I can (probably) reproduce the messages
you are seeing; I fail to see the bug, though. These messages are:

gcc-bug.c: In function `foo':
gcc-bug.c:39: warning: variable `list_ptr' might be clobbered by `longjmp' or `vfork'
gcc-bug.c:42: warning: variable `p' might be clobbered by `longjmp' or `vfork'
gcc-bug.c: In function `main':
gcc-bug.c:39: warning: variable `list_ptr' might be clobbered by `longjmp' or `vfork'
gcc-bug.c:42: warning: variable `p' might be clobbered by `longjmp' or `vfork'

Do you think that

a) the warning is factually incorrect, i.e. those variables cannot be
   "clobbered"? or

b) the warning should not be produced with that set of -W* options
   given to the compiler? or

c) the compiler produces erroneous code if it indeed allows these
   variables to be clobbered?

As for b); this seems indeed to be a bug. According to the
documentation, this message should only be produced with -W.

Both a) and c) base on the same statements of the C standard, namely
7.13.2.1/3:

# All accessible objects have values as of the time longjmp was
# called, except that the values of objects of automatic storage
# duration that are local to the function containing the invocation of
# the corresponding setjmp macro that do not have volatile-qualified
# type and have been changed between the setjmp invocation and longjmp
# call are indeterminate.

That is, if you call setjmp, and modify a local variable, then perform
longjmp, the state of this variable is indeterminate.

Since you've compiled the code with -finline-functions, the setjmp
call occurs inside foo, i.e. inside main. As a result, list_ptr is a
local variable in the same function containing setjmp. Since it is
modified in a loop, after setjmp is called, a later call to longjmp
might (!) clobber the variable. This is what the compiler warns about.

To avoid the problem, don't compile with -finline-functions. To avoid
the warning, compile with -Wno-unitialized.

If this is not a satisfying answer, please explain the problem in more
detail.

Hope this helps,
Martin


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