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: assume all fields for a struct marked with structs.HostLayout are used #1604

Open
cespare opened this issue Sep 20, 2024 · 0 comments
Labels
needs-triage Newly filed issue that needs triage

Comments

@cespare
Copy link

cespare commented Sep 20, 2024

This is related to #355.

I have some...extremely unsafe code that looks like this:

// A closure is the internal representation of a Go func.
// (Actually a Go func is a pointer to one of these.)
type closure struct {
	_ structs.HostLayout

	code unsafe.Pointer
	//lint:ignore U1000 Included to mirror representation of Go func.
	ctx unsafe.Pointer
}

The reason I need the //lint:ignore is because I don't do a conversion using unsafe.Pointer(*closure), it is unsafe.Pointer(**closure), so I assume it's bypassing the logic you added for #355.

Anyway, I just added the structs.HostLayout hint (new in Go 1.23) as a way to formally document that I care about the memory layout of this struct. That seems like it could be a good hint to staticcheck that all the fields are needed, so it should skip the U1000 checks. (In fact, this seems like a nicer -- more explicit and more straightforward -- way of detecting "struct fields needed for unsafe reasons" going forward than staticcheck's current heuristics.)

@cespare cespare added the needs-triage Newly filed issue that needs triage label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage Newly filed issue that needs triage
Projects
None yet
Development

No branches or pull requests

1 participant