sim: sh: avoid left shifting negative values

Message ID 20240107052417.28947-1-vapier@gentoo.org
State New
Headers
Series sim: sh: avoid left shifting negative values |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Mike Frysinger Jan. 7, 2024, 5:24 a.m. UTC
  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(-)
  

Patch

diff --git a/sim/sh/gencode.c b/sim/sh/gencode.c
index c121d53bb40b..8246e89432f0 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;",