From 58ec10c513dfc49286c140a86ef22d01e77662a6 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Fri, 4 Nov 2016 17:43:38 -0400 Subject: [PATCH] go/ssa/interp: handle nil *hashmap cleanly Change-Id: I2cb8eef79bc011b209b3df0b859bcddefd4c8337 Reviewed-on: https://go-review.googlesource.com/32818 Reviewed-by: Robert Griesemer --- go/ssa/interp/map.go | 8 ++++++++ go/ssa/interp/ops.go | 2 +- go/ssa/interp/reflect.go | 4 ++-- go/ssa/interp/value.go | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/go/ssa/interp/map.go b/go/ssa/interp/map.go index 4c092b3e06..577526fdd9 100644 --- a/go/ssa/interp/map.go +++ b/go/ssa/interp/map.go @@ -113,3 +113,11 @@ func (m *hashmap) len() int { } return 0 } + +// entries returns a rangeable map of entries. +func (m *hashmap) entries() map[int]*entry { + if m != nil { + return m.table + } + return nil +} diff --git a/go/ssa/interp/ops.go b/go/ssa/interp/ops.go index c7a0a4064f..2de2fa86f1 100644 --- a/go/ssa/interp/ops.go +++ b/go/ssa/interp/ops.go @@ -1098,7 +1098,7 @@ func rangeIter(x value, t types.Type) iter { // reflect.(Value).MapKeys machinery. it := make(mapIter) go func() { - for _, e := range x.table { + for _, e := range x.entries() { for e != nil { it <- [2]value{e.key, e.value} e = e.next diff --git a/go/ssa/interp/reflect.go b/go/ssa/interp/reflect.go index 48bb911214..688f737b42 100644 --- a/go/ssa/interp/reflect.go +++ b/go/ssa/interp/reflect.go @@ -333,7 +333,7 @@ func ext۰reflect۰Value۰MapKeys(fr *frame, args []value) value { } case *hashmap: - for _, e := range v.table { + for _, e := range v.entries() { for ; e != nil; e = e.next { keys = append(keys, makeReflectValue(tKey, e.key)) } @@ -365,7 +365,7 @@ func ext۰reflect۰Value۰Pointer(fr *frame, args []value) value { case []value: return reflect.ValueOf(v).Pointer() case *hashmap: - return reflect.ValueOf(v.table).Pointer() + return reflect.ValueOf(v.entries()).Pointer() case map[value]value: return reflect.ValueOf(v).Pointer() case *ssa.Function: diff --git a/go/ssa/interp/value.go b/go/ssa/interp/value.go index 2194b013f5..4f5a705098 100644 --- a/go/ssa/interp/value.go +++ b/go/ssa/interp/value.go @@ -384,7 +384,7 @@ func writeValue(buf *bytes.Buffer, v value) { case *hashmap: buf.WriteString("map[") sep := " " - for _, e := range v.table { + for _, e := range v.entries() { for e != nil { buf.WriteString(sep) sep = " "