https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127950
Bug ID: 127950
Summary: Under -O, "f->next = 0;" before "delete f;" is
ignored.
Product: gcc
Version: 15.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dmg at acm dot org
Target Milestone: ---
Created attachment 65876
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65876&action=edit
"tar xf gcc-Obug.tar" will give 3 files: gcc-O_bug.c++ to illustrate the bug
and good/*.ii and bad/*.ii from runing g++ -save-temps" without and with -O.
Under -O a crucial statement is ignored. In the little example I am providing,
the statement "f-next = 0;" is ignored in the following "delete f;" statement.
(If -O is not specified, all works correctly.) Output from the little example
should end with "free list after a delete: length 1:" but with -O it ends with
"
free list after a delete: length 7:".
I am running openSUSE Leap 16.1. "g++ -v" says
Configured with: ../configure CFLAGS=' -O2 -funwind-tables
-fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g'
CXXFLAGS=' -O2 -funwind-tables -fasynchronous-unwind-tables
-fstack-clash-protection -Werror=return-type -g' XCFLAGS=' -O2 -funwind-tables
-fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g'
TCFLAGS=' -O2 -funwind-tables -fasynchronous-unwind-tables
-fstack-clash-protection -Werror=return-type -g' GDCFLAGS=' -O2 -funwind-tables
-fasynchronous-unwind-tables -fstack-clash-protection -g' --prefix=/usr
--infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64
--libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,obj-c++,ada,go,d,jit,m2 --enable-host-pie
--enable-offload-targets=nvptx-none,amdgcn-amdhsa, --enable-offload-defaulted
--without-cuda-driver --enable-host-shared --enable-checking=release
--disable-werror --with-gxx-include-dir=/usr/include/c++/15
--with-libstdcxx-zoneinfo=/usr/share/zoneinfo --enable-ssp --disable-libssp
--disable-libvtv --enable-cet=auto --disable-libcc1 --disable-plugin
--with-bugurl=https://bugs.opensuse.org/ --with-pkgversion='SUSE Linux'
--with-slibdir=/lib64 --with-system-zlib --enable-libstdcxx-allocator=new
--disable-libstdcxx-pch --enable-libphobos
--enable-version-specific-runtime-libs --with-gcc-major-version-only
--enable-linker-build-id --enable-linux-futex --enable-gnu-indirect-function
--program-suffix=-15 --without-system-libunwind --enable-multilib
--with-arch-32=x86-64-v2 --with-arch=x86-64-v2 --with-tune=generic
--with-build-config=bootstrap-lto-lean --enable-link-serialization
--build=x86_64-suse-linux --host=x86_64-suse-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.3.0 (SUSE Linux)
(I am using the gcc that SuSE provides and did not compile gcc myself.)
The invocation "g++ gcc-O_bug.c++; a.out" produces no warnings and runs
correctly. The invocation "g++ -O gcc-O_bug.c++; a.out" show wrong output.