Skip to content

Commit

Permalink
lowering: fix has_fcall computation (#57395)
Browse files Browse the repository at this point in the history
Previously didn't handle ccall or cfunction that were assigned to a
variable. Required for inlining correctness.

Fixes #57023
  • Loading branch information
vtjnash authored Feb 14, 2025
1 parent f4a9d25 commit 57b7d2e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/method.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,12 @@ jl_code_info_t *jl_new_code_info_from_ir(jl_expr_t *ir)
is_flag_stmt = 1;
else if (jl_is_expr(st) && ((jl_expr_t*)st)->head == jl_return_sym)
jl_array_ptr_set(body, j, jl_new_struct(jl_returnnode_type, jl_exprarg(st, 0)));
else if (jl_is_expr(st) && (((jl_expr_t*)st)->head == jl_foreigncall_sym || ((jl_expr_t*)st)->head == jl_cfunction_sym))
li->has_fcall = 1;
else {
if (jl_is_expr(st) && ((jl_expr_t*)st)->head == jl_assign_sym)
st = jl_exprarg(st, 1);
if (jl_is_expr(st) && (((jl_expr_t*)st)->head == jl_foreigncall_sym || ((jl_expr_t*)st)->head == jl_cfunction_sym))
li->has_fcall = 1;
}
if (is_flag_stmt)
jl_array_uint32_set(li->ssaflags, j, 0);
else {
Expand Down
5 changes: 5 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8443,3 +8443,8 @@ f_call_me() = invoke(f_invoke_me, f_invoke_me_ci)
f_invalidate_me() = 2
@test_throws ErrorException invoke(f_invoke_me, f_invoke_me_ci)
@test_throws ErrorException f_call_me()

myfun57023a(::Type{T}) where {T} = (x = @ccall mycfun()::Ptr{T}; x)
@test only(code_lowered(myfun57023a)).has_fcall
myfun57023b(::Type{T}) where {T} = (x = @cfunction myfun57023a Ptr{T} (Ref{T},); x)
@test only(code_lowered(myfun57023b)).has_fcall

0 comments on commit 57b7d2e

Please sign in to comment.