aboutsummaryrefslogtreecommitdiff
path: root/opcodes
diff options
context:
space:
mode:
authorliuzhensong <liuzhensong@loongson.cn>2021-11-16 19:15:29 +0800
committerliuzhensong <liuzhensong@loongson.cn>2022-03-20 09:37:12 +0800
commite36144c932b0ad0de4774b8bb2552178e4f2f2a6 (patch)
treebb2e7622f9fdb18cf2ee64c3f6d010a756c4fa0a /opcodes
parent1ab7a698a8c95afeb8a7c305b22cbae54355aa34 (diff)
downloadgdb-e36144c932b0ad0de4774b8bb2552178e4f2f2a6.zip
gdb-e36144c932b0ad0de4774b8bb2552178e4f2f2a6.tar.gz
gdb-e36144c932b0ad0de4774b8bb2552178e4f2f2a6.tar.bz2
ubsan: loongarch : signed integer shift overflow.
opcodes/ * loongarch-coder.c : int32_t ret = 0; ret <<= sizeof (ret) * 8 - len; ret >>= sizeof (ret) * 8 - len; ... Avoid ubsan warning.
Diffstat (limited to 'opcodes')
-rw-r--r--opcodes/loongarch-coder.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/opcodes/loongarch-coder.c b/opcodes/loongarch-coder.c
index cb6d564..c957b95 100644
--- a/opcodes/loongarch-coder.c
+++ b/opcodes/loongarch-coder.c
@@ -106,11 +106,13 @@ loongarch_decode_imm (const char *bit_field, insn_t insn, int si)
else if (*bit_field_1 == '+')
ret += atoi (bit_field_1 + 1);
+ /* Extend signed bit. */
if (si)
{
- ret <<= sizeof (ret) * 8 - len;
- ret >>= sizeof (ret) * 8 - len;
+ uint32_t sign = 1u << (len - 1);
+ ret = (ret ^ sign) - sign;
}
+
return ret;
}
@@ -133,7 +135,8 @@ loongarch_encode_imm (const char *bit_field, int32_t imm)
else if (*t == '+')
uimm -= atoi (t + 1);
- uimm <<= sizeof (uimm) * 8 - width;
+ uimm = width ? (uimm << (sizeof (uimm) * 8 - width)) : 0;
+
while (1)
{
b_start = strtol (bit_field_1, &bit_field_1, 10);
@@ -141,10 +144,10 @@ loongarch_encode_imm (const char *bit_field, int32_t imm)
break;
width = strtol (bit_field_1 + 1, &bit_field_1, 10);
i = uimm;
- i >>= sizeof (i) * 8 - width;
- i <<= b_start;
+ i = width ? (i >> (sizeof (i) * 8 - width)) : 0;
+ i = (b_start == 32) ? 0 : (i << b_start);
ret |= i;
- uimm <<= width;
+ uimm = (width == 32) ? 0 : (uimm << width);
if (*bit_field_1 != '|')
break;