Skip to content

Commit

Permalink
Fix error when returning undef from function (#1054)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses authored Sep 14, 2023
1 parent 8f3e7b7 commit eca8475
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const nofreefns = Set{String}((
"jl_box_uint64", "jl_box_uint32",
"ijl_box_uint64", "ijl_box_uint32",
"ijl_box_char", "jl_box_char",
"ijl_subtype",
"jl_subtype", "julia.get_pgcstack", "jl_in_threaded_region",
"jl_object_id_", "jl_object_id", "ijl_object_id_", "ijl_object_id",
"jl_breakpoint",
Expand Down Expand Up @@ -214,6 +215,7 @@ const inactivefns = Set{String}((
"jl_box_uint64", "jl_box_uint32",
"ijl_box_uint64", "ijl_box_uint32",
"ijl_box_char", "jl_box_char",
"ijl_subtype",
"jl_subtype", "julia.get_pgcstack", "jl_in_threaded_region",
"jl_object_id_", "jl_object_id", "ijl_object_id_", "ijl_object_id",
"jl_breakpoint",
Expand Down
20 changes: 15 additions & 5 deletions src/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ function fix_decayaddr!(mod::LLVM.Module)
end
end
if !sret
@safe_show f
@safe_show inst, st, fop
println(string(f))
@show inst, st, fop
flush(stdout)
end

Expand Down Expand Up @@ -661,10 +661,8 @@ function propagate_returned!(mod::LLVM.Module)
push!(toremove, i-1)
end
end
if argn === nothing && length(toremove) == 0
continue
end
illegalUse = !(linkage(fn) == LLVM.API.LLVMInternalLinkage || linkage(fn) == LLVM.API.LLVMPrivateLinkage)
hasAnyUse = false
for u in LLVM.uses(fn)
un = LLVM.user(u)
if !isa(un, LLVM.CallInst)
Expand Down Expand Up @@ -694,8 +692,20 @@ function propagate_returned!(mod::LLVM.Module)
push!(next, LLVM.name(LLVM.parent(LLVM.parent(un))))
LLVM.replace_uses!(un, ops[argn])
end
else
for u in LLVM.uses(un)
hasAnyUse = true
break
end
end
end
#if the function return has no users whatsoever, remove it
if argn === nothing && !hasAnyUse && LLVM.return_type(LLVM.function_type(fn)) != LLVM.VoidType()
argn = -1
end
if argn === nothing && length(toremove) == 0
continue
end
if !illegalUse
push!(tofinalize, (fn, argn === nothing, toremove))
end
Expand Down

0 comments on commit eca8475

Please sign in to comment.