Skip to content

Commit

Permalink
[llvm] Fix the computation of size of gshared instances in emit_args_…
Browse files Browse the repository at this point in the history
…to_vtype ().

Fixes #13610.
  • Loading branch information
vargaz authored and marek-safar committed Mar 26, 2019
1 parent 95911b7 commit 9e7fc6c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
14 changes: 14 additions & 0 deletions mono/mini/generics.cs
Expand Up @@ -1448,6 +1448,20 @@ public Type Caller<TAwaiter>(ref TAwaiter awaiter)
var res = builder.Caller (ref awaiter);
return res == typeof (bool) ? 0 : 1;
}

struct OneThing<T1> {
public T1 Item1;
}

[MethodImpl (MethodImplOptions.NoInlining)]
static T FromResult<T> (T result) {
return result;
}

public static int test_42_llvm_gsharedvt_small_vtype_in_regs () {
var t = FromResult<OneThing<int>>(new OneThing<int> {Item1 = 42});
return t.Item1;
}
}

#if !__MOBILE__
Expand Down
12 changes: 7 additions & 5 deletions mono/mini/mini-llvm.c
Expand Up @@ -2243,12 +2243,14 @@ static void
emit_args_to_vtype (EmitContext *ctx, LLVMBuilderRef builder, MonoType *t, LLVMValueRef address, LLVMArgInfo *ainfo, LLVMValueRef *args)
{
int j, size, nslots;
MonoClass *klass;

size = mono_class_value_size (mono_class_from_mono_type (t), NULL);
t = mini_get_underlying_type (t);
klass = mono_class_from_mono_type (t);
size = mono_class_value_size (klass, NULL);

if (MONO_CLASS_IS_SIMD (ctx->cfg, mono_class_from_mono_type (t))) {
if (MONO_CLASS_IS_SIMD (ctx->cfg, klass))
address = LLVMBuildBitCast (ctx->builder, address, LLVMPointerType (LLVMInt8Type (), 0), "");
}

if (ainfo->storage == LLVMArgAsFpArgs)
nslots = ainfo->nslots;
Expand All @@ -2269,8 +2271,8 @@ emit_args_to_vtype (EmitContext *ctx, LLVMBuilderRef builder, MonoType *t, LLVMV
switch (ainfo->pair_storage [j]) {
case LLVMArgInIReg: {
part_type = LLVMIntType (part_size * 8);
if (MONO_CLASS_IS_SIMD (ctx->cfg, mono_class_from_mono_type (t))) {
index [0] = LLVMConstInt (LLVMInt32Type (), j * sizeof (gpointer), FALSE);
if (MONO_CLASS_IS_SIMD (ctx->cfg, klass)) {
index [0] = LLVMConstInt (LLVMInt32Type (), j * TARGET_SIZEOF_VOID_P, FALSE);
addr = LLVMBuildGEP (builder, address, index, 1, "");
} else {
daddr = LLVMBuildBitCast (ctx->builder, address, LLVMPointerType (IntPtrType (), 0), "");
Expand Down
2 changes: 1 addition & 1 deletion mono/mini/mini.h
Expand Up @@ -620,7 +620,7 @@ typedef struct {
LLVMArgStorage storage;

/*
* Only if storage == ArgValuetypeInReg/LLVMArgAsFpArgs.
* Only if storage == ArgVtypeInReg/LLVMArgAsFpArgs.
* This contains how the parts of the vtype are passed.
*/
LLVMArgStorage pair_storage [8];
Expand Down

0 comments on commit 9e7fc6c

Please sign in to comment.