aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/typecheck/const.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-08-22 11:50:58 -0700
committerDan Scales <danscales@google.com>2021-08-23 22:55:34 +0000
commitbe1a6934776a3c7f636932918e756b44b6510214 (patch)
treeb32e04c7aa216314ccc3b5f501691697b7efa761 /src/cmd/compile/internal/typecheck/const.go
parent8157960d7f4a89807c71b3427a0363a23fd43ca9 (diff)
downloadgo-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/typecheck/const.go')
-rw-r--r--src/cmd/compile/internal/typecheck/const.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/typecheck/const.go b/src/cmd/compile/internal/typecheck/const.go
index f8150d249a..c27cf0e646 100644
--- a/src/cmd/compile/internal/typecheck/const.go
+++ b/src/cmd/compile/internal/typecheck/const.go
@@ -881,7 +881,9 @@ func evalunsafe(n ir.Node) int64 {
case ir.OOFFSETOF:
// must be a selector.
n := n.(*ir.UnaryExpr)
- if n.X.Op() != ir.OXDOT {
+ // ODOT and ODOTPTR are allowed in case the OXDOT transformation has
+ // already happened (e.g. during -G=3 stenciling).
+ if n.X.Op() != ir.OXDOT && n.X.Op() != ir.ODOT && n.X.Op() != ir.ODOTPTR {
base.Errorf("invalid expression %v", n)
return 0
}