public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/102329] New: pointer "maybe uninitialized" right after assignment
@ 2021-09-14 16:49 hv at crypt dot org
  2021-09-14 16:56 ` [Bug c/102329] " jakub at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: hv at crypt dot org @ 2021-09-14 16:49 UTC (permalink / raw)
  To: gcc-bugs

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.

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

end of thread, other threads:[~2023-05-29 10:05 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-14 16:49 [Bug c/102329] New: pointer "maybe uninitialized" right after assignment hv at crypt dot org
2021-09-14 16:56 ` [Bug c/102329] " jakub at gcc dot gnu.org
2021-09-15  3:50 ` [Bug tree-optimization/102329] " hv at crypt dot org
2021-09-15  7:55 ` rguenth at gcc dot gnu.org
2021-09-15 15:44 ` msebor at gcc dot gnu.org
2021-09-17 11:41 ` hv at crypt dot org
2021-09-20 14:56 ` msebor at gcc dot gnu.org
2021-10-18 13:51 ` fw at gcc dot gnu.org
2021-10-18 21:10 ` [Bug tree-optimization/102329] [11/12 Regression] " pinskia at gcc dot gnu.org
2022-01-20 10:00 ` rguenth at gcc dot gnu.org
2022-04-21  7:50 ` rguenth at gcc dot gnu.org
2023-05-29 10:05 ` [Bug tree-optimization/102329] [11/12/13/14 " jakub 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).