]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/gc: handle 64-bit const i/j/k in cgen_slice on ARM
authorShenghou Ma <minux@golang.org>
Tue, 19 May 2015 07:39:30 +0000 (03:39 -0400)
committerMinux Ma <minux@golang.org>
Tue, 19 May 2015 22:58:51 +0000 (22:58 +0000)
386 is not affected because it doesn't use ginscmp.

Fixes #10843.

Change-Id: I1b3a133bd1e5fabc85236f15d060dbaa4c391cf3
Reviewed-on: https://go-review.googlesource.com/10116
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/internal/gc/cgen.go

index e003ea9f4f8403b8fe0743cc0f26170175726483..ca58b1c6a31e089692e59e6d849f4c00f551fe3a 100644 (file)
@@ -2987,6 +2987,11 @@ func cgen_append(n, res *Node) {
 // If wb is true, need write barrier updating res's base pointer.
 // On systems with 32-bit ints, i, j, k are guaranteed to be 32-bit values.
 func cgen_slice(n, res *Node, wb bool) {
+       if Debug['g'] != 0 {
+               Dump("cgen_slice-n", n)
+               Dump("cgen_slice-res", res)
+       }
+
        needFullUpdate := !samesafeexpr(n.Left, res)
 
        // orderexpr has made sure that x is safe (but possibly expensive)
@@ -3250,6 +3255,16 @@ func cgen_slice(n, res *Node, wb bool) {
        }
 
        compare := func(n1, n2 *Node) {
+               // n1 might be a 64-bit constant, even on 32-bit architectures,
+               // but it will be represented in 32 bits.
+               if Ctxt.Arch.Regsize == 4 && Is64(n1.Type) {
+                       if mpcmpfixc(n1.Val.U.(*Mpint), 1<<31) >= 0 {
+                               Fatal("missed slice out of bounds check")
+                       }
+                       var tmp Node
+                       Nodconst(&tmp, indexRegType, Mpgetfix(n1.Val.U.(*Mpint)))
+                       n1 = &tmp
+               }
                p := Thearch.Ginscmp(OGT, indexRegType, n1, n2, -1)
                panics = append(panics, p)
        }