hash-ref: guard against fixnum argument when JIT-inlined

Closes #2409
This commit is contained in:
Matthew Flatt 2018-12-01 06:15:56 -07:00
parent 3a19809268
commit 0c6d22a04a
2 changed files with 12 additions and 7 deletions

View File

@ -72,14 +72,14 @@
(test (if v 'yes 'no) (test (if v 'yes 'no)
name name
((eval `(lambda (x) (if (,op x) 'yes 'no))) arg)))))] ((eval `(lambda (x) (if (,op x) 'yes 'no))) arg)))))]
[un-exact (lambda (v op arg [check-fixnum-as-bad? #f]) [un-exact (lambda (v op arg [check-fixnum-as-bad? #f] #:name [name op])
(check-error-message op (eval `(lambda (x) (,op x)))) (check-error-message name (eval `(lambda (x) (,op x))))
(when check-fixnum-as-bad? (when check-fixnum-as-bad?
(check-error-message op (eval `(lambda (x) (,op x))) #t)) (check-error-message name (eval `(lambda (x) (,op x))) #t))
(un0 v op arg))] (un0 v op arg))]
[un (lambda (v op arg [check-fixnum-as-bad? #f]) [un (lambda (v op arg [check-fixnum-as-bad? #f] #:name [name op])
(un-exact v op arg check-fixnum-as-bad?) (un-exact v op arg check-fixnum-as-bad? #:name name)
(when (number? arg) (when (number? arg)
(let ([iv (if (number? v) (let ([iv (if (number? v)
(exact->inexact v) (exact->inexact v)
@ -1034,6 +1034,9 @@
(bin0 'yes 'thing-ref a-rock 99) (bin0 'yes 'thing-ref a-rock 99)
(bin0 99 'thing-ref 10 99) (bin0 99 'thing-ref 10 99)
(un 'b '(lambda (ht) (hash-ref ht 'a #f)) '#hash((a . b)) #t
#:name 'hash-ref)
)) ))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -5767,7 +5767,7 @@ int scheme_generate_inlined_nary(mz_jit_state *jitter, Scheme_App_Rec *app, int
return 1; return 1;
} else if (IS_NAMED_PRIM(rator, "hash-ref")) { } else if (IS_NAMED_PRIM(rator, "hash-ref")) {
GC_CAN_IGNORE jit_insn *refdone0, *refdone, *refslow; GC_CAN_IGNORE jit_insn *refdone0, *refdone, *refslow, *refslow2;
/* We only get here if we have three arguments with the last as a /* We only get here if we have three arguments with the last as a
non-procedure constant */ non-procedure constant */
@ -5779,7 +5779,8 @@ int scheme_generate_inlined_nary(mz_jit_state *jitter, Scheme_App_Rec *app, int
/* Jump to slow path for anything other than an immutable hasheq */ /* Jump to slow path for anything other than an immutable hasheq */
__START_SHORT_JUMPS__(1); __START_SHORT_JUMPS__(1);
refslow = mz_bnei_t(jit_forward(), JIT_R0, scheme_eq_hash_tree_type, JIT_R2); refslow = jit_bmsi_ul(jit_forward(), JIT_R0, 0x1);
refslow2 = mz_bnei_t(jit_forward(), JIT_R0, scheme_eq_hash_tree_type, JIT_R2);
__END_SHORT_JUMPS__(1); __END_SHORT_JUMPS__(1);
/* scheme_eq_hash_tree_get doesn't trigger a GC */ /* scheme_eq_hash_tree_get doesn't trigger a GC */
@ -5798,6 +5799,7 @@ int scheme_generate_inlined_nary(mz_jit_state *jitter, Scheme_App_Rec *app, int
/* slow path */ /* slow path */
mz_patch_branch(refslow); mz_patch_branch(refslow);
mz_patch_branch(refslow2);
__END_SHORT_JUMPS__(1); __END_SHORT_JUMPS__(1);
scheme_mz_load_retained(jitter, JIT_R2, app->args[3]); scheme_mz_load_retained(jitter, JIT_R2, app->args[3]);