ruby-changes:73217
From: Kevin <ko1@a...>
Date: Tue, 30 Aug 2022 01:03:01 +0900 (JST)
Subject: [ruby-changes:73217] 13e5b56a5d (master): Fixes (https://github.com/Shopify/ruby/pull/340)
https://git.ruby-lang.org/ruby.git/commit/?id=13e5b56a5d From 13e5b56a5d8f36815fb9aa3834d82a54b69e087a Mon Sep 17 00:00:00 2001 From: Kevin Newton <kddnewton@g...> Date: Fri, 22 Jul 2022 16:06:37 -0400 Subject: Fixes (https://github.com/Shopify/ruby/pull/340) * Fix conditional jumps to label * Bitmask immediates cannot be u64::MAX --- yjit/src/asm/arm64/arg/bitmask_imm.rs | 10 ++++++++-- yjit/src/backend/arm64/mod.rs | 13 +++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/yjit/src/asm/arm64/arg/bitmask_imm.rs b/yjit/src/asm/arm64/arg/bitmask_imm.rs index 220a7d697e..b3a821fe94 100644 --- a/yjit/src/asm/arm64/arg/bitmask_imm.rs +++ b/yjit/src/asm/arm64/arg/bitmask_imm.rs @@ -43,7 +43,7 @@ impl TryFrom<u64> for BitmaskImmediate { https://github.com/ruby/ruby/blob/trunk/yjit/src/asm/arm64/arg/bitmask_imm.rs#L43 fn try_from(value: u64) -> Result<Self, Self::Error> { // 0 is not encodable as a bitmask immediate. Immediately return here so // that we don't have any issues with underflow. - if value == 0 { + if value == 0 || value == u64::MAX { return Err(()); } @@ -137,7 +137,7 @@ impl From<BitmaskImmediate> for u32 { https://github.com/ruby/ruby/blob/trunk/yjit/src/asm/arm64/arg/bitmask_imm.rs#L137 0 | (((bitmask.n as u32) & 1) << 12) | ((bitmask.immr as u32) << 6) - | bitmask.imms as u32 + | (bitmask.imms as u32) } } @@ -260,4 +260,10 @@ mod tests { https://github.com/ruby/ruby/blob/trunk/yjit/src/asm/arm64/arg/bitmask_imm.rs#L260 let bitmask = BitmaskImmediate::try_from(0xfffffffffffffffe); assert!(matches!(bitmask, Ok(BitmaskImmediate { n: 1, immr: 0b111111, imms: 0b111110 }))); } + + #[test] + fn test_size_64_invalid() { + let bitmask = BitmaskImmediate::try_from(u64::MAX); + assert!(matches!(bitmask, Err(()))); + } } diff --git a/yjit/src/backend/arm64/mod.rs b/yjit/src/backend/arm64/mod.rs index 57943ce58f..9726a0f8f2 100644 --- a/yjit/src/backend/arm64/mod.rs +++ b/yjit/src/backend/arm64/mod.rs @@ -295,9 +295,10 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/arm64/mod.rs#L295 let opnd0 = split_store(asm, opnds[0]); asm.store(opnd0, value); }, - _ => { + Opnd::Reg(_) => { asm.mov(opnds[0], value); - } + }, + _ => unreachable!() }; }, Op::Not => { @@ -488,7 +489,7 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/arm64/mod.rs#L489 // offset. We're going to assume we can fit into a single // b.cond instruction. It will panic otherwise. cb.label_ref(label_idx, 4, |cb, src_addr, dst_addr| { - bcond(cb, CONDITION, A64Opnd::new_imm(dst_addr - src_addr)); + bcond(cb, CONDITION, A64Opnd::new_imm(dst_addr - (src_addr - 4))); }); }, Target::FunPtr(_) => unreachable!() @@ -595,8 +596,8 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/arm64/mod.rs#L596 // references to GC'd Value operands. If the value // being loaded is a heap object, we'll report that // back out to the gc_offsets list. - ldr(cb, insn.out.into(), 1); - b(cb, A64Opnd::new_imm((SIZEOF_VALUE as i64) / 4)); + ldr(cb, insn.out.into(), 2); + b(cb, A64Opnd::new_imm(1 + (SIZEOF_VALUE as i64) / 4)); cb.write_bytes(&value.as_u64().to_le_bytes()); if !value.special_const_p() { @@ -743,7 +744,7 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/arm64/mod.rs#L744 // to assume we can fit into a single b instruction. // It will panic otherwise. cb.label_ref(label_idx, 4, |cb, src_addr, dst_addr| { - b(cb, A64Opnd::new_imm((dst_addr - src_addr) / 4 + 1)); + b(cb, A64Opnd::new_imm((dst_addr - (src_addr - 4)) / 4)); }); }, _ => unreachable!() -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/