Commit f125052a authored by Robert Griesemer's avatar Robert Griesemer

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/119595Reviewed-by: default avatarDavid Chase <drchase@google.com>
parent c9930022
...@@ -1128,16 +1128,20 @@ func (p *exporter) stmtList(list Nodes) { ...@@ -1128,16 +1128,20 @@ func (p *exporter) stmtList(list Nodes) {
} }
// TODO inlining produces expressions with ninits. we can't export these yet. // TODO inlining produces expressions with ninits. we can't export these yet.
// (from fmt.go:1461ff) // (from fmt.go:1461ff)
if opprec[n.Op] < 0 { p.node(n)
p.stmt(n)
} else {
p.expr(n)
}
} }
p.op(OEND) 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) { func (p *exporter) exprList(list Nodes) {
if p.trace { if p.trace {
if list.Len() == 0 { if list.Len() == 0 {
...@@ -1552,7 +1556,7 @@ func (p *exporter) exprsOrNil(a, b *Node) { ...@@ -1552,7 +1556,7 @@ func (p *exporter) exprsOrNil(a, b *Node) {
p.expr(a) p.expr(a)
} }
if ab&2 != 0 { if ab&2 != 0 {
p.expr(b) p.node(b)
} }
} }
......
...@@ -1209,7 +1209,7 @@ func (p *importer) exprsOrNil() (a, b *Node) { ...@@ -1209,7 +1209,7 @@ func (p *importer) exprsOrNil() (a, b *Node) {
a = p.expr() a = p.expr()
} }
if ab&2 != 0 { if ab&2 != 0 {
b = p.expr() b = p.node()
} }
return return
} }
......
...@@ -970,15 +970,19 @@ func (w *exportWriter) linkname(s *types.Sym) { ...@@ -970,15 +970,19 @@ func (w *exportWriter) linkname(s *types.Sym) {
func (w *exportWriter) stmtList(list Nodes) { func (w *exportWriter) stmtList(list Nodes) {
for _, n := range list.Slice() { for _, n := range list.Slice() {
if opprec[n.Op] < 0 { w.node(n)
w.stmt(n)
} else {
w.expr(n)
}
} }
w.op(OEND) 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 // 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.). // n.Ninit and where n cannot have a natural init section (such as in "if", "for", etc.).
func (w *exportWriter) stmt(n *Node) { func (w *exportWriter) stmt(n *Node) {
...@@ -1338,7 +1342,7 @@ func (w *exportWriter) exprsOrNil(a, b *Node) { ...@@ -1338,7 +1342,7 @@ func (w *exportWriter) exprsOrNil(a, b *Node) {
w.expr(a) w.expr(a)
} }
if ab&2 != 0 { if ab&2 != 0 {
w.expr(b) w.node(b)
} }
} }
......
...@@ -1060,7 +1060,7 @@ func (r *importReader) exprsOrNil() (a, b *Node) { ...@@ -1060,7 +1060,7 @@ func (r *importReader) exprsOrNil() (a, b *Node) {
a = r.expr() a = r.expr()
} }
if ab&2 != 0 { if ab&2 != 0 {
b = r.expr() b = r.node()
} }
return return
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment