Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when returning undef from function #1054

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading