Repository navigation
Closed
Closed
Copy link
Labels
CriticalA critical problem that affects the availability or correctness of production systems built using GoA critical problem that affects the availability or correctness of production systems built using GoFrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Milestone
Description
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?
=== 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 GoA critical problem that affects the availability or correctness of production systems built using GoFrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Activity
gabyhelp commentedon Oct 25, 2024
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
[-]iter.Seq: setting outer values in functional iterators seem to have memory issues[/-][+]cmd/compile: memory corruption when setting outer values in functional iterators[/+]prattmic commentedon Oct 25, 2024
cc @golang/compiler
dmitris commentedon Oct 25, 2024
Playground version: https://go.dev/play/p/SrpUKjbzHq4
If you uncomment any of the two
fmt.Println(joined)lines, it works as expected (ex. https://go.dev/play/p/sCV-WRD9S5y), same if usingSprintfinstead of combining strings with+.scr-oath commentedon Oct 25, 2024
Curiously enough, changing
to
Seems to avoid this problem - maybe that's a clue?
fengyoulin commentedon Oct 25, 2024
It seems that currently nested rangefunc, function inline and escape analysis do not work well together.
I can reproduce this problem on the master branch code using the following code:
But, you can avoid this problem, by
-gcflags='-l'.Some calls to
runtime.concatstring3use on stack buffers, that should have been moved to the heap.dr2chase commentedon Oct 25, 2024
I suspect this involves outlives and containsClosure in escape/solve.go and I am looking there.
cuonglm commentedon Oct 25, 2024
This seems to be the nested rangefunc name generation. For example, the parent is
Bug-range1, the child isBug-range2, and with current rule,Bug-range1does not containBug-range2, while it should.dr2chase commentedon Oct 25, 2024
I think I have a fix, sorry.
I just make an explicit parent pointer, initialize it in deadlocals, use that.
gopherbot commentedon Oct 25, 2024
Change https://go.dev/cl/622715 mentions this issue:
cmd/compile: fix wrong escape analysis for nested rangefunccuonglm commentedon Oct 25, 2024
Ops, I have sent https://go-review.googlesource.com/c/go/+/622715.
Feel free to abadon if you prefer your fix.
gopherbot commentedon Oct 25, 2024
Change https://go.dev/cl/622656 mentions this issue:
cmd/compile: use a non-fragile test for "does f contain closure c?"cmd/compile: use a non-fragile test for "does f contain closure c?"
cuonglm commentedon Oct 26, 2024
@dr2chase @randall77 Should we backport this?
zigo101 commentedon Nov 5, 2024
@dmitshur
randall77 commentedon Nov 5, 2024
Probably.
@gopherbot Please open a backport issue to 1.23.
This causes a serious miscompilation in certain range-over-func situations.
gopherbot commentedon Nov 5, 2024
Backport issue(s) opened: #70198 (for 1.23).
Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.
gopherbot commentedon Jan 3, 2025
Change https://go.dev/cl/640036 mentions this issue:
gopls: update toolchain to go1.23.4gopls: update toolchain to go1.23.4