Skip to content

Commit d37b7d8

Browse files
authored
Correct logic for ccall symbol lookup (#659)
The existing logic could not distinguish between ccall(foo) and ccall(:foo) and was giving wrong errors as a result.
1 parent 126ab85 commit d37b7d8

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/optimize.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,20 @@ end
191191
# Handle :llvmcall & :foreigncall (issue #28)
192192
function build_compiled_foreigncall!(stmt::Expr, code::CodeInfo, sparams::Vector{Symbol}, evalmod::Module)
193193
TVal = evalmod == Core.Compiler ? Core.Compiler.Val : Val
194-
cfunc, RetType, ArgType = lookup_stmt(code.code, stmt.args[1]), stmt.args[2], stmt.args[3]::SimpleVector
194+
cfuncarg = stmt.args[1]
195+
while isa(cfuncarg, SSAValue)
196+
cfuncarg = code.code[cfuncarg.id]
197+
end
198+
RetType, ArgType = stmt.args[2], stmt.args[3]::SimpleVector
195199

196200
dynamic_ccall = false
197201
oldcfunc = nothing
198-
if isa(cfunc, Expr) # specification by tuple, e.g., (:clock, "libc")
199-
cfunc = something(static_eval(cfunc), cfunc)
202+
if isa(cfuncarg, Expr) || isa(cfuncarg, GlobalRef) || isa(cfuncarg, Symbol) # specification by tuple, e.g., (:clock, "libc")
203+
cfunc = something(static_eval(evalmod, cfuncarg), cfuncarg)
204+
elseif isa(cfuncarg, QuoteNode)
205+
cfunc = cfuncarg.value
206+
else
207+
cfunc = cfuncarg
200208
end
201209
if isa(cfunc, Symbol)
202210
cfunc = QuoteNode(cfunc)

src/utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,9 @@ function Base.display_error(io::IO, er, frame::Frame)
814814
println(io)
815815
end
816816

817-
function static_eval(ex)
817+
function static_eval(evalmod, ex)
818818
try
819-
eval(ex)
819+
Core.eval(evalmod, ex)
820820
catch
821821
nothing
822822
end

0 commit comments

Comments
 (0)