diff options
Diffstat (limited to 'yjit/src/backend/tests.rs')
-rw-r--r-- | yjit/src/backend/tests.rs | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/yjit/src/backend/tests.rs b/yjit/src/backend/tests.rs index 8ba9f61d25..01e87fe26c 100644 --- a/yjit/src/backend/tests.rs +++ b/yjit/src/backend/tests.rs @@ -87,7 +87,7 @@ fn test_mov_mem2mem() { let (mut asm, mut cb) = setup_asm(); - asm.comment("check that comments work too"); + asm_comment!(asm, "check that comments work too"); asm.mov(Opnd::mem(64, SP, 0), Opnd::mem(64, SP, 8)); asm.compile_with_num_regs(&mut cb, 1); @@ -231,7 +231,7 @@ fn test_jcc_ptr() { let (mut asm, mut cb) = setup_asm(); - let side_exit = Target::CodePtr(((cb.get_write_ptr().raw_ptr() as usize + 4) as *mut u8).into()); + let side_exit = Target::CodePtr(cb.get_write_ptr().add_bytes(4)); let not_mask = asm.not(Opnd::mem(32, EC, RUBY_OFFSET_EC_INTERRUPT_MASK)); asm.test( Opnd::mem(32, EC, RUBY_OFFSET_EC_INTERRUPT_FLAG), @@ -248,7 +248,7 @@ fn test_jmp_ptr() { let (mut asm, mut cb) = setup_asm(); - let stub = Target::CodePtr(((cb.get_write_ptr().raw_ptr() as usize + 4) as *mut u8).into()); + let stub = Target::CodePtr(cb.get_write_ptr().add_bytes(4)); asm.jmp(stub); asm.compile_with_num_regs(&mut cb, 0); @@ -259,7 +259,7 @@ fn test_jo() { let (mut asm, mut cb) = setup_asm(); - let side_exit = Target::CodePtr(((cb.get_write_ptr().raw_ptr() as usize + 4) as *mut u8).into()); + let side_exit = Target::CodePtr(cb.get_write_ptr().add_bytes(4)); let arg1 = Opnd::mem(64, SP, 0); let arg0 = Opnd::mem(64, SP, 8); @@ -303,25 +303,6 @@ fn test_draining_iterator() { } #[test] -fn test_lookback_iterator() { - let mut asm = Assembler::new(); - - let _ = asm.load(Opnd::None); - asm.store(Opnd::None, Opnd::None); - asm.store(Opnd::None, Opnd::None); - - let iter = asm.into_lookback_iter(); - - while let Some((index, insn)) = iter.next_unmapped() { - if index > 0 { - let opnd_iter = iter.get_previous().unwrap().opnd_iter(); - assert_eq!(opnd_iter.take(1).next(), Some(&Opnd::None)); - assert!(matches!(insn, Insn::Store { .. })); - } - } -} - -#[test] fn test_cmp_8_bit() { let (mut asm, mut cb) = setup_asm(); let reg = Assembler::get_alloc_regs()[0]; @@ -329,3 +310,21 @@ fn test_cmp_8_bit() { asm.compile_with_num_regs(&mut cb, 1); } + +#[test] +fn test_no_pos_marker_callback_when_compile_fails() { + // When compilation fails (e.g. when out of memory), the code written out is malformed. + // We don't want to invoke the pos_marker callbacks with positions of malformed code. + let mut asm = Assembler::new(); + + // Markers around code to exhaust memory limit + let fail_if_called = |_code_ptr, _cb: &_| panic!("pos_marker callback should not be called"); + asm.pos_marker(fail_if_called); + let zero = asm.load(0.into()); + let sum = asm.add(zero, 500.into()); + asm.store(Opnd::mem(64, SP, 8), sum); + asm.pos_marker(fail_if_called); + + let cb = &mut CodeBlock::new_dummy(8); + assert!(asm.compile(cb, None).is_none(), "should fail due to tiny size limit"); +} |