-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
What version of Go are you using (go version
)?
tip (49402be)
Does this issue reproduce with the latest release?
Reproducible with 1.17RC1
Not with 1.16.
What operating system and processor architecture are you using (go env
)?
darwin/amd64
What did you do?
Compiling code that calls an ABI0 function using a func value, on a register-ABI platform.
x.go
package p
func F() interface{} {
g := G
g(1)
return G
}
func G(x int) [2]int
a.s
TEXT ·G(SB),4,$0-24
RET
What did you expect to see?
Build successfully.
What did you see instead?
./x.go:6:2: internal compiler error: offset for x at ./x.go:9:8 changed from 0 to 16
goroutine 8 [running]:
runtime/debug.Stack()
/Users/cherryyz/src/go-tmp/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x262c0, 0xc0}, {0x19017a3, 0x29}, {0xc0005dd310, 0x4, 0x4})
/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/base/print.go:227 +0x154
cmd/compile/internal/base.Fatalf(...)
/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/abi.(*ABIConfig).updateOffset(0x0, 0x251ffff, 0xc0003c0910, {0xc00037e380, {0x1a35260, 0xc0003bf110}, {0xc000026228, 0x1, 0x8}, 0x0}, ...)
/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/abi/abiutils.go:477 +0x298
cmd/compile/internal/abi.(*ABIConfig).ABIAnalyze(0xc0003bef70, 0x1a4b188, 0x70)
/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/abi/abiutils.go:441 +0x232
cmd/compile/internal/ssagen.(*state).call(0xc0005ce000, 0xc000176360, 0x0, 0x0)
/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/ssagen/ssa.go:5012 +0x926
cmd/compile/internal/ssagen.(*state).callResult(0xc000176360, 0x0, 0x70)
/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/ssagen/ssa.go:4915 +0x1b
cmd/compile/internal/ssagen.(*state).stmt(0xc0005ce000, {0x1a49d38, 0xc000176360})
/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/ssagen/ssa.go:1453 +0xf05
cmd/compile/internal/ssagen.(*state).stmtList(0xc0005ce000, {0xc0000ae500, 0x6, 0x1a2f620})
/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/ssagen/ssa.go:1414 +0x5d
cmd/compile/internal/ssagen.buildssa(0xc00013c2c0, 0x1)
/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/ssagen/ssa.go:622 +0x1d33
cmd/compile/internal/ssagen.Compile(0xc00013c2c0, 0xc0005cdf90)
/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/ssagen/pgen.go:165 +0x4c
cmd/compile/internal/gc.compileFunctions.func4.1(0x0)
/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/gc/compile.go:153 +0x3a
cmd/compile/internal/gc.compileFunctions.func3.1()
/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/gc/compile.go:140 +0x4d
created by cmd/compile/internal/gc.compileFunctions.func3
/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/gc/compile.go:138 +0x7f
In the case above, G
is an ABI0 function. It is called via a func value (g
). As far as I can tell, the ABI analysis for the call (g(1)
) correctly uses ABIInternal (for ABI config), but the function's *Type
being analyzed is the same *Type
as the definition of ABI0 G
. Perhaps the line g := G
just makes g
the same *Type
as G
.
@aclements @thanm @dr2chase what ensures that we always put the ABIInternal reference to a func value? What do we do with its *Type
? The ABI analysis associates parameter/result offsets to the fields of function *Type
. So if an ABI0 reference and an ABIInternal reference have the same *Type
pointer, it blows up.
If I add an explicit type definition, var g func(int) [2]int = G
, it compiles fine.
Originally found by @mdempsky and @cuonglm when investigating #47227. See also CL https://go-review.googlesource.com/c/go/+/334883 .