public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/101793] New: Incorrect production of ‘may be used uninitialized in this function [-Werror=maybe-uninitialized]'
@ 2021-08-05 20:19 thutt at vmware dot com
  2021-08-05 20:20 ` [Bug c/101793] " thutt at vmware dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: thutt at vmware dot com @ 2021-08-05 20:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101793
           Summary: Incorrect production of ‘may be used uninitialized in
                    this function [-Werror=maybe-uninitialized]'
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thutt at vmware dot com
  Target Milestone: ---

/*
  When compiled with the following options using the C compiler:

   -Werror                                      \
   -Wmaybe-uninitialized                        \
   -O1                                          \
   -fno-diagnostics-show-caret                  \

  this code produces the following diagnostic

    ./rk.c: In function ‘f’:
    ./rk.c:26:16: error: ‘saved’ may be used uninitialized in this function
[-Werror=maybe-uninitialized]
    cc1: all warnings being treated as errors

 This warning is erroneously produced, since 'state' is saved and
 restored under the same condition ('cond').

*/

unsigned fn(void);

extern unsigned state;

unsigned
f(unsigned p)
{
   unsigned  saved;
   unsigned  v0   = fn();
   unsigned  cond = p != 0;

   if (cond) {
      saved = state;

      if (v0 != 0) {
         p = 0;
      }
   }

   if (v0 > 0) {
      return 0;
   }

   if (fn()) {
      if (cond) {
         state = saved;
      }
      return p;
   }
   return 0;
}

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

end of thread, other threads:[~2022-11-20  5:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-05 20:19 [Bug c/101793] New: Incorrect production of ‘may be used uninitialized in this function [-Werror=maybe-uninitialized]' thutt at vmware dot com
2021-08-05 20:20 ` [Bug c/101793] " thutt at vmware dot com
2021-08-05 20:33 ` [Bug tree-optimization/101793] " pinskia at gcc dot gnu.org
2021-08-05 20:59 ` thutt at vmware dot com
2021-08-05 21:14 ` pinskia at gcc dot gnu.org
2021-08-07  0:13 ` msebor at gcc dot gnu.org
2021-08-07  0:17 ` [Bug tree-optimization/101793] Incorrect -Wmaybe-uninitialized on an unreachable use at -O1 msebor at gcc dot gnu.org
2022-01-26 17:56 ` msebor at gcc dot gnu.org
2022-11-20  5:15 ` law 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).