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

            Bug ID: 101770
           Summary: -Wmaybe-uninitialized false alarm with only locals in
                    GNU diffutils
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at cs dot ucla.edu
  Target Milestone: ---

Created attachment 51256
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51256&action=edit
False alarm with gcc -O2 -Wmaybe-uninitialized and only locals

I found this problem while compiling sdiff.c from GNU diffutils. The attached
is is a simplified version. It appears to be distinct from GCC bug 101768 since
it involves only local variables.

Compile it this way:

gcc -O2 -Wmaybe-uninitialized -S w.i

The output is:

w.i: In function ‘edit’:
w.i:50:18: warning: ‘cmd1’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
   50 |           return !cmd1;
      |                  ^~~~~

This is a false alarm, because line 50 can be reached only if cmd0=='e', and if
cmd0=='e' then  the previous switch statement (inside the while loop - line 27)
guarantees that cmd1 has been initialized.

I briefly tried to simplify the example further, but failed. For example, if I
remove line 16 ("case '2':") the false alarm goes away.

This is with gcc (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1) on x86-64.

Reply via email to