mirror of
https://github.com/golang/go
synced 2024-11-23 07:20:06 -07:00
7e9d55eeeb
For non-unit increment, loopbce checks to see if the increment evenly divides the difference between (constant) loop start and end. This test panics when the increment is zero. Fix: check for zero, if found, don't optimize the loop. Also added missing copyright notice to loopbce.go. Fixes #26043. Change-Id: I5f460104879cacc94481949234c9ce8c519d6380 Reviewed-on: https://go-review.googlesource.com/120759 Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
33 lines
543 B
Go
33 lines
543 B
Go
// compile
|
|
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// This program results in a loop inferred to increment
|
|
// j by 0, causing bounds check elimination to attempt
|
|
// something%0, which panics (in the bug).
|
|
|
|
package q
|
|
|
|
func f() {
|
|
var s1 string
|
|
var b bool
|
|
if b {
|
|
b = !b
|
|
s1 += "a"
|
|
}
|
|
|
|
var s2 string
|
|
var i, j int
|
|
if (s1 <= "") || (s2 >= "") {
|
|
j = len(s1[:6])
|
|
} else {
|
|
i = len("b")
|
|
}
|
|
|
|
for j < 0 {
|
|
j += i
|
|
}
|
|
}
|