]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix exporting of 'for' loops
authorRobert Griesemer <gri@golang.org>
Mon, 18 Jun 2018 21:38:45 +0000 (14:38 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 19 Jun 2018 16:35:58 +0000 (16:35 +0000)
The existing code for encoding 'for' loops in exported, inlineable
functions incorrectly assumed that the 'Right' field points to an
'expression' node. Adjusted the code to be able to handle any kind
of node. Made matching changes for the binary and indexed exporter.

This only shows up together with other pending compiler changes that
enable exporting of such functions which contain for loops.

No tests yet because we can't test this w/o those pending compiler
changes. Once those changes are in, this code will be tested implicitly.
However, the changes were tested manually together with the patches
described in the issue.

Fixes #25222.

Change-Id: I54babb87e5d665d2c1ef6116c1de1b8c50b1138e
Reviewed-on: https://go-review.googlesource.com/119595
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/gc/bexport.go
src/cmd/compile/internal/gc/bimport.go
src/cmd/compile/internal/gc/iexport.go
src/cmd/compile/internal/gc/iimport.go

index c2672cb319ccb83c62e84b55d79c2988973af84b..0d4997ccfc0235d4e169bc4364f595849488a316 100644 (file)
@@ -1128,16 +1128,20 @@ func (p *exporter) stmtList(list Nodes) {
                }
                // TODO inlining produces expressions with ninits. we can't export these yet.
                // (from fmt.go:1461ff)
-               if opprec[n.Op] < 0 {
-                       p.stmt(n)
-               } else {
-                       p.expr(n)
-               }
+               p.node(n)
        }
 
        p.op(OEND)
 }
 
+func (p *exporter) node(n *Node) {
+       if opprec[n.Op] < 0 {
+               p.stmt(n)
+       } else {
+               p.expr(n)
+       }
+}
+
 func (p *exporter) exprList(list Nodes) {
        if p.trace {
                if list.Len() == 0 {
@@ -1552,7 +1556,7 @@ func (p *exporter) exprsOrNil(a, b *Node) {
                p.expr(a)
        }
        if ab&2 != 0 {
-               p.expr(b)
+               p.node(b)
        }
 }
 
index 8215e4652f747f9c735c867949bed21f7ec03777..c19f548e18a65eebd56426da8da3bddde6cc4b52 100644 (file)
@@ -1209,7 +1209,7 @@ func (p *importer) exprsOrNil() (a, b *Node) {
                a = p.expr()
        }
        if ab&2 != 0 {
-               b = p.expr()
+               b = p.node()
        }
        return
 }
index f6e9b8b0613344d6e86a3ac59a17bce684fc705f..3abbd15e162ce87f5d2bfddc94ca7d737fa92877 100644 (file)
@@ -970,15 +970,19 @@ func (w *exportWriter) linkname(s *types.Sym) {
 
 func (w *exportWriter) stmtList(list Nodes) {
        for _, n := range list.Slice() {
-               if opprec[n.Op] < 0 {
-                       w.stmt(n)
-               } else {
-                       w.expr(n)
-               }
+               w.node(n)
        }
        w.op(OEND)
 }
 
+func (w *exportWriter) node(n *Node) {
+       if opprec[n.Op] < 0 {
+               w.stmt(n)
+       } else {
+               w.expr(n)
+       }
+}
+
 // Caution: stmt will emit more than one node for statement nodes n that have a non-empty
 // n.Ninit and where n cannot have a natural init section (such as in "if", "for", etc.).
 func (w *exportWriter) stmt(n *Node) {
@@ -1338,7 +1342,7 @@ func (w *exportWriter) exprsOrNil(a, b *Node) {
                w.expr(a)
        }
        if ab&2 != 0 {
-               w.expr(b)
+               w.node(b)
        }
 }
 
index 4d66b4b0420caa2efe61410f268c9f2cde0a8fa3..d158899aaaa0a3efac32804f51a0f88796d7df8c 100644 (file)
@@ -1060,7 +1060,7 @@ func (r *importReader) exprsOrNil() (a, b *Node) {
                a = r.expr()
        }
        if ab&2 != 0 {
-               b = r.expr()
+               b = r.node()
        }
        return
 }