golang/go

gccgo: rejects valid program

ALTree opened this issue · 3 comments

$ gccgo --version
gccgo (Debian 12.2.0-3) 12.2.0

The following valid Go program:

package main

import "math"

func main() {
	f := func(p bool) {
		if p {
			println("hi")
		}
	}
	go f(true || math.Sqrt(2) > 1)
}

compiles and runs on gc, but is rejected by gccgo

$ gccgo main.go 
main.go:11:9: error: too few expressions for struct
   11 |         go f(true || math.Sqrt(2) > 1)
      |         ^

cc @ianlancetaylor

Just a note that the problem is that when the thunk is created the argument is not seen as constant, but when the thunk is later simplified the argument is constant (thanks to the remove_deadcode pass, which changes true || x to simply true). So we build a field in the thunk argument for the struct, but then we don't fill it in. The code needs to be consistent as to whether the argument is constant or not.

Change https://go.dev/cl/440297 mentions this issue: test: add test case that caused a bogus error from gofrontend

Change https://go.dev/cl/440298 mentions this issue: compiler: only build thunk struct type when it is needed