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: bad line numbers for deferred function in new SSA back end #14646

Closed
rsc opened this issue Mar 4, 2016 · 1 comment
Closed

cmd/compile: bad line numbers for deferred function in new SSA back end #14646

rsc opened this issue Mar 4, 2016 · 1 comment

Comments

@rsc
Copy link
Contributor

rsc commented Mar 4, 2016

$ n /tmp/x.go
    1   package main
    2   
    3   import "runtime"
    4   
    5   func main() {
    6       var file string
    7       var line int
    8       func() {
    9           defer func() {
   10               _, file, line, _ = runtime.Caller(1)
   11           }()
   12       }()
   13       println(file, line)
   14   }
$ go1.4 run /tmp/x.go
/tmp/x.go 12
$ go1.5 run /tmp/x.go
/tmp/x.go 12
$ go1.6 run /tmp/x.go
/tmp/x.go 12
$ go run /tmp/x.go
/tmp/x.go 8
$ 

The file and line of the caller of a deferred function should appear to be the end of that function or the explicit return statement that triggered the deferred function calls. It has regressed since Go 1.6 was cut to report the beginning of the function. We should fix this and add a test.

It looks like explicit returns are handled correctly and that only the implicit return inserted at the end of the function is generated with incorrect line information:

$ n /tmp/x.go
    1   package main
    2   
    3   import (
    4       "os"
    5       "runtime"
    6   )
    7   
    8   func main() {
    9       var file string
   10       var line int
   11       func() {
   12           defer func() {
   13               _, file, line, _ = runtime.Caller(1)
   14           }()
   15           if len(os.Args) > 1 {
   16               return
   17           }
   18           return
   19       }()
   20       println(file, line)
   21   }
$ go1.6 run /tmp/x.go
/tmp/x.go 18
$ go1.6 run /tmp/x.go -
/tmp/x.go 16
$ go run /tmp/x.go
/tmp/x.go 18
$ go run /tmp/x.go -
/tmp/x.go 16
$ 

/cc @randall77 @dr2chase

@rsc rsc added this to the Go1.7Early milestone Mar 4, 2016
@gopherbot
Copy link

CL https://golang.org/cl/20381 mentions this issue.

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

3 participants