]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix bug in phiopt pass
authorKeith Randall <khr@golang.org>
Thu, 1 Apr 2021 06:58:54 +0000 (23:58 -0700)
committerKeith Randall <khr@golang.org>
Fri, 2 Apr 2021 05:24:14 +0000 (05:24 +0000)
The math to invert the input index was wrong.

Fixes #45323

Change-Id: I7c68cac280e8f01a9c806ecb0f195f169267437e
Reviewed-on: https://go-review.googlesource.com/c/go/+/306431
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: fannie zhang <Fannie.Zhang@arm.com>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/ssa/phiopt.go
test/fixedbugs/issue45323.go [new file with mode: 0644]

index ee583d022522127638f569d32349edf89de3e33e..745c61cb860a950fb7efb2f6d2576e6feae5d028 100644 (file)
@@ -213,7 +213,7 @@ func phiopt(f *Func) {
                                ei := b.Preds[1].i
                                sb0 := pb1.Succs[1-ei].b
                                if sdom.IsAncestorEq(sb0, pb0) {
-                                       convertPhi(pb1, v, ei-1)
+                                       convertPhi(pb1, v, 1-ei)
                                        break
                                }
                        } else {
diff --git a/test/fixedbugs/issue45323.go b/test/fixedbugs/issue45323.go
new file mode 100644 (file)
index 0000000..870d1a2
--- /dev/null
@@ -0,0 +1,24 @@
+// compile
+
+// Copyright 2021 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
+
+func g() bool
+
+func f(y int) bool {
+       b, ok := true, false
+       if y > 1 {
+               ok = g()
+       }
+       if !ok {
+               ok = g()
+               b = false
+       }
+       if !ok {
+               return false
+       }
+       return b
+}