]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix nodedump output for types of nodes
authorDan Scales <danscales@google.com>
Tue, 20 Oct 2020 22:03:33 +0000 (15:03 -0700)
committerDan Scales <danscales@google.com>
Tue, 20 Oct 2020 23:37:53 +0000 (23:37 +0000)
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 <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/fmt.go

index 9ba1789633c51959688cd5601acf952da7ce83b6..d7ed1d2ff098cf6c84fe7864fcba46fa3f57390e 100644 (file)
@@ -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('*')