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

cmd/compile: unsafe.Offsetof returns incorrect value in embedded struct with type parameters [1.18 backport] #53159

Closed
gopherbot opened this issue May 31, 2022 · 4 comments
Labels
CherryPickApproved Used during the release process for point releases FrozenDueToAge
Milestone

Comments

@gopherbot
Copy link
Contributor

@randall77 requested issue #53137 to be considered for backport to the next 1.18 minor release.

@gopherbot please open a backport issue for 1.18.

@gopherbot
Copy link
Contributor Author

Change https://go.dev/cl/409494 mentions this issue: [release-branch.go1.18] cmd/compile: fix wrong unsafe.Offsetof evaluation inside generic function

@dmitshur
Copy link
Contributor

@randall77 Thanks for requesting the backport. Can you please include a brief rationale per https://go.dev/wiki/MinorReleases (third paragraph)—thanks.

@randall77
Copy link
Contributor

This causes the compiler to incorrectly compile some unsafe.OffsetOf calls in generic types. It's possible to work around in some cases, but probably not all (e.g. using unsafe.OffsetOf on types in a package you don't control).

@dmitshur dmitshur modified the milestones: Go1.18.3, Go1.18.4 Jun 1, 2022
@joedian joedian added the CherryPickApproved Used during the release process for point releases label Jun 22, 2022
@gopherbot gopherbot removed the CherryPickCandidate Used during the release process for point releases label Jun 22, 2022
@gopherbot
Copy link
Contributor Author

Closed by merging 3da88c0 to release-branch.go1.18.

gopherbot pushed a commit that referenced this issue Jul 6, 2022
…tion inside generic function

For instantiated generic functions, all implicit dot operations are
resolved. Thus unsafe.Offsetof may calculating the offset against the
wrong base selector.

To fix it, we must remove any implicit dot operations to find the first
non-implicit one, which is the right base selector for calculating the
offset.

Fixes #53159

Change-Id: I38504067ce0f274615b306edc8f7d7933bdb631a
Reviewed-on: https://go-review.googlesource.com/c/go/+/409355
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-on: https://go-review.googlesource.com/c/go/+/409494
bradfitz pushed a commit to tailscale/go that referenced this issue Jul 14, 2022
…tion inside generic function

For instantiated generic functions, all implicit dot operations are
resolved. Thus unsafe.Offsetof may calculating the offset against the
wrong base selector.

To fix it, we must remove any implicit dot operations to find the first
non-implicit one, which is the right base selector for calculating the
offset.

Fixes golang#53159

Change-Id: I38504067ce0f274615b306edc8f7d7933bdb631a
Reviewed-on: https://go-review.googlesource.com/c/go/+/409355
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-on: https://go-review.googlesource.com/c/go/+/409494
@golang golang locked and limited conversation to collaborators Jul 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CherryPickApproved Used during the release process for point releases FrozenDueToAge
Projects
None yet
Development

No branches or pull requests

4 participants