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;
}

Reply via email to