Skip to content

Commit f20ea2c

Browse files
committed
ZJIT: Fix fixnum folding for negative values
Use `fixnum_from_isize` instead of `fixnum_from_usize` in `fold_fixnum_bop` to properly handle negative values. Casting negative `i64` to `usize` produces large unsigned values that exceed `RUBY_FIXNUM_MAX`.
1 parent 04d43e1 commit f20ea2c

File tree

4 files changed

+1
-4
lines changed

4 files changed

+1
-4
lines changed

test/.excludes-zjit/TestFixnum.rb

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/.excludes-zjit/TestTime.rb

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/.excludes-zjit/TestTimeTZ.rb

Lines changed: 0 additions & 1 deletion
This file was deleted.

zjit/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,7 @@ impl Function {
17031703
fn fold_fixnum_bop(&mut self, insn_id: InsnId, left: InsnId, right: InsnId, f: impl FnOnce(Option<i64>, Option<i64>) -> Option<i64>) -> InsnId {
17041704
f(self.type_of(left).fixnum_value(), self.type_of(right).fixnum_value())
17051705
.filter(|&n| n >= (RUBY_FIXNUM_MIN as i64) && n <= RUBY_FIXNUM_MAX as i64)
1706-
.map(|n| self.new_insn(Insn::Const { val: Const::Value(VALUE::fixnum_from_usize(n as usize)) }))
1706+
.map(|n| self.new_insn(Insn::Const { val: Const::Value(VALUE::fixnum_from_isize(n as isize)) }))
17071707
.unwrap_or(insn_id)
17081708
}
17091709

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy