From 6fbd4a8e8baa7fe5adcaa1c11c885f741fccd250 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 27 Aug 2020 13:46:45 +0930 Subject: [PATCH] PR26467 UBSAN: cgen.c:762 shift exponent 18446744073709551615 PR 26467 * cgen.c (weak_operand_overflow_check): Handle opmask for operand length zero. Use 1UL constant. --- gas/ChangeLog | 6 ++++++ gas/cgen.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gas/ChangeLog b/gas/ChangeLog index c0d9b26a29c..92dd9784d2a 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,9 @@ +2020-08-27 Alan Modra + + PR 26467 + * cgen.c (weak_operand_overflow_check): Handle opmask for + operand length zero. Use 1UL constant. + 2020-08-26 Alan Modra PR 26508 diff --git a/gas/cgen.c b/gas/cgen.c index 0bc44f6c08c..7c924d117be 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; -- 2.30.2