Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: SIGSEGV with 'go build' #50968

Closed
olivere opened this issue Feb 2, 2022 · 3 comments
Closed

cmd/compile: SIGSEGV with 'go build' #50968

olivere opened this issue Feb 2, 2022 · 3 comments

Comments

@olivere
Copy link

@olivere olivere commented Feb 2, 2022

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

$ go version
go version go1.17.6 darwin/arm64

Does this issue reproduce with the latest release?

Yes.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/oliver/Library/Caches/go-build"
GOENV="/Users/oliver/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/oliver/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/oliver"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/oliver/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/oliver/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/oliver/tmp/dict/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/tg/tvt4qm6d71q6p6v6g8dgbwc00000gn/T/go-build160318427=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package main

import "fmt"

func main() {
	d := make(map[string]string)

	// I meant that to be:
	// for k, v := range d { ... }
	//
	// But I didn't expect it to crash a build, but get an error.
	for _, k, v := range d {
		fmt.Println(k, v)
	}
}

See code on Go Play.

What did you expect to see?

A proper build-time error.

What did you see instead?

A crash in the compiler:

$ go build
# dict.dev
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x5c pc=0x104ca1da0]

goroutine 1 [running]:
cmd/compile/internal/types.(*Type).HasPointers(0x0)
	/usr/local/go/src/cmd/compile/internal/types/type.go:1592 +0x20
cmd/compile/internal/escape.(*escape).exprSkipInit(0x140000ea1c0, {0x14000381030, 0x0, 0x0, 0x0, 0x0}, {0x10558f668, 0x14000406ea0})
	/usr/local/go/src/cmd/compile/internal/escape/escape.go:584 +0x124
cmd/compile/internal/escape.(*escape).expr(0x140000ea1c0, {0x14000381030, 0x0, 0x0, 0x0, 0x0}, {0x10558f668, 0x14000406ea0})
	/usr/local/go/src/cmd/compile/internal/escape/escape.go:566 +0x78
cmd/compile/internal/escape.(*escape).assignList(0x140000ea1c0, {0x140000ea060, 0x2, 0x2}, {0x140000ea040, 0x2, 0x2}, {0x1053613da, 0xb}, {0x10558dca0, ...})
	/usr/local/go/src/cmd/compile/internal/escape/escape.go:972 +0x354
cmd/compile/internal/escape.(*escape).stmt(0x140000ea1c0, {0x10558dca0, 0x140000b0180})
	/usr/local/go/src/cmd/compile/internal/escape/escape.go:508 +0xc74
cmd/compile/internal/escape.(*escape).stmts(0x140000ea1c0, {0x14000444100, 0xe, 0x10})
	/usr/local/go/src/cmd/compile/internal/escape/escape.go:548 +0x74
cmd/compile/internal/escape.(*escape).stmt(0x140000ea1c0, {0x10558e088, 0x140000b2140})
	/usr/local/go/src/cmd/compile/internal/escape/escape.go:400 +0x9f8
cmd/compile/internal/escape.(*escape).stmts(0x140000ea1c0, {0x1400005c140, 0x1, 0x1})
	/usr/local/go/src/cmd/compile/internal/escape/escape.go:548 +0x74
cmd/compile/internal/escape.(*escape).block(...)
	/usr/local/go/src/cmd/compile/internal/escape/escape.go:555
cmd/compile/internal/escape.(*escape).stmt(0x140000ea1c0, {0x10558f988, 0x14000404360})
	/usr/local/go/src/cmd/compile/internal/escape/escape.go:457 +0x988
cmd/compile/internal/escape.(*escape).stmts(0x140000ea1c0, {0x14000068340, 0x2, 0x2})
	/usr/local/go/src/cmd/compile/internal/escape/escape.go:548 +0x74
cmd/compile/internal/escape.(*escape).block(0x140000ea1c0, {0x14000068340, 0x2, 0x2})
	/usr/local/go/src/cmd/compile/internal/escape/escape.go:555 +0x48
cmd/compile/internal/escape.(*batch).walkFunc(0x1400000a480, 0x14000400160)
	/usr/local/go/src/cmd/compile/internal/escape/escape.go:307 +0x118
cmd/compile/internal/escape.Batch({0x140000ae070, 0x1, 0x1}, 0x0)
	/usr/local/go/src/cmd/compile/internal/escape/escape.go:229 +0x1d4
cmd/compile/internal/ir.(*bottomUpVisitor).visit(0x14000098750, 0x14000400160)
	/usr/local/go/src/cmd/compile/internal/ir/scc.go:128 +0x3a8
cmd/compile/internal/ir.VisitFuncsBottomUp({0x14000068360, 0x2, 0x2}, 0x10556a6c8)
	/usr/local/go/src/cmd/compile/internal/ir/scc.go:60 +0x11c
cmd/compile/internal/escape.Funcs(...)
	/usr/local/go/src/cmd/compile/internal/escape/escape.go:1821
cmd/compile/internal/gc.Main(0x10556a630)
	/usr/local/go/src/cmd/compile/internal/gc/main.go:253 +0xef4
main.main()
	/usr/local/go/src/cmd/compile/main.go:55 +0x144
@olivere olivere changed the title compiler: SIGSEGV with "go build" cmd/compile: SIGSEGV with "go build" Feb 2, 2022
@olivere olivere changed the title cmd/compile: SIGSEGV with "go build" cmd/compile: SIGSEGV with 'go build' Feb 2, 2022
@bcmills
Copy link
Member

@bcmills bcmills commented Feb 2, 2022

Looks like this is fixed at head (https://go.dev/play/p/VGzVWkFnZNw?v=gotip):

./prog.go:12:12: range clause permits at most two iteration variables
./prog.go:13:18: undefined: v

@olivere
Copy link
Author

@olivere olivere commented Feb 2, 2022

Oh, I'm sorry I didn't try that.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 2, 2022

Thanks for reporting the bug.

Since this will be fixed in the 1.18 release, and since the code is invalid anyhow, I don't think it's worth backporting the fix. I'm going to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants