public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] sim: sh: avoid left shifting negative values
@ 2024-01-07  5:24 Mike Frysinger
  0 siblings, 0 replies; only message in thread
From: Mike Frysinger @ 2024-01-07  5:24 UTC (permalink / raw)
  To: gdb-patches

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 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;",
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-07  5:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-07  5:24 [PATCH] sim: sh: avoid left shifting negative values Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).