public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/109530] New: Warning "is used uninitialized" raised for an initialized variable.
@ 2023-04-16  7:20 patrick.pelissier at gmail dot com
  2023-04-16  7:28 ` [Bug c/109530] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: patrick.pelissier at gmail dot com @ 2023-04-16  7:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109530

            Bug ID: 109530
           Summary: Warning "is used uninitialized" raised for an
                    initialized variable.
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: patrick.pelissier at gmail dot com
  Target Milestone: ---

For the following program:

#include <stdio.h>
#include <setjmp.h>

jmp_buf buf;
jmp_buf buf1;

typedef struct ry_s {
  struct ry_s *next;
} ry_t[1];

struct ry_s *m_global;

static inline void
ry_init(ry_t state)
{
  m_global = state;
}

static inline void
ry_clear(ry_t state)
{
  m_global = state->next;
}

int func2(void)
{
  for(_Bool b = 1 ; b ; b = 0)
    for(ry_t test1 ; b ; ry_clear(test1), b = 0 )
      if (ry_init(test1), setjmp (buf) == 0)
        {
          FILE *f = fopen("tmp","wt");
          if ((setjmp (buf1) == 0) )
            {
              fprintf(f, "This is a text\n");
              fclose(f);
            }
        }
  return 0;
}


When running with "-O2  -Wall -Wextra", I get the following warning:

<source>: In function 'func2':
<source>:31:17: warning: 'f' is used uninitialized [-Wuninitialized]
   31 |           FILE *f = fopen("tmp","wt");

whereas f is obviously initialized in the statement.
I am confused by this warning.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/109530] Warning "is used uninitialized" raised for an initialized variable.
  2023-04-16  7:20 [Bug c/109530] New: Warning "is used uninitialized" raised for an initialized variable patrick.pelissier at gmail dot com
@ 2023-04-16  7:28 ` pinskia at gcc dot gnu.org
  2023-04-16  7:43 ` [Bug middle-end/109530] " schwab@linux-m68k.org
  2023-04-17  8:02 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-16  7:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109530

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The warning is confusing but it is partly correct.
Across a setjmp, you might need volatile variables.
Gcc does not know that fprintf nor fclose will call longjmp.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/109530] Warning "is used uninitialized" raised for an initialized variable.
  2023-04-16  7:20 [Bug c/109530] New: Warning "is used uninitialized" raised for an initialized variable patrick.pelissier at gmail dot com
  2023-04-16  7:28 ` [Bug c/109530] " pinskia at gcc dot gnu.org
@ 2023-04-16  7:43 ` schwab@linux-m68k.org
  2023-04-17  8:02 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: schwab@linux-m68k.org @ 2023-04-16  7:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109530

--- Comment #2 from Andreas Schwab <schwab@linux-m68k.org> ---
It also doesn't see that setjmp()==0 means that the block is not reached a
second time.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/109530] Warning "is used uninitialized" raised for an initialized variable.
  2023-04-16  7:20 [Bug c/109530] New: Warning "is used uninitialized" raised for an initialized variable patrick.pelissier at gmail dot com
  2023-04-16  7:28 ` [Bug c/109530] " pinskia at gcc dot gnu.org
  2023-04-16  7:43 ` [Bug middle-end/109530] " schwab@linux-m68k.org
@ 2023-04-17  8:02 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-04-17  8:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109530

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-04-17
             Blocks|                            |24639
           Keywords|                            |missed-optimization
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
                 CC|                            |rguenth at gcc dot gnu.org

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Well, it actually diagnoses

<bb 2> [local count: 1073741824]:
f_4(ab) = f_9(D);
...

:/

So this is really an artifact of imperfect SSA form where we fail to
prune the PHI for 'f' before the first setjmp (into-SSA rewrite doesn't
honor scopes).

It's ethread that produces this copy by threading the loop header checks
and turning their PHIs into copies.

Btw, uninit diagnostics rely on the default defs eventually appearing in
PHIs for the may uninit case so we cannot simply skip such copies.

SSA_NAME_OCCURS_IN_ABNORMAL_PHI is also quite sticky, it's there from
original SSA and not removed after inlining ry_init.  When removing
an abnormal edge we'd have to check all other uses of destination PHI
arguments to validate clearing the flag.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639
[Bug 24639] [meta-bug] bug to track all Wuninitialized issues

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-04-17  8:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-16  7:20 [Bug c/109530] New: Warning "is used uninitialized" raised for an initialized variable patrick.pelissier at gmail dot com
2023-04-16  7:28 ` [Bug c/109530] " pinskia at gcc dot gnu.org
2023-04-16  7:43 ` [Bug middle-end/109530] " schwab@linux-m68k.org
2023-04-17  8:02 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).