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 when compiling illegal code #48818

Closed
zigo101 opened this issue Oct 6, 2021 · 3 comments
Closed

cmd/compile: crash when compiling illegal code #48818

zigo101 opened this issue Oct 6, 2021 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@zigo101
Copy link

zigo101 commented Oct 6, 2021

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

$ go version
go version go1.17.1 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

package main

func main() {
	_ = &([10]bool[1]{})
}

What did you expect to see?

Report errors

What did you see instead?

Crash

@ALTree
Copy link
Member

ALTree commented Oct 6, 2021

On tip (go1.18-55e7f7e12d) there's no crash:

$ gotip tool compile -G=0 test.go
test.go:4:19: syntax error: unexpected {, expecting )

$ gotip tool compile test.go
test.go:4:12: bool is not a generic type

But the second error message is... inscrutable.

EDIT: oh, I see. It prints that when you try to "index" with [ on a non-generic type(?)

cc @griesemer @findleyr @mdempsky to decide if the tip error message looks good.

@ALTree ALTree added this to the Go1.18 milestone Oct 6, 2021
@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 6, 2021
@findleyr
Copy link
Member

findleyr commented Oct 6, 2021

Here's the 1.17.1 panic:

go1.17.1 run issue48818.go
# command-line-arguments
panic: interface conversion: *ir.IndexExpr is not ir.Ntype: missing method CanBeNtype

goroutine 1 [running]:
cmd/compile/internal/noder.(*noder).typeExpr(...)
        /usr/local/go/src/cmd/compile/internal/noder/noder.go:885
cmd/compile/internal/noder.(*noder).expr(0xc000382bd0, {0xe38c00, 0xc00007c0a0})
        /usr/local/go/src/cmd/compile/internal/noder/noder.go:695 +0x767
cmd/compile/internal/noder.(*noder).expr(0xc000382bd0, {0xe38f90, 0xc0000360c0})
        /usr/local/go/src/cmd/compile/internal/noder/noder.go:742 +0x1693
cmd/compile/internal/noder.(*noder).exprList(0x14a5294a5294a5, {0xe38f90, 0xc0000360c0})
        /usr/local/go/src/cmd/compile/internal/noder/noder.go:668 +0x67
cmd/compile/internal/noder.(*noder).stmtFall(0xc000382bd0, {0xe38a80, 0xc000036100}, 0x0)
        /usr/local/go/src/cmd/compile/internal/noder/noder.go:1055 +0x845
cmd/compile/internal/noder.(*noder).stmtsFall(0x0, {0xc000066030, 0x1, 0x1}, 0x0)
        /usr/local/go/src/cmd/compile/internal/noder/noder.go:1005 +0xea
cmd/compile/internal/noder.(*noder).stmts(0xc00001e2c0, {0xc000066030, 0xc00007c0f0, 0x0})
        /usr/local/go/src/cmd/compile/internal/noder/noder.go:999 +0x25
cmd/compile/internal/noder.(*noder).funcBody(0xc000382bd0, 0xc00001e2c0, 0xc000036080)
        /usr/local/go/src/cmd/compile/internal/noder/noder.go:216 +0x8e
cmd/compile/internal/noder.(*noder).funcDecl(0xc000382bd0, 0xc0000720c0)
        /usr/local/go/src/cmd/compile/internal/noder/noder.go:587 +0x5a6
cmd/compile/internal/noder.(*noder).decls(0xc000382bd0, {0xc000066040, 0x1, 0x1})
        /usr/local/go/src/cmd/compile/internal/noder/noder.go:331 +0x2c5
cmd/compile/internal/noder.(*noder).node(0xc000382bd0)
        /usr/local/go/src/cmd/compile/internal/noder/noder.go:285 +0xb8
cmd/compile/internal/noder.LoadPackage({0xc0000ba140, 0x2, 0x0})
        /usr/local/go/src/cmd/compile/internal/noder/noder.go:85 +0x358
cmd/compile/internal/gc.Main(0xd16458)
        /usr/local/go/src/cmd/compile/internal/gc/main.go:192 +0xb2e
main.main()
        /usr/local/go/src/cmd/compile/main.go:55 +0xdd

The inscrutable error message in 1.18 is really unrelated. I'll open a separate issue.

@mdempsky
Copy link
Contributor

mdempsky commented Oct 6, 2021

The 1.17.1 crash is unfortunate, but the gotip errors look okay to me. Since the code is invalid anyway, I don't think it's necessary to backport any fixes.

I'm going to close. If anyone disagrees, feel free to reopen.

@mdempsky mdempsky closed this as completed Oct 6, 2021
@golang golang locked and limited conversation to collaborators Oct 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants