diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2017-04-27 09:27:52 -0700 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2017-04-27 22:10:32 +0000 |
commit | 0b6a10ef246ff55085d6ec88f68f5fd96677b141 (patch) | |
tree | f6686f3edeeb103bf84e02fc28c2c00e47a1b7ca /src/cmd/compile/internal/types/type.go | |
parent | be2ee2a4b46d1dbaf8d455038cd12d883714f08d (diff) | |
download | go-0b6a10ef246ff55085d6ec88f68f5fd96677b141.tar.gz go-0b6a10ef246ff55085d6ec88f68f5fd96677b141.zip |
cmd/compile: dowidth more in the front end
dowidth is fundamentally unsafe to call from the back end;
it will cause data races.
Replace all calls to dowidth in the backend with
assertions that the width has been calculated.
Then fix all the cases in which that was not so,
including the cases from #20145.
Fixes #20145.
Change-Id: Idba3d19d75638851a30ec2ebcdb703c19da3e92b
Reviewed-on: https://go-review.googlesource.com/41970
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types/type.go')
-rw-r--r-- | src/cmd/compile/internal/types/type.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go index b0be122d0a..62041454ca 100644 --- a/src/cmd/compile/internal/types/type.go +++ b/src/cmd/compile/internal/types/type.go @@ -849,6 +849,13 @@ func (t *Type) WidthCalculated() bool { return t.Align > 0 } +// AssertWidthCalculated calls Fatalf if t's width has not yet been calculated. +func (t *Type) AssertWidthCalculated() { + if !t.WidthCalculated() { + Fatalf("width not calculated: %v", t) + } +} + // ArgWidth returns the total aligned argument size for a function. // It includes the receiver, parameters, and results. func (t *Type) ArgWidth() int64 { @@ -857,12 +864,12 @@ func (t *Type) ArgWidth() int64 { } func (t *Type) Size() int64 { - Dowidth(t) + t.AssertWidthCalculated() return t.Width } func (t *Type) Alignment() int64 { - Dowidth(t) + t.AssertWidthCalculated() return int64(t.Align) } |