fairy-stockfish / Fairy-Stockfish

chess variant engine supporting Xiangqi, Shogi, Janggi, Makruk, S-Chess, Crazyhouse, Bughouse, and many more
https://fairy-stockfish.github.io/
GNU General Public License v3.0
612 stars 191 forks source link

Assertion failure on start when compiling with debug=yes #588

Closed antoyo closed 1 year ago

antoyo commented 1 year ago

Hi. Here are the steps to reproduce:

$ make build debug=yes ARCH=x86-64-modern
$ ./stockfish
Fairy-Stockfish 200223 by Fabian Fichter
stockfish: bitboard.h:465: Stockfish::RiderType Stockfish::pop_rider(RiderType*): Assertion `*r' failed.
fish: Job 1, './stockfish' terminated by signal SIGABRT (Abort)

Gdb backtrace:

#0  0x00007ffff7aa08ec in ?? () from /usr/lib/libc.so.6
#1  0x00007ffff7a51ea8 in raise () from /usr/lib/libc.so.6
#2  0x00007ffff7a3b53d in abort () from /usr/lib/libc.so.6
#3  0x00007ffff7a3b45c in ?? () from /usr/lib/libc.so.6
#4  0x00007ffff7a4a9f6 in __assert_fail () from /usr/lib/libc.so.6
#5  0x00005555555641e3 in Stockfish::pop_rider (r=<synthetic pointer>) at /Source/Fairy-Stockfish/src/bitboard.h:465
#6  Stockfish::attacks_bb (c=Stockfish::WHITE, occupied=0, s=<optimized out>, pt=Stockfish::BISHOP)
    at /Source/Fairy-Stockfish/src/bitboard.h:475
#7  Stockfish::Bitboards::init () at bitboard.cpp:352
#8  0x000055555555b4e8 in main (argc=1, argv=0x7fffffffe538) at main.cpp:48

Thanks to fix this issue.

ianfab commented 1 year ago

I can not reproduce this. Can you retry compiling from a clean state, i.e., after make clean, and check if it still is reproducible?

antoyo commented 1 year ago

Yes, same issue after make clean.

My CPU is AMD Ryzen 9 3900X in case it matters.

Edit: If I compile with the following command, the issue disappears:

make build optimize=no debug=yes ARCH=x86-64
ianfab commented 1 year ago

Thanks. Is it the removal of optimization or of "modern" that makes it disappear, or only both together?

antoyo commented 1 year ago

It's only the removal of the optimization. The following also fixes the issue:

make build debug=yes optimize=no ARCH=x86-64-modern
ianfab commented 1 year ago

I had the feeling I remembered a similar discussion, and indeed there is #464, which seems to be basically the same issue. I still have no clue on this though. Given that compiler optimizations shouldn't change functionality there can only be two possible explanations as far as I can judge:

  1. It is a compiler bug.
  2. The code violates the assumptions of the optimization, i.e., has undefined behavior.

Either one unfortunately is very hard to track down, but if anyone has input, that is very welcome.

To avoid duplication I will close this though and refer to #464 for further discussion.