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: panic on switch case with invalid value #21988

Closed
rogpeppe opened this issue Sep 23, 2017 · 6 comments
Closed

cmd/compile: panic on switch case with invalid value #21988

rogpeppe opened this issue Sep 23, 2017 · 6 comments
Milestone

Comments

@rogpeppe
Copy link
Contributor

go version devel +6171d05 Sat Sep 23 09:24:02 2017 +0000 linux/amd64

The following code panics when it is compiled. Go 1.8 does not panic on this code.

package main

type S struct {
	K KT
}

type KT int

const X = Wrong(0)

func (s S) Result() {
	switch s.K {
	case X:
	}
}

I see this panic:

# command-line-arguments
./gobug.go:9:11: undefined: Wrong
./gobug.go:12:2: internal compiler error: unexpected Interface for <nil>

goroutine 1 [running]:
runtime/debug.Stack(0x0, 0x0, 0x0)
	/home/rog/go/src/runtime/debug/stack.go:24 +0xa7
cmd/compile/internal/gc.Fatalf(0xb7f6ce, 0x1b, 0xc42034e0d8, 0x1, 0x1)
	/home/rog/go/src/cmd/compile/internal/gc/subr.go:181 +0x1e2
cmd/compile/internal/gc.Val.Interface(0x0, 0x0, 0xc42034e2d8, 0xc42034e2d8)
	/home/rog/go/src/cmd/compile/internal/gc/const.go:99 +0x2c8
cmd/compile/internal/gc.checkDupExprCases(0xc420321080, 0xc42000c590, 0x1, 0x1)
	/home/rog/go/src/cmd/compile/internal/gc/swt.go:614 +0x569
cmd/compile/internal/gc.typecheckswitch(0xc420321000)
	/home/rog/go/src/cmd/compile/internal/gc/swt.go:210 +0x12cc
cmd/compile/internal/gc.typecheck1(0xc420321000, 0x1, 0x4b135b)
	/home/rog/go/src/cmd/compile/internal/gc/typecheck.go:2098 +0xc10d
cmd/compile/internal/gc.typecheck(0xc420321000, 0x1, 0x3)
	/home/rog/go/src/cmd/compile/internal/gc/typecheck.go:201 +0x676
cmdgo: exit 2
/compile/internal/gc.typecheckslice(0xc42000c598, 0x1, 0x1, 0x1)
	/home/rog/go/src/cmd/compile/internal/gc/typecheck.go:55 +0x54
cmd/compile/internal/gc.Main(0xb8e7e0)
	/home/rog/go/src/cmd/compile/internal/gc/main.go:486 +0x1f3c
main.main()
	/home/rog/go/src/cmd/compile/main.go:49 +0x89
@mvdan
Copy link
Member

mvdan commented Sep 23, 2017

I was going to look at this out of curiosity, then noticed that this was likely me in 495f55d. Will investigate.

@mvdan
Copy link
Member

mvdan commented Sep 23, 2017

Manually reduced case:

package p

const X = Wrong(0)

func _() {
        switch 0 {
        case X:
        }
}

@mvdan mvdan self-assigned this Sep 23, 2017
@mvdan mvdan added this to the Go1.10 milestone Sep 23, 2017
@mvdan
Copy link
Member

mvdan commented Sep 23, 2017

Found the fix, I think. Working on a test and will send the CL.

This is technically a regression in 1.9, since 1.8 worked fine. But this is a bit obscure, so I'm not sure if it's worthy of being included into 1.9.x. @ianlancetaylor @mdempsky thoughts?

@mvdan mvdan changed the title cmd/compile: panic on invalid code cmd/compile: panic on switch case with invalid value Sep 23, 2017
@gopherbot
Copy link

Change https://golang.org/cl/65655 mentions this issue: cmd/compile: fix panic on invalid switch case value

@randall77
Copy link
Contributor

I don't think this needs a backport. It is only an ICE for an invalid program, and only after it prints the correct error.

Usually we only backport for bugs for which there is no easy workaround.

@mvdan
Copy link
Member

mvdan commented Sep 24, 2017

Sounds good - thanks for clarifying.

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

No branches or pull requests

4 participants