[Bug middle-end/91395] Report an uninitialized variable on its initialization statement (setjmp)

2019-08-08 Thread joseph at codesourcery dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91395

--- Comment #5 from joseph at codesourcery dot com  ---
It's *accessible objects* whose value on second return from setjmp is the 
same as when longjmp is called (unless non-volatile, automatic storage 
duration and changed between setjmp and longjmp).  The point is that when 
longjmp is called, save_exception_stack may not be an accessible object 
(because of having gone out of scope), so has no defined value, so it's 
just like goto jumping into the block where save_exception_stack is 
declared and thus bypassing its initialization - it's valid to jump into 
the scope like that (unless jumping into the scope of a declaration with 
variably modified type), but the variable is uninitialized.

[Bug middle-end/91395] Report an uninitialized variable on its initialization statement (setjmp)

2019-08-08 Thread ali at pivotal dot io
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91395

--- Comment #4 from Adam  ---
(In reply to Andrew Pinski from comment #3)
> In theory other can cause a call to longjmp but gcc does not know it cannot.

Thanks for the quick reply.

I got the longjmp() part, it could be called anytime. The part I don't get is
why it reports since gcc could tell that no one changes the
save_exception_stack (it has a certain short life).

The POSIX's statement as I know has two facts: "a local not-volatile variable"
and "it's been changed between setjmp() and longjmp()". Have I missed anything?

[Bug middle-end/91395] Report an uninitialized variable on its initialization statement (setjmp)

2019-08-08 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91395

--- Comment #3 from Andrew Pinski  ---
In theory other can cause a call to longjmp but gcc does not know it cannot.

[Bug middle-end/91395] Report an uninitialized variable on its initialization statement (setjmp)

2019-08-08 Thread ali at pivotal dot io
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91395

--- Comment #2 from Adam  ---
I got the point "The local variables that do not have the volatile type and
have been changed between the setjmp() invocation and longjmp() call are
indeterminate"

But save_exception_stack is not changed between the setjmp() invocation and
longjmp() call, it is defined every time. Still looks expected?

[Bug middle-end/91395] Report an uninitialized variable on its initialization statement (setjmp)

2019-08-08 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91395

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
  Component|c   |middle-end
 Resolution|--- |INVALID

--- Comment #1 from Andrew Pinski  ---
The warning is correct due to the way sigsetjmp works.
You need to mark save_exception_stack as volatile to fix the issue.

Basically any non-volatile variable in the function scope can be incorrect. 
This is what the POSIX (and C standard for setjmp) says.  GCC is just taking
into account this now.