-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: out-of-bounds panic with uint32 conversion and modulus operation in Go 1.22.0 on arm64 #66066
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
Comments
Hm, something very like this was fixed in 1.21.1. In fact, this program panics in 1.21.0 and doesn't in 1.21.1. |
Yeah, definitely the same issue. |
Probably reintroduced at CL 521496 |
@gopherbot please open a backport issue for 1.22. |
Change https://go.dev/cl/568616 mentions this issue: |
Backport issue(s) opened: #66076 (for 1.22). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
Hi, this is Ruinan Thanks for the quick fix! @randall77 After some tests, I find more issues: There are many rules like go/src/cmd/compile/internal/ssa/_gen/ARM64.rules Lines 1228 to 1232 in 6f5d774
The most tricky part is that the type of generated go/src/cmd/compile/internal/ssa/_gen/ARM64.rules Lines 1579 to 1582 in 6f5d774
A small code case: package main
//go:noinline
func test(a uint32) uint64 {
return uint64(uint32(a * 3))
}
func main() {
println(uint64(test(4294967294))) // should be same
println(uint32(test(4294967294)))
return
}
/* results:
18446744073709551610
4294967290
*/ This will also trash the high 32 bits. So we have to be very careful when we're generating And now I no longer work at Arm, so this account @RuinanSun will be deprecated. I can only contribute to Go in my spare time. If this is not in a hurry, I will do a CL after your fix. Thanks! |
Interesting. I don't think the rules you quote are actually broken. I think the actual problem then is this rule:
If the outer one has 64-bit type and the inner one has 32-bit type, then we're removing the extension we actually need. I will try to incorporate this error+fix into my CL. |
Change https://go.dev/cl/571135 mentions this issue: |
On amd64, we always zero-extend when loading arguments from the stack. On arm64, we extend based on the type. This causes problems with zeroUpper*Bits, which reports the top bits are zero when they aren't. Fix it to use the type to decide if the top bits are really zero. For tests, only f32 currently fails on arm64. Added other tests just for future-proofing. Update #66066 Change-Id: I2f13fb47198e139ef13c9a34eb1edc932eea3ee3 Reviewed-on: https://go-review.googlesource.com/c/go/+/571135 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Reviewed-by: David Chase <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
Go version
go version go1.22.0 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
On linux/arm64 and darwin/arm64, with the latest compiler, this program crashes:
What did you see happen?
go run main.go
What did you expect to see?
It should run the same as it does without optimizations:
go run -gcflags="-N -l" main.go
The text was updated successfully, but these errors were encountered: