ruby-changes:73241
From: Maxime <ko1@a...>
Date: Tue, 30 Aug 2022 01:04:58 +0900 (JST)
Subject: [ruby-changes:73241] ca68ccdadd (master): Fix C call reg alloc bug reported by Noah & Kokubun
https://git.ruby-lang.org/ruby.git/commit/?id=ca68ccdadd From ca68ccdaddb6930f2d6dc9172a8653bcfb340afd Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...> Date: Tue, 2 Aug 2022 15:12:04 -0400 Subject: Fix C call reg alloc bug reported by Noah & Kokubun --- yjit/src/backend/ir.rs | 4 ++-- yjit/src/backend/tests.rs | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/yjit/src/backend/ir.rs b/yjit/src/backend/ir.rs index 45d4378eb4..f634fb7678 100644 --- a/yjit/src/backend/ir.rs +++ b/yjit/src/backend/ir.rs @@ -633,7 +633,7 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/ir.rs#L633 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 https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/ir.rs#L702 // 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 { diff --git a/yjit/src/backend/tests.rs b/yjit/src/backend/tests.rs index dc56bd4abb..a31e16071b 100644 --- a/yjit/src/backend/tests.rs +++ b/yjit/src/backend/tests.rs @@ -195,9 +195,7 @@ fn test_base_insn_out() https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/tests.rs#L195 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() https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/tests.rs#L211 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() { -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/