@@ -1425,10 +1425,10 @@ static bool emit_getfield_unknownidx(jl_codectx_t &ctx,
14251425        Value *idx, jl_datatype_t  *stt, jl_value_t  *inbounds)
14261426{
14271427    size_t  nfields = jl_datatype_nfields (stt);
1428+     bool  maybe_null = (unsigned )stt->ninitialized  != nfields;
14281429    if  (strct.ispointer ()) { //  boxed or stack
14291430        if  (is_datatype_all_pointers (stt)) {
14301431            idx = emit_bounds_check (ctx, strct, (jl_value_t *)stt, idx, ConstantInt::get (T_size, nfields), inbounds);
1431-             bool  maybe_null = (unsigned )stt->ninitialized  != nfields;
14321432            size_t  minimum_field_size = std::numeric_limits<size_t >::max ();
14331433            size_t  minimum_align = JL_HEAP_ALIGNMENT;
14341434            for  (size_t  i = 0 ; i < nfields; ++i) {
@@ -1458,7 +1458,7 @@ static bool emit_getfield_unknownidx(jl_codectx_t &ctx,
14581458            jl_value_t  *jt = jl_field_type (stt, 0 );
14591459            idx = emit_bounds_check (ctx, strct, (jl_value_t *)stt, idx, ConstantInt::get (T_size, nfields), inbounds);
14601460            Value *ptr = maybe_decay_tracked (data_pointer (ctx, strct));
1461-             if  (!stt->mutabl ) {
1461+             if  (!stt->mutabl  && !(maybe_null && jt == ( jl_value_t *)jl_bool_type) ) {
14621462                //  just compute the pointer and let user load it when necessary
14631463                Type *fty = julia_type_to_llvm (jt);
14641464                Value *addr = ctx.builder .CreateInBoundsGEP (fty, emit_bitcast (ctx, ptr, PointerType::get (fty, 0 )), idx);
@@ -1512,6 +1512,7 @@ static jl_cgval_t emit_getfield_knownidx(jl_codectx_t &ctx, const jl_cgval_t &st
15121512    if  (type_is_ghost (elty))
15131513        return  ghostValue (jfty);
15141514    Value *fldv = NULL ;
1515+     bool  maybe_null = idx >= (unsigned )jt->ninitialized ;
15151516    if  (strct.ispointer ()) {
15161517        Value *staddr = maybe_decay_tracked (data_pointer (ctx, strct));
15171518        bool  isboxed;
@@ -1553,7 +1554,6 @@ static jl_cgval_t emit_getfield_knownidx(jl_codectx_t &ctx, const jl_cgval_t &st
15531554        }
15541555        unsigned  align = jl_field_align (jt, idx);
15551556        if  (jl_field_isptr (jt, idx)) {
1556-             bool  maybe_null = idx >= (unsigned )jt->ninitialized ;
15571557            Instruction *Load = maybe_mark_load_dereferenceable (
15581558                    ctx.builder .CreateLoad (T_prjlvalue, emit_bitcast (ctx, addr, T_pprjlvalue)),
15591559                    maybe_null, jl_field_type (jt, idx));
@@ -1586,7 +1586,7 @@ static jl_cgval_t emit_getfield_knownidx(jl_codectx_t &ctx, const jl_cgval_t &st
15861586            }
15871587            return  mark_julia_slot (addr, jfty, tindex, strct.tbaa );
15881588        }
1589-         else  if  (!jt->mutabl ) {
1589+         else  if  (!jt->mutabl  && !(maybe_null && jfty == ( jl_value_t *)jl_bool_type) ) {
15901590            //  just compute the pointer and let user load it when necessary
15911591            return  mark_julia_slot (addr, jfty, NULL , strct.tbaa );
15921592        }
0 commit comments