summaryrefslogtreecommitdiff
path: root/yjit_codegen.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2021-12-16 15:08:07 -0800
committerJohn Hawthorn <john@hawthorn.email>2021-12-17 15:26:04 -0800
commitc2197bf82171ca2dad6f7ef67521fdd30a245d9c (patch)
treee8633d5b70c9be9792cd9e9033d72e4a8763400a /yjit_codegen.c
parent83aa68447c87169b3610b6e04abebdcc592f0c16 (diff)
YJIT: Fix check for required kwargs
Previously, YJIT would not check that all the required keywords were specified in the case that there were optional arguments specified. In this case YJIT would incorrectly call the method with invalid arguments.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5285
Diffstat (limited to 'yjit_codegen.c')
-rw-r--r--yjit_codegen.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/yjit_codegen.c b/yjit_codegen.c
index 3782d8eea3..b18ec44c7a 100644
--- a/yjit_codegen.c
+++ b/yjit_codegen.c
@@ -3562,6 +3562,8 @@ gen_send_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r
// keyword parameters.
const struct rb_iseq_param_keyword *keyword = iseq->body->param.keyword;
+ int required_kwargs_filled = 0;
+
if (keyword->num > 30) {
// We have so many keywords that (1 << num) encoded as a FIXNUM
// (which shifts it left one more) no longer fits inside a 32-bit
@@ -3604,9 +3606,16 @@ gen_send_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r
GEN_COUNTER_INC(cb, send_iseq_kwargs_mismatch);
return YJIT_CANT_COMPILE;
}
+
+ // Keep a count to ensure all required kwargs are specified
+ if (callee_idx < keyword->required_num) {
+ required_kwargs_filled++;
+ }
}
- } else if (keyword->required_num != 0) {
- // No keywords provided so if any are required this is a mismatch
+ }
+
+ RUBY_ASSERT(required_kwargs_filled <= keyword->required_num);
+ if (required_kwargs_filled != keyword->required_num) {
GEN_COUNTER_INC(cb, send_iseq_kwargs_mismatch);
return YJIT_CANT_COMPILE;
}