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

unused: don't flag fields as unused for structs addressed through an unsafe.Pointer #355

Closed
cespare opened this issue Oct 11, 2018 · 4 comments

Comments

@cespare
Copy link

cespare commented Oct 11, 2018

(I feel like we've discussed this before, but I couldn't find an issue. Sorry if this is a duplicate.)

Right now if you have an unexported struct with unexported fields that you use for unsafe purposes the fields get marked as U1000.

For instance, we have some code which deals with Linux capabilities and needs to mirror some kernel structs. It's basically this code:

https://github.com/syndtr/gocapability/blob/d98352740cb2c55f81556b63d4a1ec64c5a319c2/capability/syscall_linux.go#L14-L39

Unused marks the capHeader.version field as unused (in our code that field is never referenced).

(I assume you get the idea but if it's not clear I'll make exact repro code.)

I think that if you define a struct S, if there's ever code that does unsafe.Pointer(&s) (where s is an S) then all of S's fields should be assumed used.

@dominikh
Copy link
Owner

I don't think we've talked about this before. Your solution makes sense.

@dominikh dominikh added the started Issues we've started working on label Mar 17, 2019
@dominikh
Copy link
Owner

(We've previously talked about this at dominikh/go-unused#37. The check I implemented there looks for (T)(unsafe.Pointer(v), it doesn't consider x = unsafe.Pointer(v). Will fix.)

@dominikh
Copy link
Owner

This is fixed in master.

@dominikh dominikh removed the started Issues we've started working on label Apr 10, 2019
@cespare
Copy link
Author

cespare commented Apr 10, 2019

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants