Skip to content

Commit 83a89a1

Browse files
authored
Merge pull request #23739 from JuliaLang/yyc/codegen/aa64-ccall
Fix ccall return value boxing on ARM/AArch64
2 parents 39186f6 + ca28b5f commit 83a89a1

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/ccall.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -2087,21 +2087,26 @@ jl_cgval_t function_sig_t::emit_a_ccall(
20872087
size_t rtsz = jl_datatype_size(rt);
20882088
assert(rtsz > 0);
20892089
Value *strct = emit_allocobj(ctx, rtsz, runtime_bt);
2090+
MDNode *tbaa = jl_is_mutable(rt) ? tbaa_mutab : tbaa_immut;
20902091
int boxalign = jl_datatype_align(rt);
2091-
#ifndef JL_NDEBUG
2092+
// copy the data from the return value to the new struct
20922093
#if JL_LLVM_VERSION >= 40000
20932094
const DataLayout &DL = jl_data_layout;
20942095
#else
20952096
const DataLayout &DL = jl_ExecutionEngine->getDataLayout();
20962097
#endif
2097-
// ARM and AArch64 can use a LLVM type larger than the julia
2098-
// type. However, the LLVM type size should be no larger than
2099-
// the GC allocation size. (multiple of `sizeof(void*)`)
2100-
assert(DL.getTypeStoreSize(lrt) <= LLT_ALIGN(rtsz, boxalign));
2101-
#endif
2102-
// copy the data from the return value to the new struct
2103-
MDNode *tbaa = jl_is_mutable(rt) ? tbaa_mutab : tbaa_immut;
2104-
init_bits_value(ctx, strct, result, tbaa, boxalign);
2098+
auto resultTy = result->getType();
2099+
if (DL.getTypeStoreSize(resultTy) > rtsz) {
2100+
// ARM and AArch64 can use a LLVM type larger than the julia type.
2101+
// When this happens, cast through memory.
2102+
auto slot = emit_static_alloca(ctx, resultTy);
2103+
slot->setAlignment(boxalign);
2104+
ctx.builder.CreateAlignedStore(result, slot, boxalign);
2105+
emit_memcpy(ctx, strct, slot, rtsz, boxalign, tbaa);
2106+
}
2107+
else {
2108+
init_bits_value(ctx, strct, result, tbaa, boxalign);
2109+
}
21052110
return mark_julia_type(ctx, strct, true, rt);
21062111
}
21072112
jlretboxed = false; // trigger mark_or_box_ccall_result to build the runtime box

0 commit comments

Comments
 (0)