Skip to content

Commit

Permalink
go/ssa: add position data in indexed range loops
Browse files Browse the repository at this point in the history
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: 75831d2
GitHub-Pull-Request: #190
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208599
Run-TryBot: Robert Findley <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
  • Loading branch information
vovapi authored and findleyr committed Jan 9, 2020
1 parent 89082a3 commit ac4f524
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions go/ssa/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit ac4f524

Please sign in to comment.