From 4223df94e038c653eab6cb39928184c3fcb2575f Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sun, 7 Jan 2024 00:23:41 -0500 Subject: [PATCH] sim: sh: avoid left shifting negative values We just want to create a bitmask here, so cast the mask to unsigned to avoid left shifting a negative value which is undefined behavior. --- sim/sh/gencode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sim/sh/gencode.c b/sim/sh/gencode.c index c121d53bb40..8246e89432f 100644 --- a/sim/sh/gencode.c +++ b/sim/sh/gencode.c @@ -2350,7 +2350,7 @@ static op ppi_tab[] = " res = 31;", "do", " {", - " if (Sx & ~0 << i)", + " if (Sx & ((unsigned)~0 << i))", " {", " res -= i;", " Sx >>= i;", @@ -2373,7 +2373,7 @@ static op ppi_tab[] = "res = 31;", "do", " {", - " if (Sy & ~0 << i)", + " if (Sy & ((unsigned)~0 << i))", " {", " res -= i;", " Sy >>= i;", -- 2.47.2