PR26467 UBSAN: cgen.c:762 shift exponent 18446744073709551615

Alan Modra amodra@gmail.com
Thu Aug 27 12:31:39 GMT 2020


	PR 26467
	* cgen.c (weak_operand_overflow_check): Handle opmask for
	operand length zero.  Use 1UL constant.

diff --git a/gas/cgen.c b/gas/cgen.c
index 0bc44f6c08..7c924d117b 100644
--- a/gas/cgen.c
+++ b/gas/cgen.c
@@ -759,7 +759,7 @@ weak_operand_overflow_check (const expressionS *  exp,
 {
   const unsigned long len = operand->length;
   unsigned long mask;
-  unsigned long opmask = (((1L << (len - 1)) - 1) << 1) | 1;
+  unsigned long opmask = len == 0 ? 0 : (1UL << (len - 1) << 1) - 1;
 
   if (!exp)
     return NULL;

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list