Skip to content

cmd/compile: incorrect optimization (go1.25rc2) #74557

Closed
@AlphaLxy

Description

@AlphaLxy

Go version

go version go1.25rc2 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE='on'
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='***'
GOCACHE='***'
GOCACHEPROG=''
GODEBUG=''
GOENV='***'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/6c/_j2w7w9j23db85y594fl2xmc0000gn/T/go-build3349238838=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='***'
GOMODCACHE='***'
GONOPROXY='***'
GONOSUMDB='***'
GOOS='darwin'
GOPATH='***'
GOPRIVATE='***'
GOPROXY='***'
GOROOT='***'
GOSUMDB='sum.golang.google.cn'
GOTELEMETRY='local'
GOTELEMETRYDIR='***'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='***'
GOVCS=''
GOVERSION='go1.25rc2'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

package main

import (
	"reflect"
	"unsafe"
)

var stringTypePointer = reflect.ValueOf(reflect.TypeFor[string]()).Pointer()

func main() {
	t := reflect.TypeOf(0)
	(*[2]uintptr)(unsafe.Pointer(&t))[1] = stringTypePointer
	println(t.String())
}

What did you see happen?

Without optimization:

>> go run -gcflags='all=-l -N' main.go
string

Default:

>> go run main.go
int

What did you expect to see?

string is correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions