[Bug middle-end/104958] New: missing -Wdangling-pointer leaking local address through struct member
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Mar 16 15:56:33 GMT 2022
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
More information about the Gcc-bugs
mailing list