Skip to content

cmd/compile: mysterious crashes and non-determinism with range over func #69507

@seehuhn

Description

@seehuhn

Go version

go version go1.23.0 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/voss/Library/Caches/go-build'
GOENV='/Users/voss/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/voss/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/voss/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.0'
GODEBUG=''
GOTELEMETRY='on'
GOTELEMETRYDIR='/Users/voss/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/voss/project/pdf-issues/006-go-iter/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 -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/var/folders/hn/tn2k45vx3pz4v24pbmf4zl040000gn/T/go-build3862330642=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I tried to use the new range over func loops. Here is the code:

https://go.dev/play/p/rYiGIM4RaVe

This is a pared down version of a much longer program. The code here does no longer make much sense, but has no external dependencies and still shows the problem.

What did you see happen?

There are several problems with this code:

  • On the playground, at https://go.dev/play/p/rYiGIM4RaVe, the code crashes with the message fatal error: concurrent map read and map write. Note that there is no explicit concurrency in this code. The crash goes away if the print statement on line 80 is enabled.
  • On my own system (an M2 MacBook Air), the same code crashes with the following error message:
    unexpected fault address 0xf48d0c3a929e0
    fatal error: fault
    [signal SIGSEGV: segmentation violation code=0x2 addr=0xf48d0c3a929e0 pc=0x104d58a50]
    
    I attach the full stacktrace, in case it is useful: stacktrace.txt. When I enable the print statement on line 80 the problem goes away.
  • While trying to debug the problem, similar code (which I didn't keep, sorry!) sometimes triggered the panic on line 95 with impossible key values for the map bestM.

What did you expect to see?

The code should not crash, and the absence/presence of the print statement should not change the behaviour of the program.

Metadata

Metadata

Assignees

No one assigned

    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.release-blocker

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions