From: Keith Randall Date: Thu, 1 Apr 2021 06:58:54 +0000 (-0700) Subject: cmd/compile: fix bug in phiopt pass X-Git-Tag: go1.17beta1~886 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=aebc0b473e364daa0fad3b45e4dc77366408f3cd;p=gostls13.git cmd/compile: fix bug in phiopt pass 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 Run-TryBot: Keith Randall TryBot-Result: Go Bot Reviewed-by: fannie zhang Reviewed-by: David Chase --- diff --git a/src/cmd/compile/internal/ssa/phiopt.go b/src/cmd/compile/internal/ssa/phiopt.go index ee583d0225..745c61cb86 100644 --- a/src/cmd/compile/internal/ssa/phiopt.go +++ b/src/cmd/compile/internal/ssa/phiopt.go @@ -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 index 0000000000..870d1a27f7 --- /dev/null +++ b/test/fixedbugs/issue45323.go @@ -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 +}