Skip to content

Commit

Permalink
[interp] Throw an InvalidProgramException instead of asserting when t…
Browse files Browse the repository at this point in the history
…rying to transform a method with too many locals. (#42797)

#42628.

Co-authored-by: vargaz <[email protected]>
  • Loading branch information
monojenkins and vargaz authored Sep 28, 2020
1 parent 244d939 commit 4c3d759
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ get_interp_local_offset (TransformData *td, int local)
td->locals [local].offset = offset;

td->total_locals_size = offset + size;
g_assert (td->total_locals_size < G_MAXUINT16);
//g_assert (td->total_locals_size < G_MAXUINT16);

return offset;
}
Expand Down Expand Up @@ -2353,13 +2353,15 @@ interp_inline_method (TransformData *td, MonoMethod *target_method, MonoMethodHe
td->inline_depth--;

if (!ret) {
if (!is_ok (error))
mono_error_cleanup (error);

if (td->verbose_level)
g_print ("Inline aborted method %s.%s\n", m_class_get_name (target_method->klass), target_method->name);
td->max_stack_height = prev_max_stack_height;
td->max_vt_sp = prev_max_vt_sp;
td->locals_size = prev_locals_size;


/* Remove any newly added items */
for (i = prev_n_data_items; i < td->n_data_items; i++) {
g_hash_table_remove (td->data_hash, td->data_items [i]);
Expand Down Expand Up @@ -3256,7 +3258,7 @@ interp_method_compute_offsets (TransformData *td, InterpMethod *imethod, MonoMet
}
offset = ALIGN_TO (offset, MINT_VT_ALIGNMENT);

g_assert (offset < G_MAXUINT16);
//g_assert (offset < G_MAXUINT16);
td->total_locals_size = offset;
}

Expand Down Expand Up @@ -8161,6 +8163,15 @@ generate (MonoMethod *method, MonoMethodHeader *header, InterpMethod *rtm, MonoG

generate_compacted_code (td);

if (td->total_locals_size >= G_MAXUINT16) {
char *name = mono_method_get_full_name (method);
char *msg = g_strdup_printf ("Unable to run method '%s': locals size too big.", name);
g_free (name);
mono_error_set_generic_error (error, "System", "InvalidProgramException", "%s", msg);
g_free (msg);
goto exit;
}

if (td->verbose_level) {
g_print ("Runtime method: %s %p\n", mono_method_full_name (method, TRUE), rtm);
g_print ("Locals size %d, VT stack size: %d\n", td->total_locals_size, td->max_vt_sp);
Expand Down

0 comments on commit 4c3d759

Please sign in to comment.