Skip to content

[2022.3][mono][jit] Emit a null check when storing to valuetype fields. (#82663) #1784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions mono/mini/ir-emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,13 @@ static int ccount = 0;
#define MONO_EMIT_NEW_IMPLICIT_EXCEPTION_LOAD_STORE(cfg) do { \
} while (0)

#define MONO_EMIT_EXPLICIT_NULL_CHECK(cfg, reg) do { \
cfg->flags |= MONO_CFG_HAS_CHECK_THIS; \
MONO_EMIT_NEW_BIALU_IMM (cfg, OP_COMPARE_IMM, -1, (reg), 0); \
MONO_EMIT_NEW_COND_EXC (cfg, EQ, "NullReferenceException"); \
MONO_EMIT_NEW_UNALU (cfg, OP_NOT_NULL, -1, reg); \
} while (0)

/* Emit an explicit null check which doesn't depend on SIGSEGV signal handling */
#define MONO_EMIT_NULL_CHECK(cfg, reg, out_of_page) do { \
if (cfg->explicit_null_checks || (out_of_page)) { \
Expand Down
4 changes: 4 additions & 0 deletions mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -9661,6 +9661,10 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
EMIT_NEW_BIALU_IMM (cfg, ptr, OP_PADD_IMM, dreg, sp [0]->dreg, foffset);
store = mini_emit_storing_write_barrier (cfg, ptr, sp [1]);
} else {
if (MONO_TYPE_ISSTRUCT (field->type))
/* The decomposition might end up calling a copy/wbarrier function which doesn't do null checks */
MONO_EMIT_EXPLICIT_NULL_CHECK (cfg, sp [0]->dreg);

EMIT_NEW_STORE_MEMBASE_TYPE (cfg, store, field->type, sp [0]->dreg, foffset, sp [1]->dreg);
}
}
Expand Down