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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/mono/mono/sgen/sgen-array-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 uses AI. Check for mistakes.

return 31 - leading_zero_bits;
else
return 32;
}
#elif defined(ENABLE_MSVC_LZCNT) && defined(_MSC_VER)
static inline guint32
Expand Down
Loading