go/ssa: add position data in indexed range loops

Indexed range loops are lacking position data
in their SSA representation, so add the position data
into an index operation.

This improves the nilness output by providing position data
with the message.

Updates golang/go#31008

Change-Id: I664c8668bc74207e770657e21129d20fd70e7af6
GitHub-Last-Rev: 75831d240efd2a79ff95cc18041d29d332dc94ab
GitHub-Pull-Request: golang/tools#190
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208599
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
vovapi 2020-01-08 18:40:29 +00:00 committed by Robert Findley
parent 89082a3841
commit ac4f524c16
1 changed files with 3 additions and 0 deletions

View File

@ -1746,6 +1746,7 @@ func (b *builder) rangeIndexed(fn *Function, x Value, tv types.Type, pos token.P
Index: k,
}
instr.setType(t.Elem())
instr.setPos(x.Pos())
v = fn.emit(instr)
case *types.Pointer: // *array
@ -1754,6 +1755,7 @@ func (b *builder) rangeIndexed(fn *Function, x Value, tv types.Type, pos token.P
Index: k,
}
instr.setType(types.NewPointer(t.Elem().Underlying().(*types.Array).Elem()))
instr.setPos(x.Pos())
v = emitLoad(fn, fn.emit(instr))
case *types.Slice:
@ -1762,6 +1764,7 @@ func (b *builder) rangeIndexed(fn *Function, x Value, tv types.Type, pos token.P
Index: k,
}
instr.setType(types.NewPointer(t.Elem()))
instr.setPos(x.Pos())
v = emitLoad(fn, fn.emit(instr))
default: