-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment incorrect size calculations, false positives #44877
Comments
/cc @leitzler |
I'll defer to @mdempsky who knows the calculations way better than I do :) |
Note that diagnostic is about pointer bytes, not about size. That is, how many bytes of the object that the GC has to potentially scan for pointers.
That said, this is a pretty niche optimization opportunity, and probably not worth reporting to users by default. While shrinking size may be beneficial, it's likely to be small and there are a lot more tradeoffs here to consider. |
Interesting. At least in case of golangci-lint, which had pretty old maligned version (from 2018), it was pretty unexpected to encounter such new diagnostic when trying to use fieldalignment as a drop-in replacement to maligned linter. But this seem to be an issue for golangci-lint, since nothing is wrong with fieldalignment and it does not break expectations set from modern maligned. Nevertheless it is an interesting diagnostic and probably should be better documented, as current documentation does not suggest any diagnostic other than memory size. |
fieldalignment replaces maligned. This currently raises a number of linting errors because fieldalignment cares about pointer ordering (for GC); see golang/go#44877 for details. Fixes: submariner-io#1252 Signed-off-by: Stephen Kitt <[email protected]>
fieldalignment replaces maligned. Errors related to pointer ordering (for GC) are ignored; see golang/go#44877 for details. Fixes: submariner-io#1252 Signed-off-by: Stephen Kitt <[email protected]>
fieldalignment replaces maligned. Errors related to pointer ordering (for GC) are ignored; see golang/go#44877 for details. Fixes: submariner-io#1252 Signed-off-by: Stephen Kitt <[email protected]>
fieldalignment replaces maligned. Errors related to pointer ordering (for GC) are ignored; see golang/go#44877 for details. Signed-off-by: Stephen Kitt <[email protected]>
fieldalignment replaces maligned. Errors related to pointer ordering (for GC) are ignored; see golang/go#44877 for details. Signed-off-by: Stephen Kitt <[email protected]>
fieldalignment replaces maligned. Errors related to pointer ordering (for GC) are ignored; see golang/go#44877 for details. Signed-off-by: Stephen Kitt <[email protected]>
fieldalignment replaces maligned. Errors related to pointer ordering (for GC) are ignored; see golang/go#44877 for details. Signed-off-by: Stephen Kitt <[email protected]>
fieldalignment replaces maligned. Errors related to pointer ordering (for GC) are ignored; see golang/go#44877 for details. Signed-off-by: Stephen Kitt <[email protected]>
fieldalignment replaces maligned. Errors related to pointer ordering (for GC) are ignored; see golang/go#44877 for details. Signed-off-by: Stephen Kitt <[email protected]>
fieldalignment replaces maligned. Errors related to pointer ordering (for GC) are ignored; see golang/go#44877 for details. Signed-off-by: Stephen Kitt <[email protected]>
fieldalignment replaces maligned. Errors related to pointer ordering (for GC) are ignored; see golang/go#44877 for details. Signed-off-by: Stephen Kitt <[email protected]>
fieldalignment replaces maligned. Errors related to pointer ordering (for GC) are ignored; see golang/go#44877 for details. Signed-off-by: Stephen Kitt <[email protected]>
fieldalignment replaces maligned. Errors related to pointer ordering (for GC) are ignored; see golang/go#44877 for details. Signed-off-by: Stephen Kitt <[email protected]>
fieldalignment replaces maligned. Errors related to pointer ordering (for GC) are ignored; see golang/go#44877 for details. Fixes: #1252 Signed-off-by: Stephen Kitt <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Reproduces from upstream tools repository
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
running
./fieldalignment /tmp/z/foo.go
onWhat did you expect to see?
(1) Since string alone is 16 bytes long, and int32 is 4 bytes long, report should read "struct with 24 pointer bytes could be 20" (16+4+4 | 16+4)
Maybe it also superfluous to report structures that cannot be made any smaller such as in this case, since 20 would still be aligned to 24. At very least this should be indicated in report.
(2) No error reported. Since string alone is 16 bytes long and *int32 is 8 bytes long, it would be 16+8 = 24 regardless of position of F.
What did you see instead?
The text was updated successfully, but these errors were encountered: