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:
parent
0823260546
commit
ca68ccdadd
2 changed files with 13 additions and 5 deletions
|
@ -633,7 +633,7 @@ impl Assembler
|
||||||
let reg_index = regs.iter().position(|elem| elem.reg_no == reg.reg_no);
|
let reg_index = regs.iter().position(|elem| elem.reg_no == reg.reg_no);
|
||||||
|
|
||||||
if let Some(reg_index) = reg_index {
|
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;
|
*pool |= 1 << reg_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -702,7 +702,7 @@ impl Assembler
|
||||||
// We do this to improve register allocation on x86
|
// We do this to improve register allocation on x86
|
||||||
// e.g. out = add(reg0, reg1)
|
// e.g. out = add(reg0, reg1)
|
||||||
// reg0 = add(reg0, reg1)
|
// reg0 = add(reg0, reg1)
|
||||||
if opnds.len() > 0 {
|
else if opnds.len() > 0 {
|
||||||
if let Opnd::InsnOut{idx, ..} = opnds[0] {
|
if let Opnd::InsnOut{idx, ..} = opnds[0] {
|
||||||
if live_ranges[idx] == index {
|
if live_ranges[idx] == index {
|
||||||
if let Opnd::Reg(reg) = asm.insns[idx].out {
|
if let Opnd::Reg(reg) = asm.insns[idx].out {
|
||||||
|
|
|
@ -195,9 +195,7 @@ fn test_base_insn_out()
|
||||||
fn test_c_call()
|
fn test_c_call()
|
||||||
{
|
{
|
||||||
c_callable! {
|
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();
|
let (mut asm, mut cb) = setup_asm();
|
||||||
|
@ -213,6 +211,16 @@ fn test_c_call()
|
||||||
asm.compile_with_num_regs(&mut cb, 1);
|
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]
|
#[test]
|
||||||
fn test_lea_ret()
|
fn test_lea_ret()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue