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

            Bug ID: 115767
           Summary: GCC looses track of value on aarch64 with -O2
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugs at qult dot net
  Target Milestone: ---

I've stumbled upon what looks like a compiler bug with the following code,
compiled for aarch64:

#include <cassert>
#include <boost/bimap.hpp>
#include <boost/bimap/unordered_set_of.hpp>

int main()
{
  using map_type = boost::bimap<boost::bimaps::set_of<int>,
                                boost::bimaps::unordered_set_of<int>>;
  map_type      map;
  auto  x = map.insert({0, 0}).first;
  map.replace_right(x, 42);
  auto  y = map.find(map_type::value_type{0, 42});
  assert(y != map.end());
  assert(x == y);
  assert(&x->right == &y->right);
  assert(y->right != 0);
  assert(x->right != 0);
}

The last assert fails with -O2.  I've managed to track the optimization flags
down to -O1 -fcode-hoisting -fipa-sra -fstrict-aliasing .

In the .s, it looks like x is kept in register x19 while x->right is kept in
w23, but after the call to replace_right, w23 is not updated using x19 and thus
holds the old value (0).

I've tested that with GCC master (e9fb6efa1cf542353fd44ddcbb5136344c463fd0) and
Boost/bimap master (6865e94cc56a33bb8b162bf8d62cfe620b06d2b6), cross-compiled
with GCC 13.2.0-23ubuntu4 for aarch64 using Buildroot 2024.02.1 with the
following configure flags:

Using built-in specs.
COLLECT_AS_OPTIONS='--version'
COLLECT_GCC=[...]/host/bin/aarch64-linux-g++.br_real
COLLECT_LTO_WRAPPER=[...]/host/libexec/gcc/aarch64-buildroot-linux-musl/15.0.0/lto-wrapper
aarch64-linux-g++.br_real (Buildroot 2024.02.1-6309-g2fd20014a8) 15.0.0
20240703 (experimental)
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Target: aarch64-buildroot-linux-musl
Configured with: ./configure --prefix=[...]/host --sysconfdir=[...]/host/etc
--enable-static --target=aarch64-buildroot-linux-musl
--with-sysroot=[...]/host/aarch64-buildroot-linux-musl/sysroot
--enable-__cxa_atexit --with-gnu-ld --disable-libssp --disable-multilib
--disable-decimal-float --enable-plugins --enable-lto --with-gmp=[...]/host
--with-mpc=[...]/host --with-mpfr=[...]/host --with-pkgversion='Buildroot
2024.02.1-6309-g2fd20014a8' --with-bugurl=http://bugs.buildroot.net/
--without-zstd --with-debug-prefix-map=[...]=buildroot --disable-libmpx
--disable-libquadmath --disable-libquadmath-support --disable-libsanitizer
--enable-tls --enable-threads --without-isl --without-cloog --with-abi=lp64
--with-cpu=cortex-a53 --enable-languages=c,c++
--with-build-time-tools=[...]/host/aarch64-buildroot-linux-musl/bin
--enable-shared --disable-libgomp
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20240703 (experimental) (Buildroot
2024.02.1-6309-g2fd20014a8) 
COMPILER_PATH=[...]/host/libexec/gcc/aarch64-buildroot-linux-musl/15.0.0/:[...]/host/libexec/gcc/aarch64-buildroot-linux-musl/15.0.0/:[...]/host/libexec/gcc/aarch64-buildroot-linux-musl/:[...]/host/lib/gcc/aarch64-buildroot-linux-musl/15.0.0/:[...]/host/lib/gcc/aarch64-buildroot-linux-musl/:[...]/host/lib/gcc/aarch64-buildroot-linux-musl/15.0.0/../../../../aarch64-buildroot-linux-musl/bin/
LIBRARY_PATH=[...]/host/lib/gcc/aarch64-buildroot-linux-musl/15.0.0/:[...]/host/lib/gcc/aarch64-buildroot-linux-musl/15.0.0/../../../../aarch64-buildroot-linux-musl/lib/../lib64/:[...]/host/aarch64-buildroot-linux-musl/sysroot/lib/../lib64/:[...]/host/aarch64-buildroot-linux-musl/sysroot/usr/lib/../lib64/:[...]/host/lib/gcc/aarch64-buildroot-linux-musl/15.0.0/../../../../aarch64-buildroot-linux-musl/lib/:[...]/host/aarch64-buildroot-linux-musl/sysroot/lib/:[...]/host/aarch64-buildroot-linux-musl/sysroot/usr/lib/
COLLECT_GCC_OPTIONS='--sysroot=[...]/host/aarch64-buildroot-linux-musl/sysroot'
'-fstack-protector-strong' '-ffile-prefix-map=[...]=buildroot' '-fPIE' '-pie'
'--version' '-v' '-shared-libgcc' '-mcpu=cortex-a53' '-mlittle-endian'
'-mabi=lp64' '-dumpdir' 'a.'
 [...]/host/libexec/gcc/aarch64-buildroot-linux-musl/15.0.0/collect2 -plugin
[...]/host/libexec/gcc/aarch64-buildroot-linux-musl/15.0.0/liblto_plugin.so
-plugin-opt=[...]/host/libexec/gcc/aarch64-buildroot-linux-musl/15.0.0/lto-wrapper
-plugin-opt=-fresolution=/tmp/ccP2tEjt.res -plugin-opt=-pass-through=-lgcc_s
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc
--sysroot=[...]/host/aarch64-buildroot-linux-musl/sysroot --eh-frame-hdr
-dynamic-linker /lib/ld-musl-aarch64.so.1 -X -EL -maarch64linux -pie --version
[...]/host/aarch64-buildroot-linux-musl/sysroot/lib/../lib64/Scrt1.o
[...]/host/aarch64-buildroot-linux-musl/sysroot/lib/../lib64/crti.o
[...]/host/lib/gcc/aarch64-buildroot-linux-musl/15.0.0/crtbeginS.o
-L[...]/host/lib/gcc/aarch64-buildroot-linux-musl/15.0.0
-L[...]/host/lib/gcc/aarch64-buildroot-linux-musl/15.0.0/../../../../aarch64-buildroot-linux-musl/lib/../lib64
-L[...]/host/aarch64-buildroot-linux-musl/sysroot/lib/../lib64
-L[...]/host/aarch64-buildroot-linux-musl/sysroot/usr/lib/../lib64
-L[...]/host/lib/gcc/aarch64-buildroot-linux-musl/15.0.0/../../../../aarch64-buildroot-linux-musl/lib
-L[...]/host/aarch64-buildroot-linux-musl/sysroot/lib
-L[...]/host/aarch64-buildroot-linux-musl/sysroot/usr/lib -z max-page-size=4096
-z common-page-size=4096 --build-id=none -z relro -lstdc++ -lm -lgcc_s -lgcc
-lc -lgcc_s -lgcc
[...]/host/lib/gcc/aarch64-buildroot-linux-musl/15.0.0/crtendS.o
[...]/host/aarch64-buildroot-linux-musl/sysroot/lib/../lib64/crtn.o
collect2 version 15.0.0 20240703 (experimental)
[...]/host/lib/gcc/aarch64-buildroot-linux-musl/15.0.0/../../../../aarch64-buildroot-linux-musl/bin/ld
-plugin
[...]/host/libexec/gcc/aarch64-buildroot-linux-musl/15.0.0/liblto_plugin.so
-plugin-opt=[...]/host/libexec/gcc/aarch64-buildroot-linux-musl/15.0.0/lto-wrapper
-plugin-opt=-fresolution=/tmp/ccP2tEjt.res -plugin-opt=-pass-through=-lgcc_s
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc
--sysroot=[...]/host/aarch64-buildroot-linux-musl/sysroot --eh-frame-hdr
-dynamic-linker /lib/ld-musl-aarch64.so.1 -X -EL -maarch64linux -pie --version
[...]/host/aarch64-buildroot-linux-musl/sysroot/lib/../lib64/Scrt1.o
[...]/host/aarch64-buildroot-linux-musl/sysroot/lib/../lib64/crti.o
[...]/host/lib/gcc/aarch64-buildroot-linux-musl/15.0.0/crtbeginS.o
-L[...]/host/lib/gcc/aarch64-buildroot-linux-musl/15.0.0
-L[...]/host/lib/gcc/aarch64-buildroot-linux-musl/15.0.0/../../../../aarch64-buildroot-linux-musl/lib/../lib64
-L[...]/host/aarch64-buildroot-linux-musl/sysroot/lib/../lib64
-L[...]/host/aarch64-buildroot-linux-musl/sysroot/usr/lib/../lib64
-L[...]/host/lib/gcc/aarch64-buildroot-linux-musl/15.0.0/../../../../aarch64-buildroot-linux-musl/lib
-L[...]/host/aarch64-buildroot-linux-musl/sysroot/lib
-L[...]/host/aarch64-buildroot-linux-musl/sysroot/usr/lib -z max-page-size=4096
-z common-page-size=4096 --build-id=none -z relro -lstdc++ -lm -lgcc_s -lgcc
-lc -lgcc_s -lgcc
[...]/host/lib/gcc/aarch64-buildroot-linux-musl/15.0.0/crtendS.o
[...]/host/aarch64-buildroot-linux-musl/sysroot/lib/../lib64/crtn.o
GNU ld (GNU Binutils) 2.40
Copyright (C) 2023 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
COLLECT_GCC_OPTIONS='--sysroot=[...]/host/aarch64-buildroot-linux-musl/sysroot'
'-fstack-protector-strong' '-ffile-prefix-map=[...]=buildroot' '-fPIE' '-pie'
'--version' '-v' '-shared-libgcc' '-mcpu=cortex-a53' '-mlittle-endian'
'-mabi=lp64' '-dumpdir' 'a.'

Reply via email to