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

gccgo: fails to reject unsafe.Offsetof(*&(s.f)) #40291

Open
mdempsky opened this issue Jul 19, 2020 · 0 comments
Open

gccgo: fails to reject unsafe.Offsetof(*&(s.f)) #40291

mdempsky opened this issue Jul 19, 2020 · 0 comments
Milestone

Comments

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Jul 19, 2020

This source code is rejected by cmd/compile and go/types, but prints 0 when run using gccgo:

package main

import "unsafe"

var s struct{ f float64 }

func main() {
	println(unsafe.Offsetof(*&(s.f)))
}

It seems like gccgo is optimizing *&(s.f) to (s.f) before checking that the argument to unsafe.Offsetof is well formed.

/cc @ianlancetaylor

Edit: I think the same issue affects unsafe.Alignof too.

@mdempsky mdempsky added this to the Gccgo milestone Jul 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.