@@ -3022,8 +3022,12 @@ static void emit_assignment(jl_value_t *l, jl_value_t *r, jl_codectx_t *ctx)
3022
3022
3023
3023
if (!bp && !vi.hasGCRoot && vi.used && !vi.isArgument &&
3024
3024
!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
3027
3031
}
3028
3032
Value *rval = emit_assignment (bp, r, vi.declType , vi.isVolatile , vi.used , ctx);
3029
3033
@@ -3503,7 +3507,7 @@ static void finalize_gc_frame(jl_codectx_t *ctx)
3503
3507
}
3504
3508
BasicBlock::iterator bbi (gc->gcframe );
3505
3509
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
3507
3511
// Allocate the real GC frame
3508
3512
// n_frames++;
3509
3513
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)
4548
4552
assert (false );
4549
4553
}
4550
4554
}
4555
+ else {
4556
+ assert (vi.memvalue == NULL );
4557
+ }
4551
4558
}
4552
4559
4553
4560
// step 14. associate labels with basic blocks to resolve forward jumps
0 commit comments