Skip to content

cmd/compile: panic during generic deadcode #56777

@olegbespalov

Description

@olegbespalov

What version of Go are you using (go version)?

$  gotip version
go version devel go1.20-fee0ab8b Thu Nov 17 03:47:35 2022 +0000 linux/amd64

Does this issue reproduce with the latest release?

Not from my experience

What operating system and processor architecture are you using (go env)?

gotip env Output
$ gotip env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/olegbespalov/.cache/go-build"
GOENV="/home/olegbespalov/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/olegbespalov/go/pkg/mod"
GOOS="linux"
GOPATH="/home/olegbespalov/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/olegbespalov/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/olegbespalov/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.20-fee0ab8b Thu Nov 17 03:47:35 2022 +0000"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/olegbespalov/projects/sandbox/go/panic2/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1161513378=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Run

gotip run main.go

main.go

package main

func main() {
}

func fn(setText []rune, negate bool) int {
	ranges := []singleRange{}

	if len(setText) > 0 {
		fillFirst := false
		l := len(setText)
		if negate {
			if setText[0] == 0 {
				setText = setText[1:]
			} else {
				l++
				fillFirst = true
			}
		}

		if l%2 == 0 {
			ranges = make([]singleRange, l/2)
		} else {
			ranges = make([]singleRange, l/2+1)
		}

		first := true
		if fillFirst {
			ranges[0] = singleRange{first: 0}
			first = false
		}

		i := 0
		for _, r := range setText {
			if first {
				// lower bound in a new range
				ranges[i] = singleRange{first: r}
				first = false
			} else {
				ranges[i].last = r - 1
				i++
				first = true
			}
		}
	}

	return len(ranges)
}

type singleRange struct {
	first rune
	last  rune
}

What did you expect to see?

No panics.

What did you see instead?

A panic during generic deadcode.

panic during generic deadcode
 gotip run main.go
go build command-line-arguments: # command-line-arguments
./main.go:9:20: internal compiler error: 'fn': panic during generic deadcode while compiling fn:

runtime error: index out of range [1] with length 1

goroutine 9 [running]:
cmd/compile/internal/ssa.Compile.func1()
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/ssa/compile.go:49 +0x71
panic({0xd84160, 0xc00002eb28})
        /home/olegbespalov/sdk/gotip/src/runtime/panic.go:884 +0x213
cmd/compile/internal/ssa.liveValues(0xc000442b60, {0xc000028bd0, 0x23, 0x1e?})
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/ssa/deadcode.go:145 +0x6a8
cmd/compile/internal/ssa.deadcode(0xc000442b60)
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/ssa/deadcode.go:206 +0x1cc
cmd/compile/internal/ssa.Compile(0xc000442b60)
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/ssa/compile.go:97 +0x963
cmd/compile/internal/ssagen.buildssa(0xc00042f900, 0x3)
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/ssagen/ssa.go:572 +0x2027
cmd/compile/internal/ssagen.Compile(0xc00042f900, 0x0?)
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/ssagen/pgen.go:185 +0x4c
cmd/compile/internal/gc.compileFunctions.func5.1(0xc000083980?)
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/gc/compile.go:171 +0x3a
cmd/compile/internal/gc.compileFunctions.func3.1()
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/gc/compile.go:153 +0x32
created by cmd/compile/internal/gc.compileFunctions.func3
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/gc/compile.go:152 +0x245



goroutine 9 [running]:
runtime/debug.Stack()
        /home/olegbespalov/sdk/gotip/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x46d7f0?, 0xc0?}, {0xc00002be00, 0x32}, {0xc0004599a0, 0x5, 0x5})
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/base/print.go:227 +0x1d7
cmd/compile/internal/base.Fatalf(...)
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/ssagen.(*ssafn).Fatalf(0xc00046d828?, {0x6ac31e88?, 0x7f89?}, {0xde0d3c, 0x2c}, {0xc00044dc00, 0x4, 0x0?})
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/ssagen/ssa.go:7831 +0x177
cmd/compile/internal/ssa.(*Func).Fatalf(0xc000442b60, {0xde0d3c, 0x2c}, {0xc00044dc00, 0x4, 0x4})
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/ssa/func.go:719 +0x28b
cmd/compile/internal/ssa.Compile.func1()
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/ssa/compile.go:54 +0x1bc
panic({0xd84160, 0xc00002eb28})
        /home/olegbespalov/sdk/gotip/src/runtime/panic.go:884 +0x213
cmd/compile/internal/ssa.liveValues(0xc000442b60, {0xc000028bd0, 0x23, 0x1e?})
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/ssa/deadcode.go:145 +0x6a8
cmd/compile/internal/ssa.deadcode(0xc000442b60)
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/ssa/deadcode.go:206 +0x1cc
cmd/compile/internal/ssa.Compile(0xc000442b60)
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/ssa/compile.go:97 +0x963
cmd/compile/internal/ssagen.buildssa(0xc00042f900, 0x3)
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/ssagen/ssa.go:572 +0x2027
cmd/compile/internal/ssagen.Compile(0xc00042f900, 0x0?)
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/ssagen/pgen.go:185 +0x4c
cmd/compile/internal/gc.compileFunctions.func5.1(0xc000083980?)
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/gc/compile.go:171 +0x3a
cmd/compile/internal/gc.compileFunctions.func3.1()
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/gc/compile.go:153 +0x32
created by cmd/compile/internal/gc.compileFunctions.func3
        /home/olegbespalov/sdk/gotip/src/cmd/compile/internal/gc/compile.go:152 +0x245

We saw it recently in our CI. The panicing code is from one of our dependencies.

I tried to git bisect, and it showed me that this commit fd59c6c is the one where it started, but maybe I'm wrong here 🤷

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions