Skip to content

Commit f113643

Browse files
committed
Fix ILGeneration tests errors
1 parent f4a08ad commit f113643

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/mono/mono/metadata/marshal-lightweight.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2829,18 +2829,21 @@ emit_managed_wrapper_ilgen (MonoMethodBuilder *mb, MonoMethodSignature *invoke_s
28292829

28302830
/* we first do all conversions */
28312831
tmp_locals = g_newa (int, sig->param_count);
2832+
int arg_shift = 0; // used to skip arguments when we have lowered structs
28322833
for (i = 0; i < sig->param_count; i ++) {
28332834
MonoType *t = sig->params [i];
28342835
MonoMarshalSpec *spec = mspecs [i + 1];
28352836

28362837
if (spec && spec->native == MONO_NATIVE_CUSTOM) {
2837-
tmp_locals [i] = mono_emit_marshal (m, i, t, mspecs [i + 1], 0, &sig->params [i], MARSHAL_ACTION_MANAGED_CONV_IN);
2838+
tmp_locals [i] = mono_emit_marshal (m, i, t, mspecs [i + 1], 0, &csig->params [i + arg_shift], MARSHAL_ACTION_MANAGED_CONV_IN);
28382839
} else {
28392840
switch (t->type) {
28402841
case MONO_TYPE_VALUETYPE:
28412842
if (mono_method_signature_has_ext_callconv (csig, MONO_EXT_CALLCONV_SWIFTCALL))
28422843
{
28432844
tmp_locals [i] = 0;
2845+
if(!swift_lowering[i].by_reference)
2846+
arg_shift+=swift_lowering[i].num_lowered_elements - 1;
28442847
break;
28452848
}
28462849
case MONO_TYPE_OBJECT:
@@ -2849,7 +2852,7 @@ emit_managed_wrapper_ilgen (MonoMethodBuilder *mb, MonoMethodSignature *invoke_s
28492852
case MONO_TYPE_SZARRAY:
28502853
case MONO_TYPE_STRING:
28512854
case MONO_TYPE_BOOLEAN:
2852-
tmp_locals [i] = mono_emit_marshal (m, i, t, mspecs [i + 1], 0, &sig->params [i], MARSHAL_ACTION_MANAGED_CONV_IN);
2855+
tmp_locals [i] = mono_emit_marshal (m, i, t, mspecs [i + 1], 0, &csig->params [i + arg_shift], MARSHAL_ACTION_MANAGED_CONV_IN);
28532856
break;
28542857
default:
28552858
tmp_locals [i] = 0;
@@ -2873,7 +2876,7 @@ emit_managed_wrapper_ilgen (MonoMethodBuilder *mb, MonoMethodSignature *invoke_s
28732876
mono_mb_emit_icall (mb, mono_gchandle_get_target_internal);
28742877
}
28752878

2876-
int arg_shift = 0;
2879+
arg_shift = 0;
28772880
int lowered_struct_so_far = 0;
28782881
for (i = 0; i < csig->param_count; i++) {
28792882
MonoType *t = csig->params [i];

src/mono/mono/metadata/marshal.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4091,7 +4091,6 @@ static MonoMethod *
40914091
marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, MonoGCHandle target_handle, gboolean runtime_init_callback, MonoError *error)
40924092
{
40934093
SwiftPhysicalLowering *swift_lowering;
4094-
int **tmp_struct_locals;
40954094
MonoMethodSignature *sig, *csig, *invoke_sig;
40964095
MonoMethodBuilder *mb;
40974096
MonoMethod *res, *invoke;
@@ -4190,24 +4189,21 @@ marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, Mono
41904189
MonoClass *swift_self = mono_class_try_get_swift_self_class ();
41914190
MonoClass *swift_error = mono_class_try_get_swift_error_class ();
41924191
swift_lowering = g_newa (SwiftPhysicalLowering, sig->param_count);
4193-
tmp_struct_locals = g_newa (int*, sig->param_count);
41944192
GArray *new_params = g_array_sized_new (FALSE, FALSE, sizeof (MonoType*), csig->param_count);
41954193
uint32_t new_param_count = 0;
41964194

41974195

41984196

4199-
for (int i =0; i < csig->param_count; i++) {
4200-
MonoType *ptype = csig->params [i];
4197+
for (int j =0; j < csig->param_count; j++) {
4198+
MonoType *ptype = csig->params [j];
42014199
MonoClass *klass = mono_class_from_mono_type_internal (ptype);
4202-
tmp_struct_locals [i] = NULL;
42034200

42044201
if (mono_type_is_struct (ptype) && !(klass == swift_self || klass == swift_error))
42054202
{
42064203
SwiftPhysicalLowering lowered_swift_struct = mono_marshal_get_swift_physical_lowering (ptype, FALSE);
42074204
if (!lowered_swift_struct.by_reference)
42084205
{
4209-
swift_lowering [i] = lowered_swift_struct;
4210-
tmp_struct_locals [i] = g_newa (int, lowered_swift_struct.num_lowered_elements);
4206+
swift_lowering [j] = lowered_swift_struct;
42114207

42124208
for (uint32_t idx_lowered = 0; idx_lowered < lowered_swift_struct.num_lowered_elements; ++idx_lowered) {
42134209
g_array_append_val (new_params, lowered_swift_struct.lowered_elements [idx_lowered]);

0 commit comments

Comments
 (0)