Skip to content

Commit 460c78a

Browse files
vtjnashKristofferC
authored andcommitted
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 (cherry picked from commit 57b7d2e)
1 parent ebdc636 commit 460c78a

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
@@ -432,8 +432,12 @@ static void jl_code_info_set_ir(jl_code_info_t *li, jl_expr_t *ir)
432432
is_flag_stmt = 1;
433433
else if (jl_is_expr(st) && ((jl_expr_t*)st)->head == jl_return_sym)
434434
jl_array_ptr_set(body, j, jl_new_struct(jl_returnnode_type, jl_exprarg(st, 0)));
435-
else if (jl_is_expr(st) && (((jl_expr_t*)st)->head == jl_foreigncall_sym || ((jl_expr_t*)st)->head == jl_cfunction_sym))
436-
li->has_fcall = 1;
435+
else {
436+
if (jl_is_expr(st) && ((jl_expr_t*)st)->head == jl_assign_sym)
437+
st = jl_exprarg(st, 1);
438+
if (jl_is_expr(st) && (((jl_expr_t*)st)->head == jl_foreigncall_sym || ((jl_expr_t*)st)->head == jl_cfunction_sym))
439+
li->has_fcall = 1;
440+
}
437441
if (is_flag_stmt)
438442
jl_array_uint32_set(li->ssaflags, j, 0);
439443
else {

test/core.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8158,3 +8158,8 @@ let M = @__MODULE__
81588158
end
81598159

81608160
@test Base.unsafe_convert(Ptr{Int}, [1]) !== C_NULL
8161+
8162+
myfun57023a(::Type{T}) where {T} = (x = @ccall mycfun()::Ptr{T}; x)
8163+
@test only(code_lowered(myfun57023a)).has_fcall
8164+
myfun57023b(::Type{T}) where {T} = (x = @cfunction myfun57023a Ptr{T} (Ref{T},); x)
8165+
@test only(code_lowered(myfun57023b)).has_fcall

0 commit comments

Comments
 (0)