Skip to content

Commit dcf046f

Browse files
committed
cmd/compile/internal: refactor coverage ir.Name flags
Minor refactoring to eliminate one of the ir.Name flag values used when building in coverage mode (no changes to functionality). This is intended to free up a bit in the uint16 flags field to be used in a subsequent patch. Change-Id: I4aedb9a55fde24c808ff3f7b077ee0552aa979af Reviewed-on: https://go-review.googlesource.com/c/go/+/572055 Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 7979c8f commit dcf046f

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

src/cmd/compile/internal/coverage/cover.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func Fixup() {
7575
}
7676
if strings.HasPrefix(s.Name, counterPrefix) {
7777
ckTypSanity(nm, "countervar")
78-
nm.SetCoverageCounter(true)
78+
nm.SetCoverageAuxVar(true)
7979
s := nm.Linksym()
8080
s.Type = objabi.SCOVERAGE_COUNTER
8181
}

src/cmd/compile/internal/gc/obj.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func dumpGlobal(n *ir.Name) {
154154
}
155155
types.CalcSize(n.Type())
156156
ggloblnod(n)
157-
if n.CoverageCounter() || n.CoverageAuxVar() || n.Linksym().Static() {
157+
if n.CoverageAuxVar() || n.Linksym().Static() {
158158
return
159159
}
160160
base.Ctxt.DwarfGlobal(types.TypeSymName(n.Type()), n.Linksym())
@@ -253,6 +253,11 @@ func ggloblnod(nam *ir.Name) {
253253
linkname := nam.Sym().Linkname
254254
name := nam.Sym().Name
255255

256+
var saveType objabi.SymKind
257+
if nam.CoverageAuxVar() {
258+
saveType = s.Type
259+
}
260+
256261
// We've skipped linkname'd globals's instrument, so we can skip them here as well.
257262
if base.Flag.ASan && linkname == "" && pkginit.InstrumentGlobalsMap[name] != nil {
258263
// Write the new size of instrumented global variables that have
@@ -266,8 +271,9 @@ func ggloblnod(nam *ir.Name) {
266271
if nam.Libfuzzer8BitCounter() {
267272
s.Type = objabi.SLIBFUZZER_8BIT_COUNTER
268273
}
269-
if nam.CoverageCounter() {
270-
s.Type = objabi.SCOVERAGE_COUNTER
274+
if nam.CoverageAuxVar() && saveType == objabi.SCOVERAGE_COUNTER {
275+
// restore specialized counter type (which Globl call above overwrote)
276+
s.Type = saveType
271277
}
272278
if nam.Sym().Linkname != "" {
273279
// Make sure linkname'd symbol is non-package. When a symbol is

src/cmd/compile/internal/inline/inl.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,10 @@ func isIndexingCoverageCounter(n ir.Node) bool {
11621162
return false
11631163
}
11641164
nn := ixn.X.(*ir.Name)
1165-
return nn.CoverageCounter()
1165+
// CoverageAuxVar implies either a coverage counter or a package
1166+
// ID; since the cover tool never emits code to index into ID vars
1167+
// this is effectively testing whether nn is a coverage counter.
1168+
return nn.CoverageAuxVar()
11661169
}
11671170

11681171
// isAtomicCoverageCounterUpdate examines the specified node to

src/cmd/compile/internal/ir/name.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ const (
192192
nameInlLocal // PAUTO created by inliner, derived from callee local
193193
nameOpenDeferSlot // if temporary var storing info for open-coded defers
194194
nameLibfuzzer8BitCounter // if PEXTERN should be assigned to __sancov_cntrs section
195-
nameCoverageCounter // instrumentation counter var for cmd/cover
196-
nameCoverageAuxVar // instrumentation pkg ID variable cmd/cover
195+
nameCoverageAuxVar // instrumentation counter var or pkg ID for cmd/cover
197196
nameAlias // is type name an alias
198197
)
199198

@@ -209,7 +208,6 @@ func (n *Name) InlFormal() bool { return n.flags&nameInlFormal !=
209208
func (n *Name) InlLocal() bool { return n.flags&nameInlLocal != 0 }
210209
func (n *Name) OpenDeferSlot() bool { return n.flags&nameOpenDeferSlot != 0 }
211210
func (n *Name) Libfuzzer8BitCounter() bool { return n.flags&nameLibfuzzer8BitCounter != 0 }
212-
func (n *Name) CoverageCounter() bool { return n.flags&nameCoverageCounter != 0 }
213211
func (n *Name) CoverageAuxVar() bool { return n.flags&nameCoverageAuxVar != 0 }
214212

215213
func (n *Name) setReadonly(b bool) { n.flags.set(nameReadonly, b) }
@@ -224,7 +222,6 @@ func (n *Name) SetInlFormal(b bool) { n.flags.set(nameInlFormal,
224222
func (n *Name) SetInlLocal(b bool) { n.flags.set(nameInlLocal, b) }
225223
func (n *Name) SetOpenDeferSlot(b bool) { n.flags.set(nameOpenDeferSlot, b) }
226224
func (n *Name) SetLibfuzzer8BitCounter(b bool) { n.flags.set(nameLibfuzzer8BitCounter, b) }
227-
func (n *Name) SetCoverageCounter(b bool) { n.flags.set(nameCoverageCounter, b) }
228225
func (n *Name) SetCoverageAuxVar(b bool) { n.flags.set(nameCoverageAuxVar, b) }
229226

230227
// OnStack reports whether variable n may reside on the stack.

0 commit comments

Comments
 (0)