diff options
author | Alan Modra <amodra@gmail.com> | 2019-12-16 09:35:30 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2019-12-16 17:33:53 +1030 |
commit | 4bdb25fe6902963ca9cf91d6b2688cf888527bf8 (patch) | |
tree | c59b543c40bf8bc2d741c3b0ed2b1a5a7397746a /include | |
parent | cf950fd4dd4581849a445a76b57514d72074927d (diff) | |
download | gdb-4bdb25fe6902963ca9cf91d6b2688cf888527bf8.zip gdb-4bdb25fe6902963ca9cf91d6b2688cf888527bf8.tar.gz gdb-4bdb25fe6902963ca9cf91d6b2688cf888527bf8.tar.bz2 |
ubsan: nds32: left shift cannot be represented in type 'int'
Note that using 1u in N32_BIT makes all of N32_BIT, __MASK, __MF, __GF
and __SEXT evaluate as unsigned int (the latter three when when their
v arg is int or smaller). This would be a problem if assigning the
result to a bfd_vma, long, or other type wider than an int since the
__SEXT result would be zero extended to the wider type. Fortunately
nds32 target code doesn't use wider types unnecessarily.
include/
* opcode/nds32.h (N32_BIT): Define using 1u.
(__SEXT): Use __MASK and N32_BIT.
(N32_IMMS): Remove duplicate mask.
opcodes/
* nds32-dis.c (print_insn16, print_insn32): Remove forward decls.
(struct objdump_disasm_info): Delete.
(nds32_parse_audio_ext, nds32_parse_opcode): Cast result of
N32_IMMS to unsigned before shifting left.
Diffstat (limited to 'include')
-rw-r--r-- | include/ChangeLog | 6 | ||||
-rw-r--r-- | include/opcode/nds32.h | 7 |
2 files changed, 10 insertions, 3 deletions
diff --git a/include/ChangeLog b/include/ChangeLog index 1444cc9..7f6cc9b 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,9 @@ +2019-12-16 Alan Modra <amodra@gmail.com> + + * opcode/nds32.h (N32_BIT): Define using 1u. + (__SEXT): Use __MASK and N32_BIT. + (N32_IMMS): Remove duplicate mask. + 2019-12-12 Luis Machado <luis.machado@linaro.org> * diagnostics.h (DIAGNOSTIC_IGNORE_UNUSED_FUNCTION). Remove diff --git a/include/opcode/nds32.h b/include/opcode/nds32.h index 7791864..0e60840 100644 --- a/include/opcode/nds32.h +++ b/include/opcode/nds32.h @@ -51,11 +51,12 @@ static const int nds32_r54map[] ATTRIBUTE_UNUSED = -1, -1, -1, -1, -1, -1, -1, -1 }; -#define N32_BIT(n) (1 << (n)) +#define N32_BIT(n) (1u << (n)) #define __MASK(n) (N32_BIT (n) - 1) #define __MF(v, off, bs) (((v) & __MASK (bs)) << (off)) #define __GF(v, off, bs) (((v) >> off) & __MASK (bs)) -#define __SEXT(v, bs) ((((v) & ((1 << (bs)) - 1)) ^ (1 << ((bs) - 1))) - (1 << ((bs) - 1))) +#define __SEXT(v, bs) \ + ((((v) & __MASK ((bs))) ^ N32_BIT ((bs) - 1)) - N32_BIT ((bs) - 1)) /* Make nds32 instructions. */ @@ -150,7 +151,7 @@ static const int nds32_r54map[] ATTRIBUTE_UNUSED = #define N32_SUB6(insn) (((insn) >> 0) & 0x3f) #define N32_SWID(insn) (((insn) >> 5) & 0x3ff) #define N32_IMMU(insn, bs) ((insn) & __MASK (bs)) -#define N32_IMMS(insn, bs) ((signed) __SEXT (((insn) & __MASK (bs)), bs)) +#define N32_IMMS(insn, bs) ((signed) __SEXT ((insn), (bs))) #define N32_IMM5U(insn) N32_IMMU (insn, 5) #define N32_IMM12S(insn) N32_IMMS (insn, 12) #define N32_IMM14S(insn) N32_IMMS (insn, 14) |