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

Allow ccall(..., llvmcall, ...) to external functions. #31403

Merged
merged 1 commit into from
Mar 21, 2019
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
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