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 inlining function with FOR loop with labeled breaks/continues #49100

Closed
danscales opened this issue Oct 21, 2021 · 1 comment
Closed
Labels
NeedsFix
Milestone

Comments

@danscales
Copy link
Contributor

@danscales danscales commented Oct 21, 2021

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

Go tip

Does this issue reproduce with the latest release?

No, this is only on tip.

What did you do?

package main

func f(j int) {
loop:
	for i := 0; i < 4; i++ {
		if i == 1 {
			continue loop
		}
		println(j, i)
	}
}

func main() {
loop:
	for j := 0; j < 5; j++ {
		f(j)
		if j == 3 {
			break loop
		}
	}
}

What did you expect to see?

0 0
0 2
0 3
1 0
1 2
1 3
2 0
2 2
2 3
3 0
3 2
3 3

What did you see instead?

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

goroutine 1 [running]:
cmd/compile/internal/ssa.(*Block).AddEdgeTo(...)
go/src/cmd/compile/internal/ssa/block.go:274
cmd/compile/internal/ssagen.(*state).stmt(0xc0000e4700, {0xe43e50, 0xc0003dfad0})
go/src/cmd/compile/internal/ssagen/ssa.go:1731 +0x1461
cmd/compile/internal/ssagen.(*state).stmtList(0xc0000e4700, {0xc00006f3d0, 0x1, 0xc0004b7e00})
go/src/cmd/compile/internal/ssagen/ssa.go:1374 +0x5d
cmd/compile/internal/ssagen.(*state).stmt(0xc0000e4700, {0xe44b98, 0xc0003ef570})
go/src/cmd/compile/internal/ssagen/ssa.go:1678 +0x2d95
cmd/compile/internal/ssagen.(*state).stmtList(0xc0000e4700, {0xc0000e4200, 0x9, 0x4})
go/src/cmd/compile/internal/ssagen/ssa.go:1374 +0x5d
cmd/compile/internal/ssagen.(*state).stmt(0xc0000e4700, {0xe447b0, 0xc00036e3f0})
go/src/cmd/compile/internal/ssagen/ssa.go:1781 +0x20c9
cmd/compile/internal/ssagen.(*state).stmtList(0xc0000e4700, {0xc000418780, 0x4, 0x7ff37d75d768})
go/src/cmd/compile/internal/ssagen/ssa.go:1374 +0x5d
cmd/compile/internal/ssagen.buildssa(0xc000412c60, 0x0)
go/src/cmd/compile/internal/ssagen/ssa.go:567 +0x1d13
cmd/compile/internal/ssagen.Compile(0xc000412c60, 0xc000414ca0)
go/src/cmd/compile/internal/ssagen/pgen.go:183 +0x4c
cmd/compile/internal/gc.compileFunctions.func4.1(0x1)
go/src/cmd/compile/internal/gc/compile.go:153 +0x3a
cmd/compile/internal/gc.compileFunctions.func2(0x0)
go/src/cmd/compile/internal/gc/compile.go:125 +0x1e
cmd/compile/internal/gc.compileFunctions.func4({0xc00006f490, 0x2, 0x2})
go/src/cmd/compile/internal/gc/compile.go:152 +0x53
cmd/compile/internal/gc.compileFunctions()
go/src/cmd/compile/internal/gc/compile.go:163 +0x162
cmd/compile/internal/gc.Main(0xd13090)
go/src/cmd/compile/internal/gc/main.go:314 +0x1016
main.main()
go/src/cmd/compile/main.go:55 +0xdd

This is happening because of the identical labels between the inlined function and the outer function. We already have some code to make labels in inlined functions be unique, but we're not using it for labeled breaks/continues/for loops.

@danscales danscales self-assigned this Oct 21, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Oct 21, 2021

Change https://golang.org/cl/357649 mentions this issue: cmd/compile: fix inlining of labeled for loops

@seankhliao seankhliao added the NeedsFix label Oct 21, 2021
@dmitshur dmitshur added this to the Go1.18 milestone Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix
Projects
None yet
Development

No branches or pull requests

4 participants