Skip to content

Commit f1476bb

Browse files
Workaround MSVC miscompiling sgen_clz (#114904)
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. Co-authored-by: Alexander Köplinger <[email protected]>
1 parent 557c9c9 commit f1476bb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/mono/mono/sgen/sgen-array-list.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ static inline guint32
6060
sgen_clz (guint32 x)
6161
{
6262
gulong leading_zero_bits;
63-
return _BitScanReverse (&leading_zero_bits, (gulong)x) ? 31 - leading_zero_bits : 32;
63+
if (_BitScanReverse (&leading_zero_bits, (gulong)x))
64+
return 31 - leading_zero_bits;
65+
else
66+
return 32;
6467
}
6568
#elif defined(ENABLE_MSVC_LZCNT) && defined(_MSC_VER)
6669
static inline guint32

0 commit comments

Comments
 (0)