diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2015-02-13 05:46:09 +0000 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2015-02-13 05:46:09 +0000 |
commit | 037e1d009e2fcb80784d37f0e12aa999787d46d4 (patch) | |
tree | b90a6ed279eede689b2a3965b9813e664c833cb0 | |
parent | e167adc9d9f5df4f8109aecd4552c407fdce094a (diff) |
target-arm: A64: Avoid left shifting negative integers in disas_pc_rel_addr
Shifting a negative integer left is undefined behaviour in C.
Avoid it by assembling and shifting the offset fields as
unsigned values and then sign extending as the final action.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 1423233250-15853-4-git-send-email-peter.maydell@linaro.org
-rw-r--r-- | target-arm/translate-a64.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c index 94b3bf40f6..68c5b23914 100644 --- a/target-arm/translate-a64.c +++ b/target-arm/translate-a64.c @@ -2662,11 +2662,12 @@ static void disas_pc_rel_adr(DisasContext *s, uint32_t insn) { unsigned int page, rd; uint64_t base; - int64_t offset; + uint64_t offset; page = extract32(insn, 31, 1); /* SignExtend(immhi:immlo) -> offset */ - offset = ((int64_t)sextract32(insn, 5, 19) << 2) | extract32(insn, 29, 2); + offset = sextract64(insn, 5, 19); + offset = offset << 2 | extract32(insn, 29, 2); rd = extract32(insn, 0, 5); base = s->pc - 4; |