Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions bootstraptest/test_yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5535,3 +5535,23 @@ def compiled_method
# Resume the fiber — compiled_method's iseq must still be valid
fiber.resume.to_s
}

# regression test for register mapping of methods with over 256 locals
# [Bug #22074]
assert_equal "ok", %q{
source = +"def many_locals\n"
source << " total = 0\n"

128.times do |i|
source << " y#{i} = 1\n"
source << " x#{i} = Object.new\n"
end

source << " total += 1\n"
source << " raise total.inspect unless total == 1\n"
source << "end\n"

eval(source)
many_locals
"ok"
}
4 changes: 3 additions & 1 deletion yjit/src/backend/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ impl Opnd
let last_idx = stack_size as i32 + VM_ENV_DATA_SIZE as i32 - 1;
assert!(last_idx <= idx, "Local index {} must be >= last local index {}", idx, last_idx);
assert!(idx <= last_idx + num_locals as i32, "Local index {} must be < last local index {} + local size {}", idx, last_idx, num_locals);
RegOpnd::Local((last_idx + num_locals as i32 - idx) as u8)
// Indices that don't fit in u8 are capped to u8::MAX, which is greater than MAX_CTX_LOCALS.
let local_idx = last_idx + num_locals as i32 - idx;
RegOpnd::Local(local_idx.try_into().unwrap_or(u8::MAX))
} else {
assert!(idx < stack_size as i32);
RegOpnd::Stack((stack_size as i32 - idx - 1) as u8)
Expand Down