public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: gdb-patches@sourceware.org
Subject: [PATCH] sim: bfin: avoid left shifting negative values
Date: Sun,  7 Jan 2024 00:24:09 -0500	[thread overview]
Message-ID: <20240107052409.28931-1-vapier@gentoo.org> (raw)

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/bfin/bfin-sim.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sim/bfin/bfin-sim.c b/sim/bfin/bfin-sim.c
index 1a9b499ebb4c..2e7a5632fffe 100644
--- a/sim/bfin/bfin-sim.c
+++ b/sim/bfin/bfin-sim.c
@@ -786,7 +786,7 @@ lshift (SIM_CPU *cpu, bu64 val, int cnt, int size, bool saturate, bool overflow)
      However, it's a little more complex than looking at sign bits, we need
      to see if we are shifting the sign information away...  */
   if (((val << cnt) >> size) == 0
-      || (((val << cnt) >> size) == ~(~0 << cnt)
+      || (((val << cnt) >> size) == ~((bu32)~0 << cnt)
 	  && ((new_val >> (size - 1)) & 0x1)))
     v_i = 0;
   else
@@ -5880,7 +5880,7 @@ decode_dsp32shiftimm_0 (SIM_CPU *cpu, bu16 iw0, bu16 iw1)
 	      bu16 inshift = in << shift;
 
 	      if (((inshift & ~0xFFFF)
-		   && ((inshift & ~0xFFFF) >> 16) != ~(~0 << shift))
+		   && ((inshift & ~0xFFFF) >> 16) != ~((bu32)~0 << shift))
 		  || (inshift & 0x8000) != (in & 0x8000))
 		{
 		  if (in & 0x8000)
-- 
2.43.0


                 reply	other threads:[~2024-01-07  5:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240107052409.28931-1-vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).