diff options
author | Dan Scales <danscales@google.com> | 2021-08-22 11:50:58 -0700 |
---|---|---|
committer | Dan Scales <danscales@google.com> | 2021-08-23 22:55:34 +0000 |
commit | be1a6934776a3c7f636932918e756b44b6510214 (patch) | |
tree | b32e04c7aa216314ccc3b5f501691697b7efa761 /src/cmd/compile/internal/noder/validate.go | |
parent | 8157960d7f4a89807c71b3427a0363a23fd43ca9 (diff) | |
download | go-be1a6934776a3c7f636932918e756b44b6510214.tar.gz go-be1a6934776a3c7f636932918e756b44b6510214.zip |
cmd/compile: fixes for non-constant Sizeof/Alignof/Offsetof
Includes Robert's suggested fix in validate.go to not fail on
non-constant alignof/offsetof/sizeof calls. Further changes to wait on
transforming these calls until stenciling time, when we can call
EvalConst() to evaluate them once all the relevant types are known.
Added a bunch of new tests for non-constant Sizeof/Alignof/Offsetof.
Fixes #47716
Change-Id: I469af888eb9ce3a853124d919eda753971009b3e
Reviewed-on: https://go-review.googlesource.com/c/go/+/344250
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
Diffstat (limited to 'src/cmd/compile/internal/noder/validate.go')
-rw-r--r-- | src/cmd/compile/internal/noder/validate.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/noder/validate.go b/src/cmd/compile/internal/noder/validate.go index 68a059b96f..dcacae7480 100644 --- a/src/cmd/compile/internal/noder/validate.go +++ b/src/cmd/compile/internal/noder/validate.go @@ -81,7 +81,16 @@ func (g *irgen) validateBuiltin(name string, call *syntax.CallExpr) { // Check that types2+gcSizes calculates sizes the same // as cmd/compile does. - got, ok := constant.Int64Val(g.info.Types[call].Value) + tv := g.info.Types[call] + if !tv.IsValue() { + base.FatalfAt(g.pos(call), "expected a value") + } + + if tv.Value == nil { + break // unsafe op is not a constant, so no further validation + } + + got, ok := constant.Int64Val(tv.Value) if !ok { base.FatalfAt(g.pos(call), "expected int64 constant value") } |