-
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
[Mono AOT] Fix error when returning zero sized struct #106013
Conversation
/cc @vitek-karas |
Won't this break scenarios where we might call an AOTed method from the JIT or vice-versa? Or does this not leak out into callers? What happens if you set the ret type to void? do we get ill-formed LLVM IR because we end up trying to return a value? |
I'm not sure I get it. The change is made only on llvm codegen level. The size of the struct is not overridden for any other calls. Without this change we would just encounter compile time error. Am I missing something? I don't think void return type would even enter this code path. Will verify. |
I have disabled the new test on x64 as it results in a new issue #106259 |
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
18f8a70
to
fbb6d5e
Compare
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
Failures seem to be unrelated. |
Is this PR also going to be merged into version 8.0? |
@jkurdek when you have some time, please open a backport, I'll try to get it through the triage. I think it should be doable. |
/backport to release/8.0-staging |
Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/10636307769 |
This PR allows Mono AOT to handle returns of zero sized structs in registers.
Example:
The
[StructLayout(LayoutKind.Sequential, Size = 1)]
attribute will be added during compilation SharpLab.However, adding an explicit
[StructLayout(LayoutKind.Sequential]
or[StructLayout(LayoutKind.Auto)]
will not generate any explicit size metadata causing the struct to have size 0 SharpLab.Mono Codegen:
When processing the return of the
GetFoo()
method mono will evaluate size of structFoo
to be equal to zero. Then it tries to pass it in registers, calculating that it needs0
registers to do so.runtime/src/mono/mono/mini/mini-arm64.c
Line 1708 in bedf340
Mono JIT handles this by omitting codegen part when
cinfo->ret.nregs
is equal to zero.runtime/src/mono/mono/mini/mini-arm64.c
Lines 3894 to 3911 in d606c60
This PR proposes to fix the issue in Mono AOT by treating zero sized structs as if they have size 1.
Fixes #103628
Fixes #106259