From: Keith Randall Date: Thu, 14 Apr 2016 20:47:58 +0000 (-0700) Subject: cmd/compile: fix register size for ODOTPTR result X-Git-Tag: go1.7beta1~668 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ac8127d7e6ead390bc44c89d47d16be587c3ac11;p=gostls13.git cmd/compile: fix register size for ODOTPTR result The result of ODOTPTR, as well as a bunch of other ops, should be the type of the result, not always a pointer type. This fixes an amd64p32 bug where we were incorrectly truncating a 64-bit slice index to 32 bits, and then barfing on a weird load-64-bits-but-then-truncate-to-32-bits op that doesn't exist. Fixes #15252 Change-Id: Ie62f4315fffd79f233e5449324ccc0879f5ac343 Reviewed-on: https://go-review.googlesource.com/22094 Run-TryBot: Keith Randall Reviewed-by: Josh Bleecher Snyder TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/compile/internal/gc/cgen.go b/src/cmd/compile/internal/gc/cgen.go index 32ca1ae940..658cc8a50e 100644 --- a/src/cmd/compile/internal/gc/cgen.go +++ b/src/cmd/compile/internal/gc/cgen.go @@ -946,7 +946,7 @@ func Cgenr(n *Node, a *Node, res *Node) { OCALLINTER: var n1 Node Igen(n, &n1, res) - Regalloc(a, Types[Tptr], &n1) + Regalloc(a, n.Type, &n1) Thearch.Gmove(&n1, a) Regfree(&n1) diff --git a/test/fixedbugs/issue15252.go b/test/fixedbugs/issue15252.go new file mode 100644 index 0000000000..370a885c7f --- /dev/null +++ b/test/fixedbugs/issue15252.go @@ -0,0 +1,32 @@ +// 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. + +// This test makes sure that we use all 64 bits of an +// index, even on 32 bit machines. It also tests that nacl +// can compile 64 bit indexes loaded from ODOTPTR properly. + +package main + +type T struct { + i int64 +} + +func f(t *T) byte { + b := [2]byte{3, 4} + return b[t.i] +} + +func main() { + t := &T{0x100000001} + defer func() { + r := recover() + if r == nil { + panic("panic wasn't recoverable") + } + }() + f(t) + panic("index didn't panic") +}