Skip to content

Commit 7c43923

Browse files
jhcdunity3dbholmes
andauthored
Emit a null check when loading valuetype fields (#1868)
Co-authored-by: Bill Holmes <bill.holmes@unity3d.com>
1 parent 54e486f commit 7c43923

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

mono/mini/method-to-ir.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9745,7 +9745,9 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
97459745
} else {
97469746
MonoInst *load;
97479747

9748-
MONO_EMIT_NULL_CHECK (cfg, sp [0]->dreg, foffset > mono_target_pagesize ());
9748+
// We may call a copy / wbarrier function which doesn't do null checks;
9749+
// passing MONO_TYPE_ISSTRUCT to macro so that we emit the null check when accessing fields that are structs */
9750+
MONO_EMIT_NULL_CHECK (cfg, sp [0]->dreg, foffset > mono_target_pagesize () || MONO_TYPE_ISSTRUCT(field->type));
97499751

97509752
#ifdef MONO_ARCH_SIMD_INTRINSICS
97519753
if (sp [0]->opcode == OP_LDADDR && m_class_is_simd_type (klass) && cfg->opt & MONO_OPT_SIMD) {

0 commit comments

Comments
 (0)