]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use only bit patterns in isNonNegative
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 9 Mar 2020 13:37:49 +0000 (06:37 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 9 Mar 2020 20:19:25 +0000 (20:19 +0000)
CL 212777 added a check to isNonNegative
to return true for unsigned values.
However, the SSA backend isn't type safe
enough for that to be sound.
The other checks in isNonNegative
look only at the pattern of bits.
Remove the type-based check.

Updates #37753

Change-Id: I059d0e86353453133f2a160dce53af299f42e533
Reviewed-on: https://go-review.googlesource.com/c/go/+/222620
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/prove.go
test/fixedbugs/issue37753.go [new file with mode: 0644]

index 4788f2d803adbda55b56c6e089b659a1637db059..12c2580c957eea366eb3e13b02114d29b889ed4c 100644 (file)
@@ -1305,9 +1305,9 @@ func isNonNegative(v *Value) bool {
        if !v.Type.IsInteger() {
                panic("isNonNegative bad type")
        }
-       if !v.Type.IsSigned() {
-               return true
-       }
+       // TODO: return true if !v.Type.IsSigned()
+       // SSA isn't type-safe enough to do that now (issue 37753).
+       // The checks below depend only on the pattern of bits.
 
        switch v.Op {
        case OpConst64:
diff --git a/test/fixedbugs/issue37753.go b/test/fixedbugs/issue37753.go
new file mode 100644 (file)
index 0000000..ac311e3
--- /dev/null
@@ -0,0 +1,18 @@
+// run
+
+// Copyright 2020 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 main
+
+//go:noinline
+func f(a, b uint) int {
+       return int(a-b) / 8
+}
+
+func main() {
+       if x := f(1, 2); x != 0 {
+               panic(x)
+       }
+}