diff --git a/src/coreclr/interpreter/compiler.cpp b/src/coreclr/interpreter/compiler.cpp index 354427c9c6a899..b2ea69924dbdc6 100644 --- a/src/coreclr/interpreter/compiler.cpp +++ b/src/coreclr/interpreter/compiler.cpp @@ -3500,6 +3500,16 @@ int InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo) m_pLastNewIns->SetDVar(m_pStackPointer[-1].var); m_ip++; break; + case CEE_SIZEOF: + { + CORINFO_CLASS_HANDLE clsHnd = ResolveClassToken(getU4LittleEndian(m_ip + 1)); + AddIns(INTOP_LDC_I4); + m_pLastNewIns->data[0] = m_compHnd->getClassSize(clsHnd); + PushStackType(StackTypeI4, NULL); + m_pLastNewIns->SetDVar(m_pStackPointer[-1].var); + m_ip += 5; + break; + } default: assert(0); break; diff --git a/src/tests/JIT/interpreter/Interpreter.cs b/src/tests/JIT/interpreter/Interpreter.cs index fd80f67991b7d0..866102e9f2e480 100644 --- a/src/tests/JIT/interpreter/Interpreter.cs +++ b/src/tests/JIT/interpreter/Interpreter.cs @@ -416,6 +416,9 @@ public static void RunInterpreterTests() if (!TestArray()) Environment.FailFast(null); + if (!TestSizeof()) + Environment.FailFast(null); + System.GC.Collect(); } @@ -945,4 +948,15 @@ public static bool ArrayDouble(int length, double value) return true; } + + public static unsafe bool TestSizeof() + { + if (sizeof(int) != 4) + return false; + if (sizeof(double) != 8) + return false; + if (sizeof(MyStruct) != 4) + return false; + return true; + } }