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: crash in type loop detection #44266

Closed
fhs opened this issue Feb 15, 2021 · 13 comments
Closed

cmd/compile: crash in type loop detection #44266

fhs opened this issue Feb 15, 2021 · 13 comments
Labels
Milestone

Comments

@fhs
Copy link
Contributor

@fhs fhs commented Feb 15, 2021

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

$ go version
go version devel +33d72fd412 Mon Feb 15 01:54:22 2021 +0000 linux/amd64

Does this issue reproduce with the latest release?

No (tested with go1.15.8)

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/fhs/.cache/go-build"
GOENV="/home/fhs/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/fhs/go/pkg/mod"
GOOS="linux"
GOPATH="/home/fhs/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/big/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/big/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel +33d72fd412 Mon Feb 15 01:54:22 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2015226142=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version devel +33d72fd412 Mon Feb 15 01:54:22 2021 +0000 linux/amd64
GOROOT/bin/go tool compile -V: compile version devel +33d72fd412 Mon Feb 15 01:54:22 2021 +0000
uname -sr: Linux 5.10.11-arch1-1
LSB Version:	1.4
Distributor ID:	Arch
Description:	Arch Linux
Release:	rolling
Codename:	n/a
/usr/lib/libc.so.6: GNU C Library (GNU libc) release release version 2.33.
gdb --version: GNU gdb (GDB) 10.1

What did you do?

Run this program: https://play.golang.org/p/JghmS05HSAj

What did you expect to see?

The compiler shouldn't crash

What did you see instead?

$ go run crash.go 
# command-line-arguments
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0xa42da5]

goroutine 1 [running]:
cmd/compile/internal/gc.findTypeLoop(0xc0000d8e40, 0xc0001088d8, 0xc00009c160)
	/home/big/go/src/cmd/compile/internal/gc/align.go:202 +0x105
cmd/compile/internal/gc.findTypeLoop(0xc0000d8d80, 0xc0001088d8, 0x1)
	/home/big/go/src/cmd/compile/internal/gc/align.go:223 +0x225
cmd/compile/internal/gc.findTypeLoop(0xc0000d8d20, 0xc0001088d8, 0xc0000980d8)
	/home/big/go/src/cmd/compile/internal/gc/align.go:202 +0x117
cmd/compile/internal/gc.findTypeLoop(0xc0000d91a0, 0xc0001088d8, 0x0)
	/home/big/go/src/cmd/compile/internal/gc/align.go:216 +0x2c5
cmd/compile/internal/gc.findTypeLoop(0xc0000d9140, 0xc0001088d8, 0x11)
	/home/big/go/src/cmd/compile/internal/gc/align.go:202 +0x117
cmd/compile/internal/gc.reportTypeLoop(0xc0000d9140)
	/home/big/go/src/cmd/compile/internal/gc/align.go:240 +0x76
cmd/compile/internal/gc.dowidth(0xc0000d9140)
	/home/big/go/src/cmd/compile/internal/gc/align.go:282 +0x1105
cmd/compile/internal/gc.widstruct(0xc0000d9140, 0xc0000d9140, 0x0, 0x1, 0x203000)
	/home/big/go/src/cmd/compile/internal/gc/align.go:114 +0xd3
cmd/compile/internal/gc.dowidth(0xc0000d9140)
	/home/big/go/src/cmd/compile/internal/gc/align.go:435 +0x4cf
cmd/compile/internal/gc.widstruct(0xc0000d91a0, 0xc0000d91a0, 0x0, 0x1, 0x8)
	/home/big/go/src/cmd/compile/internal/gc/align.go:114 +0xd3
cmd/compile/internal/gc.dowidth(0xc0000d91a0)
	/home/big/go/src/cmd/compile/internal/gc/align.go:435 +0x4cf
cmd/compile/internal/gc.resumecheckwidth()
	/home/big/go/src/cmd/compile/internal/gc/align.go:526 +0x4c
cmd/compile/internal/gc.typecheckdef(0xc0000c9b30)
	/home/big/go/src/cmd/compile/internal/gc/typecheck.go:3695 +0x8e5
cmd/compile/internal/gc.typecheck1(0xc0000c9b30, 0x4, 0x0)
	/home/big/go/src/cmd/compile/internal/gc/typecheck.go:343 +0xbace
cmd/compile/internal/gc.typecheck(0xc0000c9b30, 0x4, 0x0)
	/home/big/go/src/cmd/compile/internal/gc/typecheck.go:299 +0x785
cmd/compile/internal/gc.typecheck1(0xc0000ce300, 0x1, 0x0)
	/home/big/go/src/cmd/compile/internal/gc/typecheck.go:2077 +0x4e65
cmd/compile/internal/gc.typecheck(0xc0000ce300, 0x1, 0x0)
	/home/big/go/src/cmd/compile/internal/gc/typecheck.go:299 +0x785
cmd/compile/internal/gc.Main(0xcc7d50)
	/home/big/go/src/cmd/compile/internal/gc/main.go:603 +0x2aa5
main.main()
	/home/big/go/src/cmd/compile/main.go:52 +0xb1
@tpaschalis
Copy link
Contributor

@tpaschalis tpaschalis commented Feb 15, 2021

Might be obvious, but I ran a git bisect, this behavior was there all along in 0e85fd7.

Changing this line to also check for p.Ntype != nil fixes the issue; tests pass and we get the correct error message

./main.go:9:6: invalid recursive type T2
	/Users/paschalistsilias/44266-golang/main.go:9:6: T2 refers to
	/Users/paschalistsilias/44266-golang/main.go:9:6: T2

I can prepare and send a CL with a test if there's no objection, or could I be missing something in the bigger picture?

Loading

@ALTree
Copy link
Member

@ALTree ALTree commented Feb 15, 2021

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 15, 2021

Change https://golang.org/cl/292149 mentions this issue: cmd/compile: fix ICE in reporting of recursive types with interfaces

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 16, 2021

Change https://golang.org/cl/292469 mentions this issue: cmd/compile: fix ICE in findTypeLoop with symbols from imported packages

Loading

@toothrot
Copy link
Contributor

@toothrot toothrot commented Feb 16, 2021

It looks like @mdempsky and @randall77 are cc'd on the CLs, also cc'ing @griesemer as an owner.

This is currently labeled as a release-blocking issue, and is currently blocking the Go 1.16 release today.

Loading

@randall77
Copy link
Contributor

@randall77 randall77 commented Feb 16, 2021

Removed release blocker. This is a compiler crash on an invalid program, which shouldn't block the release.

Loading

@odeke-em
Copy link
Member

@odeke-em odeke-em commented Feb 16, 2021

Thanks Keith for the status report. In that case I’ll also move this issue to Go1.17, and out of the Go1.16 milestone.

Loading

@odeke-em odeke-em removed this from the Go1.16 milestone Feb 16, 2021
@odeke-em odeke-em added this to the Go1.17 milestone Feb 16, 2021
@mdempsky
Copy link
Member

@mdempsky mdempsky commented Feb 16, 2021

I believe this issue is already fixed on dev.regabi with golang.org/cl/274294. If this isn't a blocker for Go 1.16, I suggest we wait until dev.regabi is merged to fix this on the main branch. And we can just backport a fix to the Go 1.16 release branch when appropriate.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 16, 2021

Change https://golang.org/cl/292470 mentions this issue: [dev.regabi] test: add test for findTypeLoop with symbols from other packages

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 17, 2021

Change https://golang.org/cl/292889 mentions this issue: [dev.regabi] test: add test for findTypeLoop with symbols from other packages

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 17, 2021

Change https://golang.org/cl/292889 mentions this issue: test: add test for findTypeLoop with symbols from other packages

Loading

@cuonglm
Copy link
Member

@cuonglm cuonglm commented Feb 17, 2021

dev.regabi was merged to master, so we can close this issue now.

Loading

@dmitshur
Copy link
Contributor

@dmitshur dmitshur commented Feb 17, 2021

Thanks, I can confirm the ICE no longer reproduces on tip.

Closing, fixed by CL 292709.

Loading

@dmitshur dmitshur closed this Feb 17, 2021
gopherbot pushed a commit that referenced this issue Feb 23, 2021
CL 274294 improved findTypeLoop but also fixed a new found bug on master
branch. This Cl adds test cases for this.

Updates #44266

Change-Id: Ie4a07a3487758a1e4ad2f2847dcde975b10d2a77
Reviewed-on: https://go-review.googlesource.com/c/go/+/292889
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet