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

cmd/compile: sparse slices with struct items are not initialized #31987

Closed
kdarkhan opened this issue May 12, 2019 · 4 comments
Closed

cmd/compile: sparse slices with struct items are not initialized #31987

kdarkhan opened this issue May 12, 2019 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@kdarkhan
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.12.4 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/user/opt/go-src/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build290432406=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Sparse slices with struct items are not initialized properly.
This test fails on 1.12 but passes on 1.11

type container struct {
	Value string
}

func TestSparseSlice(t *testing.T) {
	s := []container {
		7: {Value: "string value"},
	}
	if len(s) != 8 || s[7].Value != "string value" {
		t.Errorf("wanted string=\"string value\", got %s", s[7].Value)
	}
}

What did you expect to see?

7th entry in the slice containing {Value: "some string"} and test passing.

What did you see instead?

All elements in the slice are zero-valued. Reverting the change introduced here https://go-review.googlesource.com/c/go/+/151319/ fixes the issue.

@ALTree
Copy link
Member

ALTree commented May 12, 2019

Thanks for the report.

cc @randall77

@ALTree ALTree added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels May 12, 2019
@ALTree ALTree added this to the Go1.13 milestone May 13, 2019
@gopherbot
Copy link

Change https://golang.org/cl/176904 mentions this issue: cmd/compile: make sure to initialize static entries of slices

@randall77
Copy link
Contributor

@gopherbot Please open a backport to 1.12.

@gopherbot
Copy link

Backport issue(s) opened: #32013 (for 1.12).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

@golang golang locked and limited conversation to collaborators May 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants