-
Notifications
You must be signed in to change notification settings - Fork 211
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
retrieveUnexportedField violates Go 1.14's checkptr validation, fails under -race #167
Comments
/cc @mdempsky |
The logic for this is here: Line 22 in b1c9c48
The ability to compare unexported fields is critical to many tests. Matt, you got any ideas for how to more safely retrieve an unexported field? |
You have to convert UnsafeAddr to unsafe.Pointer before converting back to uintptr for pointer arithmetic. I admit that's annoying, but it's what the unsafe rules strictly require (at least my reading of them). (Edit: Explained further below: #167 (comment)) |
IIUC, you are suggesting this? return reflect.NewAt(f.Type, unsafe.Pointer(uintptr(unsafe.Pointer(v.UnsafeAddr()))+f.Offset)).Elem() |
@dsnet, try it and see? Does that make checkptr happy? |
@dsnet Yeah, that should work. |
I find the situation funny, and I'm glad others share my compiler nerd sense of humor. :) I thought I'd elaborate a bit though to make sure folks understand this isn't a strictly theoretical/pedantic issue. When compiling an expression with multiple function calls like In the case of an expression like The compiler specially recognizes calls of the form In go-cmp's code above, (Hopefully this was worthwhile to write up and share.) |
Personally, I think the oddity is more so due to the Had the |
@dsnet Yeah, I think the design of "safe" mode has had unfortunate long-term consequences for packages reflect and unsafe. |
To fix our race build. Updates google/go-cmp#167 Change-Id: I8d57cb4b7e0244f7d0944717b2e472afdfec218d Reviewed-on: https://go-review.googlesource.com/c/build/+/203880 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
CI was failing under -race on go 1.14 due to go-cmp. This is now fixed for google/go-cmp#167 in go-cmp master.
To fix our -race test under Go 1.14. See google/go-cmp#167
To fix our -race test under Go 1.14. See google/go-cmp#167
To fix our race build. Updates google/go-cmp#167 Change-Id: I8d57cb4b7e0244f7d0944717b2e472afdfec218d Reviewed-on: https://go-review.googlesource.com/c/build/+/203880 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
Upgrade google/go-cmp to version 0.4.0. This release contains fixes for unsafe pointer conversions which would trigger a test failure under the race detector for Go 1.14 and later. See google/go-cmp#167 Signed-off-by: Dave Cheney <[email protected]>
Upgrade google/go-cmp to version 0.4.0. This release contains fixes for unsafe pointer conversions which would trigger a test failure under the race detector for Go 1.14 and later. See google/go-cmp#167 Signed-off-by: Dave Cheney <[email protected]>
Upgrade google/go-cmp to version 0.4.0. This release contains fixes for unsafe pointer conversions which would trigger a test failure under the race detector for Go 1.14 and later. See google/go-cmp#167 Signed-off-by: Dave Cheney <[email protected]>
Mostly to fix google/go-cmp#167, but we also pinned at some random commit, rather than at a release version.
* update go-cmpt to work with 1.14. Mostly to fix google/go-cmp#167, but we also pinned at some random commit, rather than at a release version. * add new pkg
* update go-cmpt to work with 1.14. Mostly to fix google/go-cmp#167, but we also pinned at some random commit, rather than at a release version. * add new pkg * Make sure we use same versions in pkg and serving
* update go-cmpt to work with 1.14. Mostly to fix google/go-cmp#167, but we also pinned at some random commit, rather than at a release version. * add new pkg * Make sure we use same versions in pkg and serving * Fix the defaulting for the leader election cm This was missing, but now we can provide the default values. * Fix the defaulting for the leader election cm This was missing, but now we can provide the default values.
When running with -race, checkptr complained. The reason (and the solution) is decribed in google/go-cmp#167 (comment)
The unsafe.Pointer safety rules have three separate rules allowing conversion of uintptr to unsafe.Pointer: (3) allows converting unsafe.Pointer to uintptr, performing arithmetic, and converting back; (5) allows converting the results from calling reflect.Value.{Pointer,UnsafeAddr} to unsafe.Pointer; and (6) allows converting the Data field of reflect.{Slice,String}Header to unsafe.Pointer. Notably, these are three separate rules, and they're not allowed to be arbitrarily mixed. For example, this is not allowed: unsafe.Pointer(v.UnsafeAddr() + x) // BAD It needs to instead be written as: unsafe.Pointer(uintptr(unsafe.Pointer(v.UnsafeAddr())) + x) (For further explanation on why this is necessary, see google/go-cmp#167 (comment).) This CL brings cmd/vet's unsafeptr check inline with the unsafe.Pointer rules and cmd/compile's implementation thereof. Change-Id: I1844e0f71dcc8fb7aafacc144b86cc80a2b83b42 Reviewed-on: https://go-review.googlesource.com/c/tools/+/248191 Run-TryBot: Matthew Dempsky <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Trust: Matthew Dempsky <[email protected]>
According to google/go-cmp#167 go-cmp triggers go's "-race" validation. It's supposedly fixed in 0.4.0 but 0.5.2 is the latest so let's try that.
With Go tip (to become Go 1.14) and its new checkptr mode (enabled by default in
-race
mode on anything but Windows for now):The text was updated successfully, but these errors were encountered: