Skip to content

Commit 4a35ad6

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 58f2e9b commit 4a35ad6

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/method.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,13 @@ static void jl_code_info_set_ir(jl_code_info_t *li, jl_expr_t *ir)
380380
}
381381
bd[j] = jl_nothing;
382382
}
383-
else if (jl_is_expr(st) && ((jl_expr_t*)st)->head == jl_return_sym) {
383+
else if (jl_is_expr(st) && ((jl_expr_t*)st)->head == jl_return_sym)
384384
jl_array_ptr_set(body, j, jl_new_struct(jl_returnnode_type, jl_exprarg(st, 0)));
385-
}
386-
else if (jl_is_expr(st) && (((jl_expr_t*)st)->head == jl_foreigncall_sym || ((jl_expr_t*)st)->head == jl_cfunction_sym)) {
387-
li->has_fcall = 1;
385+
else {
386+
if (jl_is_expr(st) && ((jl_expr_t*)st)->head == jl_assign_sym)
387+
st = jl_exprarg(st, 1);
388+
if (jl_is_expr(st) && (((jl_expr_t*)st)->head == jl_foreigncall_sym || ((jl_expr_t*)st)->head == jl_cfunction_sym))
389+
li->has_fcall = 1;
388390
}
389391
if (is_flag_stmt)
390392
jl_array_uint8_set(li->ssaflags, j, 0);

test/core.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8130,3 +8130,8 @@ let widen_diagonal(x::UnionAll) = Base.rewrap_unionall(Base.widen_diagonal(Base.
81308130
@test Tuple === widen_diagonal(Union{Tuple{Vararg{S}}, Tuple{Vararg{T}}} where {S, T})
81318131
@test Tuple{Vararg{Val{<:Set}}} == widen_diagonal(Tuple{Vararg{T}} where T<:Val{<:Set})
81328132
end
8133+
8134+
myfun57023a(::Type{T}) where {T} = (x = @ccall mycfun()::Ptr{T}; x)
8135+
@test only(code_lowered(myfun57023a)).has_fcall
8136+
myfun57023b(::Type{T}) where {T} = (x = @cfunction myfun57023a Ptr{T} (Ref{T},); x)
8137+
@test only(code_lowered(myfun57023b)).has_fcall

0 commit comments

Comments
 (0)