public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* resolve gas shift expressions with large exponents to zero
@ 2023-01-26 21:52 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-01-26 21:52 UTC (permalink / raw)
  To: binutils

	* expr.c (resolve_expression <O_left_shift, O_right_shift>): Resolve
	shifts exceeding bits in a valueT to zero.

diff --git a/gas/expr.c b/gas/expr.c
index ba3d2109b9d..794be6f09d8 100644
--- a/gas/expr.c
+++ b/gas/expr.c
@@ -2320,8 +2320,18 @@ resolve_expression (expressionS *expressionP)
 	    return 0;
 	  left = (offsetT) left % (offsetT) right;
 	  break;
-	case O_left_shift:		left <<= right; break;
-	case O_right_shift:		left >>= right; break;
+	case O_left_shift:
+	  if (right >= sizeof (left) * CHAR_BIT)
+	    left = 0;
+	  else
+	    left <<= right;
+	  break;
+	case O_right_shift:
+	  if (right >= sizeof (left) * CHAR_BIT)
+	    left = 0;
+	  else
+	    left >>= right;
+	  break;
 	case O_bit_inclusive_or:	left |= right; break;
 	case O_bit_or_not:		left |= ~right; break;
 	case O_bit_exclusive_or:	left ^= right; break;

-- 
Alan Modra
Australia Development Lab, IBM

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

only message in thread, other threads:[~2023-01-26 21:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-26 21:52 resolve gas shift expressions with large exponents to zero Alan Modra

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).