public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/108467] New: false positive -Wmaybe-uninitialized warning at -O1 or higher
@ 2023-01-19 16:08 vincent-gcc at vinc17 dot net
  2023-01-19 16:15 ` [Bug tree-optimization/108467] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2023-01-19 16:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108467
           Summary: false positive -Wmaybe-uninitialized warning at -O1 or
                    higher
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincent-gcc at vinc17 dot net
  Target Milestone: ---

Consider the following code, derived from MPFR's sub1sp.c (where the issue
occurred since at least GCC 4.9.4 and the warning was silenced with the "sh =
sh" trick via an INITIALIZED() macro):

extern long emin;
extern long emax;

int f(void);

int g(void)
{
  int sh, rb, sb;

  if (f())
    rb = sb = 0;
  else
    {
      sh = f();
      sb = f();
      rb = f();
    }

  (0 >= emin && 0 <= emax) || (f(), __builtin_unreachable(), 0);
  if (rb == 0 && sb == 0)
    return 0;
  else
    return sh;
}

With gcc-12 (Debian 12.2.0-14) 12.2.0, I get:

$ gcc-12 -O2 -Wmaybe-uninitialized -c tst.c
tst.c: In function ‘g’:
tst.c:23:12: warning: ‘sh’ may be used uninitialized [-Wmaybe-uninitialized]
   23 |     return sh;
      |            ^~
tst.c:8:7: note: ‘sh’ was declared here
    8 |   int sh, rb, sb;
      |       ^~

The warning also occurs at -O1 and -O3. It disappears if I slightly modify the
code.

Note: During the code reduction, I also got the warning, but with a different
location. However, the code was more complex, and I've already reported
PR108466 about a location issue (where the -Wmaybe-uninitialized is correct).
So I haven't reported an additional issue about the location.

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

end of thread, other threads:[~2024-06-15  9:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-19 16:08 [Bug tree-optimization/108467] New: false positive -Wmaybe-uninitialized warning at -O1 or higher vincent-gcc at vinc17 dot net
2023-01-19 16:15 ` [Bug tree-optimization/108467] " pinskia at gcc dot gnu.org
2023-01-20  8:28 ` rguenth at gcc dot gnu.org
2024-06-15  2:07 ` sjames at gcc dot gnu.org
2024-06-15  9:41 ` vincent-gcc at vinc17 dot net

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).