@@ -2087,21 +2087,26 @@ jl_cgval_t function_sig_t::emit_a_ccall(
2087
2087
size_t rtsz = jl_datatype_size (rt);
2088
2088
assert (rtsz > 0 );
2089
2089
Value *strct = emit_allocobj (ctx, rtsz, runtime_bt);
2090
+ MDNode *tbaa = jl_is_mutable (rt) ? tbaa_mutab : tbaa_immut;
2090
2091
int boxalign = jl_datatype_align (rt);
2091
- # ifndef JL_NDEBUG
2092
+ // copy the data from the return value to the new struct
2092
2093
#if JL_LLVM_VERSION >= 40000
2093
2094
const DataLayout &DL = jl_data_layout;
2094
2095
#else
2095
2096
const DataLayout &DL = jl_ExecutionEngine->getDataLayout ();
2096
2097
#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
+ }
2105
2110
return mark_julia_type (ctx, strct, true , rt);
2106
2111
}
2107
2112
jlretboxed = false ; // trigger mark_or_box_ccall_result to build the runtime box
0 commit comments