Removing bugs from bug free functions

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Dann Corbit
Posts: 12540
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Removing bugs from bug free functions

Post by Dann Corbit »

Do you have a public repository?
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
Cardoso
Posts: 362
Joined: Thu Mar 16, 2006 7:39 pm
Location: Portugal
Full name: Alvaro Cardoso

Re: Removing bugs from bug free functions

Post by Cardoso »

Dann Corbit wrote: Tue Jun 16, 2020 10:39 pm Do you have a public repository?
Thanks Dann for the helping spirit, I dont have a public repository because I'm competing against two other programs, Triturator from Spain and Aurora Borealis from Russia.
It's OK, I've been making a match against Aurora Borealis from Russia, I think we have played more than 70 games from a total of 98 games at 30 minutes plus 20 seconds, and my engine has won I think more than 10 games with zero losses, I think 2 wins were from testing games with critical openings. My friend Herson from Costa Rica keeps all the records from the ongoing match not yet published.
http://damasclasicas.blogspot.com/
My engine didn't crash a single time during the match and never made a blunder so I guess we can't rule out the possibility of MVC compiler having bugs.
noobpwnftw
Posts: 560
Joined: Sun Nov 08, 2015 11:10 pm

Re: Removing bugs from bug free functions

Post by noobpwnftw »

Raise stack reserve size. Inlining this function causes stack overflow.
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Removing bugs from bug free functions

Post by Ras »

Cardoso wrote: Tue Jun 16, 2020 10:09 pmBut with optimizations disabled and the nonsense code disabled the engine doesn't crash and no errors are reported.
Yes, that's typical for undefined behaviour. With optimisations enabled, the compiler is just more likely to make assumptions that no undefined behaviour exists and omit code parts or situations that would imply undefined behaviour. That can be e.g. signed integer wrap-around, or some shift operation that is at least as wide as the data type. Like, shifting a 64 bit integer by 64 bit or more. Adding or omitting any code may prevent such an optimisation in a specific case by sheer accident.

You could try raising the warning level, see https://docs.microsoft.com/en-us/cpp/bu ... ew=vs-2019 , and using the free static code checker CppCheck, see http://cppcheck.sourceforge.net/ .
Rasmus Althoff
https://www.ct800.net
Dann Corbit
Posts: 12540
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Removing bugs from bug free functions

Post by Dann Corbit »

I highly recommend CLANG not for compiling, which is just on par with gcc, but as a free Lint, because the error checking is so good.
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: Removing bugs from bug free functions

Post by mvanthoor »

Cardoso wrote: Tue Jun 16, 2020 6:46 pm So I guess I'm going back to the faster way of fixing this with the code:

Code: Select all

if (4 == 5) PrintGeneralText(" 4 == 5 ");
This is strange. "if (4 == 5) doSomething()" is the same as "if (false) doSomething()". You have an unreachable branch.

In Rust, the compiler will warn you about that, and proceed to strip it from the code. Having it in there or not would make no difference to the final program. I would expect that a C or C++ compiler does the same. In case of CLANG, it probably will, because CLANG and rustc both compile down to LLVM intermittent code, where the LLVM backend takes over for optimization. I don't know about GCC-compilers or MSVC.
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
mar
Posts: 2555
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Removing bugs from bug free functions

Post by mar »

if you can use VS2019 and do a 32-bit build, you can try to enable ASAN (finally) to see if it detects any problems. 64-bit ASAN will come in the next version I think.
One can never rule out compiler bugs, but these are rare. Also don't forget that in debug mode everything is pre/post-filled with specific patterns (I'm talking Microsoft compiler here), like uninitialized memory has a specific filler, freed memory another and so on => this might explain the difference between debug and release build.
Martin Sedlak
Sesse
Posts: 300
Joined: Mon Apr 30, 2018 11:51 pm

Re: Removing bugs from bug free functions

Post by Sesse »

Or you can use Clang, which has 64-bit ASan (also on Windows).
Cardoso
Posts: 362
Joined: Thu Mar 16, 2006 7:39 pm
Location: Portugal
Full name: Alvaro Cardoso

Re: Removing bugs from bug free functions

Post by Cardoso »

Thank you all for your help, as soon as I get some free time I'll try again.
best regards,
Alvaro
MOBMAT
Posts: 385
Joined: Sat Feb 04, 2017 11:57 pm
Location: USA

Re: Removing bugs from bug free functions

Post by MOBMAT »

bob wrote: Tue Jun 16, 2020 6:26 am That isn't a bug-free function most likely. Typically when you can add code and hide the bug, look for uninitialized data that moves around on the stack depending on what extra code you insert...

In your case, function parameters can be wrong as well. IE you reference arrays using subscripts that might be invalid. I'd start by inserting code (or asserts) to verify that every argument is valid every time you call the thing.
I agree with Bob. Put in assert() in every method to test the passed parameters. Square numbers, color, etc. assert()s will automatically commented out when you build for performance. assert() has saved my "ass" so many times! LOL
i7-6700K @ 4.00Ghz 32Gb, Win 10 Home, EGTBs on PCI SSD
Benchmark: Stockfish15.1 NNUE x64 bmi2 (nps): 1277K