PR26468 UBSAN: tc-mep.c:1684 left shift of negative value

Alan Modra amodra@gmail.com
Mon Aug 31 10:50:32 GMT 2020


	PR 26468
	* config/tc-mep.c (md_convert_frag): Use uint32_t for addend and
	other variables.

diff --git a/gas/config/tc-mep.c b/gas/config/tc-mep.c
index 6b52841fa9..e588a30afc 100644
--- a/gas/config/tc-mep.c
+++ b/gas/config/tc-mep.c
@@ -1617,7 +1617,7 @@ md_convert_frag (bfd *abfd  ATTRIBUTE_UNUSED,
 		 segT seg ATTRIBUTE_UNUSED,
 		 fragS *fragP)
 {
-  int addend, rn, bit = 0;
+  uint32_t addend, rn, bit = 0;
   int operand;
   int where = fragP->fr_opcode - fragP->fr_literal;
   int e = target_big_endian ? 0 : 1;
@@ -1697,7 +1697,7 @@ md_convert_frag (bfd *abfd  ATTRIBUTE_UNUSED,
 	/* The default relax_frag doesn't change the state if there is no
 	   growth, so we must manually handle converting out-of-range BEQ
 	   instructions to JMP.  */
-	if (addend <= 65535 && addend >= -65536)
+	if (addend + 65536 < 131071)
 	  {
 	    if (core_mode)
 	      fragP->fr_fix += 2;


More information about the Binutils mailing list