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: SEGV in go 1.8 compiler (gc.typecheck1) with go build #19323

Closed
bstarynk opened this issue Feb 28, 2017 · 7 comments

Comments

Projects
None yet
5 participants
@bstarynk
Copy link

commented Feb 28, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8 linux/amd64

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

Linux/x86-64
Debian/Sid/x86-64

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

What did you do?

If possible, provide a recipe for reproducing the error.

For some reason, I am not able to upload the faulty tarball via this interface.
Uploading monimelt-go-segv.tar.gz…

But I have installed that gzipped tar archive on http://gcc-melt.org/monimelt-go-segv.tar.gz

Its md5sum is c1036d5473fa30a3b23dbb72e6f6389f
It is a small file of 19234 bytes (less than twenty kilobytes)
and it is exactly the commit bstarynk/monimelt@507be38

Extract it into some directory monimelt-go-segv
then the three commands
export GOPATH=$PWD/monimelt-go-segv
cd monimelt-go-segv
go build src/monimelt.go
gives (in a reproducible fashion)

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x58 pc=0x998773]

goroutine 1 [running]:
cmd/compile/internal/gc.typecheck1(0xc42050d320, 0x1, 0xc42050cab0)
/usr/local/go/src/cmd/compile/internal/gc/typecheck.go:1122 +0xa2c3
cmd/compile/internal/gc.typecheck(0xc42050d320, 0x1, 0xc42050cab0)
/usr/local/go/src/cmd/compile/internal/gc/typecheck.go:188 +0x608
cmd/compile/internal/gc.typecheckslice(0xc4200aef80, 0xd, 0x10, 0x1)
/usr/local/go/src/cmd/compile/internal/gc/typecheck.go:49 +0x4e
cmd/compile/internal/gc.Main()
/usr/local/go/src/cmd/compile/internal/gc/main.go:374 +0x1938
main.main()
/usr/local/go/src/cmd/compile/main.go:50 +0xfe

A complete runnable program is good.
A link on play.golang.org is best.

What did you expect to see?

I am a newbie, perhaps making newbie mistakes. I am expecting compiler error messages, not SEGV

What did you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x58 pc=0x998773]
and the shown backtrace is indeed inside the Go compiler & runtime.

@ianlancetaylor ianlancetaylor changed the title SEGV in go 1.8 compiler (gc.typecheck1) with go build cmd/compile: SEGV in go 1.8 compiler (gc.typecheck1) with go build Feb 28, 2017

@ianlancetaylor ianlancetaylor added this to the Go1.8.1 milestone Feb 28, 2017

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Feb 28, 2017

@bstarynk

This comment has been minimized.

Copy link
Author

commented Feb 28, 2017

Ian and others, are you able to get the gzipped archive?
You should also be able to fetch it with
wget http://gcc-melt.org/monimelt-go-segv.tar.gz

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Feb 28, 2017

@bstarynk Yes, I was able to retrieve it, and I was able to recreate the problem.

It's a crash-on-invalid. The crashing line is

sort.Sort(ordSliceObptr(coparr))[:l-nbnil]

The Go function sort.Sort does not return anything. When you give it a slice, it sorts the slice in place. It doesn't return a sorted slice. So you are trying to slice a missing expression. The bug is that the compiler is crashing rather than reporting an error.

Here is a smaller case that recreates the problem:

package p

import "sort"

func F(a []string) {
	sort.Strings(a)[:]
}
@josharian

This comment has been minimized.

Copy link
Contributor

commented Feb 28, 2017

On it.

@gopherbot

This comment has been minimized.

Copy link

commented Feb 28, 2017

CL https://golang.org/cl/37584 mentions this issue.

josharian added a commit to josharian/go that referenced this issue Mar 1, 2017

cmd/compile: don't crash when slicing expression without type
Fixes golang#19323

Change-Id: I92d1bdefb15de6178a577a4fa0f0dc004f791904

josharian added a commit to josharian/go that referenced this issue Mar 2, 2017

cmd/compile: don't crash when slicing non-slice
Fixes golang#19323

Change-Id: I92d1bdefb15de6178a577a4fa0f0dc004f791904

@gopherbot gopherbot closed this in 542a60f Mar 2, 2017

@bstarynk

This comment has been minimized.

Copy link
Author

commented Mar 2, 2017

Thanks a lot for being so responsive.

@gopherbot

This comment has been minimized.

Copy link

commented Apr 5, 2017

CL https://golang.org/cl/39601 mentions this issue.

gopherbot pushed a commit that referenced this issue Apr 5, 2017

[release-branch.go1.8] cmd/compile: don't crash when slicing non-slice
Fixes #19323
Fixes #19638 (backport)

Change-Id: I92d1bdefb15de6178a577a4fa0f0dc004f791904
Reviewed-on: https://go-review.googlesource.com/39601
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

@golang golang locked and limited conversation to collaborators Apr 5, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.