Open Karitham opened 3 years ago
CC @stamblerre via https://dev.golang.org/owners
Taking a quick stab at this: it looks like the analysis is assuming you're on a 32-bit platform, which is somewhat surprising to me. On a 64-bit platform that struct is 96 bytes (see https://play.golang.org/p/gbSmYJ9-2XW).
What's even weirder is if on linux/amd64
I run the above program as GOARCH=386
I get 60, which isn't either of the numbers the message is giving you.
BTW if I add back in the Permission
type instead of a raw int64
, I get the same numbers.
This is almost certainly due to AST trimming of packages outside of the workspace: time.Time is effectively a struct{} in the definition of sql.NullTime. This analyzer unfortunately doesn't make any sense in the presence of non-workspace types.
We need a general solution for this, or should consider walking back the AST memory optimizations.
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Have a struct with a custom type, for example
What did you see?
struct of size 72 could be 64
What did you expect to see instead?
No warning, since that same exact struct passes with https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/fieldalignment.
The warning also disappears if I replace my custom type with
From my understanding, this issue only applied to types outside the standard library, since I get the issue on all the structs that contains custom types, either mines or from imported packages, such as https://github.com/shopspring/decimal's decimal.Decimal