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: panic with Go 1.17 slice-to-array conversions when converting to a newtype #48281

Closed
ainar-g opened this issue Sep 9, 2021 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@ainar-g
Copy link
Contributor

ainar-g commented Sep 9, 2021

This is probably related to #46987. Consider this code:

package main

import (
	"fmt"
)

type arr [2]int

func main() {
	s := []int{1, 2, 3, 4}
	fmt.Println(*(*arr)(s))
}

This program works and produces the intended output with Go 1.17. But checking it with any SSA-based analyser seems to trigger a panic. For example, using nilness:

goroutine 195 [running]:
golang.org/x/tools/go/ssa.emitConv(0xc0000fac80, {0x7c6120, 0xc00049cea0}, {0x7bf368, 0xc000078810})
        /home/ainar/go/pkg/mod/golang.org/x/tools@v0.1.6-0.20210908235426-076821bd2bbc/go/ssa/emit.go:252 +0x8ee
golang.org/x/tools/go/ssa.(*builder).expr0(0x6fe800, 0xc0000fac80, {0x7bfac8, 0xc0001163c0}, {0x7, {0x7bf368, 0xc000078810}, {0x0, 0x0}})
        /home/ainar/go/pkg/mod/golang.org/x/tools@v0.1.6-0.20210908235426-076821bd2bbc/go/ssa/builder.go:573 +0x925
golang.org/x/tools/go/ssa.(*builder).expr(0x0, 0xc0000fac80, {0x7bfac8, 0xc0001163c0})
        /home/ainar/go/pkg/mod/golang.org/x/tools@v0.1.6-0.20210908235426-076821bd2bbc/go/ssa/builder.go:530 +0x19f

But if you replace a newtype with a type alias, it works:

-type arr [2]int
+type arr = [2]int
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 9, 2021
@gopherbot gopherbot added this to the Unreleased milestone Sep 9, 2021
@cuonglm cuonglm self-assigned this Sep 9, 2021
@cuonglm cuonglm added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 9, 2021
@gopherbot
Copy link

Change https://golang.org/cl/348511 mentions this issue: go/ssa: fix slice to array ptr conversions for named type

@ainar-g
Copy link
Contributor Author

ainar-g commented Sep 13, 2021

Thanks again for a quick response! I confim that the issue is fixed on the master branch.

ainar-g added a commit to ainar-g/unparam that referenced this issue Sep 15, 2021
Make sure that golang/go#48281 doesn't affect unparam by updating module
golang.org/x/tools to the latest master version.

    go get golang.org/x/tools@master
    go mod tidy

There are no manual changes.
mvdan pushed a commit to mvdan/unparam that referenced this issue Sep 15, 2021
Make sure that golang/go#48281 doesn't affect unparam by updating module
golang.org/x/tools to the latest master version.

    go get golang.org/x/tools@master
    go mod tidy

There are no manual changes.
@rsc rsc unassigned cuonglm Jun 23, 2022
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants