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: "add some generic composite type optimizations" improperly discards writes to non-autos #26153

Closed
heschi opened this issue Jun 29, 2018 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@heschi
Copy link
Contributor

heschi commented Jun 29, 2018

CL 106495 (commit f31a18d) adds a pass, "dead auto elim", that eliminates local variables that are only written, not read. Under certain circumstances, it can discard writes to non-autos. In this example:

package main

import "fmt"

func main() {
	var s string
	mangle(&s)
	fmt.Println(s)
}

//go:noinline
func mangle(ps *string) {
	if ps == nil {
		var s string
		ps = &s
	}
	*ps = "hello world"
}

The write on the last line to *ps will be discarded. I think the problem is that elimDeadAutosGeneric totally ignores non-autos, even when their existence is important. The phi op that unifies ps after the if takes two values, essentially &s and ps. Because the function doesn't care about non-autos, it ignores ps, and considers the phi to be dead if s is dead, which of course it is. Really the whole thing should be kept alive by the (potential) write through ps.

cc @randall77, @TocarIP, @mundaym

@heschi heschi added this to the Go1.11 milestone Jun 29, 2018
@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 29, 2018
@gopherbot
Copy link

Change https://golang.org/cl/121796 mentions this issue: cmd/compile: keep autos whose address reaches a phi

@mundaym
Copy link
Member

mundaym commented Jun 30, 2018

Thanks for the bug report @heschik. I think CL 121796 should be enough to fix the problem.

@golang golang locked and limited conversation to collaborators Jul 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants