]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: don't use line numbers from ONAME and named OLITERALs
authorKeith Randall <khr@golang.org>
Tue, 26 Apr 2016 22:22:33 +0000 (15:22 -0700)
committerKeith Randall <khr@golang.org>
Wed, 27 Apr 2016 15:03:38 +0000 (15:03 +0000)
The line numbers of ONAMEs are the location of their
declaration, not their use.

The line numbers of named OLITERALs are also the location
of their declaration.

Ignore both of these.  Instead, we will inherit the line number from
the containing syntactic item.

Fixes #14742
Fixes #15430

Change-Id: Ie43b5b9f6321cbf8cead56e37ccc9364d0702f2f
Reviewed-on: https://go-review.googlesource.com/22479
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/ssa.go

index 758f29d0982e1a9b21e26130009c49db5b83b983..1006fcd40ecb4b4a1cd9cbe8914012cfce094a56 100644 (file)
@@ -1414,8 +1414,12 @@ func (s *state) ssaRotateOp(op Op, t *Type) ssa.Op {
 
 // expr converts the expression n to ssa, adds it to s and returns the ssa result.
 func (s *state) expr(n *Node) *ssa.Value {
-       s.pushLine(n.Lineno)
-       defer s.popLine()
+       if !(n.Op == ONAME || n.Op == OLITERAL && n.Sym != nil) {
+               // ONAMEs and named OLITERALs have the line number
+               // of the decl, not the use. See issue 14742.
+               s.pushLine(n.Lineno)
+               defer s.popLine()
+       }
 
        s.stmtList(n.Ninit)
        switch n.Op {
@@ -1463,14 +1467,7 @@ func (s *state) expr(n *Node) *ssa.Value {
                        }
                        return s.entryNewValue0A(ssa.OpConstString, n.Type, u)
                case bool:
-                       v := s.constBool(u)
-                       // For some reason the frontend gets the line numbers of
-                       // CTBOOL literals totally wrong. Fix it here by grabbing
-                       // the line number of the enclosing AST node.
-                       if len(s.line) >= 2 {
-                               v.Line = s.line[len(s.line)-2]
-                       }
-                       return v
+                       return s.constBool(u)
                case *NilVal:
                        t := n.Type
                        switch {