diff --git a/src/cmd/compile/internal/ssa/prove.go b/src/cmd/compile/internal/ssa/prove.go index 4788f2d803..12c2580c95 100644 --- a/src/cmd/compile/internal/ssa/prove.go +++ b/src/cmd/compile/internal/ssa/prove.go @@ -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 index 0000000000..ac311e3715 --- /dev/null +++ b/test/fixedbugs/issue37753.go @@ -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) + } +}