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

[interp] Fix loading of ThreadStatic value types #53391

Merged
merged 2 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -4090,14 +4090,21 @@ interp_emit_sfld_access (TransformData *td, MonoClassField *field, MonoClass *fi

// Do a load/store to this address
if (is_load) {
int opcode = (mt == MINT_TYPE_VT) ? MINT_LDOBJ_VT : interp_get_ldind_for_mt (mt);
interp_add_ins (td, opcode);
interp_ins_set_sreg (td->last_ins, td->sp [-1].local);
td->sp--;
push_simple_type (td, stack_type [mt]);
interp_ins_set_dreg (td->last_ins, td->sp [-1].local);
if (mt == MINT_TYPE_VT)
td->last_ins->data [0] = get_data_item_index (td, field_class);
if (mt == MINT_TYPE_VT) {
int field_size = mono_class_value_size (field_class, NULL);
interp_add_ins (td, MINT_LDOBJ_VT);
interp_ins_set_sreg (td->last_ins, td->sp [-1].local);
td->sp--;
push_type_vt (td, field_class, field_size);
interp_ins_set_dreg (td->last_ins, td->sp [-1].local);
td->last_ins->data [0] = field_size;
} else {
interp_add_ins (td, interp_get_ldind_for_mt (mt));
interp_ins_set_sreg (td->last_ins, td->sp [-1].local);
td->sp--;
push_type (td, stack_type [mt], field_class);
interp_ins_set_dreg (td->last_ins, td->sp [-1].local);
}
} else {
int opcode = (mt == MINT_TYPE_VT) ? MINT_STOBJ_VT : interp_get_stind_for_mt (mt);
interp_add_ins (td, opcode);
Expand Down
38 changes: 38 additions & 0 deletions src/tests/baseservices/threading/threadstatic/threadstatic08.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.IO;
using System.Threading;

public struct Struct
{
public uint a;
public uint b;
}

public class Program
{
[ThreadStatic]
private static Struct TSStruct;

public static int Main(string[] args)
{
if(TSStruct.a != 0 || TSStruct.b != 0)
return 101;

Struct str = new Struct ();
str.a = 0xdeadbeef;
str.b = 0xba5eba11;

TSStruct = str;
if(TSStruct.a != 0xdeadbeef || TSStruct.b != 0xba5eba11)
return 102;

Struct str2 = TSStruct;
if(str2.a != 0xdeadbeef || str2.b != 0xba5eba11)
return 103;

Console.WriteLine("Test Succeeded.");
return 100;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<CLRTestPriority>0</CLRTestPriority>
</PropertyGroup>
<ItemGroup>
<Compile Include="threadstatic08.cs" />
</ItemGroup>
</Project>