golang/go

cmd/compile: hangs converting int const to complex64

dvyukov opened this issue · 4 comments

gc hangs compiling the following program:

package p
func f() { _ = complex64(0x9EEbcab0Aa2DDe942Ea0aef5Aeb6bFF2dfcaf) }

go version devel +71832ff Fri Jul 3 21:39:04 2015 +0000 linux/amd64

The compiler gets stuck trying to print an error message.

While compiling the above snippet, gc reaches the following line in the overflow function inside gc/compile/const.go:

Yyerror("constant %s overflows %v", Vconv(v, 0), t)

Vconv calls the Fconv function in gc/compile/mparith3, where gc dies in an infinite loop caused by the fact that the number to be printed in the error message is +Inf, but Fconv tries to scale it to a reasonable size in a loop before printing the error, dividing it by 10 and checking for m => 10 (which will never became false if m is +Inf).

A quick way to fix this is to change the overflow function so that it doesn't print any error when it gets Inf floats (which is correct, since +Inf does not overflows float32 o float64: it's a valid float32 value).

A const xxxx overflows float32 is already printed by the frontend when the number is parsed the first time, so we shouldn't loose any informative error message (I hope).

Nope, looks like we lose the error message in certain cases. It's probably better to fix the Fconv function so that at least it prints something on Inf input.

CL https://golang.org/cl/16620 mentions this issue.

rsc commented

Dup of #11590.