]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile/internal/ssa: fix string slice types.
authorAlexandru Moșoi <mosoi@google.com>
Tue, 8 Sep 2015 16:18:59 +0000 (18:18 +0200)
committerKeith Randall <khr@golang.org>
Tue, 8 Sep 2015 19:13:22 +0000 (19:13 +0000)
Change-Id: I28bc6373bb42d9abf4f179664dbaab8d514a6ab9
Reviewed-on: https://go-review.googlesource.com/14376
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/gc/testdata/string_ssa.go

index 70990bbd183539104d9fe9a4502050be91e62191..a554a1dfd9a207ca704243a08d5d065ece5e43bb 100644 (file)
@@ -1722,12 +1722,12 @@ func (s *state) expr(n *Node) *ssa.Value {
                if n.Right.Left == nil {
                        low = zero
                } else {
-                       low = s.expr(n.Right.Left)
+                       low = s.extendIndex(s.expr(n.Right.Left))
                }
                if n.Right.Right == nil {
                        high = len
                } else {
-                       high = s.expr(n.Right.Right)
+                       high = s.extendIndex(s.expr(n.Right.Right))
                }
 
                // Panic if slice indices are not in bounds.
index efc734e1a235f582cbef6bedf689210f9a2ed7a4..448433acd3e8e127fe71a1d2077925cf7baa85cd 100644 (file)
@@ -86,9 +86,39 @@ func testStringSlicePanic() {
        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() {
        testStringSlice()
        testStringSlicePanic()
+       testStructSlice()
+       testSmallIndexType()
 
        if failed {
                panic("failed")