Skip to content

Commit d0d21fd

Browse files
authored
[mono] Added null-checks for LDFLDA on pointers. (#77827)
* Added a null check for LDFLDA with pointers. * Reenabled LDFLDA pointer null-check runtime test for mono. * Added null check for LDFLDA in Mono interpreter. * [mono][interp] LDFLDA fix for null pointers now keeps more optimizations intact.
1 parent c7a40cf commit d0d21fd

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

src/mono/mono/mini/interp/transform.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -6034,12 +6034,12 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
60346034
/* TODO: metadata-update: implement me. If it's an added field, emit a call to the helper method instead of MINT_LDFLDA_UNSAFE */
60356035
g_assert (!m_field_is_from_update (field));
60366036
int foffset = m_class_is_valuetype (klass) ? m_field_get_offset (field) - MONO_ABI_SIZEOF (MonoObject) : m_field_get_offset (field);
6037-
if (td->sp->type == STACK_TYPE_O) {
6037+
if (td->sp->type == STACK_TYPE_O || td->sp->type == STACK_TYPE_I) {
60386038
interp_add_ins (td, MINT_LDFLDA);
60396039
td->last_ins->data [0] = GINT_TO_UINT16 (foffset);
60406040
} else {
60416041
int sp_type = td->sp->type;
6042-
g_assert (sp_type == STACK_TYPE_MP || sp_type == STACK_TYPE_I);
6042+
g_assert (sp_type == STACK_TYPE_MP);
60436043
if (foffset) {
60446044
interp_add_ins (td, MINT_LDFLDA_UNSAFE);
60456045
td->last_ins->data [0] = GINT_TO_UINT16 (foffset);

src/mono/mono/mini/method-to-ir.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -10007,7 +10007,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
1000710007
}
1000810008

1000910009
if (il_op == MONO_CEE_LDFLDA) {
10010-
if (sp [0]->type == STACK_OBJ) {
10010+
if (sp [0]->type == STACK_OBJ || sp [0]->type == STACK_PTR) {
1001110011
MONO_EMIT_NEW_BIALU_IMM (cfg, OP_COMPARE_IMM, -1, sp [0]->dreg, 0);
1001210012
MONO_EMIT_NEW_COND_EXC (cfg, EQ, "NullReferenceException");
1001310013
}

src/tests/issues.targets

-3
Original file line numberDiff line numberDiff line change
@@ -1478,9 +1478,6 @@
14781478
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/GitHub_15291/GitHub_15291/**">
14791479
<Issue>Doesn't pass after LLVM AOT compilation.</Issue>
14801480
</ExcludeList>
1481-
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/Runtime_77640/Runtime_77640/**">
1482-
<Issue>https://github.com/dotnet/runtime/issues/77647</Issue>
1483-
</ExcludeList>
14841481
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/CLR-x86-JIT/V1-M09.5-PDC/b16928/b16928/**">
14851482
<Issue>Doesn't pass after LLVM AOT compilation.</Issue>
14861483
</ExcludeList>

0 commit comments

Comments
 (0)