mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: fix gcSizes.Sizeof for a zero-sized struct
(*gcSizes).Sizeof was requiring the last field of a zero-sized struct to be at least one byte. But that rule (fix for #9401, see logic in calcStructOffset) only applies to a struct that has some non-zero sized fields. Fix (*gcSizes).Sizeof to have the logic like calcStructOffset. Fixes running the gotests with -G=3 enabled. Fixes #45390 Change-Id: I011f40e3de3a327392bbbb791b9422be75336313 Reviewed-on: https://go-review.googlesource.com/c/go/+/307549 Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com>
This commit is contained in:
parent
84162b8832
commit
5cd8a34495
1 changed files with 2 additions and 2 deletions
|
|
@ -115,10 +115,10 @@ func (s *gcSizes) Sizeof(T types2.Type) int64 {
|
||||||
}
|
}
|
||||||
offsets := s.Offsetsof(fields)
|
offsets := s.Offsetsof(fields)
|
||||||
|
|
||||||
// gc: The last field of a struct is not allowed to
|
// gc: The last field of a non-zero-sized struct is not allowed to
|
||||||
// have size 0.
|
// have size 0.
|
||||||
last := s.Sizeof(fields[n-1].Type())
|
last := s.Sizeof(fields[n-1].Type())
|
||||||
if last == 0 {
|
if last == 0 && offsets[n-1] > 0 {
|
||||||
last = 1
|
last = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue