-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Implement sizeof() in the interpreter #115745
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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_pLastNewIns->SetDVar(m_pStackPointer[-1].var); | |
| m_pLastNewIns->SetDVar(m_pStackPointer[-1].var); | |
| // Increment the instruction pointer by 5 to account for the 1-byte opcode | |
| // and the 4-byte operand (e.g., a token or offset) of the CEE_SIZEOF instruction. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -416,6 +416,9 @@ public static void RunInterpreterTests() | |||||
| if (!TestArray()) | ||||||
| Environment.FailFast(null); | ||||||
|
|
||||||
| if (!TestSizeof()) | ||||||
| Environment.FailFast(null); | ||||||
|
||||||
| Environment.FailFast(null); | |
| Environment.FailFast("TestSizeof failed."); |
Copilot
AI
May 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider adding a comment explaining the assumptions behind MyStruct's size (e.g. packing or field types) to clarify why the expected size is 4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems it would make sense to add CHECK_STACK(1);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I thought CHECK_STACK was "make sure this many items are on the stack"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I guess I am wrong in this case, I haven't realized the token is not on the stack.