{"dwarfinl", "print information about DWARF inlined function creation", &Debug_gendwarfinl},
{"softfloat", "force compiler to emit soft-float code", &Debug_softfloat},
{"defer", "print information about defer compilation", &Debug_defer},
+ {"fieldtrack", "enable fieldtracking", &objabi.Fieldtrack_enabled},
}
const debugHelpHeader = `usage: -d arg[,arg]* and arg is <key>[=<value>]
import (
"cmd/compile/internal/types"
- "cmd/internal/objabi"
"fmt"
"strings"
)
return t
}
-type typeSymKey struct {
- t *types.Type
- s *types.Sym
-}
-
-// dotField maps (*types.Type, *types.Sym) pairs to the corresponding struct field (*types.Type with Etype==TFIELD).
-// It is a cache for use during usefield in walk.go, only enabled when field tracking.
-var dotField = map[typeSymKey]*types.Field{}
-
func lookdot(n *Node, t *types.Type, dostrcmp int) *types.Field {
s := n.Sym
}
n.Xoffset = f1.Offset
n.Type = f1.Type
- if objabi.Fieldtrack_enabled > 0 {
- dotField[typeSymKey{t.Orig, s}] = f1
- }
if t.IsInterface() {
if n.Left.Type.IsPtr() {
n.Left = nod(ODEREF, n.Left, nil) // implicitstar
}
n.Op = ODOTINTER
+ } else {
+ n.SetOpt(f1)
}
return f1
if t.IsPtr() {
t = t.Elem()
}
- field := dotField[typeSymKey{t.Orig, n.Sym}]
+ field := n.Opt().(*types.Field)
if field == nil {
Fatalf("usefield %v %v without paramfld", n.Left.Type, n.Sym)
}
+ if field.Sym != n.Sym || field.Offset != n.Xoffset {
+ Fatalf("field inconsistency: %v,%v != %v,%v", field.Sym, field.Offset, n.Sym, n.Xoffset)
+ }
if !strings.Contains(field.Note, "go:\"track\"") {
return
}
--- /dev/null
+// compile -d=fieldtrack
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+func a(x struct{ f int }) { _ = x.f }
+
+func b() { a(struct{ f int }{}) }