official-stockfish / Stockfish

A free and strong UCI chess engine
https://stockfishchess.org/
GNU General Public License v3.0
11.62k stars 2.28k forks source link

Strange stack behaviour: unexcpected ss->inCheck override #2648

Closed pb00068 closed 4 years ago

pb00068 commented 4 years ago

Playing around with ss->inCheck and getting unexpected bench changes I discovered that ss->inCheck get strangely overridden between search line 636 (assignment) and line 954 (moves_loop: mark), so that following verify makes abort a bench run: if (ss->inCheck != pos.checkers()) sync_cout << pos << " ss->inCheck != pos.checkers(), search depth: " << depth << sync_endl, abort();

stockfish.exe bench
Stockfish 270420 64 POPCNT by T. Romstad, M. Costalba, J. Kiiski, G. Linscott

Position: 1/47
info depth 1 seldepth 1 multipv 1 score cp 110 nodes 20 nps 10000 tbhits 0 time 2 pv e2e3
info depth 2 seldepth 2 multipv 1 score cp 122 nodes 55 nps 27500 tbhits 0 time 2 pv e2e3 b7b6
info depth 3 seldepth 3 multipv 1 score cp 120 nodes 150 nps 50000 tbhits 0 time 3 pv e2e3 b7b6 f1c4
info depth 4 seldepth 4 multipv 1 score cp 60 nodes 557 nps 185666 tbhits 0 time 3 pv g1h3 h7h6 e2e3 e7e6
info depth 5 seldepth 5 multipv 1 score cp 63 nodes 1023 nps 255750 tbhits 0 time 4 pv g1f3 e7e6 e2e3 b8c6 b1c3

 +---+---+---+---+---+---+---+---+
 | r | n | b | q | k | b | n | r |
 +---+---+---+---+---+---+---+---+
 | p | p | p |   | p | p | p | p |
 +---+---+---+---+---+---+---+---+
 |   |   |   |   |   |   |   |   |
 +---+---+---+---+---+---+---+---+
 |   | B |   | p |   |   |   |   |
 +---+---+---+---+---+---+---+---+
 |   |   |   |   |   |   |   |   |
 +---+---+---+---+---+---+---+---+
 |   |   |   |   | P |   |   |   |
 +---+---+---+---+---+---+---+---+
 | P | P | P | P |   | P | P | P |
 +---+---+---+---+---+---+---+---+
 | R | N | B | Q | K |   | N | R |
 +---+---+---+---+---+---+---+---+

Fen: rnbqkbnr/ppp1pppp/8/1B1p4/8/4P3/PPPP1PPP/RNBQK1NR b KQkq - 1 2
Key: A072C677D3FD3BF0
Checkers: b5  ss->inCheck != pos.checkers(), search depth: 1

It can be reproduced by merging this into master

curl -s https://github.com/pb00068/Stockfish/compare/bb5589b...06445f0.diff | git apply

and after compile run a normal bench. Since I cannot explain this, I fear also other variables of the Stack might be overridden unnoticed. @vondele, @snicolet ?

pb00068 commented 4 years ago

Sorry for the noise, was just comparing apples with oranges (bool with bitboard)