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 inline function variable #59572

Closed
wdvxdr1123 opened this issue Apr 12, 2023 · 4 comments
Closed

cmd/compile: incorrect inline function variable #59572

wdvxdr1123 opened this issue Apr 12, 2023 · 4 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@wdvxdr1123
Copy link
Contributor

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

$ go version
go version go1.20.1 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

package main

func foo() {
	println("foo")
}

func main() {
	fn := foo
	for _, fn = range list {
		fn()
	}
}

var list = []func(){
	func() {
		println("1")
	},
	func() {
		println("2")
	},
	func() {
		println("3")
	},
}

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

What did you expect to see?

output

1
2
3

What did you see instead?

output

foo
foo
foo
go run -gcflags='-m=1' a.go
# command-line-arguments
./a.go:3:6: can inline foo
./a.go:7:6: can inline main
./a.go:10:5: inlining call to foo
./a.go:15:2: can inline glob..func1
./a.go:18:2: can inline glob..func2
./a.go:21:2: can inline glob..func3

I'll send a CL to fix soon.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Apr 12, 2023
@gopherbot
Copy link

Change https://go.dev/cl/483855 mentions this issue: cmd/compile: fix ir.StaticValue for ORANGE

@randall77
Copy link
Contributor

@gopherbot please open backport issues. This is a bad miscompilation.

@gopherbot
Copy link

Backport issue(s) opened: #59579 (for 1.19), #59580 (for 1.20).

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

@ianlancetaylor
Copy link
Contributor

Works in Go 1.15, broken since then. Works in gccgo.

@mknyszek mknyszek modified the milestones: Backlog, Go1.21 Apr 12, 2023
@mknyszek mknyszek added the NeedsFix The path to resolution is known, but the work has not been done. label Apr 12, 2023
@golang golang locked and limited conversation to collaborators Apr 11, 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 NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants