1
0
mirror of https://github.com/golang/go synced 2024-11-06 07:26:10 -07:00
go/test/fixedbugs/issue43444.go
Matthew Dempsky 68e6fa4f68 [dev.regabi] cmd/compile: fix package-initialization order
This CL fixes package initialization order by creating the init task
before the general deadcode-removal pass.

It also changes noder to emit zero-initialization assignments (i.e.,
OAS with nil RHS) for package-block variables, so that initOrder can
tell the variables still need initialization. To allow this, we need
to also extend the static-init code to recognize zero-initialization
assignments.

This doesn't pass toolstash -cmp, because it reorders some package
initialization routines.

Fixes #43444.

Change-Id: I0da7996a62c85e15e97ce965298127e075390a7e
Reviewed-on: https://go-review.googlesource.com/c/go/+/280976
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-01-01 10:52:33 +00:00

29 lines
343 B
Go

// run
package main
var sp = ""
func f(name string, _ ...interface{}) int {
print(sp, name)
sp = " "
return 0
}
var a = f("a", x)
var b = f("b", y)
var c = f("c", z)
var d = func() int {
if false {
_ = z
}
return f("d")
}()
var e = f("e")
var x int
var y int = 42
var z int = func() int { return 42 }()
func main() { println() }