Skip to content
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

[dim] Emit error when calling abstract methods #15433

Merged
merged 2 commits into from Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions mono/metadata/jit-icall-reg.h
Expand Up @@ -302,6 +302,7 @@ MONO_JIT_ICALL (mono_threads_exit_gc_unsafe_region_unbalanced) \
MONO_JIT_ICALL (mono_threads_state_poll) \
MONO_JIT_ICALL (mono_throw_exception) \
MONO_JIT_ICALL (mono_throw_method_access) \
MONO_JIT_ICALL (mono_throw_bad_image) \
MONO_JIT_ICALL (mono_trace_enter_method) \
MONO_JIT_ICALL (mono_trace_leave_method) \
MONO_JIT_ICALL (mono_upgrade_remote_class_wrapper) \
Expand Down
8 changes: 8 additions & 0 deletions mono/mini/jit-icalls.c
Expand Up @@ -1522,6 +1522,14 @@ mono_throw_method_access (MonoMethod *caller, MonoMethod *callee)
g_free (caller_name);
}

void
mono_throw_bad_image ()
{
ERROR_DECL (error);
mono_error_set_generic_error (error, "System", "BadImageFormatException", "Bad IL format.");
mono_error_set_pending_exception (error);
}

void
mono_dummy_jit_icall (void)
{
Expand Down
2 changes: 2 additions & 0 deletions mono/mini/jit-icalls.h
Expand Up @@ -219,6 +219,8 @@ G_EXTERN_C double mono_ckfinite (double d);

G_EXTERN_C void mono_throw_method_access (MonoMethod *caller, MonoMethod *callee);

G_EXTERN_C void mono_throw_bad_image (void);

G_EXTERN_C void mono_dummy_jit_icall (void);

#endif /* __MONO_JIT_ICALLS_H__ */
10 changes: 7 additions & 3 deletions mono/mini/method-to-ir.c
Expand Up @@ -2243,6 +2243,12 @@ emit_method_access_failure (MonoCompile *cfg, MonoMethod *caller, MonoMethod *ca
mono_emit_jit_icall (cfg, mono_throw_method_access, args);
}

static void
emit_bad_image_failure (MonoCompile *cfg, MonoMethod *caller, MonoMethod *callee)
{
mono_emit_jit_icall (cfg, mono_throw_bad_image, NULL);
}

static MonoMethod*
get_method_nofail (MonoClass *klass, const char *method_name, int num_params, int flags)
{
Expand Down Expand Up @@ -7038,8 +7044,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
ensure_method_is_allowed_to_call_method (cfg, method, cil_method);

if (!virtual_ && (cmethod->flags & METHOD_ATTRIBUTE_ABSTRACT))
/* MS.NET seems to silently convert this to a callvirt */
virtual_ = TRUE;
emit_bad_image_failure (cfg, method, cil_method);
thaystg marked this conversation as resolved.
Show resolved Hide resolved

{
/*
Expand Down Expand Up @@ -7810,7 +7815,6 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
}
emit_seq_point (cfg, method, next_ip, FALSE, TRUE);
}

break;
}
case MONO_CEE_RET:
Expand Down
1 change: 1 addition & 0 deletions mono/mini/mini-runtime.c
Expand Up @@ -4632,6 +4632,7 @@ register_icalls (void)
register_icall (mono_get_assembly_object, mono_icall_sig_object_ptr, TRUE);
register_icall (mono_get_method_object, mono_icall_sig_object_ptr, TRUE);
register_icall (mono_throw_method_access, mono_icall_sig_void_ptr_ptr, FALSE);
register_icall (mono_throw_bad_image, mono_icall_sig_void, FALSE);
register_icall_no_wrapper (mono_dummy_jit_icall, mono_icall_sig_void);

register_icall_with_wrapper (mono_monitor_enter_internal, mono_icall_sig_int32_obj);
Expand Down