Re: [hatari-devel] undefined behaviour fixes

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Am Mon, 6 Jan 2025 14:11:05 +0100
schrieb Andreas Grabher <andreas_g86@xxxxxxxxxx>:
....
> Using -fwrapv flag with my compiler reduces the amount of warnings.

Thanks for checking - that patch looks more reasonable to me now.

> There are still some warnings about shifting beyond type size (uae_u32 x
> >> 32 and uae_u32 x << 32) and shifting with negative value (x << -1).
> Appended patch should fix them.

diff -ru a/src/cpu/gencpu.c b/src/cpu/gencpu.c
--- a/src/cpu/gencpu.c	2024-05-04 20:10:03
+++ b/src/cpu/gencpu.c	2025-01-06 14:04:13
@@ -9224,7 +9224,7 @@
 			if (curi->dmode == Dreg) {
 				out("uae_u32 tmp = m68k_dreg(regs, dstreg);\n");
 				out("offset &= 0x1f;\n");
-				out("tmp = (tmp << offset) | (tmp >> (32 - offset));\n");
+				out("tmp = (offset > 0 && offset < 32) ? ((tmp << offset) | (tmp >> (32 - offset))) : tmp;\n"); 

offset is restricted to 0x1f, so it is always < 32, i.e. it should be
sufficient to check for "offset != 0" in above condition. I'd maybe also
rather write it like this:

 out("tmp = (tmp << offset)\n");
 out("if (offset) tmp |= (tmp >> (32 - offset));\n");

?

 Thomas



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/