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
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mdempsky
Copy link
Member

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
@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants