@@ -1549,10 +1549,25 @@ static jl_cgval_t typed_store(jl_codectx_t &ctx,
15491549 bool needlock, bool issetfield, bool isreplacefield, bool maybe_null_if_boxed)
15501550{
15511551 assert (!needlock || parent != nullptr );
1552- jl_cgval_t oldval = rhs;
15531552 Type *elty = isboxed ? T_prjlvalue : julia_type_to_llvm (ctx, jltype);
1554- if (type_is_ghost (elty))
1555- return oldval;
1553+ if (type_is_ghost (elty)) {
1554+ if (isStrongerThanMonotonic (Order))
1555+ ctx.builder .CreateFence (Order);
1556+ if (issetfield) {
1557+ return rhs;
1558+ }
1559+ else if (isreplacefield) {
1560+ Value *Success = emit_f_is (ctx, cmp, ghostValue (jltype));
1561+ Success = ctx.builder .CreateZExt (Success, T_int8);
1562+ jl_cgval_t argv[2 ] = {ghostValue (jltype), mark_julia_type (ctx, Success, false , jl_bool_type)};
1563+ // TODO: do better here
1564+ Value *instr = emit_jlcall (ctx, jltuple_func, V_rnull, argv, 2 , JLCALL_F_CC);
1565+ return mark_julia_type (ctx, instr, true , jl_any_type);
1566+ }
1567+ else {
1568+ return ghostValue (jltype);
1569+ }
1570+ }
15561571 Value *intcast = nullptr ;
15571572 if (!isboxed && Order != AtomicOrdering::NotAtomic && !elty->isIntOrPtrTy ()) {
15581573 const DataLayout &DL = jl_data_layout;
@@ -1590,6 +1605,7 @@ static jl_cgval_t typed_store(jl_codectx_t &ctx,
15901605 BasicBlock *DoneBB = issetfield || (!isreplacefield && !isboxed) ? nullptr : BasicBlock::Create (jl_LLVMContext, " done_xchg" , ctx.f );
15911606 if (needlock)
15921607 emit_lockstate_value (ctx, parent, true );
1608+ jl_cgval_t oldval = rhs;
15931609 if (issetfield || Order == AtomicOrdering::NotAtomic) {
15941610 if (!issetfield) {
15951611 instr = ctx.builder .CreateAlignedLoad (elty, ptr, Align (alignment));
@@ -3230,6 +3246,12 @@ static jl_cgval_t emit_setfield(jl_codectx_t &ctx,
32303246 }
32313247 if (needlock)
32323248 emit_lockstate_value (ctx, strct, false );
3249+ if (isreplacefield) {
3250+ jl_cgval_t argv[2 ] = {oldval, mark_julia_type (ctx, Success, false , jl_bool_type)};
3251+ // TODO: do better here
3252+ Value *instr = emit_jlcall (ctx, jltuple_func, V_rnull, argv, 2 , JLCALL_F_CC);
3253+ oldval = mark_julia_type (ctx, instr, true , jl_any_type);
3254+ }
32333255 return oldval;
32343256 }
32353257 else {
0 commit comments