]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix pos of typenames created during SSA construction
authorJosh Bleecher Snyder <josharian@gmail.com>
Tue, 21 Mar 2017 02:00:14 +0000 (19:00 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 21 Mar 2017 04:14:26 +0000 (04:14 +0000)
Prior to this CL, the function's position was used.
The dottype Node's position is clearly better.

I'm not thrilled about introducing a reference to
lineno in the middle of SSA construction;
I will have to remove it later.
My immediate goal is stability and correctness of positions,
though, since that aids refactoring, so this is an improvement.

An example from package io:

func (t *multiWriter) WriteString(s string) (n int, err error) {
var p []byte // lazily initialized if/when needed
for _, w := range t.writers {
if sw, ok := w.(stringWriter); ok {
n, err = sw.WriteString(s)

The w.(stringWriter) type assertion includes loading
the address of static type data for stringWriter:

LEAQ type."".stringWriter(SB), R10

Prior to this CL, this instruction was given the line number
of the function declaration.
After this CL, this instruction is given the line number
of the type assertion itself.

Change-Id: Ifcca274b581a5a57d7e3102c4d7b7786bf307210
Reviewed-on: https://go-review.googlesource.com/38389
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/ssa.go

index 87a84285b69f0eabcff0b8fcf89b29f69c2b5de5..6726bdd621c93f29e6b33cdfc4c67dab0d38d7c5 100644 (file)
@@ -3954,6 +3954,7 @@ func (s *state) floatToUint(cvttab *f2uCvtTab, n *Node, x *ssa.Value, ft, tt *Ty
 // If commaok is false, resok will be nil.
 func (s *state) dottype(n *Node, commaok bool) (res, resok *ssa.Value) {
        iface := s.expr(n.Left)            // input interface
+       lineno = n.Pos                     // for typename call
        target := s.expr(typename(n.Type)) // target type
        byteptr := s.f.Config.Types.BytePtr