Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/go/ssa: slice to array conversion has the wrong type #57790

Closed
aykevl opened this issue Jan 13, 2023 · 3 comments
Closed

x/tools/go/ssa: slice to array conversion has the wrong type #57790

aykevl opened this issue Jan 13, 2023 · 3 comments
Assignees
Labels
FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@aykevl
Copy link

aykevl commented Jan 13, 2023

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.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jan 13, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jan 13, 2023
@ianlancetaylor
Copy link
Contributor

CC @timothy-king @adonovan

@gopherbot
Copy link

Change https://go.dev/cl/462175 mentions this issue: go/ssa: fix phi node type in slice to array conversion

@gopherbot
Copy link

Change https://go.dev/cl/462050 mentions this issue: go/ssa: sanity check the types of phi nodes

gopherbot pushed a commit to golang/tools that referenced this issue Jan 17, 2023
Adds a sanity check that the types of phi edges are types.Identical
to the Phi instruction.

This would have caught golang/go#57790.

Change-Id: I9818fc47fda368bfc009bfe4de66e23de759f6ca
Reviewed-on: https://go-review.googlesource.com/c/tools/+/462050
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Tim King <taking@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
aykevl added a commit to tinygo-org/tinygo that referenced this issue Feb 6, 2023
deadprogram pushed a commit to tinygo-org/tinygo that referenced this issue Feb 7, 2023
waj334 pushed a commit to waj334/tinygo that referenced this issue Feb 7, 2023
deadprogram pushed a commit to tinygo-org/tinygo that referenced this issue Feb 14, 2023
waj334 pushed a commit to waj334/tinygo that referenced this issue Feb 19, 2023
waj334 pushed a commit to waj334/tinygo that referenced this issue Feb 24, 2023
LiuJiazheng pushed a commit to LiuJiazheng/tinygo that referenced this issue Aug 20, 2023
@golang golang locked and limited conversation to collaborators Jan 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants