Skip to content

Commit 1d02ea3

Browse files
authored
Merge pull request #480 from JuliaDebug/sds/fix_479
fix #479: buggy handling of ccall
2 parents 737d928 + 8315ec5 commit 1d02ea3

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/optimize.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ function extract_inner_call!(stmt::Expr, idx, once::Bool=false)
2525
return nothing
2626
end
2727

28-
function replace_ssa!(@nospecialize(stmt), ssalookup)
29-
isa(stmt, Expr) || return nothing
30-
for (i, a) in enumerate(stmt.args)
28+
function replace_ssa(@nospecialize(stmt), ssalookup)
29+
isa(stmt, Expr) || return stmt
30+
return Expr(stmt.head, Any[
3131
if isa(a, SSAValue)
32-
stmt.args[i] = SSAValue(ssalookup[a.id])
32+
SSAValue(ssalookup[a.id])
3333
elseif isa(a, NewSSAValue)
34-
stmt.args[i] = SSAValue(a.id)
34+
SSAValue(a.id)
3535
else
36-
replace_ssa!(a, ssalookup)
36+
replace_ssa(a, ssalookup)
3737
end
38-
end
39-
return nothing
38+
for a in stmt.args
39+
]...)
4040
end
4141

4242
function renumber_ssa!(stmts::Vector{Any}, ssalookup)
@@ -54,10 +54,11 @@ function renumber_ssa!(stmts::Vector{Any}, ssalookup)
5454
elseif isa(stmt, NewSSAValue)
5555
stmts[i] = SSAValue(stmt.id)
5656
elseif isa(stmt, Expr)
57-
replace_ssa!(stmt, ssalookup)
57+
stmt = replace_ssa(stmt, ssalookup)
5858
if (stmt.head === :gotoifnot || stmt.head === :enter) && isa(stmt.args[end], Int)
5959
stmt.args[end] = jumplookup(ssalookup, stmt.args[end])
6060
end
61+
stmts[i] = stmt
6162
elseif is_GotoIfNot(stmt)
6263
cond = (stmt::Core.GotoIfNot).cond
6364
if isa(cond, SSAValue)
@@ -287,7 +288,7 @@ function build_compiled_call!(stmt::Expr, fcall, code, idx, nargs::Int, sparams:
287288
push!(args, cconvert_expr.args[3])
288289
elseif arg isa SlotNumber
289290
index = findfirst(code.code) do expr
290-
expr isa Expr || return false
291+
Meta.isexpr(expr, :(=)) || return false
291292
lhs = expr.args[1]
292293
return lhs isa SlotNumber && lhs.id === arg.id
293294
end

test/interpret.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,4 +782,12 @@ end
782782
@unreachable foobar() = "nope"
783783

784784
@test @interpret(foobar()) == foobar()
785-
end
785+
end
786+
787+
@testset "issue #479" begin
788+
function f()
789+
ptr = @cfunction(+, Int, (Int, Int))
790+
ccall(ptr::Ptr{Cvoid}, Int, (Int, Int), 1, 2)
791+
end
792+
@test @interpret(f()) === 3
793+
end

0 commit comments

Comments
 (0)