mirror of
https://github.com/golang/go
synced 2024-10-05 19:11:22 -06:00
[dev.ssa] cmd/compile/internal/ssa: fix string slice types.
Change-Id: I28bc6373bb42d9abf4f179664dbaab8d514a6ab9 Reviewed-on: https://go-review.googlesource.com/14376 Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
ca9e450bed
commit
c684d4d26c
@ -1722,12 +1722,12 @@ func (s *state) expr(n *Node) *ssa.Value {
|
|||||||
if n.Right.Left == nil {
|
if n.Right.Left == nil {
|
||||||
low = zero
|
low = zero
|
||||||
} else {
|
} else {
|
||||||
low = s.expr(n.Right.Left)
|
low = s.extendIndex(s.expr(n.Right.Left))
|
||||||
}
|
}
|
||||||
if n.Right.Right == nil {
|
if n.Right.Right == nil {
|
||||||
high = len
|
high = len
|
||||||
} else {
|
} else {
|
||||||
high = s.expr(n.Right.Right)
|
high = s.extendIndex(s.expr(n.Right.Right))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Panic if slice indices are not in bounds.
|
// Panic if slice indices are not in bounds.
|
||||||
|
@ -86,9 +86,39 @@ func testStringSlicePanic() {
|
|||||||
failed = true
|
failed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const _Accuracy_name = "BelowExactAbove"
|
||||||
|
|
||||||
|
var _Accuracy_index = [...]uint8{0, 5, 10, 15}
|
||||||
|
|
||||||
|
func testSmallIndexType_ssa(i int) string {
|
||||||
|
switch { // prevent inlining
|
||||||
|
}
|
||||||
|
return _Accuracy_name[_Accuracy_index[i]:_Accuracy_index[i+1]]
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSmallIndexType() {
|
||||||
|
tests := []struct {
|
||||||
|
i int
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{0, "Below"},
|
||||||
|
{1, "Exact"},
|
||||||
|
{2, "Above"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, t := range tests {
|
||||||
|
if got := testSmallIndexType_ssa(t.i); got != t.want {
|
||||||
|
println("#", i, "got ", got, ", wanted", t.want)
|
||||||
|
failed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
testStringSlice()
|
testStringSlice()
|
||||||
testStringSlicePanic()
|
testStringSlicePanic()
|
||||||
|
testStructSlice()
|
||||||
|
testSmallIndexType()
|
||||||
|
|
||||||
if failed {
|
if failed {
|
||||||
panic("failed")
|
panic("failed")
|
||||||
|
Loading…
Reference in New Issue
Block a user