Skip to content

Commit ea78ccf

Browse files
committed
ccall: add checks for zero-sized argument and return types in llvmcall
1 parent 054b2c5 commit ea78ccf

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/ccall.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,11 @@ static jl_cgval_t emit_llvmcall(jl_codectx_t &ctx, jl_value_t **args, size_t nar
909909
jl_value_t *tti = jl_svecref(tt,i);
910910
bool toboxed;
911911
Type *t = julia_type_to_llvm(ctx, tti, &toboxed);
912+
if (jl_is_datatype(tti) && jl_datatype_size((jl_datatype_t*)tti) == 0) {
913+
emit_error(ctx, "llvmcall does not support zero-sized argument types");
914+
JL_GC_POP();
915+
return jl_cgval_t();
916+
}
912917
argtypes.push_back(t);
913918
if (4 + i > nargs) {
914919
emit_error(ctx, "Missing arguments to llvmcall!");
@@ -927,6 +932,11 @@ static jl_cgval_t emit_llvmcall(jl_codectx_t &ctx, jl_value_t **args, size_t nar
927932
jl_value_t *rtt = rt;
928933
bool retboxed;
929934
Type *rettype = julia_type_to_llvm(ctx, rtt, &retboxed);
935+
if (jl_is_datatype(rtt) && jl_datatype_size((jl_datatype_t*)rtt) == 0) {
936+
emit_error(ctx, "llvmcall does not support zero-sized return types");
937+
JL_GC_POP();
938+
return jl_cgval_t();
939+
}
930940

931941
// Make sure to find a unique name
932942
std::string ir_name;

test/llvmcall.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,9 @@ s = MyStruct()
218218
@test eltype(supertype(Core.LLVMPtr{UInt8,1})) <: UInt8
219219
@test s.kern == 0
220220
@test reinterpret(Int, s.ptr) == 0
221+
222+
f_zero_arg(x::T) where T = Base.llvmcall("ret i8 %0", Int8, Tuple{T}, x)
223+
@test_throws ErrorException f_zero_arg(nothing)
224+
225+
f_zero_ret(x::Int8) = Base.llvmcall("ret void", Nothing, Tuple{Int8}, x)
226+
@test_throws ErrorException f_zero_ret(Int8(1))

0 commit comments

Comments
 (0)