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

fix: type sizing when cross-compiling (32-bit) #5053

Merged
merged 2 commits into from
Oct 3, 2024
Merged

Conversation

gh2o
Copy link
Contributor

@gh2o gh2o commented Oct 3, 2024

golangci-lint should respect GOARCH when performing typechecking.

For example, the code below fails to build with GOARCH=arm, but succeeds with GOARCH=amd64:

// -uintptr(x-y) creates a static assertion of x==y
const _ = -uintptr(unsafe.Sizeof((*byte)(nil)) - 8)

golangci-lint currently does not respect GOARCH for typechecking because it does not set types.Config.Sizes, which tells the typecheck package how to determine the size of machine-specific types (like pointers and uintptr). By default, if types.Config.Sizes is nil, SizesFor("gc", "amd64") is used by default. This will notably break typechecking for 32-bit platforms.

This PR sets types.Config.Sizes from build.Default, which is set by the GOARCH environment variable.

Copy link

boring-cyborg bot commented Oct 3, 2024

Hey, thank you for opening your first Pull Request !

@CLAassistant
Copy link

CLAassistant commented Oct 3, 2024

CLA assistant check
All committers have signed the CLA.

@ldez ldez self-requested a review October 3, 2024 19:50
@ldez ldez changed the title Fix type sizing when cross-compiling fix: type sizing when cross-compiling Oct 3, 2024
@ldez ldez added the bug Something isn't working label Oct 3, 2024
@ldez ldez changed the title fix: type sizing when cross-compiling fix: type sizing when cross-compiling (32bits) Oct 3, 2024
@ldez ldez changed the title fix: type sizing when cross-compiling (32bits) fix: type sizing when cross-compiling (32-bit) Oct 3, 2024
@ldez ldez added this to the next milestone Oct 3, 2024
Copy link
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ldez ldez merged commit a86d8ba into golangci:master Oct 3, 2024
15 checks passed
@ldez ldez modified the milestones: next, v1.62 Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants