aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/gc/main.go
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/gc/main.go
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/gc/main.go')
-rw-r--r--src/cmd/compile/internal/gc/main.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go
index df6a9d8e45..c1f51e4f1d 100644
--- a/src/cmd/compile/internal/gc/main.go
+++ b/src/cmd/compile/internal/gc/main.go
@@ -208,6 +208,11 @@ func Main(archInit func(*ssagen.ArchInfo)) {
dwarfgen.RecordPackageName()
ssagen.CgoSymABIs()
+ // Build init task.
+ if initTask := pkginit.Task(); initTask != nil {
+ typecheck.Export(initTask)
+ }
+
// Compute Addrtaken for names.
// We need to wait until typechecking is done so that when we see &x[i]
// we know that x has its address taken if x is an array, but not if x is a slice.
@@ -249,11 +254,6 @@ func Main(archInit func(*ssagen.ArchInfo)) {
typecheck.AllImportedBodies()
}
- // Build init task.
- if initTask := pkginit.Task(); initTask != nil {
- typecheck.Export(initTask)
- }
-
// Inlining
base.Timer.Start("fe", "inlining")
if base.Flag.LowerL != 0 {