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

            Bug ID: 102329
           Summary: pointer "maybe uninitialized" right after assignment
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hv at crypt dot org
  Target Milestone: ---

Reduced from perl source code:

% cat test.c
extern void *malloc (long unsigned int size);
extern void f1 (const void *pointer);

void perl_alloc(void) {
    void *vp1 = malloc(1);
    /* *(char*)vp1 = 0; */
    f1((const void *)vp1);
}
% gcc-11.2.0 -c -Wmaybe-uninitialized -O2 test.c
test.c: In function 'perl_alloc':
test.c:7:5: warning: 'vp1' may be used uninitialized [-Wmaybe-uninitialized]
    8 |     f1((const void *)vp1);
      |     ^~~~~~~~~~~~~~~~~~~~~
test.c:2:13: note: by argument 1 of type 'const void *' to 'f1' declared here
    3 | extern void f1 (const void *pointer);
      |             ^~
% 

This build of gcc was configured as follows (including the error in prefix):
  ../gcc/configure --prefix=/opt/gcc-12 --disable-gcov --disable-multilib
--enable-languages=c --disable-nls --disable-decimal-float

No warning is seen under my system "gcc-9 (Ubuntu 9.2.1-17ubuntu1~18.04.1)
9.2.1 20191102", nor does 11.2.0 complain if the commented-out assignment is
uncommented, nor if 'malloc' is renamed to 'f2', nor if 'const' is removed from
the signature of f1 along with the corresponding cast.

Is the warning intended to imply that the memory pointed to by vp1 may be
uninitialized, rather than vp1 itself? If so, perhaps it is only that the
message is misleadingly worded, and making possibly inappropriate assumptions
about what f1() may do.

Reply via email to