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 problem described in golang/go#31008
by providing position data with the nilness message
  • Loading branch information
vovapi committed Nov 23, 2019
1 parent 2a6ccf2 commit 75831d2
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 75831d2

Please sign in to comment.