public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/104761] New: [12 Regression] False positive -Wdangling-pointer warning on NetworkManager since r12-6606
Date: Wed, 02 Mar 2022 15:19:28 +0000	[thread overview]
Message-ID: <bug-104761-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 104761
           Summary: [12 Regression] False positive -Wdangling-pointer
                    warning on NetworkManager since r12-6606
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

With -O0 -Wdangling-pointer or -O2 -Wall (the latter is a regression) the
following testcase emits 2 false positive warnings:
nm-shared-utils.i: In function ‘test’:
nm-shared-utils.i:21:40: warning: dangling pointer to ‘error’ may be used
[-Wdangling-pointer=]
   21 |           corge (qux (addrbin.s), error->t);
      |                                        ^~
nm-shared-utils.i:18:45: note: ‘error’ declared here
   18 |       __attribute__((__cleanup__ (bar))) T *error = (T *) 0;
      |                                             ^~~~~
nm-shared-utils.i:21:11: warning: dangling pointer to ‘addrbin’ may be used
[-Wdangling-pointer=]
   21 |           corge (qux (addrbin.s), error->t);
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nm-shared-utils.i:13:5: note: ‘addrbin’ declared here
   13 |   S addrbin;
      |     ^~~~~~~
Commenting out the endless loop makes it go away.
Started with the addition of -Wdangling-pointer in
r12-6606-g9d6a0f388eb048f8d87f.

typedef struct { unsigned int s; } S;
int foo (S *);
typedef struct { char *t; } T;
void garply (T *);
static inline void bar (T **v) { if (*v) garply (*v); }
int baz (T **);
const char *qux (unsigned);
void corge (const char *, const char *);

int
test (int x)
{
  S addrbin;
  if (foo (&addrbin) != 1)
    return 0;
  if (x == 2)
    {
      __attribute__((__cleanup__ (bar))) T *error = (T *) 0;
      if (!baz (&error))
        {
          corge (qux (addrbin.s), error->t);
          for (;;)
            ;
        }
    }
  return 1;
}

             reply	other threads:[~2022-03-02 15:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-02 15:19 jakub at gcc dot gnu.org [this message]
2022-03-02 15:19 ` [Bug middle-end/104761] " jakub at gcc dot gnu.org
2022-03-02 15:51 ` jakub at gcc dot gnu.org
2022-03-02 16:07 ` jakub at gcc dot gnu.org
2022-03-02 20:35 ` msebor at gcc dot gnu.org
2022-03-02 23:16 ` [Bug middle-end/104761] [12 Regression] bogus -Wdangling-pointer with cleanup and infinite loop msebor at gcc dot gnu.org
2022-03-03 21:02 ` cvs-commit at gcc dot gnu.org
2022-03-03 21:02 ` msebor 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-104761-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).