Repository navigation
Description
Go version
go version go1.27.1 linux/amd64
go version go1.26.8 linux/amd64
go version go1.28-devel_12c76d44 Tue Sep 22 02:16:50 2026 -0700 linux/amd64
All three gc versions reproduce the problem. The development version was built from unmodified commit 12c76d447f576e6c14c566c8524c13a0c0d476b9, the master HEAD fetched on 2026-09-22.
Output of go env in your module/workspace
Relevant go env -json output from the fresh Go 1.27.1 container:
{
"CGO_ENABLED": "0",
"GOARCH": "amd64",
"GOCACHE": "/work/cache",
"GOENV": "",
"GOEXPERIMENT": "",
"GOFLAGS": "",
"GOHOSTARCH": "amd64",
"GOHOSTOS": "linux",
"GOMODCACHE": "/work/modcache",
"GOOS": "linux",
"GOPATH": "/work/gopath",
"GOPROXY": "off",
"GOROOT": "/usr/local/go",
"GOSUMDB": "off",
"GOTOOLCHAIN": "local",
"GOTOOLDIR": "/usr/local/go/pkg/tool/linux_amd64",
"GOVERSION": "go1.27.1"
}The other two versions used /opt/go as GOROOT, /opt/go/pkg/tool/linux_amd64 as GOTOOLDIR, and their corresponding GOVERSION values. The checks used fresh Debian 12 containers on the same Linux/amd64 host, with gc, networking disabled, and an explicitly cleared environment. GOENV=off was set; go env reported the empty value shown above. Build caches started empty for each version and were shared only among that version's cases.
What did you do?
Save this as make-trace-assert.go:
package main
var trace int
func f(x int) int { trace = trace*10 + x; return x }
func main() {
s := make([]int, f(1), f(3))
if trace != 13 { panic(trace) }
if len(s) != 1 || cap(s) != 3 { panic("shape") }
}Build and run with the stock gc toolchain:
GOTOOLCHAIN=local GOENV=off GOFLAGS= GOEXPERIMENT= CGO_ENABLED=0 go build -p 2 -o program make-trace-assert.go
./programThe assertion records call order in an integer and checks the resulting slice length and capacity.
What did you see happen?
On all three versions, the default executable panics with panic: 31 and exits with status 2. This indicates that f(3) ran before f(1). Builds succeed with exit 0. Stdout is empty. The exact stderr from the Go 1.27.1 container is:
panic: 31
goroutine 1 [running]:
main.main()
/work/sources/make-trace-assert.go:9 +0x46
The result matrix below is identical for Go 1.26.8, Go 1.27.1, and the development commit:
| Build setting | Assertion result |
|---|---|
| default | panic: 31, executable exit 2 |
-gcflags=-N |
panic: 31, executable exit 2 |
-gcflags=-l |
normal exit 0 |
-gcflags='-N -l' |
normal exit 0 |
Adding //go:noinline to f, or evaluating f(1) and f(3) in separate preceding statements, also made the program exit normally on all three versions.
What did you expect to see?
Normal exit: the calls to f(1) and f(3) should occur in that order, leaving trace == 13 and a slice with length 1 and capacity 3.
The order-of-evaluation rule specifies lexical left-to-right order for function calls. Both size operands here are function calls; this is not a question about the unspecified ordering of a plain variable read relative to a call. The make specification does not provide an exception for these calls.
Related report
#74379 is related history concerning missing side effects. Its make regression test uses one explicit size argument. In the example here, both calls occur, but their order is reversed. I did not find an exact matching report in the issue search; please link a duplicate if one exists.
Discovery context
I encountered this behavior while developing executable Go semantics in the K Framework and comparing specification-derived test cases against the Go compiler. The reproducer above uses only the Go toolchain.
A snapshot of the semantics implementation is available at ba97042.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
thepudds commentedon Sep 23, 2026
Hi @0xkohe, thank you for the report. I'll take a look.
gabyhelp commentedon Sep 23, 2026
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
zigo101 commentedon Sep 26, 2026
This doesn't look like an evaluation order problem. It looks like theffunction is called one time more than expected.[Edit] Aha, not really.
randall77 commentedon Sep 26, 2026
This looks like an evaluation order bug in escape analysis. Both calls to
fare inlined, and the compiler notices that the capacity is constant. It rewrites themaketo have a literal constant capacity so it can be stack allocated. It also makes sure the previous capacity expression is evaluated, for its side effects. But it doesn't consider that the length expression might have side effects, so the capacity expression ends up being evaluated first.Seems related to CL 684116. Maybe just that that CL is incomplete. @thepudds
gopherbot commentedon Sep 27, 2026
Change https://go.dev/cl/839725 mentions this issue:
cmd/compile: keep make's evaluation order when rewriting with literalscmd/compile: keep make's evaluation order when rewriting with literals