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
heschik opened this issue Jun 29, 2018 · 2 comments

Comments

@heschik
Copy link
Contributor

@heschik heschik 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

@heschik heschik added this to the Go1.11 milestone Jun 29, 2018
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Jun 30, 2018

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

@mundaym

This comment has been minimized.

Copy link
Member

@mundaym mundaym commented Jun 30, 2018

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

@gopherbot gopherbot closed this in adfa8b8 Jul 2, 2018
@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.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.