Skip to content

Commit

Permalink
[llvm] Fix passing vtypes received by value as arguments, they need t…
Browse files Browse the repository at this point in the history
…o be copied. Fixes mono#11378. (mono#11429)
  • Loading branch information
monojenkins authored and luhenry committed Oct 30, 2018
1 parent ea740d2 commit d90fbe3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
11 changes: 9 additions & 2 deletions mono/mini/mini-llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -5917,8 +5917,15 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
addresses [ins->sreg1] = build_alloca (ctx, t);
g_assert (values [ins->sreg1]);
LLVMBuildStore (builder, convert (ctx, values [ins->sreg1], type_to_llvm_type (ctx, t)), addresses [ins->sreg1]);
addresses [ins->dreg] = addresses [ins->sreg1];
} else if (values [ins->sreg1] == addresses [ins->sreg1]) {
/* LLVMArgVtypeByRef, have to make a copy */
addresses [ins->dreg] = build_alloca (ctx, t);
LLVMValueRef v = LLVMBuildLoad (builder, addresses [ins->sreg1], "");
LLVMBuildStore (builder, convert (ctx, v, type_to_llvm_type (ctx, t)), addresses [ins->dreg]);
} else {
addresses [ins->dreg] = addresses [ins->sreg1];
}
addresses [ins->dreg] = addresses [ins->sreg1];
}
break;
}
Expand Down Expand Up @@ -7195,7 +7202,7 @@ emit_method_inner (EmitContext *ctx)
else
name = g_strdup_printf ("arg_%d", i);
}
LLVMSetValueName (values [cfg->args [i + sig->hasthis]->dreg], name);
LLVMSetValueName (LLVMGetParam (method, pindex), name);
g_free (name);
if (ainfo->storage == LLVMArgVtypeByVal)
mono_llvm_add_param_attr (LLVMGetParam (method, pindex), LLVM_ATTR_BY_VAL);
Expand Down
35 changes: 35 additions & 0 deletions mono/mini/objects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,41 @@ class SimpleContainer {
public static int test_0_dup_vtype () {
return new SimpleContainer ().SetFields ();
}

public struct Vec3 {
public int X, Y, Z;

[MethodImplAttribute (MethodImplOptions.NoInlining)]
public Vec3(int x, int y, int z) {
X = x;
Y = y;
Z = z;
}
}

[MethodImplAttribute (MethodImplOptions.NoInlining)]
public static int gh_11378_inner_1 (Vec3 p1, Vec3 p2) {
p1.X -= p2.X;
p1.Y -= p2.Y;
p1.Z -= p2.Z;

return (int)p2.Y;
}

[MethodImplAttribute (MethodImplOptions.NoInlining)]
public static int gh_11378_inner_2 (Vec3 c, Vec3 pos) {
return gh_11378_inner_1 (pos, c);
}

static int gh_11378_inner_3 (Vec3 c) {
var c2 = c;
return gh_11378_inner_2 (c, c2);
}

public static int test_2_gh_11378 () {
return gh_11378_inner_3 (new Vec3(0, 2, -20));
}

}

#if __MOBILE__
Expand Down

0 comments on commit d90fbe3

Please sign in to comment.