[Bug c/106868] New: Bogus -Wdangling-pointer warning with -O1
medhefgo at web dot de
gcc-bugzilla@gcc.gnu.org
Wed Sep 7 08:47:03 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106868
Bug ID: 106868
Summary: Bogus -Wdangling-pointer warning with -O1
Product: gcc
Version: 12.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: medhefgo at web dot de
Target Milestone: ---
The following code gives me a (afaik) bogus dangling pointer warning:
# cat testcase.c
void alloc(void **p);
void false_dangling(char **p) {
{
void *q;
alloc(&q);
*p = q;
}
char *a = __builtin_memcpy(*p, "", 1);
*a = 0;
}
$ gcc -c -o/dev/null testcase.c -Wdangling-pointer -O1
testcase.c: In function ‘false_dangling’:
testcase.c:9:6: warning: using dangling pointer ‘a’ to ‘q’
[-Wdangling-pointer=]
9 | *a = 0;
| ~~~^~~
testcase.c:4:11: note: ‘q’ declared here
4 | void *q;
|
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-bootstrap
--prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--with-build-config=bootstrap-lto --with-linker-hash-style=gnu
--with-system-zlib --enable-__cxa_atexit --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (GCC)
More information about the Gcc-bugs
mailing list