-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
cmd/compile: does not diagnose constant division by zero #11674
Comments
The spec is not super-clear, but this appears to be a compiler bug: The untyped constants (1e-47, 1e-1000) are converted to float32/complex64 values before the operation, and the conversion results in silent underflow to 0, hence the div-by-zero error. For comparison, in package main ( http://play.golang.org/p/YrUx9sSX3w ) the compiler does exactly that: it converts the untyped 128 into an int8 which is not possible and thus returns an error. |
Analysis: in
Note the call to
here, because For
unfortunately, the
i.e. it moves the value of the real part to
here passes, because rv (the real part) in not zero, and the
lines is not called. I have a simple patch for this (we just need to call |
CL https://golang.org/cl/37891 mentions this issue. |
When casting an ideal to complex{64,128}, for example during the evaluation of var a = complex64(0) / 1e-50 we want the compiler to report a division-by-zero error if a divisor would be zero after the cast. We already do this for floats; for example var b = float32(0) / 1e-50 generates a 'division by zero' error at compile time (because float32(1e-50) is zero, and the cast is done before performing the division). There's no such check in the path for complex{64,128} expressions, and no cast is performed before the division in the evaluation of var a = complex64(0) / 1e-50 which compiles just fine. This patch changes the convlit1 function so that complex ideals components (real and imag) are correctly truncated to float{32,64} when doing an ideal -> complex{64, 128} cast. Fixes golang#11674 Change-Id: Ic5f8ee3c8cfe4c3bb0621481792c96511723d151 Reviewed-on: https://go-review.googlesource.com/37891 Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
gc produces an error for c and d, but not for a and b:
gotype produces errors for all 4 variables.
go version devel +9b04852 Sat Jul 11 00:08:50 2015 +0000 linux/amd64
The text was updated successfully, but these errors were encountered: