Skip to content

Commit

Permalink
codegen: Bail out early if OC has wrong argtypes
Browse files Browse the repository at this point in the history
Once we know something is guaranteed to throw, we just need to bail
out as soon as possible, as it is generrally a bad idea to try to keep
looking at the dead code. Fixes 51016.
  • Loading branch information
Keno committed Aug 23, 2023
1 parent 6ea2200 commit 525d127
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4587,6 +4587,8 @@ static jl_cgval_t emit_specsig_oc_call(jl_codectx_t &ctx, jl_value_t *oc_type, j
typ = jl_unwrap_vararg(typ);
emit_typecheck(ctx, argv[i+1], typ, "typeassert");
argv[i+1] = update_julia_type(ctx, argv[i+1], typ);
if (argv[i+1].typ == jl_bottom_type)
return jl_cgval_t();
}
jl_returninfo_t::CallingConv cc = jl_returninfo_t::CallingConv::Boxed;
unsigned return_roots = 0;
Expand All @@ -4609,6 +4611,9 @@ static jl_cgval_t emit_call(jl_codectx_t &ctx, jl_expr_t *ex, jl_value_t *rt, bo
size_t nargs = jl_array_dim0(ex->args);
assert(nargs >= 1);
jl_cgval_t f = emit_expr(ctx, args[0]);
if (f.typ == jl_bottom_type) {
return jl_cgval_t();
}

if (f.constant && jl_typetagis(f.constant, jl_intrinsic_type)) {
JL_I::intrinsic fi = (intrinsic)*(uint32_t*)jl_data_ptr(f.constant);
Expand Down
6 changes: 6 additions & 0 deletions test/opaque_closure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,9 @@ let (bt, did_gc) = make_oc_and_collect_bt()
return frame.linfo.def.is_for_opaque_closure
end
end

# Opaque closure with mismatch struct argtype
const op_arg_restrict2 = @opaque (x::Tuple{Int64}, y::Base.RefValue{Int64})->x+y
ccall_op_arg_restrict2_bad_args() = op_arg_restrict2((1.,), 2)

@test_throws TypeError ccall_op_arg_restrict2_bad_args()

0 comments on commit 525d127

Please sign in to comment.