74b52d9519
CL 399694 added constant-fold switch early in compilation. So function: func f() string { switch intSize { case 32: return "32" case 64: return "64" default: panic("unreachable") } } will be constant-fold to: func f() string { switch intSize { case 64: return "64" } } When this function get inlined, there is a check whether we can delay declaring the result parameter until the "return" statement. For the original function, we can't delay the result, because there's more than one return statement. However, the constant-fold one can, because there's on one return statement in the body now. The result parameter ~R0 ends up declaring inside the switch statement scope. Now, when walking the switch statement, it's re-written into if-else statement. Without typecheck.EvalConst, the if condition "if 64 == 64" is passed as-is to the ssa generation pass. Because "64 == 64" is not a constant, the ssagen creates normal blocks for branching the results. This confuses the liveness analysis, because ~R0 is only live inside the if block. With typecheck.EvalConst, "64 == 64" is evaluated to "true", so ssagen can branch the result without emitting conditional blocks. Instead, the constant-fold can be re-written as: switch { case true: // Body } So it does not depend on the delay results check during inlining. Adding a test, which will fail when typecheck.EvalConst is removed, so we can do the cleanup without breaking things. Change-Id: I638730bb147140de84260653741431b807ff2f15 Reviewed-on: https://go-review.googlesource.com/c/go/+/484316 Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> |
||
---|---|---|
.github | ||
api | ||
doc | ||
lib/time | ||
misc | ||
src | ||
test | ||
.gitattributes | ||
.gitignore | ||
codereview.cfg | ||
CONTRIBUTING.md | ||
go.env | ||
LICENSE | ||
PATENTS | ||
README.md | ||
SECURITY.md |
The Go Programming Language
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 4.0 Attributions license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Download and Install
Binary Distributions
Official binary distributions are available at https://go.dev/dl/.
After downloading a binary release, visit https://go.dev/doc/install for installation instructions.
Install From Source
If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.
Contributing
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.