]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.11] cmd/compile: in prove, fix fence-post implications for unsign...
authorGiovanni Bajo <rasky@develer.com>
Fri, 31 Aug 2018 00:15:26 +0000 (02:15 +0200)
committerFilippo Valsorda <filippo@golang.org>
Sat, 1 Sep 2018 07:57:44 +0000 (07:57 +0000)
commitebf5d985d1a51440d19bd6ac6a43654179527fdc
treee61eb5ac2d1c1cd5f67708265847428a84337072
parentad116f72b96530edeece030da4ee3f7f7d711ddd
[release-branch.go1.11] cmd/compile: in prove, fix fence-post implications for unsigned domain

Fence-post implications of the form "x-1 >= w && x > min ⇒ x > w"
were not correctly handling unsigned domain, by always checking signed
limits.

This bug was uncovered once we taught prove that len(x) is always
>= 0 in the signed domain.

In the code being miscompiled (s[len(s)-1]), prove checks
whether len(s)-1 >= len(s) in the unsigned domain; if it proves
that this is always false, it can remove the bound check.

Notice that len(s)-1 >= len(s) can be true for len(s) = 0 because
of the wrap-around, so this is something prove should not be
able to deduce.

But because of the bug, the gate condition for the fence-post
implication was len(s) > MinInt64 instead of len(s) > 0; that
condition would be good in the signed domain but not in the
unsigned domain. And since in CL105635 we taught prove that
len(s) >= 0, the condition incorrectly triggered
(len(s) >= 0 > MinInt64) and things were going downfall.

Fixes #27378

Change-Id: I3dbcb1955ac5a66a0dcbee500f41e8d219409be5
Reviewed-on: https://go-review.googlesource.com/132495
Reviewed-by: Keith Randall <khr@golang.org>
(cherry picked from commit 09ea3c08e8fd1915515383f8cb4c0bb237d2b87d)
Reviewed-on: https://go-review.googlesource.com/132575
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/cmd/compile/internal/ssa/prove.go
test/fixedbugs/issue27289.go [new file with mode: 0644]
test/prove.go