Skip to content

Commit 57b7d2e

Browse files
authored
lowering: fix has_fcall computation (#57395)
Previously didn't handle ccall or cfunction that were assigned to a variable. Required for inlining correctness. Fixes #57023
1 parent f4a9d25 commit 57b7d2e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/method.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,12 @@ jl_code_info_t *jl_new_code_info_from_ir(jl_expr_t *ir)
485485
is_flag_stmt = 1;
486486
else if (jl_is_expr(st) && ((jl_expr_t*)st)->head == jl_return_sym)
487487
jl_array_ptr_set(body, j, jl_new_struct(jl_returnnode_type, jl_exprarg(st, 0)));
488-
else if (jl_is_expr(st) && (((jl_expr_t*)st)->head == jl_foreigncall_sym || ((jl_expr_t*)st)->head == jl_cfunction_sym))
489-
li->has_fcall = 1;
488+
else {
489+
if (jl_is_expr(st) && ((jl_expr_t*)st)->head == jl_assign_sym)
490+
st = jl_exprarg(st, 1);
491+
if (jl_is_expr(st) && (((jl_expr_t*)st)->head == jl_foreigncall_sym || ((jl_expr_t*)st)->head == jl_cfunction_sym))
492+
li->has_fcall = 1;
493+
}
490494
if (is_flag_stmt)
491495
jl_array_uint32_set(li->ssaflags, j, 0);
492496
else {

test/core.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8443,3 +8443,8 @@ f_call_me() = invoke(f_invoke_me, f_invoke_me_ci)
84438443
f_invalidate_me() = 2
84448444
@test_throws ErrorException invoke(f_invoke_me, f_invoke_me_ci)
84458445
@test_throws ErrorException f_call_me()
8446+
8447+
myfun57023a(::Type{T}) where {T} = (x = @ccall mycfun()::Ptr{T}; x)
8448+
@test only(code_lowered(myfun57023a)).has_fcall
8449+
myfun57023b(::Type{T}) where {T} = (x = @cfunction myfun57023a Ptr{T} (Ref{T},); x)
8450+
@test only(code_lowered(myfun57023b)).has_fcall

0 commit comments

Comments
 (0)