-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.
Milestone
Description
What version of Go are you using (go version
)?
$ go version go version go1.20rc2 linux/arm64
And I'm using the latest version of x/tools/go/ssa: 03eac81
Does this issue reproduce with the latest release?
No, slice to array conversions were added in Go 1.20.
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="" GOARCH="arm64" GOBIN="" GOCACHE="/home/ayke/.cache/go-build" GOENV="/home/ayke/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/ayke/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/ayke" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_arm64" GOVCS="" GOVERSION="go1.20rc2" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/home/ayke/src/tinygo/tools/go.mod" GOWORK="" CGO_CFLAGS="-O2 -g" CGO_CPPFLAGS="" CGO_CXXFLAGS="-O2 -g" CGO_FFLAGS="-O2 -g" CGO_LDFLAGS="-O2 -g" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build6976675=/tmp/go-build -gno-record-gcc-switches"
What did you do?
I created a simple Go file with the following contents:
package main
func sliceToArray(s []int) [4]int {
return [4]int(s)
}
Then I dumped the SSA output using ssadump
:
$ ssadump -build CFI slice2array.go
# Name: command-line-arguments.init
# Package: command-line-arguments
# Synthetic: package initializer
func init():
0: entry P:0 S:0
return
# Name: command-line-arguments.sliceToArray
# Package: command-line-arguments
# Location: /home/ayke/tmp/slice2array.go:3:6
# Locals:
# 0: t2 [4]int
func sliceToArray(s []int) [4]int:
0: entry P:0 S:2
t0 = slice to array pointer *[4]int <- []int (s) *[4]int
t1 = t0 == nil:*[4]int bool
if t1 goto 1 else 2
1: slicetoarray.nil P:1 S:1
t2 = local [4]int () *[4]int
jump 3
2: slicetoarray.nonnil P:1 S:1
jump 3
3: slicetoarray.done P:2 S:0
t3 = phi [1: t2, 2: t0] #slicetoarray [4]int
t4 = *t3 [4]int
return t4
The problem here is that t3
has the wrong type. It should be *[4]int
(a pointer) but instead it is [4]int
(an array). This triggers an issue on the following line:
t4 = *t3 [4]int
Here, t3
(which should be of pointer type but is an array here) is dereferenced. This leads to a panic in my code, which expects to dereference a pointer and not an array.
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.