public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/101770] New: -Wmaybe-uninitialized false alarm with only locals in GNU diffutils
@ 2021-08-03 23:50 eggert at cs dot ucla.edu
  2021-08-04  6:34 ` [Bug tree-optimization/101770] " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: eggert at cs dot ucla.edu @ 2021-08-03 23:50 UTC (permalink / raw)
  To: gcc-bugs

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.

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

end of thread, other threads:[~2023-05-19 21:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-03 23:50 [Bug tree-optimization/101770] New: -Wmaybe-uninitialized false alarm with only locals in GNU diffutils eggert at cs dot ucla.edu
2021-08-04  6:34 ` [Bug tree-optimization/101770] " rguenth at gcc dot gnu.org
2021-08-05 14:59 ` msebor at gcc dot gnu.org
2022-11-20  5:00 ` law at gcc dot gnu.org
2022-11-28 22:36 ` pinskia at gcc dot gnu.org
2023-05-19 21:16 ` eggert at cs dot ucla.edu
2023-05-19 21:44 ` eggert at cs dot ucla.edu

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