mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-07 20:43:40 +00:00
loader, unicode/utf8: fix hiBits overflow on 16-bit AVR targets
Go 1.26 added SWAR optimizations to unicode/utf8 that use: const ptrSize = 4 << (^uintptr(0) >> 63) const hiBits = 0x8080808080808080 >> (64 - 8*ptrSize) This formula only distinguishes 32-bit and 64-bit architectures. On AVR (16-bit uintptr), ptrSize computes as 4, and hiBits becomes 0x80808080 (2155905152) which overflows the 16-bit uintptr type. Fix by providing a patched unicode/utf8 overlay for Go 1.26+ that uses a ptrSize formula handling all three sizes (16/32/64-bit): const ptrSize = 1 << (^uintptr(0)>>15&1 + ^uintptr(0)>>31&1 + ^uintptr(0)>>63&1) This evaluates to 2 on AVR, 4 on 32-bit, and 8 on 64-bit. The word() helper also gains a ptrSize==2 case for 16-bit loads.
This commit is contained in:
@@ -273,6 +273,16 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool {
|
||||
paths["internal/syscall/"] = true
|
||||
paths["internal/syscall/unix/"] = false
|
||||
}
|
||||
|
||||
if goMinor >= 26 {
|
||||
// Go 1.26 added SWAR optimizations to unicode/utf8 that use
|
||||
// constants assuming at least 32-bit uintptr. TinyGo supports
|
||||
// 16-bit targets (AVR) where these constants overflow, so we
|
||||
// provide a patched version.
|
||||
paths["unicode/"] = true
|
||||
paths["unicode/utf8/"] = false
|
||||
}
|
||||
|
||||
return paths
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user