2020/07/17 20:01:56 0xc0000721e0 1
panic: wtf
goroutine 1 [running]:
main.run(...)
/www/xx/go/test/main.go:18
main.main()
/www/xx/go/test/main.go:13 +0xd0
Process finished with exit code 2
为什么 run 里面是...
代码如下:
func main() {
a := "1"
run(a)
}
func run(a string) {
log.Println(a)
panic("wtf")
}
1
katsusan 2020-07-17 22:11:50 +08:00
run 函数被内联了,可以在编译时加入-gcflags "-l"禁止内联。
➜ /tmp go build -gcflags "-m" panic.go # command-line-arguments ./panic.go:10:6: can inline run ./panic.go:5:6: can inline main ./panic.go:7:5: inlining call to run ./panic.go:7:5: main ... argument does not escape ./panic.go:7:5: a escapes to heap ./panic.go:10:10: leaking param: a ./panic.go:11:13: run ... argument does not escape ./panic.go:11:13: a escapes to heap |