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.

Backports commit 037e1d009e2fcb80784d37f0e12aa999787d46d4 from qemu
This commit is contained in:
Peter Maydell 2018-02-12 15:03:37 -05:00 committed by Lioncash
parent 0e9a6a26f5
commit 4ea6fdc986
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -2698,11 +2698,12 @@ static void disas_pc_rel_adr(DisasContext *s, uint32_t insn)
TCGContext *tcg_ctx = s->uc->tcg_ctx;
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;