Skip to content

Commit c92a44e

Browse files
authored
ZJIT: Use Mem.num_bits in Mem split (ruby#15177)
Fix the ``` write(2, "ruby: ZJIT has panicked. More info to follow...\n", 48) = 48 write(2, "\nthread '<unnamed>' panicked at zjit/src/backend/lir.rs:160:17:\nassertion failed: num_bits <= out_num_bits\n", 107) = 107 ``` based on ``` #25 0x0000aaaaaae8fb14 in zjit::backend::lir::Opnd::mem (num_bits=64, base=..., disp=0) at zjit/src/backend/lir.rs:160 #26 zjit::backend::arm64::{impl#3}::arm64_split::split_memory_address (asm=<optimized out>, opnd=<error reading variable: Cannot access memory at address 0x0>) at zjit/src/backend/arm64/mod.rs:260 #27 zjit::backend::arm64::{impl#3}::arm64_split::split_load_operand (asm=<optimized out>, opnd=...) at zjit/src/backend/arm64/mod.rs:273 ```
1 parent e826f81 commit c92a44e

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

zjit/src/backend/arm64/mod.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ impl Assembler {
256256
if mem_disp_fits_bits(mem.disp) {
257257
opnd
258258
} else {
259-
let base = asm.lea(opnd);
260-
Opnd::mem(64, base, 0)
259+
let base = asm.lea(Opnd::Mem(Mem { num_bits: 64, ..mem }));
260+
Opnd::mem(mem.num_bits, base, 0)
261261
}
262262
},
263263
_ => unreachable!("Can only split memory addresses.")
@@ -2735,4 +2735,46 @@ mod tests {
27352735
");
27362736
assert_snapshot!(cb.hexdump(), @"300080d2b0831ff8af835ff8eff97fd3af831ff8a0835ff8");
27372737
}
2738+
2739+
#[test]
2740+
fn test_split_load16_mem_mem_with_large_displacement() {
2741+
let (mut asm, mut cb) = setup_asm();
2742+
2743+
let _ = asm.load(Opnd::mem(16, C_RET_OPND, 0x200));
2744+
asm.compile(&mut cb).unwrap();
2745+
2746+
assert_disasm_snapshot!(cb.disasm(), @r"
2747+
0x0: add x0, x0, #0x200
2748+
0x4: ldurh w0, [x0]
2749+
");
2750+
assert_snapshot!(cb.hexdump(), @"0000089100004078");
2751+
}
2752+
2753+
#[test]
2754+
fn test_split_load32_mem_mem_with_large_displacement() {
2755+
let (mut asm, mut cb) = setup_asm();
2756+
2757+
let _ = asm.load(Opnd::mem(32, C_RET_OPND, 0x200));
2758+
asm.compile(&mut cb).unwrap();
2759+
2760+
assert_disasm_snapshot!(cb.disasm(), @r"
2761+
0x0: add x0, x0, #0x200
2762+
0x4: ldur w0, [x0]
2763+
");
2764+
assert_snapshot!(cb.hexdump(), @"00000891000040b8");
2765+
}
2766+
2767+
#[test]
2768+
fn test_split_load64_mem_mem_with_large_displacement() {
2769+
let (mut asm, mut cb) = setup_asm();
2770+
2771+
let _ = asm.load(Opnd::mem(64, C_RET_OPND, 0x200));
2772+
asm.compile(&mut cb).unwrap();
2773+
2774+
assert_disasm_snapshot!(cb.disasm(), @r"
2775+
0x0: add x0, x0, #0x200
2776+
0x4: ldur x0, [x0]
2777+
");
2778+
assert_snapshot!(cb.hexdump(), @"00000891000040f8");
2779+
}
27382780
}

0 commit comments

Comments
 (0)