Skip to content

Fix load and store field IL instructions for value types in stack #3186

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

Merged
Merged
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
58 changes: 55 additions & 3 deletions src/CLR/Core/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2569,7 +2569,33 @@ HRESULT CLR_RT_Thread::Execute_IL(CLR_RT_StackFrame &stackArg)
CLR_RT_HeapBlock *obj = &evalPos[0];
NanoCLRDataType dt = obj->DataType();

NANOCLR_CHECK_HRESULT(CLR_RT_TypeDescriptor::ExtractObjectAndDataType(obj, dt));
// If it's a byref, it must be a struct instance on the stack/heap
bool instanceIsByRef =
(obj->DataType() == DATATYPE_BYREF) || (obj->DataType() == DATATYPE_ARRAY_BYREF);

if (instanceIsByRef)
{
// extra check for DATATYPE_DATETIME and DATATYPE_TIMESPAN (special cases)
if (obj->Dereference()->DataType() == DATATYPE_DATETIME ||
obj->Dereference()->DataType() == DATATYPE_TIMESPAN)
{
NANOCLR_CHECK_HRESULT(CLR_RT_TypeDescriptor::ExtractObjectAndDataType(obj, dt));
}
else
{
// we already have a pointer to the raw struct
dt = DATATYPE_VALUETYPE;

obj = obj->Dereference();
FAULT_ON_NULL(obj);
}
}
else
{
// ordinary object/array
FAULT_ON_NULL(obj);
NANOCLR_CHECK_HRESULT(CLR_RT_TypeDescriptor::ExtractObjectAndDataType(obj, dt));
}

switch (dt)
{
Expand Down Expand Up @@ -2665,9 +2691,35 @@ HRESULT CLR_RT_Thread::Execute_IL(CLR_RT_StackFrame &stackArg)
}

CLR_RT_HeapBlock *obj = &evalPos[1];
NanoCLRDataType dt = obj->DataType();
NanoCLRDataType dt;

NANOCLR_CHECK_HRESULT(CLR_RT_TypeDescriptor::ExtractObjectAndDataType(obj, dt));
// If it's a byref, it must be a struct instance on the stack/heap
bool instanceIsByRef =
(obj->DataType() == DATATYPE_BYREF) || (obj->DataType() == DATATYPE_ARRAY_BYREF);

if (instanceIsByRef)
{
// extra check for DATATYPE_DATETIME and DATATYPE_TIMESPAN (special cases)
if (obj->Dereference()->DataType() == DATATYPE_DATETIME ||
obj->Dereference()->DataType() == DATATYPE_TIMESPAN)
{
NANOCLR_CHECK_HRESULT(CLR_RT_TypeDescriptor::ExtractObjectAndDataType(obj, dt));
}
else
{
// we already have a pointer to the raw struct
dt = DATATYPE_VALUETYPE;

// follow the byref so obj really points at the struct
obj = obj->Dereference();
}
}
else
{
// ordinary object/array
FAULT_ON_NULL(obj);
NANOCLR_CHECK_HRESULT(CLR_RT_TypeDescriptor::ExtractObjectAndDataType(obj, dt));
}

switch (dt)
{
Expand Down