gvisor icon indicating copy to clipboard operation
gvisor copied to clipboard

[checklocks] Use function line info for error messages when return instruction has no line numbers attached

Open uzairnawaz opened this issue 1 month ago • 2 comments

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.

uzairnawaz avatar Dec 04 '25 00:12 uzairnawaz

Can you squash your commits, we don't have the ability to squash and merge yet.

ayushr2 avatar Dec 09 '25 17:12 ayushr2

This patch breaks our nogo tests: https://buildkite.com/gvisor/pipeline/builds/39110#019b0462-f212-4d38-91fc-74395d051691

ayushr2 avatar Dec 10 '25 09:12 ayushr2

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?

uzairnawaz avatar Dec 11 '25 22:12 uzairnawaz

Thanks for the investigation.

Do you think this should be a separate PR or include it here?

It should be a separate PR.

ayushr2 avatar Dec 12 '25 06:12 ayushr2