1
0
mirror of https://github.com/golang/go synced 2024-11-23 04:10:04 -07:00

cmd/gc: fix divide by zero error in compiler

Fixes #6399.

R=ken2
CC=golang-dev
https://golang.org/cl/13253055
This commit is contained in:
Russ Cox 2013-09-16 14:22:37 -04:00
parent a70cbf1329
commit 51266761fd
2 changed files with 28 additions and 1 deletions

View File

@ -1295,7 +1295,7 @@ walkexpr(Node **np, NodeList **init)
t = n->type; t = n->type;
if(n->esc == EscNone if(n->esc == EscNone
&& smallintconst(l) && smallintconst(r) && 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 // var arr [r]T
// n = arr[:l] // n = arr[:l]
t = aindex(r, t->type); // [r]T t = aindex(r, t->type); // [r]T

View File

@ -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()
}
}