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, types2: incorrect computation of unsafe.Sizeof() #45390
Comments
Stand-alone reproducer: package main
import "unsafe"
func main() {
println(unsafe.Sizeof(RegArgs{}))
}
type RegArgs struct {
Ints [IntArgRegs]uintptr // untyped integer registers
Floats [FloatArgRegs]uint64 // untyped float registers
// Fields above this point are known to assembly.
// Ptrs is a space that duplicates Ints but with pointer type,
// used to make pointers passed or returned in registers
// visible to the GC by making the type unsafe.Pointer.
Ptrs [IntArgRegs]unsafe.Pointer
// ReturnIsPtr is a bitmap that indicates which registers
// contain or will contain pointers on the return path from
// a reflectcall. The i'th bit indicates whether the i'th
// register contains or will contain a valid Go pointer.
ReturnIsPtr IntArgRegBitmap
}
// IntArgRegBitmap is a bitmap large enough to hold one bit per
// integer argument/return register.
type IntArgRegBitmap [(IntArgRegs + 7) / 8]uint8
const IntArgRegs = 0
const FloatArgRegs = 0 Running it:
The relevant code is in // gc: The last field of a struct is not allowed to
// have size 0.
last := s.Sizeof(fields[n-1].Type())
if last == 0 {
last = 1
} This looks like an inconsistency in the compiler/compiler validation code. |
See also #9401 for background info. |
Commenting out those lines ( |
Change https://golang.org/cl/307549 mentions this issue: |
What version of Go are you using (
go version
)?Current master (pre-release Go 1.17)
What did you do?
After building current master with ./make.bash, run:
I expected that to run normally, but I get this error:
This is from validation code in noder2. It looks like types2 is calculating unsafe.Sizeof(abi.RegArgs{}) as 8, when it should be zero. This only started failing when runtime/stack.go:1316 was added:
so the bug may have been around for a while (i.e. it wasn't a recent change in types2 that caused it to show up).
The text was updated successfully, but these errors were encountered: