[checklocks] Use function line info for error messages when return instruction has no line numbers attached
Resolves line information issues described by #11203
For functions that don't include explicit return statements in the Go source code, the ssa package inserts return instructions without line information attached, leading to poor error messages. Ex: -: return with unexpected locks held (locks: &({param:f}.mu) exclusively)
Quick fix is to instead use the line number information of the parent function instead.
Can you squash your commits, we don't have the ability to squash and merge yet.
This patch breaks our nogo tests: https://buildkite.com/gvisor/pipeline/builds/39110#019b0462-f212-4d38-91fc-74395d051691
It appears that errors that contain no line info are currently getting discarded. Ex (on the master branch):
$ go build tools/checklocks/cmd/checklocks
$ ./checklocks tools/checklocks/tests/methods.go
-: lock a.mu (&({param:a}.mu)) not held exclusively (locks: no locks held)
But, running the tests with bazel:
$ bazel test //tools/checklocks/test:test_nogo
shows that they all pass. This same bazel test fails on this branch with the same error as above (lock not held exclusively). My guess is that attaching the line numbers causes us to now see all the errors that were previously being discarded.
I can go through and annotate other occurences of this to prevent failures. Do you think this should be a separate PR or include it here?
Thanks for the investigation.
Do you think this should be a separate PR or include it here?
It should be a separate PR.