Skip to content

Commit

Permalink
codegen: take gc roots (and alloca alignment) more seriously
Browse files Browse the repository at this point in the history
Due to limitations in the LLVM implementation, we are forced to emit
fairly bad code here. But we need to make sure it is still correct with
respect to GC rooting.

Fixes #54720
  • Loading branch information
vtjnash committed Aug 1, 2024
1 parent f4a022c commit bd84693
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 78 deletions.
10 changes: 5 additions & 5 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ static Value *julia_to_native(
// pass the address of an alloca'd thing, not a box
// since those are immutable.
Value *slot = emit_static_alloca(ctx, to);
unsigned align = julia_alignment(jlto);
cast<AllocaInst>(slot)->setAlignment(Align(align));
Align align(julia_alignment(jlto));
cast<AllocaInst>(slot)->setAlignment(align);
setName(ctx.emission_context, slot, "native_convert_buffer");
if (!jvinfo.ispointer()) {
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, jvinfo.tbaa);
Expand Down Expand Up @@ -2230,7 +2230,7 @@ jl_cgval_t function_sig_t::emit_a_ccall(
Value *strct = emit_allocobj(ctx, (jl_datatype_t*)rt, true);
setName(ctx.emission_context, strct, "ccall_ret_box");
MDNode *tbaa = jl_is_mutable(rt) ? ctx.tbaa().tbaa_mutab : ctx.tbaa().tbaa_immut;
int boxalign = julia_alignment(rt);
Align boxalign(julia_alignment(rt));
// copy the data from the return value to the new struct
const DataLayout &DL = ctx.builder.GetInsertBlock()->getModule()->getDataLayout();
auto resultTy = result->getType();
Expand All @@ -2240,8 +2240,8 @@ jl_cgval_t function_sig_t::emit_a_ccall(
// When this happens, cast through memory.
auto slot = emit_static_alloca(ctx, resultTy);
setName(ctx.emission_context, slot, "type_pun_slot");
slot->setAlignment(Align(boxalign));
ctx.builder.CreateAlignedStore(result, slot, Align(boxalign));
slot->setAlignment(boxalign);
ctx.builder.CreateAlignedStore(result, slot, boxalign);
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, tbaa);
emit_memcpy(ctx, strct, ai, slot, ai, rtsz, boxalign, boxalign);
}
Expand Down
Loading

0 comments on commit bd84693

Please sign in to comment.