Skip to content

[mono] Workaround MSVC miscompiling sgen_clz #114786

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

Merged
merged 1 commit into from
Apr 17, 2025

Conversation

akoeplinger
Copy link
Member

After the recent VS upgrade from 17.12.5 to 17.13.2 we started seeing access violations in the mono-aot-cross.exe when targetting wasm.

We tracked it down to sgen_clz being miscompiled, we can workaround the compiler bug by switching from ternary condition to if/else.

Thanks to @lateralusX for the great help :)

After the recent VS upgrade from 17.12.5 to 17.13.2 we started seeing access violations in the mono-aot-cross.exe when targetting wasm.

We tracked it down to sgen_clz being miscompiled, we can workaround the compiler bug by switching from ternary condition to if/else.
@Copilot Copilot AI review requested due to automatic review settings April 17, 2025 15:55
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

@@ -60,7 +60,10 @@ static inline guint32
sgen_clz (guint32 x)
{
gulong leading_zero_bits;
return _BitScanReverse (&leading_zero_bits, (gulong)x) ? 31 - leading_zero_bits : 32;
if (_BitScanReverse (&leading_zero_bits, (gulong)x))
Copy link
Preview

Copilot AI Apr 17, 2025

Choose a reason for hiding this comment

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

Consider adding an inline comment above this if/else block to explain that the change is a workaround for the MSVC miscompilation issue encountered in VS 17.13.2.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

@akoeplinger
Copy link
Member Author

/ba-g CI is blocked due to other issues but this is a no-op change so merging to unblock the runtime -> sdk flow

@akoeplinger
Copy link
Member Author

/backport to release/9.0-staging

@akoeplinger
Copy link
Member Author

/backport to release/8.0-staging

Copy link
Contributor

Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/14593713790

Copy link
Contributor

Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/14593716274

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants