public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/110091] New: bogus -Wdangling-pointer on non-pointer values
@ 2023-06-02 12:00 patrickdepinguin at gmail dot com
  2023-06-02 22:05 ` [Bug tree-optimization/110091] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: patrickdepinguin at gmail dot com @ 2023-06-02 12:00 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110091
           Summary: bogus -Wdangling-pointer on non-pointer values
           Product: gcc
           Version: 12.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: patrickdepinguin at gmail dot com
  Target Milestone: ---

Following reduced testcase gives a bogus -Wdangling-pointer:

struct tEntry
{
    int value;
};

struct tOut
{
    int outvalue;
};
extern struct tOut *out;

extern int otherfunc(struct tEntry *);
extern void anotherfunc(int val);

void bar()
{
    struct tEntry entry = { 0 };

    if (otherfunc(&entry) != 0)
    {
        return;
    }

    if (out)
    {
        out->outvalue = entry.value;
    }

    anotherfunc(5);
}

void foo()
{
    bar();
}



$ gcc -O2  -Wall -Werror /opt/test.c
/opt/test.c: In function 'bar':
/opt/test.c:26:30: error: dangling pointer to 'entry' may be used
[-Werror=dangling-pointer=]
   26 |         out->outvalue = entry.value;
      |                         ~~~~~^~~~~~
/opt/test.c:17:19: note: 'entry' declared here
   17 |     struct tEntry entry = { 0 };
      |                   ^~~~~
In function 'bar',
    inlined from 'foo' at /opt/test.c:34:5:
/opt/test.c:26:30: error: dangling pointer to 'entry' may be used
[-Werror=dangling-pointer=]
   26 |         out->outvalue = entry.value;
      |                         ~~~~~^~~~~~
/opt/test.c: In function 'foo':
/opt/test.c:17:19: note: 'entry' declared here
   17 |     struct tEntry entry = { 0 };
      |                   ^~~~~
cc1: all warnings being treated as errors


entry is a local struct, initialized to 0, and passed as pointer to an external
function.
But the use being warned about is not using any pointer.


Tested with 12.2.0 (Debian), 12.2.1 (Gentoo), 12.3.0 (official gcc docker
image), 13.1.0 (official gcc docker image).

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

end of thread, other threads:[~2024-01-12 14:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-02 12:00 [Bug middle-end/110091] New: bogus -Wdangling-pointer on non-pointer values patrickdepinguin at gmail dot com
2023-06-02 22:05 ` [Bug tree-optimization/110091] " pinskia at gcc dot gnu.org
2023-06-02 22:07 ` [Bug tree-optimization/110091] [12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-01-10 15:40 ` jamborm at gcc dot gnu.org
2024-01-12 14:13 ` rguenth 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).