Skip to content

Commit 6ae7707

Browse files
committed
ensure the lazy memloc local_slot creation is moved to the right basicblock to dominate the function
1 parent e20f4c0 commit 6ae7707

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/codegen.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,8 +3022,12 @@ static void emit_assignment(jl_value_t *l, jl_value_t *r, jl_codectx_t *ctx)
30223022

30233023
if (!bp && !vi.hasGCRoot && vi.used && !vi.isArgument &&
30243024
!is_stable_expr(r, ctx)) {
3025-
vi.hasGCRoot = true; // this has been discovered to need a gc root
3026-
vi.memvalue = bp = emit_local_slot(ctx->gc.argSpaceSize++, ctx);
3025+
Instruction *newroot = cast<Instruction>(emit_local_slot(ctx->gc.argSpaceSize++, ctx));
3026+
newroot->removeFromParent(); // move it to the gc frame basic block so it can be reused as needed
3027+
newroot->insertAfter(ctx->gc.last_gcframe_inst);
3028+
vi.memvalue = bp = newroot;
3029+
vi.hasGCRoot = true; // this has been discovered to need a gc root, add it now
3030+
//TODO: move this logic after the emit_expr
30273031
}
30283032
Value *rval = emit_assignment(bp, r, vi.declType, vi.isVolatile, vi.used, ctx);
30293033

@@ -3503,7 +3507,7 @@ static void finalize_gc_frame(jl_codectx_t *ctx)
35033507
}
35043508
BasicBlock::iterator bbi(gc->gcframe);
35053509
AllocaInst *newgcframe = gc->gcframe;
3506-
builder.SetInsertPoint(++gc->last_gcframe_inst); // set insert *before* point
3510+
builder.SetInsertPoint(++gc->last_gcframe_inst); // set insert *before* point, e.g. after the gcframe
35073511
// Allocate the real GC frame
35083512
// n_frames++;
35093513
newgcframe->setOperand(0, ConstantInt::get(T_int32, 2 + gc->argSpaceSize + gc->maxDepth)); // fix up the size of the gc frame
@@ -4548,6 +4552,9 @@ static Function *emit_function(jl_lambda_info_t *lam)
45484552
assert(false);
45494553
}
45504554
}
4555+
else {
4556+
assert(vi.memvalue == NULL);
4557+
}
45514558
}
45524559

45534560
// step 14. associate labels with basic blocks to resolve forward jumps

0 commit comments

Comments
 (0)