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>
This commit is contained in:
Dan Scales 2021-08-22 11:50:58 -07:00
parent 8157960d7f
commit be1a693477
6 changed files with 95 additions and 5 deletions

View file

@ -811,7 +811,10 @@ func transformBuiltin(n *ir.CallExpr) ir.Node {
return transformRealImag(u1.(*ir.UnaryExpr))
case ir.OPANIC:
return transformPanic(u1.(*ir.UnaryExpr))
case ir.OCLOSE, ir.ONEW, ir.OALIGNOF, ir.OOFFSETOF, ir.OSIZEOF:
case ir.OALIGNOF, ir.OOFFSETOF, ir.OSIZEOF:
// This corresponds to the EvalConst() call near end of typecheck().
return typecheck.EvalConst(u1)
case ir.OCLOSE, ir.ONEW:
// nothing more to do
return u1
}