-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Error out when struct size is bigger than int.MaxValue #104393
Conversation
Do we need a test? |
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
@jkotas This PR is ready to be reviewed again. |
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. |
@MichalStrehovsky Is there a way to stop the new test from being compiled by NativeAOT? |
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 |
@MichalStrehovsky Based on Jan's comment from earlier. Loading |
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 = new BigArray();
long before = GC.GetAllocatedBytesForCurrentThread();
BigArray.Instance = new BigArray();
Console.WriteLine(GC.GetAllocatedBytesForCurrentThread() - before);
[StructLayout(LayoutKind.Sequential, Size = int.MaxValue)]
struct BigArray
{
public static object Instance;
} Will print 2,147,483,664, which is larger than int.MaxValue. |
/azp list |
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. |
@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. |
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. |
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 |
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. |
/azp run runtime-coreclr crossgen2 |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-coreclr crossgen2 |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-coreclr crossgen2 |
Azure Pipelines successfully started running 1 pipeline(s). |
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.