[Bug tree-optimization/108467] New: false positive -Wmaybe-uninitialized warning at -O1 or higher

vincent-gcc at vinc17 dot net gcc-bugzilla@gcc.gnu.org
Thu Jan 19 16:08:18 GMT 2023


            Bug ID: 108467
           Summary: false positive -Wmaybe-uninitialized warning at -O1 or
           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;
      sh = f();
      sb = f();
      rb = f();

  (0 >= emin && 0 <= emax) || (f(), __builtin_unreachable(), 0);
  if (rb == 0 && sb == 0)
    return 0;
    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

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.

More information about the Gcc-bugs mailing list