From: Dan Scales Date: Tue, 20 Oct 2020 22:03:33 +0000 (-0700) Subject: cmd/compile: fix nodedump output for types of nodes X-Git-Tag: go1.16beta1~627 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f121e0eddd64aa0084b916e94c9a540edf859539;p=gostls13.git cmd/compile: fix nodedump output for types of nodes The Dbg dumping of complex types was broken, because (I think) of a recent change to handle recursive types correctly. Before this fix, the Dump output of a closure node (where the last thing on the line is the type of the node) was: . . CLOSURE l(8) esc(h) tc(1) FUNC-@0 after this change it is: . . CLOSURE l(8) esc(h) tc(1) FUNC-func(int) int The problem is that that the 'mode == Fdbg' code was immediately aborting the descent into tconv2, since it was calling down with the same node that was just entered into the hash table. Change-Id: Iee106b967cea1856dd92d4350681401dd34a23b3 Reviewed-on: https://go-review.googlesource.com/c/go/+/264025 Trust: Dan Scales Reviewed-by: Keith Randall --- diff --git a/src/cmd/compile/internal/gc/fmt.go b/src/cmd/compile/internal/gc/fmt.go index 9ba1789633..d7ed1d2ff0 100644 --- a/src/cmd/compile/internal/gc/fmt.go +++ b/src/cmd/compile/internal/gc/fmt.go @@ -792,6 +792,13 @@ func tconv2(b *bytes.Buffer, t *types.Type, flag FmtFlag, mode fmtMode, visited return } + if mode == FDbg { + b.WriteString(t.Etype.String()) + b.WriteByte('-') + tconv2(b, t, flag, FErr, visited) + return + } + // At this point, we might call tconv2 recursively. Add the current type to the visited list so we don't // try to print it recursively. // We record the offset in the result buffer where the type's text starts. This offset serves as a reference @@ -805,12 +812,6 @@ func tconv2(b *bytes.Buffer, t *types.Type, flag FmtFlag, mode fmtMode, visited visited[t] = b.Len() defer delete(visited, t) - if mode == FDbg { - b.WriteString(t.Etype.String()) - b.WriteByte('-') - tconv2(b, t, flag, FErr, visited) - return - } switch t.Etype { case TPTR: b.WriteByte('*')