Skip to content

cmd/compile: runtime.KeepAlive doesn't work #22458

@aclements

Description

@aclements

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

go version devel +bd48d37e30 Thu Oct 26 17:29:27 2017 +0000 linux/amd64

Does this issue reproduce with the latest release?

Go 1.9 produces an internal compiler error.
Go 1.8 works.

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/austin/r/go"
GORACE=""
GOROOT="/home/austin/gotmp"
GOTOOLDIR="/home/austin/gotmp/pkg/tool/linux_amd64"
GCCGO="/usr/bin/gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build276745456=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

The following program creates a 64MB linked list and then starts to reverse it. (This is distilled from a benchmark.)

https://play.golang.org/p/P3GLK4gz7u

What did you expect to see?

The program uses runtime.KeepAlive to keep the list alive until the function returns, so I would expect the heap size before and after the reversal to be the same:

heap size before: 64 MB
heap size after (should be the same): 64 MB

What did you see instead?

In Go 1.8, I get the above output.

In Go 1.9, I get an ICE (this can be seen on the playground):

./xxx.go:41:19: internal compiler error: internal error: main prev (type *node) recorded as live on entry

goroutine 1 [running]:
runtime/debug.Stack(0x0, 0x0, 0x0)
	/home/austin/gotmp/src/runtime/debug/stack.go:24 +0xa7
cmd/compile/internal/gc.Fatalf(0xb6e637, 0x2f, 0xc42036b418, 0x2, 0x2)
	/home/austin/gotmp/src/cmd/compile/internal/gc/subr.go:181 +0x230
cmd/compile/internal/gc.livenessepilogue(0xc4200c63c0)
	/home/austin/gotmp/src/cmd/compile/internal/gc/plive.go:772 +0x12c8
cmd/compile/internal/gc.liveness(0xc420395cb0, 0xc42000e3c0, 0x0)
	/home/austin/gotmp/src/cmd/compile/internal/gc/plive.go:1293 +0xad
cmd/compile/internal/gc.genssa(0xc42000e3c0, 0xc42008e820)
	/home/austin/gotmp/src/cmd/compile/internal/gc/ssa.go:4383 +0x12d6
cmd/compile/internal/gc.compileSSA(0xc420390160, 0x0)
	/home/austin/gotmp/src/cmd/compile/internal/gc/pgen.go:242 +0x7e
cmd/compile/internal/gc.compile(0xc420390160)
	/home/austin/gotmp/src/cmd/compile/internal/gc/pgen.go:219 +0x218
cmd/compile/internal/gc.funccompile(0xc420390160)
	/home/austin/gotmp/src/cmd/compile/internal/gc/dcl.go:1049 +0xb7
cmd/compile/internal/gc.Main(0xb73f98)
	/home/austin/gotmp/src/cmd/compile/internal/gc/main.go:585 +0x29d2
main.main()
	/home/austin/gotmp/src/cmd/compile/main.go:49 +0x95

command failed: exit status 2

On master, I get:

heap size before: 64 MB
heap size after (should be the same): 0 MB

Which suggests KeepAlive just isn't working.

If I uncomment the println(prev, head) at the end, all three produce the expected output.

/cc @iant @randall77

Metadata

Metadata

Assignees

No one assigned

    Labels

    CherryPickApprovedUsed during the release process for point releasesFrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions