]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix register size for ODOTPTR result
authorKeith Randall <khr@golang.org>
Thu, 14 Apr 2016 20:47:58 +0000 (13:47 -0700)
committerKeith Randall <khr@golang.org>
Thu, 14 Apr 2016 21:19:12 +0000 (21:19 +0000)
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 <khr@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/cgen.go
test/fixedbugs/issue15252.go [new file with mode: 0644]

index 32ca1ae9401ec12e25d92936560b728c3b102380..658cc8a50ef532895003abc93f55590059a3624f 100644 (file)
@@ -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 (file)
index 0000000..370a885
--- /dev/null
@@ -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")
+}