go.tools/go/ssa: fix range iteration over values of pointer to named array type

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/107800045
This commit is contained in:
Peter Collingbourne 2014-06-05 17:19:58 -04:00 committed by Alan Donovan
parent 83c1b4e7d4
commit afea1b1755
2 changed files with 14 additions and 1 deletions

View File

@ -1641,7 +1641,7 @@ func (b *builder) rangeIndexed(fn *Function, x Value, tv types.Type) (k, v Value
X: x,
Index: k,
}
instr.setType(types.NewPointer(t.Elem().(*types.Array).Elem()))
instr.setType(types.NewPointer(t.Elem().Underlying().(*types.Array).Elem()))
v = emitLoad(fn, fn.emit(instr))
case *types.Slice:

View File

@ -642,3 +642,16 @@ func bug7840() bool {
// This creates a single-predecessor block with a φ-node.
return false && a == 0 && a == 0
}
// Regression test for range of pointer to named array type.
func init() {
type intarr [3]int
ia := intarr{1, 2, 3}
var count int
for _, x := range &ia {
count += x
}
if count != 6 {
panic(count)
}
}