Skip to content

cmd/compile: internal compiler error len larger than cap for OSLICEHEADER #77919

Closed

Description

@lmaltsis

Go version

go version go1.27-devel_b5c2bd7e05 Mon Mar 2 18:43:01 2026 -0800 linux/amd64

Output of go env in your module/workspace:

$ /research/compilers/go env
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3429397299=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/user/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/user/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/user/software/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/user/software/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.27-devel_b5c2bd7e05 Mon Mar 2 18:43:01 2026 -0800'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

go.dev/play link: https://go.dev/play/p/8hCTRC1ehCi?v=gotip

on stable

$ go build /tmp/bug.go
# command-line-arguments
/tmp/bug.go:9:16: internal compiler error: len larger than cap for OSLICEHEADER

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
$ cat /tmp/bug.go
package main
import (
	"fmt"
)

func main() {
	i := 0
	output := make([]string, 8, i)
	fmt.Println(output)
}
$ go version
go version go1.25.7 linux/amd64

on trunk with stacktrace

$ go build /tmp/bug.go
# command-line-arguments
/tmp/bug.go:9:16: internal compiler error: len larger than cap for OSLICEHEADER

[stacktrace below]
$ go version
go version go1.27-devel_b5c2bd7e05 Mon Mar 2 18:43:01 2026 -0800 linux/amd64

What did you see happen?

goroutine 1 [running]:
runtime/debug.Stack()
        /home/user/software/go/src/runtime/debug/stack.go:26 +0x5e
cmd/compile/internal/base.FatalfAt({0xfc5038?, 0x0?}, {0xf97731, 0x24}, {0x0, 0x0, 0x0})
        /home/user/software/go/src/cmd/compile/internal/base/print.go:232 +0x18b
cmd/compile/internal/base.Fatalf(...)
        /home/user/software/go/src/cmd/compile/internal/base/print.go:197
cmd/compile/internal/typecheck.tcSliceHeader(0x10f06a768120)
        /home/user/software/go/src/cmd/compile/internal/typecheck/expr.go:838 +0x34a
cmd/compile/internal/typecheck.typecheck1({0xfd2e28?, 0x10f06a768120?}, 0x12)
        /home/user/software/go/src/cmd/compile/internal/typecheck/typecheck.go:373 +0x1e16
cmd/compile/internal/typecheck.typecheck({0xfd2e28, 0x10f06a768120}, 0x12)
        /home/user/software/go/src/cmd/compile/internal/typecheck/typecheck.go:179 +0x1ad
cmd/compile/internal/typecheck.assign({0xfd36c0, 0x10f06a7625f0}, {0x10f069d72c88, 0x1, 0x60d7e5?}, {0x10f069d72c78, 0x1, 0x2?})
        /home/user/software/go/src/cmd/compile/internal/typecheck/stmt.go:82 +0xa5
cmd/compile/internal/typecheck.tcAssign(...)
        /home/user/software/go/src/cmd/compile/internal/typecheck/stmt.go:36
cmd/compile/internal/typecheck.typecheck1({0xfd36c0?, 0x10f06a7625f0?}, 0x1)
        /home/user/software/go/src/cmd/compile/internal/typecheck/typecheck.go:509 +0x305
cmd/compile/internal/typecheck.typecheck({0xfd36c0, 0x10f06a7625f0}, 0x1)
        /home/user/software/go/src/cmd/compile/internal/typecheck/typecheck.go:179 +0x1ad
cmd/compile/internal/typecheck.Stmt(...)
        /home/user/software/go/src/cmd/compile/internal/typecheck/typecheck.go:20
cmd/compile/internal/walk.appendWalkStmt(0x10f069d73770, {0xfd36c0, 0x10f06a7625f0})
        /home/user/software/go/src/cmd/compile/internal/walk/walk.go:263 +0x46
cmd/compile/internal/walk.walkMakeSlice(0x10f069d863c0, 0x10f069d73770)
        /home/user/software/go/src/cmd/compile/internal/walk/builtin.go:545 +0x16a9
cmd/compile/internal/walk.walkExpr1({0xfd4728, 0x10f069d863c0}, 0x10f069d73770)
        /home/user/software/go/src/cmd/compile/internal/walk/expr.go:312 +0x89e
cmd/compile/internal/walk.walkExpr({0xfd4728, 0x10f069d863c0}, 0x10f069d73770)
        /home/user/software/go/src/cmd/compile/internal/walk/expr.go:60 +0x328
cmd/compile/internal/walk.walkAssign(0x10f069d73770, {0xfd36c0, 0x10f069d77a90})
        /home/user/software/go/src/cmd/compile/internal/walk/assign.go:73 +0xd2f
cmd/compile/internal/walk.walkExpr1({0xfd36c0, 0x10f069d77a90}, 0x10f069d73770)
        /home/user/software/go/src/cmd/compile/internal/walk/expr.go:204 +0x408
cmd/compile/internal/walk.walkExpr({0xfd36c0, 0x10f069d77a90}, 0x10f069d73770)
        /home/user/software/go/src/cmd/compile/internal/walk/expr.go:60 +0x328
cmd/compile/internal/walk.walkStmt({0xfd36c0, 0x10f069d77a90})
        /home/user/software/go/src/cmd/compile/internal/walk/stmt.go:60 +0x51a
cmd/compile/internal/walk.walkStmtList(...)
        /home/user/software/go/src/cmd/compile/internal/walk/stmt.go:176
cmd/compile/internal/walk.Walk(0x10f069cf1180)
        /home/user/software/go/src/cmd/compile/internal/walk/walk.go:43 +0x27b
cmd/compile/internal/gc.prepareFunc(0x10f069cf1180)
        /home/user/software/go/src/cmd/compile/internal/gc/compile.go:123 +0x105
cmd/compile/internal/gc.enqueueFunc(0x10f069cf1180, 0x10f069d73bb0)
        /home/user/software/go/src/cmd/compile/internal/gc/compile.go:85 +0x351
cmd/compile/internal/gc.Main(0x18fdb50)
        /home/user/software/go/src/cmd/compile/internal/gc/main.go:333 +0x152b
main.main()
        /home/user/software/go/src/cmd/compile/main.go:57 +0xf9

What did you expect to see?

Same behavior as https://go.dev/play/p/63hF9Fibhsy?v=gotip

$ cat /tmp/correct.go
package main
import (
        "fmt"
)

func main() {
        output := make([]string, 8, 0)
        fmt.Println(output)
}
$ go build /tmp/correct.go
./prog.go:8:27: invalid argument: length and capacity swapped

Activity

  1. changed the title [-]len larger than cap for OSLICEHEADER[/-] [+]ICE: len larger than cap for OSLICEHEADER[/+] on Mar 3, 2026
  2. added
    BugReportIssues describing a possible bug in the Go implementation.
    on Mar 3, 2026
  3. gopherbot commented on Mar 3, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/751040 mentions this issue: cmd/compile/internal/typecheck: simplify tcSliceHeader

  4. self-assigned this
    on Mar 3, 2026
  5. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Mar 3, 2026
  6. cuonglm commented on Mar 3, 2026

    @cuonglm
    Member

    @gopherbot Please backport this to go1.25 and go1.26 branch.

    This causes an ICE when compiling certain programs with non-constant argument to make.

  7. gopherbot commented on Mar 3, 2026

    @gopherbot
    Contributor

    Backport issue(s) opened: #77921 (for 1.25), #77922 (for 1.26).

    Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

  8. changed the title [-]ICE: len larger than cap for OSLICEHEADER[/-] [+]cmd/compile: internal compiler error len larger than cap for OSLICEHEADER[/+] on Mar 3, 2026
  9. gopherbot commented on Mar 4, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/751380 mentions this issue: cmd/compile: remove left over constant checking

  10. added this to the Go1.27 milestone on Mar 4, 2026
  11. added
    FixPendingIssues that have a fix which has not yet been reviewed or submitted.
    and removed
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Mar 4, 2026
  12. added a commit that references this issue on Mar 6, 2026
    bf1b097
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions