Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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: 10 additions & 0 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,11 @@ static jl_cgval_t emit_llvmcall(jl_codectx_t &ctx, jl_value_t **args, size_t nar
jl_value_t *tti = jl_svecref(tt,i);
bool toboxed;
Type *t = julia_type_to_llvm(ctx, tti, &toboxed);
if (t == getVoidTy(ctx.builder.getContext())) {
emit_error(ctx, "llvmcall does not support zero-sized argument types");
JL_GC_POP();
return jl_cgval_t();
}
argtypes.push_back(t);
if (4 + i > nargs) {
emit_error(ctx, "Missing arguments to llvmcall!");
Expand All @@ -927,6 +932,11 @@ static jl_cgval_t emit_llvmcall(jl_codectx_t &ctx, jl_value_t **args, size_t nar
jl_value_t *rtt = rt;
bool retboxed;
Type *rettype = julia_type_to_llvm(ctx, rtt, &retboxed);
if (jl_is_datatype(rtt) && jl_datatype_size((jl_datatype_t*)rtt) == 0) {
emit_error(ctx, "llvmcall does not support zero-sized return types");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about void functions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a check for that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The semantics here of checking if the user made an egregious typo are still wrong. This is also well formed:

julia> mutable struct A end

julia> f() = Core.Intrinsics.llvmcall("ret ptr addrspace(10) null", A, Tuple{})

This sort of random checking for user error doesn't really make sense to me. The point of llvmcall is an unsafe escape hatch into unsafe territory. If you don't like that, just don't use it.

JL_GC_POP();
return jl_cgval_t();
}

// Make sure to find a unique name
std::string ir_name;
Expand Down
6 changes: 6 additions & 0 deletions test/llvmcall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,9 @@ s = MyStruct()
@test eltype(supertype(Core.LLVMPtr{UInt8,1})) <: UInt8
@test s.kern == 0
@test reinterpret(Int, s.ptr) == 0

f_zero_arg(x::T) where T = Base.llvmcall("ret i8 %0", Int8, Tuple{T}, x)
@test_throws ErrorException f_zero_arg(nothing)

f_zero_ret(x::Int8) = Base.llvmcall("ret void", Nothing, Tuple{Int8}, x)
@test_throws ErrorException f_zero_ret(Int8(1))