cmd/compile: initialize line number properly for temporaries

The expansion of structure, array, slice, and map literals
does not use the right line number in its introduced assignments
to temporaries, which leads to incorrect line number attribution
for expressions in those literals.

Inlining also incorrectly replaced the line numbers of args to
inlined functions.

This was revealed in CL 9721 because a now-avoided temporary
assignment introduced the correct line number.
I.e. before CL 9721
  "tmp_wrongline := expr"
was transformed to
  "tmp_rightline := expr; tmp_wrongline := tmp_rightline"

Also includes a repair to CL 10334 involving line numbers
where a spurious -1 remained (should have been 0, now is 0).

Fixes #11400.

Change-Id: I3a4687efe463977fa1e2c996606f4d91aaf22722
Reviewed-on: https://go-review.googlesource.com/11730
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Sameer Ajmani <sameer@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
David Chase 2015-06-29 16:30:19 -04:00 committed by Russ Cox
parent 2028077899
commit 7929a0ddfa
4 changed files with 123 additions and 1 deletions

View file

@ -380,6 +380,7 @@ func staticcopy(l *Node, r *Node, out **NodeList) bool {
rr.Orig = rr // completely separate copy
rr.Type = ll.Type
rr.Xoffset += e.Xoffset
setlineno(rr)
*out = list(*out, Nod(OAS, ll, rr))
}
}
@ -484,6 +485,7 @@ func staticassign(l *Node, r *Node, out **NodeList) bool {
if e.Expr.Op == OLITERAL {
gdata(&n1, e.Expr, int(n1.Type.Width))
} else {
setlineno(e.Expr)
a = Nod(OXXX, nil, nil)
*a = n1
a.Orig = a // completely separate copy
@ -636,6 +638,7 @@ func structlit(ctxt int, pass int, n *Node, var_ *Node, init **NodeList) {
}
// build list of var.field = expr
setlineno(value)
a = Nod(ODOT, var_, newname(index.Sym))
a = Nod(OAS, a, value)
@ -703,6 +706,7 @@ func arraylit(ctxt int, pass int, n *Node, var_ *Node, init **NodeList) {
}
// build list of var[index] = value
setlineno(value)
a = Nod(OINDEX, var_, index)
a = Nod(OAS, a, value)
@ -866,6 +870,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init **NodeList) {
}
// build list of var[c] = expr
setlineno(value)
a = Nod(OAS, a, value)
typecheck(&a, Etop)
@ -954,6 +959,7 @@ func maplit(ctxt int, n *Node, var_ *Node, init **NodeList) {
if isliteral(index) && isliteral(value) {
// build vstat[b].a = key;
setlineno(index)
a = Nodintconst(b)
a = Nod(OINDEX, vstat, a)
@ -965,6 +971,7 @@ func maplit(ctxt int, n *Node, var_ *Node, init **NodeList) {
*init = list(*init, a)
// build vstat[b].b = value;
setlineno(value)
a = Nodintconst(b)
a = Nod(OINDEX, vstat, a)
@ -1032,15 +1039,18 @@ func maplit(ctxt int, n *Node, var_ *Node, init **NodeList) {
val = temp(var_.Type.Type)
}
setlineno(r.Left)
a = Nod(OAS, key, r.Left)
typecheck(&a, Etop)
walkstmt(&a)
*init = list(*init, a)
setlineno(r.Right)
a = Nod(OAS, val, r.Right)
typecheck(&a, Etop)
walkstmt(&a)
*init = list(*init, a)
setlineno(val)
a = Nod(OAS, Nod(OINDEX, var_, key), val)
typecheck(&a, Etop)
walkstmt(&a)