Skip to contentSkip to conversation

tcg/aarch64: Fix illegal insn from out-of-range shli

PATCH In review Richard Henderson 2 participants 2 messages Jun 2, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcg/aarch64: Fix illegal insn from out-of-range shli

The masking in tcg_out_shl was incorrect, producing an illegal instruction, rather than merely unspecified results for the out-of-range shift.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1051

---
 tcg/aarch64/tcg-target.c.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/aarch64/tcg-target.c.inc +1 -1
index 61e284bb5c..d997f7922a 100644
@@ -1261,7 +1261,7 @@ static inline void tcg_out_shl(TCGContext *s, TCGType ext,
 {
     int bits = ext ? 64 : 32;
     int max = bits - 1;
-    tcg_out_ubfm(s, ext, rd, rn, bits - (m & max), max - (m & max));
+    tcg_out_ubfm(s, ext, rd, rn, (bits - m) & max, (max - m) & max);
 }
 
 static inline void tcg_out_shr(TCGContext *s, TCGType ext,
Signature · 1 line
2.34.1
Tested-by on v1 1/1
#1 lore raw
Quoted 7 lines · Richard Henderson

The masking in tcg_out_shl was incorrect, producing an illegal instruction, rather than merely unspecified results for the out-of-range shift.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1051

I can confirm this fixes the issue I reported, thanks Richard.

Quoted 21 lines
---
 tcg/aarch64/tcg-target.c.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/aarch64/tcg-target.c.inc +1 -2
index 61e284bb5c..d997f7922a 100644
@@ -1261,7 +1261,7 @@ static inline void tcg_out_shl(TCGContext *s, TCGType ext,
 {
     int bits = ext ? 64 : 32;
     int max = bits - 1;
-    tcg_out_ubfm(s, ext, rd, rn, bits - (m & max), max - (m & max));
+    tcg_out_ubfm(s, ext, rd, rn, (bits - m) & max, (max - m) & max);
 }
 
 static inline void tcg_out_shr(TCGContext *s, TCGType ext,
--

2.34.1