"os"
"path/filepath"
"sort"
+ "strconv"
"strings"
"cmd/internal/edit"
}
funcId := f.mdb.AddFunc(fd)
- // Generate the registration hook for the function, and insert it
- // into the prolog.
+ hookWrite := func(cv string, which int, val string) string {
+ return fmt.Sprintf("%s[%d] = %s", cv, which, val)
+ }
+ if *mode == "atomic" {
+ hookWrite = func(cv string, which int, val string) string {
+ return fmt.Sprintf("%s.StoreUint32(&%s[%d], %s)", atomicPackageName,
+ cv, which, val)
+ }
+ }
+
+ // Generate the registration hook sequence for the function. This
+ // sequence looks like
+ //
+ // counterVar[0] = <num_units>
+ // counterVar[1] = pkgId
+ // counterVar[2] = fnId
+ //
cv := f.fn.counterVar
- regHook := fmt.Sprintf("%s[0] = %d ; %s[1] = %s ; %s[2] = %d",
- cv, len(f.fn.units), cv, mkPackageIdExpression(), cv, funcId)
+ regHook := hookWrite(cv, 0, strconv.Itoa(len(f.fn.units))) + " ; " +
+ hookWrite(cv, 1, mkPackageIdExpression()) + " ; " +
+ hookWrite(cv, 2, strconv.Itoa(int(funcId)))
- // Insert a function registration sequence into the function.
+ // Insert the registration sequence into the function.
boff := f.offset(body.Pos())
ipos := f.fset.File(body.Pos()).Pos(boff + 1)
f.edit.Insert(f.offset(ipos), regHook+" ; ")
--- /dev/null
+[short] skip
+[!race] skip
+
+go test -race -cover issue.56370/filter
+
+-- go.mod --
+module issue.56370
+
+go 1.20
+
+-- filter/filter.go --
+
+package filter
+
+func New() func(error) bool {
+ return func(error) bool {
+ return false
+ }
+}
+
+-- filter/filter_test.go --
+
+package filter_test
+
+import (
+ "testing"
+
+ "issue.56370/filter"
+)
+
+func Test1(t *testing.T) {
+ t.Parallel()
+
+ _ = filter.New()
+}
+
+func Test2(t *testing.T) {
+ t.Parallel()
+
+ _ = filter.New()
+}
+
+func Test3(t *testing.T) {
+ t.Parallel()
+
+ _ = filter.New()
+}
+
+func Test4(t *testing.T) {
+ t.Parallel()
+
+ _ = filter.New()
+}
+