cmd/compile: only allow integer expressions as keys in array literals

Fixes #16439
Updates #16679

Change-Id: Idff4b313f29351866b1a649786501adee85fd580
Reviewed-on: https://go-review.googlesource.com/29011
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Alberto Donizetti 2016-09-10 13:24:35 +02:00 committed by Robert Griesemer
parent c2735039f3
commit 7f1bc53379
4 changed files with 56 additions and 47 deletions

View file

@ -1226,10 +1226,11 @@ func initplan(n *Node) {
case OARRAYLIT, OSLICELIT:
for _, a := range n.List.Slice() {
if a.Op != OKEY || !smallintconst(a.Left) {
index := nonnegintconst(a.Left)
if a.Op != OKEY || index < 0 {
Fatalf("initplan fixedlit")
}
addvalue(p, n.Type.Elem().Width*a.Left.Int64(), a.Right)
addvalue(p, index*n.Type.Elem().Width, a.Right)
}
case OSTRUCTLIT: