Commit a5b759aa authored by David Chase's avatar David Chase

cmd/compile: adjust lineno during import to get Pos right

Binary import sometimes constructs nodes using functions
that use the global lineno for the Position.  This causes
spurious numbers to appear in the assembly and the
debugging output.

Fix (targeted, because late in the cycle): save and restore
lineno around bimport calls known to use lineno-sensitive
functions.

Updates #22600.
(Comment: "This is a weird line to step through")

Change-Id: I9c4094670380609fe4b6696443fb02579521c596
Reviewed-on: https://go-review.googlesource.com/80115
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
parent 71a9c443
......@@ -202,6 +202,13 @@ func Import(imp *types.Pkg, in *bufio.Reader) {
}
f.Func.Inl.Set(body)
f.Func.InlCost = int32(inlCost)
if Debug['E'] > 0 && Debug['m'] > 2 && f.Func.Inl.Len() != 0 {
if Debug['m'] > 3 {
fmt.Printf("inl body for %v: %+v\n", f, f.Func.Inl)
} else {
fmt.Printf("inl body for %v: %v\n", f, f.Func.Inl)
}
}
funcbody()
} else {
// function already imported - read body but discard declarations
......@@ -369,7 +376,11 @@ func (p *importer) obj(tag int) {
n := newfuncnamel(pos, sym)
n.Type = sig
// TODO(mdempsky): Stop clobbering n.Pos in declare.
savedlineno := lineno
lineno = pos
declare(n, PFUNC)
lineno = savedlineno
p.funcList = append(p.funcList, n)
importlist = append(importlist, n)
......@@ -377,9 +388,6 @@ func (p *importer) obj(tag int) {
if Debug['E'] > 0 {
fmt.Printf("import [%q] func %v \n", p.imp.Path, n)
if Debug['m'] > 2 && n.Func.Inl.Len() != 0 {
fmt.Printf("inl body: %v\n", n.Func.Inl)
}
}
default:
......@@ -493,7 +501,11 @@ func (p *importer) typ() *types.Type {
// read underlying type
t0 := p.typ()
// TODO(mdempsky): Stop clobbering n.Pos in declare.
savedlineno := lineno
lineno = pos
p.importtype(t, t0)
lineno = savedlineno
// interfaces don't have associated methods
if t0.IsInterface() {
......@@ -547,9 +559,6 @@ func (p *importer) typ() *types.Type {
if Debug['E'] > 0 {
fmt.Printf("import [%q] meth %v \n", p.imp.Path, n)
if Debug['m'] > 2 && n.Func.Inl.Len() != 0 {
fmt.Printf("inl body: %v\n", n.Func.Inl)
}
}
}
......@@ -963,21 +972,26 @@ func (p *importer) node() *Node {
// unimplemented
case OPTRLIT:
n := npos(p.pos(), p.expr())
pos := p.pos()
n := npos(pos, p.expr())
if !p.bool() /* !implicit, i.e. '&' operator */ {
if n.Op == OCOMPLIT {
// Special case for &T{...}: turn into (*T){...}.
n.Right = nod(OIND, n.Right, nil)
n.Right = nodl(pos, OIND, n.Right, nil)
n.Right.SetImplicit(true)
} else {
n = nod(OADDR, n, nil)
n = nodl(pos, OADDR, n, nil)
}
}
return n
case OSTRUCTLIT:
n := nodl(p.pos(), OCOMPLIT, nil, typenod(p.typ()))
// TODO(mdempsky): Export position information for OSTRUCTKEY nodes.
savedlineno := lineno
lineno = p.pos()
n := nodl(lineno, OCOMPLIT, nil, typenod(p.typ()))
n.List.Set(p.elemList()) // special handling of field names
lineno = savedlineno
return n
// case OARRAYLIT, OSLICELIT, OMAPLIT:
......
......@@ -8,9 +8,7 @@
61: sink = dx + dy //gdb-opt=(dx,dy)
63: hist := make([]int, 7) //gdb-opt=(sink,dx/O,dy/O)
64: var reader io.Reader = strings.NewReader(cannedInput) //gdb-dbg=(hist/A,cannedInput/A)
19: "strings"
65: if len(os.Args) > 1 {
14: "bufio"
74: for scanner.Scan() { //gdb-opt=(scanner/A)
76: i, err := strconv.ParseInt(s, 10, 64)
77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i)
......
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