diff --git a/src/cmd/compile/internal/coverage/cover.go b/src/cmd/compile/internal/coverage/cover.go index d17940fd401..5320f004da6 100644 --- a/src/cmd/compile/internal/coverage/cover.go +++ b/src/cmd/compile/internal/coverage/cover.go @@ -22,9 +22,9 @@ import ( "strings" ) -// Names records state information collected in the first fixup +// names records state information collected in the first fixup // phase so that it can be passed to the second fixup phase. -type Names struct { +type names struct { MetaVar *ir.Name PkgIdVar *ir.Name InitFn *ir.Func @@ -32,13 +32,17 @@ type Names struct { CounterGran coverage.CounterGranularity } -// FixupVars is the first of two entry points for coverage compiler -// fixup. It collects and returns the package ID and meta-data -// variables being used for this "-cover" build, along with the -// coverage counter mode and granularity. It also reclassifies selected -// variables (for example, tagging coverage counter variables with -// flags so that they can be handled properly downstream). -func FixupVars() Names { +// Fixup adds calls to the pkg init function as appropriate to +// register coverage-related variables with the runtime. +// +// It also reclassifies selected variables (for example, tagging +// coverage counter variables with flags so that they can be handled +// properly downstream). +func Fixup() { + if base.Flag.Cfg.CoverageInfo == nil { + return // not using coverage + } + metaVarName := base.Flag.Cfg.CoverageInfo.MetaVar pkgIdVarName := base.Flag.Cfg.CoverageInfo.PkgIdVar counterMode := base.Flag.Cfg.CoverageInfo.CounterMode @@ -92,18 +96,13 @@ func FixupVars() Names { counterGran) } - return Names{ + cnames := names{ MetaVar: metavar, PkgIdVar: pkgidvar, CounterMode: cm, CounterGran: cg, } -} -// FixupInit is the second main entry point for coverage compiler -// fixup. It adds calls to the pkg init function as appropriate to -// register coverage-related variables with the runtime. -func FixupInit(cnames Names) { for _, fn := range typecheck.Target.Funcs { if ir.FuncName(fn) == "init" { cnames.InitFn = fn @@ -144,7 +143,7 @@ func metaHashAndLen() ([16]byte, int) { return hv, base.Flag.Cfg.CoverageInfo.MetaLen } -func registerMeta(cnames Names, hashv [16]byte, mdlen int) { +func registerMeta(cnames names, hashv [16]byte, mdlen int) { // Materialize expression for hash (an array literal) pos := cnames.InitFn.Pos() elist := make([]ir.Node, 0, 16) diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index 39505a37b11..c1090c58c17 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -211,21 +211,12 @@ func Main(archInit func(*ssagen.ArchInfo)) { // because it generates itabs for initializing global variables. ssagen.InitConfig() - // First part of coverage fixup (if applicable). - var cnames coverage.Names - if base.Flag.Cfg.CoverageInfo != nil { - cnames = coverage.FixupVars() - } - // Create "init" function for package-scope variable initialization // statements, if any. pkginit.MakeInit() - // Second part of code coverage fixup (init func modification), - // if applicable. - if base.Flag.Cfg.CoverageInfo != nil { - coverage.FixupInit(cnames) - } + // Apply coverage fixups, if applicable. + coverage.Fixup() // Compute Addrtaken for names. // We need to wait until typechecking is done so that when we see &x[i]