Skip to content

Commit

Permalink
Merge pull request #31403 from JuliaLang/tb/llvmcall_extern
Browse files Browse the repository at this point in the history
Allow ccall(..., llvmcall, ...) to external functions.
  • Loading branch information
vchuravy authored Mar 21, 2019
2 parents f611b46 + b437e61 commit 54fe55b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1949,8 +1949,14 @@ jl_cgval_t function_sig_t::emit_a_ccall(
}
else {
assert(symarg.f_name != NULL);
llvmf = jl_Module->getOrInsertFunction(symarg.f_name, functype);
if (!isa<Function>(llvmf) || cast<Function>(llvmf)->getIntrinsicID() == Intrinsic::not_intrinsic)
const char* f_name = symarg.f_name;
bool f_extern = (strncmp(f_name, "extern ", 7) == 0);
if (f_extern)
f_name += 7;
llvmf = jl_Module->getOrInsertFunction(f_name, functype);
if (!f_extern &&
(!isa<Function>(llvmf) ||
cast<Function>(llvmf)->getIntrinsicID() == Intrinsic::not_intrinsic))
jl_error("llvmcall only supports intrinsic calls");
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/llvmcall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,11 @@ module LLVMCallFunctionTest
@test really_complicated_identity(x) === x
end
end

# support for calling external functions
let
f() = ccall("time", llvmcall, Cvoid, (Ptr{Cvoid},), C_NULL)
@test_throws ErrorException f()
f() = ccall("extern time", llvmcall, Cvoid, (Ptr{Cvoid},), C_NULL)
f()
end

0 comments on commit 54fe55b

Please sign in to comment.