public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/104958] New: missing -Wdangling-pointer leaking local address through struct member
Date: Wed, 16 Mar 2022 15:56:33 +0000	[thread overview]
Message-ID: <bug-104958-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2022-03-16 15:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-16 15:56 msebor at gcc dot gnu.org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-104958-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).