1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Fix C call reg alloc bug reported by Noah & Kokubun

This commit is contained in:
Maxime Chevalier-Boisvert 2022-08-02 15:12:04 -04:00 committed by Takashi Kokubun
parent 0823260546
commit ca68ccdadd
No known key found for this signature in database
GPG key ID: 6FFC433B12EE23DD
2 changed files with 13 additions and 5 deletions

View file

@ -633,7 +633,7 @@ impl Assembler
let reg_index = regs.iter().position(|elem| elem.reg_no == reg.reg_no);
if let Some(reg_index) = reg_index {
assert_eq!(*pool & (1 << reg_index), 0);
assert_eq!(*pool & (1 << reg_index), 0, "register already allocated");
*pool |= 1 << reg_index;
}
@ -702,7 +702,7 @@ impl Assembler
// We do this to improve register allocation on x86
// e.g. out = add(reg0, reg1)
// reg0 = add(reg0, reg1)
if opnds.len() > 0 {
else if opnds.len() > 0 {
if let Opnd::InsnOut{idx, ..} = opnds[0] {
if live_ranges[idx] == index {
if let Opnd::Reg(reg) = asm.insns[idx].out {

View file

@ -195,9 +195,7 @@ fn test_base_insn_out()
fn test_c_call()
{
c_callable! {
fn dummy_c_fun(v0: usize, v1: usize)
{
}
fn dummy_c_fun(v0: usize, v1: usize) {}
}
let (mut asm, mut cb) = setup_asm();
@ -213,6 +211,16 @@ fn test_c_call()
asm.compile_with_num_regs(&mut cb, 1);
}
#[test]
fn test_alloc_ccall_regs() {
let mut asm = Assembler::new();
let out1 = asm.ccall(0 as *const u8, vec![]);
let out2 = asm.ccall(0 as *const u8, vec![out1]);
asm.mov(EC, out2);
let mut cb = CodeBlock::new_dummy(1024);
asm.compile_with_regs(&mut cb, Assembler::get_alloc_regs());
}
#[test]
fn test_lea_ret()
{