kstenerud / Musashi

Motorola 680x0 emulator written in C
412 stars 94 forks source link

Undefined behaviour #67

Open dirkwhoffmann opened 4 years ago

dirkwhoffmann commented 4 years ago

Under some circumstances, Musashi uses too large bit-shift values. This results in undefined behaviour.

This is what the UndefinedBehaviorSanitizer (which is part of clang) reports:

Bildschirmfoto 2020-01-10 um 18 33 03 Bildschirmfoto 2020-01-10 um 18 33 39 Bildschirmfoto 2020-01-10 um 18 34 27

The problem with undefined behaviour shouldn't be underestimated, because some modern compilers (such as clang) make use of it to aggressively optimise code. Code with undefined behaviour can behave differently when compiled with "clang -O0" or "clang -O1", respectively (even on the same machine).