From 791bb4f5aefdf3d7ae8aea7d360dec6cb238698a Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Tue, 19 May 2015 03:39:30 -0400 Subject: [PATCH] cmd/internal/gc: handle 64-bit const i/j/k in cgen_slice on ARM 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 --- src/cmd/internal/gc/cgen.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/cmd/internal/gc/cgen.go b/src/cmd/internal/gc/cgen.go index e003ea9f4f8403..ca58b1c6a31e08 100644 --- a/src/cmd/internal/gc/cgen.go +++ b/src/cmd/internal/gc/cgen.go @@ -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) }