mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: add sizeCalculationDisabled flag
Use it to ensure that dowidth is not called from the backend on a type whose size has not yet been calculated. This is an alternative to CL 42016. Change-Id: I8c7b4410ee4c2a68573102f6b9b635f4fdcf392e Reviewed-on: https://go-review.googlesource.com/42018 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
dae5389d3d
commit
c51559813f
4 changed files with 22 additions and 15 deletions
|
|
@ -9,6 +9,10 @@ import (
|
|||
"sort"
|
||||
)
|
||||
|
||||
// sizeCalculationDisabled indicates whether it is safe
|
||||
// to calculate Types' widths and alignments. See dowidth.
|
||||
var sizeCalculationDisabled bool
|
||||
|
||||
// machine size and rounding alignment is dictated around
|
||||
// the size of a pointer, set in betypeinit (see ../amd64/galign.go).
|
||||
var defercalc int
|
||||
|
|
@ -151,6 +155,10 @@ func widstruct(errtype *types.Type, t *types.Type, o int64, flag int) int64 {
|
|||
return o
|
||||
}
|
||||
|
||||
// dowidth calculates and stores the size and alignment for t.
|
||||
// If sizeCalculationDisabled is set, and the size/alignment
|
||||
// have not already been calculated, it calls Fatal.
|
||||
// This is used to prevent data races in the back end.
|
||||
func dowidth(t *types.Type) {
|
||||
if Widthptr == 0 {
|
||||
Fatalf("dowidth without betypeinit")
|
||||
|
|
@ -174,6 +182,10 @@ func dowidth(t *types.Type) {
|
|||
return
|
||||
}
|
||||
|
||||
if sizeCalculationDisabled {
|
||||
Fatalf("width not calculated: %v", t)
|
||||
}
|
||||
|
||||
// break infinite recursion if the broken recursive type
|
||||
// is referenced again
|
||||
if t.Broke() && t.Width == 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue