]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: adjust lineno during import to get Pos right
authorDavid Chase <drchase@google.com>
Mon, 27 Nov 2017 23:06:17 +0000 (18:06 -0500)
committerDavid Chase <drchase@google.com>
Tue, 28 Nov 2017 22:36:55 +0000 (22:36 +0000)
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: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/bimport.go
src/cmd/compile/internal/ssa/testdata/hist.opt-dlv.nexts

index 2b95ac5375393c6c614c1c101b85a421edfd0127..71d20ec37bd8297c58e488703027a0145ea85f50 100644 (file)
@@ -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:
index a6321d904beadcca801b58605668bce58624eb10..7aab219552036439014a46eb2ed0d772f1bbefe7 100644 (file)
@@ -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)