Re: [hatari-devel] undefined behaviour fixes |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [hatari-devel] undefined behaviour fixes
- From: Thomas Huth <th.huth@xxxxxxxxx>
- Date: Thu, 23 Jan 2025 07:14:40 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1737616481; bh=F+kl4X2fhNu8Sli+uMKkmVo+FrigDBPRxB56FJuVNjk=; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type: Content-Transfer-Encoding:From; b=oPaCZxU+GWypA/1sFMFmZ8Q0gGobsrXOP3Eu8ILb71FdeNtwlRX33e75oBDky5N5p nPpWJJDdnj8ttCprZD2q4gMO/EodCPn0GOkZuTpCmJK/r92RKd6CPHg+MCMmFKPy6T 4XumBxGCjN5V+yFNrJbsrFuXC4TUzowJtDnR3F/cxmgkR2xEDDwM0eF2fs3uWtf4ks Su6CQSwyfIaiyOlYyZY/xdRzgTem+VGPFIKyPUGVOyh9/KTMa+/w1iTfk3oGWCgtud xWetCHSlO0JNm4XU3JOZaPHPCqc4tQI0TQIZ7bjM2O+HK74BW8BwSn6o4R2tQjICcW Ol/oDGvIMJzGg==
On 07/01/2025 18.23, Andreas Grabher wrote:
....
I saw this commit and I am not sure if it should be done this way: https://
git.tuxfamily.org/hatari/hatari.git/commit/?
id=108c56a1cb71e78326f142f0d892a6cadf5460dc <https://git.tuxfamily.org/
hatari/hatari.git/commit/?id=108c56a1cb71e78326f142f0d892a6cadf5460dc>
I think -fwrapv should always be set, because it produces different (safe
from undefined behaviour) code. See here for an example: https://
stackoverflow.com/questions/47232954/what-does-fwrapv-do <https://
stackoverflow.com/questions/47232954/what-does-fwrapv-do>
Because I still think it is bad coding style to shift negative values and
similar in my opinion we should only set -fwrapv where really necessary. So
we should probably only do that in the CPU core, like in my previous patch.
As I said previously, the parts of Hatari that are used in Previous
including the DSP do not trigger any warning. So Hatari is aside from the
CPU core likely to be clean and should stay like that.
Furthermore I think the CPU code should be cleaned from those cases on the
long term. So probably do not set -fwrapv if the sanitiser is activated to
keep the affected code visible.
FWIW, I just spotted by accident that the new C23 standard will enforce
two's complement for negative values:
https://en.wikipedia.org/wiki/C23_(C_standard_revision)#Obsolete_features
.... so I hope that undefined behavior with shifting negative values should
be gone with future versions of the C compilers.
Thomas