]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: fix divide by zero error in compiler
authorRuss Cox <rsc@golang.org>
Mon, 16 Sep 2013 18:22:37 +0000 (14:22 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 16 Sep 2013 18:22:37 +0000 (14:22 -0400)
Fixes #6399.

R=ken2
CC=golang-dev
https://golang.org/cl/13253055

src/cmd/gc/walk.c
test/fixedbugs/issue6399.go [new file with mode: 0644]

index e9a594d1ef1408c802a09632d97d21b692df25ab..489b947143ae0efbe27e0f7493dfb743c1139df5 100644 (file)
@@ -1295,7 +1295,7 @@ walkexpr(Node **np, NodeList **init)
                t = n->type;
                if(n->esc == EscNone
                        && smallintconst(l) && smallintconst(r)
-                       && mpgetfix(r->val.u.xval) < (1ULL<<16) / t->type->width) {
+                       && (t->type->width == 0 || mpgetfix(r->val.u.xval) < (1ULL<<16) / t->type->width)) {
                        // var arr [r]T
                        // n = arr[:l]
                        t = aindex(r, t->type); // [r]T
diff --git a/test/fixedbugs/issue6399.go b/test/fixedbugs/issue6399.go
new file mode 100644 (file)
index 0000000..b3d1c85
--- /dev/null
@@ -0,0 +1,27 @@
+// compile
+
+package main
+
+type Foo interface {
+       Print()
+}
+
+type Bar struct{}
+
+func (b Bar) Print() {}
+
+func main() {
+       b := make([]Bar, 20)
+       f := make([]Foo, 20)
+       for i := range f {
+               f[i] = b[i]
+       }
+       T(f)
+       _ = make([]struct{}, 1)
+}
+
+func T(f []Foo) {
+       for i := range f {
+               f[i].Print()
+       }
+}