[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Bug middle-end/19430] taking address of a var causes missing uninitialized warning (virtual PHI with MEM)



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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #35 from Martin Sebor <msebor at gcc dot gnu.org> ---
GCC 11 issues a warning when the address of an uninitialized variable is passed
to a function that takes a const pointer but it (still) doesn't warn when the
address escapes.  In both cases, it's possible for the called function to store
a value into the variable but because it's highly unlikely issuing a warning
regardless would be appropriate.  In addition, in cases where the address of
the variable doesn't escape until after the function call its value cannot be
affected even when the address is assigned to a non-const pointer.  The escape
analysis is flow insensitive so it alone cannot be relied on to make the
distinction.  But modifying variables this way is rare so issuing the warning
regardless is likely worthwhile.

$ cat a.c && gcc -O2 -S -Wall a.c
extern void f (const void*);

int g (void)
{
  int i;
  f (&i);       // -Wmaybe-uninitialized
  return i;
}

int h (void)
{
  extern const void *p;

  int i;
  f (0);
  p = &i;
  return i;     // missing -Wmaybe-uninitialized
}

a.c: In function ‘int g()’:
a.c:6:5: warning: ‘i’ may be used uninitialized [-Wmaybe-uninitialized]
    6 |   f (&i);
      |   ~~^~~~
a.c:1:13: note: by argument 1 of type ‘const void*’ to ‘void f(const void*)’
declared here
    1 | extern void f (const void*);
      |             ^
a.c:5:7: note: ‘i’ declared here
    5 |   int i;
      |       ^

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply to: