From 9d7c9b4384db01afd2acb27d3a4636b60e957f08 Mon Sep 17 00:00:00 2001 From: Tal Shprecher Date: Thu, 5 May 2016 15:14:08 -0700 Subject: [PATCH] cmd/compile: properly handle map assignments for OAS2DOTTYPE The boolean destination in an OAS2DOTTYPE expression craps out during compilation when trying to assign to a map entry because, unlike slice entries, map entries are not directly addressable in memory. The solution is to properly order the boolean destination node so that map entries are set via autotmp variables. Fixes #14678 Change-Id: If344e8f232b5bdac1b53c0f0d21eeb43ab17d3de Reviewed-on: https://go-review.googlesource.com/22833 Reviewed-by: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/gc/order.go | 26 ++++++++++++++++---------- test/fixedbugs/issue14678.go | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 test/fixedbugs/issue14678.go diff --git a/src/cmd/compile/internal/gc/order.go b/src/cmd/compile/internal/gc/order.go index 7026ad79ef..d432b43460 100644 --- a/src/cmd/compile/internal/gc/order.go +++ b/src/cmd/compile/internal/gc/order.go @@ -569,18 +569,24 @@ func orderstmt(n *Node, order *Order) { orderexprlist(n.List, order) n.Rlist.First().Left = orderexpr(n.Rlist.First().Left, order, nil) // i in i.(T) - if isblank(n.List.First()) { - order.out = append(order.out, n) - } else { - typ := n.Rlist.First().Type - tmp1 := ordertemp(typ, order, haspointers(typ)) - order.out = append(order.out, n) - r := Nod(OAS, n.List.First(), tmp1) - r = typecheck(r, Etop) - ordermapassign(r, order) - n.List.Set([]*Node{tmp1, n.List.Second()}) + + results := n.List.Slice() + var assigns [2]*Node + + for r, res := range results { + if !isblank(res) { + results[r] = ordertemp(res.Type, order, haspointers(res.Type)) + assigns[r] = Nod(OAS, res, results[r]) + } } + order.out = append(order.out, n) + for _, assign := range assigns { + if assign != nil { + assign = typecheck(assign, Etop) + ordermapassign(assign, order) + } + } cleantemp(t, order) // Special: use temporary variables to hold result, diff --git a/test/fixedbugs/issue14678.go b/test/fixedbugs/issue14678.go new file mode 100644 index 0000000000..94ca86d26c --- /dev/null +++ b/test/fixedbugs/issue14678.go @@ -0,0 +1,27 @@ +// run + +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + m := make(map[int]bool) + i := interface{}(1) + var v int + + // Ensure map is updated properly + _, m[1] = i.(int) + v, m[2] = i.(int) + + if v != 1 { + panic("fail: v should be 1") + } + if m[1] == false { + panic("fail: m[1] should be true") + } + if m[2] == false { + panic("fail: m[2] should be true") + } +} -- 2.48.1