Skip to content

cmd/compile: bad stack for index panic in arg to inlined call #19799

@rsc

Description

@rsc
$ cat /tmp/x.go
package main

func f(x int) int {
	return x + 1
}

func main() {
	var v []int
	println("%d\n", f(v[0]))
}
$ go run /tmp/x.go
panic: runtime error: index out of range

goroutine 1 [running]:
main.f(...)
	/tmp/x.go:9
main.main()
	/tmp/x.go:9 +0x11
exit status 2

At first glance I thought the line number was wrong, since main.f and main.main are not both on line 9.

But in fact the bug is that main.f shows up at all. The index panic happens preparing the argument to f, not in the inlined copy of f. The line number is correct - v[0] is on line 9. What's wrong is that main.f shows up at all. It should not.

/cc @davidlazar @aclements

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions