Skip to content

ZJIT: Remove more Option from codegen #14265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tekknolagi
Copy link
Contributor

No description provided.

@tekknolagi
Copy link
Contributor Author

tekknolagi commented Aug 18, 2025

segfault in not-ZJIT :(

@tekknolagi tekknolagi marked this pull request as ready for review August 18, 2025 19:46
@tekknolagi tekknolagi requested a review from a team August 18, 2025 19:46
@@ -1184,7 +1180,7 @@ fn gen_guard_type(jit: &mut JITState, asm: &mut Assembler, val: lir::Opnd, guard
// Static symbols have (val & 0xff) == RUBY_SYMBOL_FLAG
// Use 8-bit comparison like YJIT does
debug_assert!(val.try_num_bits(8).is_some(), "GuardType should not be used for a known constant, but val was: {val:?}");
asm.cmp(val.try_num_bits(8)?, Opnd::UImm(RUBY_SYMBOL_FLAG as u64));
asm.cmp(val.try_num_bits(8).unwrap(), Opnd::UImm(RUBY_SYMBOL_FLAG as u64));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have an HIR validator for GuardType not using known operands and we're going to unwrap this, let's remove the try_num_bits function from Opnd and use with_num_bits(8) instead.

}

fn gen_invokebuiltin(jit: &JITState, asm: &mut Assembler, state: &FrameState, bf: &rb_builtin_function, args: Vec<Opnd>) -> lir::Opnd {
assert!(bf.argc + 2 <= C_ARG_OPNDS.len() as i32, "Builtin function {} has too many arguments: {}", unsafe { std::ffi::CStr::from_ptr(bf.name).to_str().unwrap() }, bf.argc);
Copy link
Member

@k0kubun k0kubun Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no such guarantee. You shouldn't crash just because a Primitive takes 5+ arguments.

Copy link
Member

@k0kubun k0kubun Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're checking it on gen_insn. I hope the panic message explains that it should not happen because it's checked by the caller gen_insn. There's nothing wrong in "Builtin function {} has too many arguments" itself.

Copy link
Member

@k0kubun k0kubun Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g.

Suggested change
assert!(bf.argc + 2 <= C_ARG_OPNDS.len() as i32, "Builtin function {} has too many arguments: {}", unsafe { std::ffi::CStr::from_ptr(bf.name).to_str().unwrap() }, bf.argc);
assert!(
bf.argc + 2 <= C_ARG_OPNDS.len() as i32,
"gen_invokebuiltin should not be called for builtin function {} with too many arguments: {}",
unsafe { std::ffi::CStr::from_ptr(bf.name).to_str().unwrap() }, bf.argc,
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants