]> Cypherpunks repositories - gostls13.git/commit
[dev.ssa] cmd/compile: used Bounded field to fix empty range loops
authorKeith Randall <khr@golang.org>
Tue, 18 Aug 2015 21:17:30 +0000 (14:17 -0700)
committerKeith Randall <khr@golang.org>
Wed, 19 Aug 2015 21:44:44 +0000 (21:44 +0000)
commit46e62f873a34b06348bdaf231f1b72367950732e
tree4552ee2f16cac33dc2ff534a9e717630c4f234c0
parent67cbd5b51d3700fc1976f71a711882bfdd7e8304
[dev.ssa] cmd/compile: used Bounded field to fix empty range loops

    for i, v := range a {
    }

Walk converts this to a regular for loop, like this:

    for i := 0, p := &a[0]; i < len(a); i++, p++ {
        v := *p
    }

Unfortunately, &a[0] fails its bounds check when a is
the empty slice (or string).  The old compiler gets around this
by marking &a[0] as Bounded, meaning "don't emit bounds checks
for this index op".  This change makes SSA honor that same mark.

The SSA compiler hasn't implemented bounds check panics yet,
so the failed bounds check just causes the current routine
to return immediately.

Fixes bytes package tests.

Change-Id: Ibe838853ef4046c92f76adbded8cca3b1e449e0b
Reviewed-on: https://go-review.googlesource.com/13685
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/gc/testdata/ctl_ssa.go