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).

Reply via email to