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: incorrect inlining of function swapping two funcs #59108

Closed
fabe-xx opened this issue Mar 18, 2023 · 6 comments
Closed

cmd/compile: incorrect inlining of function swapping two funcs #59108

fabe-xx opened this issue Mar 18, 2023 · 6 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge

Comments

@fabe-xx
Copy link

fabe-xx commented Mar 18, 2023

What version of Go are you using (go version)?

$ go version
go version go1.19.7 windows/amd64

Does this issue reproduce with the latest release?

It does with 1.19; not with 1.20.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\telic\AppData\Local\go-build
set GOENV=C:\Users\telic\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\telic\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\telic\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.19.7
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\F2\Texter\go.mod
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\telic\AppData\Local\Temp\go-build2840717194=/tmp/go-build -gno-record-gcc-switches

What did you do?

See test in playground.
By uncommenting the commented-out line in test() (introducing two blank variables) you can get the test to pass, presumably by preventing inlining.

What did you expect to see?

Output "01", indicating first the first, then the second func getting called.

What did you see instead?

Output "00", indicating the first func instead got called twice.

@thoro
Copy link

thoro commented Mar 18, 2023

According to the decompilation at https://godbolt.org/z/hacWM8Ejd

The bug is introduced with 1.16, 1.15 still has both functions, starting with 1.16 to 1.19 the inlined b function is optimized away.

@seankhliao seankhliao changed the title Incorrect inlining of function swapping two funcs cmd/compile: incorrect inlining of function swapping two funcs Mar 18, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Mar 18, 2023
@thoro
Copy link

thoro commented Mar 18, 2023

Fixed for Go1.20 here: #54632

@seankhliao
Copy link
Member

Duplicate of #54632

@seankhliao seankhliao marked this as a duplicate of #54632 Mar 18, 2023
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Mar 18, 2023
@christophberger
Copy link

Curious: Is a fix for Go 1.19.x planned?

@ianlancetaylor
Copy link
Contributor

@gopherbot Please open backport issue for 1.19

Reportedly this issue occurs in 1.19 as well.

@gopherbot
Copy link
Contributor

Backport issue(s) opened: #59158 (for 1.19).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@golang golang locked and limited conversation to collaborators Mar 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge
Projects
None yet
Development

No branches or pull requests

6 participants