aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssagen
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2021-03-14 14:24:47 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2021-04-21 00:53:48 +0000
commitfaa4fa1a6e94fce4f6fa22524a2bece5125213b6 (patch)
treeecd5c4b860564b5b1926725f6ffafcebfac3b3d9 /src/cmd/compile/internal/ssagen
parent1c268431f49ee2fc843eac52a0854aea3d02a6e0 (diff)
downloadgo-faa4fa1a6e94fce4f6fa22524a2bece5125213b6.tar.gz
go-faa4fa1a6e94fce4f6fa22524a2bece5125213b6.zip
cmd/compile: allow conversion from slice to array ptr
Panic if the slice is too short. Updates #395 Change-Id: I90f4bff2da5d8f3148ba06d2482084f32b25c29a Reviewed-on: https://go-review.googlesource.com/c/go/+/301650 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/ssagen')
-rw-r--r--src/cmd/compile/internal/ssagen/ssa.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go
index c5b1ae2e4a..10f02fc987 100644
--- a/src/cmd/compile/internal/ssagen/ssa.go
+++ b/src/cmd/compile/internal/ssagen/ssa.go
@@ -164,6 +164,7 @@ func InitConfig() {
BoundsCheckFunc[ssa.BoundsSlice3BU] = typecheck.LookupRuntimeFunc("goPanicSlice3BU")
BoundsCheckFunc[ssa.BoundsSlice3C] = typecheck.LookupRuntimeFunc("goPanicSlice3C")
BoundsCheckFunc[ssa.BoundsSlice3CU] = typecheck.LookupRuntimeFunc("goPanicSlice3CU")
+ BoundsCheckFunc[ssa.BoundsConvert] = typecheck.LookupRuntimeFunc("goPanicSliceConvert")
} else {
BoundsCheckFunc[ssa.BoundsIndex] = typecheck.LookupRuntimeFunc("panicIndex")
BoundsCheckFunc[ssa.BoundsIndexU] = typecheck.LookupRuntimeFunc("panicIndexU")
@@ -181,6 +182,7 @@ func InitConfig() {
BoundsCheckFunc[ssa.BoundsSlice3BU] = typecheck.LookupRuntimeFunc("panicSlice3BU")
BoundsCheckFunc[ssa.BoundsSlice3C] = typecheck.LookupRuntimeFunc("panicSlice3C")
BoundsCheckFunc[ssa.BoundsSlice3CU] = typecheck.LookupRuntimeFunc("panicSlice3CU")
+ BoundsCheckFunc[ssa.BoundsConvert] = typecheck.LookupRuntimeFunc("panicSliceConvert")
}
if Arch.LinkArch.PtrSize == 4 {
ExtendCheckFunc[ssa.BoundsIndex] = typecheck.LookupRuntimeVar("panicExtendIndex")
@@ -3148,6 +3150,18 @@ func (s *state) expr(n ir.Node) *ssa.Value {
p, l, _ := s.slice(v, i, j, nil, n.Bounded())
return s.newValue2(ssa.OpStringMake, n.Type(), p, l)
+ case ir.OSLICE2ARRPTR:
+ // if arrlen > slice.len {
+ // panic(...)
+ // }
+ // slice.ptr
+ n := n.(*ir.ConvExpr)
+ v := s.expr(n.X)
+ arrlen := s.constInt(types.Types[types.TINT], n.Type().Elem().NumElem())
+ cap := s.newValue1(ssa.OpSliceLen, types.Types[types.TINT], v)
+ s.boundsCheck(arrlen, cap, ssa.BoundsConvert, false)
+ return s.newValue1(ssa.OpSlicePtrUnchecked, types.Types[types.TINT], v)
+
case ir.OCALLFUNC:
n := n.(*ir.CallExpr)
if ir.IsIntrinsicCall(n) {