@@ -3131,7 +3131,8 @@ static jl_cgval_t emit_getfield_knownidx(jl_codectx_t &ctx, const jl_cgval_t &st
31313131 bool isptr = (union_max == 0 );
31323132 assert (!isptr && fsz < jl_field_size (jt, idx)); (void )isptr;
31333133 Value *ptindex = emit_ptrgep (ctx, addr, fsz1);
3134- return emit_unionload (ctx, addr, ptindex, jfty, fsz, al, tbaa, false , union_max, strct.tbaa );
3134+ auto tindex_tbaa = jl_is_mutable (strct.typ ) ? ctx.tbaa ().tbaa_mutable_unionselbyte : ctx.tbaa ().tbaa_immut_unionselbyte ;
3135+ return emit_unionload (ctx, addr, ptindex, jfty, fsz, al, tbaa, false , union_max, tindex_tbaa);
31353136 }
31363137 else if (jfty == (jl_value_t *)jl_bool_type) {
31373138 unsigned align = jl_field_align (jt, idx);
@@ -3166,7 +3167,8 @@ static jl_cgval_t emit_getfield_knownidx(jl_codectx_t &ctx, const jl_cgval_t &st
31663167 assert (!isptr && fsz < jl_field_size (jt, idx)); (void )isptr;
31673168 size_t fsz1 = jl_field_size (jt, idx) - 1 ;
31683169 Value *ptindex = emit_ptrgep (ctx, staddr, byte_offset + fsz1);
3169- auto val = emit_unionload (ctx, addr, ptindex, jfty, fsz, al, tbaa, !jl_field_isconst (jt, idx), union_max, strct.tbaa );
3170+ auto tindex_tbaa = jl_is_mutable (strct.typ ) ? ctx.tbaa ().tbaa_mutable_unionselbyte : ctx.tbaa ().tbaa_immut_unionselbyte ;
3171+ auto val = emit_unionload (ctx, addr, ptindex, jfty, fsz, al, tbaa, !jl_field_isconst (jt, idx), union_max, tindex_tbaa);
31703172 if (val.V && val.V != addr) {
31713173 setNameWithField (ctx.emission_context , val.V , get_objname, jt, idx, Twine ());
31723174 }
@@ -4141,7 +4143,7 @@ static jl_cgval_t emit_setfield(jl_codectx_t &ctx,
41414143 size_t fsz1 = jl_field_size (sty, idx0) - 1 ;
41424144 Value *ptindex = emit_ptrgep (ctx, addr, fsz1);
41434145 setNameWithField (ctx.emission_context , ptindex, get_objname, sty, idx0, Twine (" .tindex_ptr" ));
4144- return union_store (ctx, addr, ptindex, rhs, cmp, jfty, tbaa, ctx.tbaa ().tbaa_unionselbyte ,
4146+ return union_store (ctx, addr, ptindex, rhs, cmp, jfty, tbaa, ctx.tbaa ().tbaa_mutable_unionselbyte ,
41454147 Order, FailOrder,
41464148 needlock, issetfield, isreplacefield, isswapfield, ismodifyfield, issetfieldonce,
41474149 modifyop, fname);
@@ -4325,7 +4327,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
43254327 }
43264328 else {
43274329 Value *ptindex = emit_ptrgep (ctx, strct, offs + fsz1);
4328- jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA (ctx, ctx.tbaa ().tbaa_unionselbyte );
4330+ jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA (ctx, ctx.tbaa ().tbaa_immut_unionselbyte );
43294331 ai.decorateInst (ctx.builder .CreateAlignedStore (tindex, ptindex, Align (1 )));
43304332 if (!rhs_union.isghost )
43314333 emit_unionmove (ctx, dest, ctx.tbaa ().tbaa_stack , fval_info, nullptr );
@@ -4409,7 +4411,8 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
44094411 undef_derived_strct (ctx, strct, sty, strctinfo.tbaa );
44104412 for (size_t i = nargs; i < nf; i++) {
44114413 if (!jl_field_isptr (sty, i) && jl_is_uniontype (jl_field_type (sty, i))) {
4412- jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA (ctx, ctx.tbaa ().tbaa_unionselbyte );
4414+ auto tindex_tbaa = jl_is_mutable (sty) ? ctx.tbaa ().tbaa_mutable_unionselbyte : ctx.tbaa ().tbaa_immut_unionselbyte ;
4415+ jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA (ctx, tindex_tbaa);
44134416 ai.decorateInst (ctx.builder .CreateAlignedStore (
44144417 ConstantInt::get (getInt8Ty (ctx.builder .getContext ()), 0 ),
44154418 emit_ptrgep (ctx, strct, jl_field_offset (sty, i) + jl_field_size (sty, i) - 1 ),
0 commit comments