Skip to content

Commit 81864ab

Browse files
committed
runtime (gc): work around IR generation bug with right shifts
Right shifting more than the size of a type is considered legal by the Go spec, but not by LLVM. As a result, alignMask was returning poison values on 16-bit and 32-bit systems. This is a temporary workaround that assumes that the input size is small.
1 parent b941eb4 commit 81864ab

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/runtime/gc_conservative.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,11 @@ func alignMask(size uintptr) uintptr {
242242
x = x | (x >> 2)
243243
x = x | (x >> 4)
244244
x = x | (x >> 8)
245-
x = x | (x >> 16)
246-
x = x | (x >> 32)
245+
246+
// These do not work due to bugs in our codegen for right shifts.
247+
// These are not strictly necessary for this use case, as the input is known to be < 256.
248+
//x = x | (x >> 16)
249+
//x = x | (x >> 32)
247250

248251
// The highest bit's value is the alignment.
249252
// Shifting down gives us a mask that is one less than the alignment.

0 commit comments

Comments
 (0)