Skip to content

cmd/compile: memory corruption when setting outer values in functional iterators #70035

Closed
@scr-oath

Description

@scr-oath

Go version

go version go1.23.2 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/scr/Library/Caches/go-build'
GOENV='/Users/scr/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/scr/.asdf/installs/golang/1.23.2/packages/pkg/mod'
GONOPROXY='go.ouryahoo.com'
GONOSUMDB='go.ouryahoo.com'
GOOS='darwin'
GOPATH='/Users/scr/.asdf/installs/golang/1.23.2/packages'
GOPRIVATE='go.ouryahoo.com'
GOPROXY='https://goproxy.ouryahoo.com:4443/goproxy,https://proxy.golang.org,direct'
GOROOT='/Users/scr/.asdf/installs/golang/1.23.2/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/scr/.asdf/installs/golang/1.23.2/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.2'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/scr/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/scr/GolandProjects/scr/show-iteration-failure/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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/wj/29xj08zd0vn3trjdyh197h_00000gq/T/go-build942010698=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Wrote and ran this test

package bug

import (
	"slices"
	"testing"
)

func Bug() string {
	var ret string
	prefixes := []string{"prefix"}
	stringValues := []string{"foo", "bar", "baz"}
	for prefix := range slices.Values(prefixes) {
		var joined string
		for stringValue := range slices.Values(stringValues) {
			if joined == "" {
				joined = stringValue
			} else {
				joined = joined + "_" + stringValue
			}
		}
		ret = prefix + "+" + joined
	}
	return ret
}

func Test_Bug(t *testing.T) {
	got := Bug()
	want := "prefix+foo_bar_baz"
	if got != want {
		t.Errorf("Bug() = %v, want %v", got, want)
	}
}

What did you see happen?

image
=== RUN   Test_Bug
    bug_test.go:30: Bug() = prefix+foo_bar_IJ�, want prefix+foo_bar_baz
--- FAIL: Test_Bug (0.00s)

FAIL

What did you expect to see?

I expected not to see a result that contained uninitialized memory - it's different every time and seems to refer to bad bytes.

Metadata

Metadata

Labels

CriticalA critical problem that affects the availability or correctness of production systems built using GoNeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions