melonDS-emu / melonDS

DS emulator, sorta
https://melonds.kuribo64.net
GNU General Public License v3.0
2.98k stars 493 forks source link

melonDS relies on 2's complement for shifting #2055

Closed CasualPokePlayer closed 1 week ago

CasualPokePlayer commented 4 weeks ago

Putting this as an issue here, this issue first was noticed in BizHawk builds (now fixed) although still shows up in upstream melonDS (using clang 18.1.6). The issue ends up manifesting into weird rendering issues with the software renderer.

Fix would be either putting in -fwrapv or bumping up the C++ standard to C++20 (where 2's complement is mandated and various UB shift operations are no longer UB). The latter option appears to have unrelated build failures, so the former seems like a simpler fix.

Arisotura commented 1 week ago

Could you point me to specific examples of this?

CasualPokePlayer commented 1 week ago

Don't know where the code is actually relying on it. The issue is just visible if you compile the code with the latest clang, and goes away if you add -fwrapv.

CasualPokePlayer commented 1 week ago

https://github.com/melonDS-emu/melonDS/commit/cbb0f4b872ea8a5e2348c7f1a22695056968192f