Uh oh!
There was an error while loading. Please reload this page.
Error out when struct size is bigger than int.MaxValue - #104393
Conversation
jkotas
commented
Jul 3, 2024
Do we need a test? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
@jkotas This PR is ready to be reviewed again. |
MichalStrehovsky
commented
Jul 11, 2024
I've pushed out a change that makes further progress in the handling within the managed type system, but the test probably still won't compile because CoreCLR is fine with this overflowing but the managed type system isn't. I'm not sure if the overflow is an actual problem but fixing it doesn't look exactly trivial. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
fanyang-mono
commented
Jul 15, 2024
@MichalStrehovsky Is there a way to stop the new test from being compiled by NativeAOT? |
MichalStrehovsky
commented
Jul 15, 2024
Only by placing Note that this is the managed type system that is shared with crossgen2. Might want to run crossgen2 outerloop testing to see whether this also needs to be removed from precompilation there. The managed type system doesn't handle this test because the size of the |
fanyang-mono
commented
Jul 15, 2024
@MichalStrehovsky Based on Jan's comment from earlier. Loading |
MichalStrehovsky
commented
Jul 15, 2024
The size of it gets aligned when boxing it, because it's 8 bytes larger (MethodTable pointer) and aligned. On CoreCLR today, doing: BigArray.Instance=newBigArray();longbefore=GC.GetAllocatedBytesForCurrentThread();BigArray.Instance=newBigArray();Console.WriteLine(GC.GetAllocatedBytesForCurrentThread()-before);[StructLayout(LayoutKind.Sequential,Size=int.MaxValue)]structBigArray{publicstaticobjectInstance;}Will print 2,147,483,664, which is larger than int.MaxValue. |
fanyang-mono
commented
Jul 15, 2024
/azp list |
MichalStrehovsky
commented
Jul 15, 2024
We chatted with Fan on Teams about this and apparently the program I posted only works on a Release build (also without debugger attached) and throws InvalidProgram otherwise. On .NET 8 CoreCLR-JIT. Curious. |
fanyang-mono
commented
Aug 7, 2024
@MichalStrehovsky CoreCLR and Mono side of work has been completed and approved. The remaining piece of work is related to NativeAOT/Crossgen2. I am going to transfer the ownership of this PR to you, since you will be working on that. Additionally, this could probably be merged for .NET9, as I don't think that this is a breaking change. @jkotas Please correct me, if I were wrong. |
MichalStrehovsky
commented
Aug 7, 2024
I'll not have time to look at this any time soon. Might be better to just block the test on an issue and not block this PR.
Throwing an exception in a situation that didn't throw before is the definition of a breaking change. |
fanyang-mono
commented
Aug 7, 2024
Discussed with @jkotas offline. He suggested to wait for .NET10 to merge it, together with the NativeAOT change, when it is ready. There is no rush. @MichalStrehovsky |
fanyang-mono
commented
Aug 9, 2024
I plan to merge this PR when main is .NET10. The managed type system part used by NativeAOT and crossgen can be worked on later during .NET10 release. |
fanyang-mono
commented
Aug 9, 2024
/azp run runtime-coreclr crossgen2 |
|
Azure Pipelines successfully started running 1 pipeline(s). |
fanyang-mono
commented
Aug 11, 2024
/azp run runtime-coreclr crossgen2 |
|
Azure Pipelines successfully started running 1 pipeline(s). |
fanyang-mono
commented
Aug 15, 2024
/azp run runtime-coreclr crossgen2 |
|
Azure Pipelines successfully started running 1 pipeline(s). |
fanyang-mono
commented
Aug 21, 2024
CI failures are unrelated to this PR. |
Fixes: #97412
sizeof()in C# returns a signed integer. This PR is to adjust the runtime to match with that.Added a check for struct size and a test.