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

Comments

@kdarkhan
Copy link

@kdarkhan kdarkhan commented May 12, 2019

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

This comment has been minimized.

Copy link
Member

@ALTree ALTree commented May 12, 2019

Thanks for the report.

cc @randall77

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented May 13, 2019

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

@randall77

This comment has been minimized.

Copy link
Contributor

@randall77 randall77 commented May 13, 2019

@gopherbot Please open a backport to 1.12.

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented May 13, 2019

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.

@gopherbot gopherbot closed this in a9e107c May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.