-
Notifications
You must be signed in to change notification settings - Fork 18k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
cmd/compile: float64 to int64 conversion gives different result between amd64 and arm64 on overflows #45588
Comments
For some reason I think this is actually implementation-define behavior, but I'll have a look at the spec real quick. Will CC people in if I can't figure it out. |
Yes, this appears to be working-as-intended. From https://golang.org/ref/spec#Conversions:
That's what specified now. If you think it should work differently, please file a proposal issue for it. Closing this one for now. |
FWIW #6923 seems somewhat related (I think for constants this sort of conversion may be well-defined), but I don't actually see any proposals. I believe for constants these non-representable conversions are caught at compile-time. |
@mknyszek Can you clarify "implementation-dependent" and how to contact the corresponding contributors? |
I think it means specifically that Go implementations are free to choose the behavior, which includes allowing these differences across architectures. I suspect this particular rule is chosen as a performance optimization. In general, the result of such a conversion is fairly non-sensical when you can't represent some value in the new type. By allowing a broad range of behaviors, the compiler is able to generate faster code by not having to deal with the case where the conversion fails. Note that there are lots of places where Go doesn't choose implementation-defined behavior for both platform compatibility and just general programmer sanity, but to me this particular case seems sensible because one frequently can't do anything much with such a conversion. If you'd like to start a discussion about this, the golang-nuts group is a good place to do so. If you have a specific proposal in mind for how this should work, feel free to file a new issue about it with "proposal:" in the title. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
Output (amd64)go env
Output (arm64)What did you do?
Run the following small program on amd64 and arm64: https://play.golang.org/p/8nY1Dwgq-BU
What did you expect to see?
Same result on both platforms.
What did you see instead?
-9223372036854775808
on amd64 and9223372036854775807
on arm64.The text was updated successfully, but these errors were encountered: