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

            Bug ID: 125312
           Summary: [16 Regression] x86_64-w64-mingw32: weak_ptr::lock() /
                    shared_from_this() multi-thread stress fails
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tadeja.kadunc at gmail dot com
  Target Milestone: ---

Created attachment 64459
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64459&action=edit
Minimal standalone repro for MinGW gcc 16.1 shared_ptr/weak_ptr regression.

A multi-thread stress of std::shared_ptr / std::weak_ptr /
std::enable_shared_from_this fails on x86_64-w64-mingw32 under GCC 16.1 with a
range of different symptoms:
  - weak_ptr.lock() failed while owning shared_ptr was alive, exit 2
  - silent destruction-time crash, exit 127
  - SIGSEGV during operation, exit 139
The same source built in the same MSYS2 environment with clang++ and libc++
runs OK for the configured duration (32 threads, 30 seconds, ~80M successful
weak_ptr.lock() + shared_from_this() iterations).


Reproduces on every CI run. Compiles warning-clean with -Wall -Wextra.


Minimal standalone repro (standard library only) for MinGW gcc 16.1:
Attached (also available here:
https://github.com/tadeja/arrow/blob/6a0cc7aa572eac9f3d6065463f73c3d74cf56503/cpp/tools/gh-49958-mingw-bad-weak-ptr-repro.cc
and
belonging .ii + .s files in a .zip available on CI runs download here:
https://github.com/apache/arrow/actions/runs/25857678307/artifacts/6993396634)


Running reproducer on MinGW with:
(
https://github.com/apache/arrow/actions/runs/25857678307/job/75979557628?pr=49961#step:6:1
)
  g++ \
    -std=gnu++20 \
    -O2 \
    -g \
    -Wall \
    -Wextra \
    -pthread \
    -save-temps=cwd \
    cpp/tools/gh-49958-mingw-bad-weak-ptr-repro.cc \
    -o gh-49958-mingw-bad-weak-ptr-repro.exe
  ./gh-49958-mingw-bad-weak-ptr-repro.exe 30

Error: Process completed with exit code 127.


> g++ -v
Using built-in specs.
COLLECT_GCC=D:\a\_temp\msys64\mingw64\bin\g++.exe
COLLECT_LTO_WRAPPER=D:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-16.1.0/configure --prefix=/mingw64
--with-local-prefix=/mingw64/local --libexecdir=/mingw64/lib --enable-bootstrap
--enable-checking=release --with-arch=nocona --with-tune=generic
--enable-mingw-wildcard
--enable-languages=c,c++,ada,fortran,lto,objc,obj-c++,jit --enable-shared
--enable-static --enable-libatomic --enable-threads=posix --enable-tls
--enable-graphite --enable-fully-dynamic-string
--enable-libstdcxx-backtrace=yes --enable-libstdcxx-filesystem-ts
--enable-libstdcxx-time --disable-libstdcxx-pch --enable-libgomp
--disable-libssp --disable-multilib --disable-rpath --disable-win32-registry
--disable-nls --disable-werror --disable-symvers --with-libiconv
--with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64
--with-isl=/mingw64 --with-pkgversion='Rev3, Built by MSYS2 project'
--with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as
--with-gnu-ld --with-libstdcxx-zoneinfo=yes --disable-libstdcxx-debug
--enable-lto --with-boot-ldflags=-static-libstdc++
--with-stage1-ldflags=-static-libstdc++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.1.0 (Rev3, Built by MSYS2 project) 
( See:
https://github.com/apache/arrow/actions/runs/25857678307/job/75979557628?pr=49961#step:6:1
)

 * Disclaimer: Compiler is from MSYS2 16.1.0 package. We have not verified on
upstream GCC 16.1.0 build for x86_64-w64-mingw32.


Verified with -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations:
(
https://github.com/apache/arrow/actions/runs/25857678307/job/75979557628?pr=49961#step:9:1
)
REPRODUCED: weak_ptr.lock() failed while owning shared_ptr was alive
Error: Process completed with exit code 2.


Verified with -D_GLIBCXX_ASSERTIONS:
(
https://github.com/apache/arrow/actions/runs/25857678307/job/75979557628?pr=49961#step:7:1
)
Error: Process completed with exit code 127.


Verified with -D_GLIBCXX_DEBUG:
(
https://github.com/apache/arrow/actions/runs/25857678307/job/75979557628?pr=49961#step:8:1
)
D:\a\_temp\3f3284a1-e827-4d32-a161-30cef687eb09: line 9:  1031 Segmentation
fault         ./gh-49958-mingw-bad-weak-ptr-repro-debug.exe 30
Error: Process completed with exit code 139.


Known working/failing:
Previously GCC 15.2.0  (x86_64-w64-mingw32, posix threads): OK
Updated to GCC 16.1.0  (x86_64-w64-mingw32, posix threads): FAIL

The same repro source built with the same flags on:
 * MSYS2 CLANG64 (clang + libc++) on same Windows host:  OK (~80M iters)
 * Ubuntu 24.04, g++-13 + libstdc++:                     OK
 * Ubuntu 24.04, clang++-18 + libstdc++:                 OK
 * macOS 14, Apple Clang + libc++:                       OK



Downstream Apache Arrow CI diagnostics:
https://github.com/apache/arrow/pull/49961#issuecomment-4450663500
https://github.com/apache/arrow/pull/49961#issuecomment-4444272861
(and older investigation issue https://github.com/apache/arrow/issues/49958 )


(Compare bug 124247: sibling wrong-code on same target/version but different
mechanism: AVX-only, requires -march >=x86-64-v3. This case uses MSYS2
--with-arch=nocona.)

Reply via email to