aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/staticinit
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2020-12-31 23:45:36 -0800
committerMatthew Dempsky <mdempsky@google.com>2021-01-01 10:52:33 +0000
commit68e6fa4f6852b4ef0fe61789618c093f4e2185c9 (patch)
tree0d05c5a184ef8a3e68c642e3bbb962c26f4499ef /src/cmd/compile/internal/staticinit
parent3a4474cdfda0096b5d88c769f81ad81d6f0168c7 (diff)
downloadgo-68e6fa4f6852b4ef0fe61789618c093f4e2185c9.tar.gz
go-68e6fa4f6852b4ef0fe61789618c093f4e2185c9.zip
[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>
Diffstat (limited to 'src/cmd/compile/internal/staticinit')
-rw-r--r--src/cmd/compile/internal/staticinit/sched.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/staticinit/sched.go b/src/cmd/compile/internal/staticinit/sched.go
index 1b0af1b05d..8e4ce55954 100644
--- a/src/cmd/compile/internal/staticinit/sched.go
+++ b/src/cmd/compile/internal/staticinit/sched.go
@@ -86,17 +86,22 @@ func (s *Schedule) staticcopy(l *ir.Name, loff int64, rn *ir.Name, typ *types.Ty
if rn.Class_ != ir.PEXTERN || rn.Sym().Pkg != types.LocalPkg {
return false
}
- if rn.Defn == nil { // probably zeroed but perhaps supplied externally and of unknown value
- return false
- }
if rn.Defn.Op() != ir.OAS {
return false
}
if rn.Type().IsString() { // perhaps overwritten by cmd/link -X (#34675)
return false
}
+ if rn.Embed != nil {
+ return false
+ }
orig := rn
r := rn.Defn.(*ir.AssignStmt).Y
+ if r == nil {
+ // No explicit initialization value. Probably zeroed but perhaps
+ // supplied externally and of unknown value.
+ return false
+ }
for r.Op() == ir.OCONVNOP && !types.Identical(r.Type(), typ) {
r = r.(*ir.ConvExpr).X
@@ -185,6 +190,11 @@ func (s *Schedule) staticcopy(l *ir.Name, loff int64, rn *ir.Name, typ *types.Ty
}
func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Type) bool {
+ if r == nil {
+ // No explicit initialization value. Either zero or supplied
+ // externally.
+ return true
+ }
for r.Op() == ir.OCONVNOP {
r = r.(*ir.ConvExpr).X
}