aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2018-06-25 15:26:45 -0400
committerDavid Chase <drchase@google.com>2018-06-25 20:36:42 +0000
commit7e9d55eeeb183ee95d26b3ed4ff171902605decf (patch)
tree5739d3711787f80403e6616d11285454508d7b99 /src/cmd/compile/internal
parent6d709528972aa572a6dafb06cd3446348d337aa7 (diff)
downloadgo-7e9d55eeeb183ee95d26b3ed4ff171902605decf.tar.xz
cmd/compile: avoid remainder in loopbce when increment=0
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>
Diffstat (limited to 'src/cmd/compile/internal')
-rw-r--r--src/cmd/compile/internal/ssa/loopbce.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/ssa/loopbce.go b/src/cmd/compile/internal/ssa/loopbce.go
index 0c09de0bfc..2ab05711ad 100644
--- a/src/cmd/compile/internal/ssa/loopbce.go
+++ b/src/cmd/compile/internal/ssa/loopbce.go
@@ -1,3 +1,7 @@
+// 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.
+
package ssa
import "fmt"
@@ -154,7 +158,7 @@ nextb:
// if the increment is ±1 or when the limits are constants.
if inc.AuxInt != 1 && inc.AuxInt != -1 {
ok := false
- if min.Op == OpConst64 && max.Op == OpConst64 {
+ if min.Op == OpConst64 && max.Op == OpConst64 && inc.AuxInt != 0 {
if max.AuxInt > min.AuxInt && max.AuxInt%inc.AuxInt == min.AuxInt%inc.AuxInt { // handle overflow
ok = true
}