1
0
mirror of https://github.com/golang/go synced 2024-11-06 13:36:12 -07:00

cmd/compile: fix exporting of 'for' loops

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>
This commit is contained in:
Robert Griesemer 2018-06-18 14:38:45 -07:00
parent c99300229d
commit f125052ad5
4 changed files with 22 additions and 14 deletions

View 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)
}
}

View 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
}

View 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)
}
}

View 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
}