public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/104958] New: missing -Wdangling-pointer leaking local address through struct member
@ 2022-03-16 15:56 msebor at gcc dot gnu.org
  2022-03-16 15:57 ` [Bug middle-end/104958] " msebor at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-03-16 15:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104958
           Summary: missing -Wdangling-pointer leaking local address
                    through struct member
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

As discussed in
https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590230.html both
functions in the following test case leak the address of the local variable to
their caller and should trigger a -Wdangling pointer but only one of them does.
 The patch submitted to implement this missing functionality was deferred until
GCC 13:

https://gcc.gnu.org/pipermail/gcc-patches/attachments/20220210/2641dce0/attachment-0003.bin

$ cat x.c && gcc -S -Wall x.c
struct S { void *p; };

void f (struct S *p)
{
  int j;
  p->p = &j;             // -Wdangling-pointer
}

struct S g (void)
{
  int i;
  struct S s = { &i };   // missing -Wdangling-pointer
  return s;
}

x.c: In function ‘f’:
x.c:6:8: warning: storing the address of local variable ‘j’ in ‘*p.p’
[-Wdangling-pointer=]
    6 |   p->p = &j;             // -Wdangling-pointer
      |   ~~~~~^~~~
x.c:5:7: note: ‘j’ declared here
    5 |   int j;
      |       ^
x.c:5:7: note: ‘p’ declared here

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

end of thread, other threads:[~2022-12-11  1:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-16 15:56 [Bug middle-end/104958] New: missing -Wdangling-pointer leaking local address through struct member msebor at gcc dot gnu.org
2022-03-16 15:57 ` [Bug middle-end/104958] " msebor at gcc dot gnu.org
2022-12-11  1:55 ` pinskia at gcc dot gnu.org
2022-12-11  1:56 ` pinskia 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).