Skip to content
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][mini] Fix conversion from r4/r8 to native u #85964

Merged
merged 3 commits into from
Jun 20, 2023

Conversation

BrzVlad
Copy link
Member

@BrzVlad BrzVlad commented May 9, 2023

When converting from float point to unsigned integer, we always do a conversion to u8, then do a simple integer conversion with range checks. The problem is that the first conversion to u8 pushes a STACK_I8 and doing a further conversion to u8 is not actually a nop since it will throw if the result of the previous conversion is negative.

Fixes #69794

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 9, 2023
@ghost ghost assigned BrzVlad May 9, 2023
@BrzVlad BrzVlad added area-Codegen-JIT-mono and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels May 9, 2023
@@ -8992,7 +8995,10 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
if (sp [-1]->type == STACK_R8 || sp [-1]->type == STACK_R4) {
/* floats are always signed, _UN has no effect */
ADD_UNOP (CEE_CONV_OVF_U8);
ADD_UNOP (il_op);
if (TARGET_SIZEOF_VOID_P == 8 && il_op == MONO_CEE_CONV_OVF_U)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be if (!(....)) ADD_UNOP..

@SamMonoRT
Copy link
Member

@BrzVlad - are CI failures related ?

@BrzVlad
Copy link
Member Author

BrzVlad commented May 18, 2023

Yes but only happening on arm64 apparently. VM software would be useful here

When converting from float point to unsigned integer, we always do a conversion to u8, then do a simple integer conversion with range checks. The problem is that the first conversion to u8 pushes a STACK_I8 and doing a further conversion to u8 is not actually a nop since it will throw if the result of the previous conversion is negative.
These follow CoreCLR implementation and don't rely on undefined behavior from out of range conversions.
@BrzVlad BrzVlad merged commit 6352c39 into dotnet:main Jun 20, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jul 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mono incorrectly handles nuint to floating-point conversions
3 participants