From: Cuong Manh Le Date: Tue, 16 Jul 2024 16:56:56 +0000 (+0700) Subject: cmd/compile: run checkbce after fuseLate pass X-Git-Tag: go1.24rc1~1417 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=864aa8644879983d903e59995e6a31c95c50e8ff;p=gostls13.git cmd/compile: run checkbce after fuseLate pass So the bounds check which are eliminated during late fuse pass could be detected correctly. Fixes #67329 Change-Id: Id7992fbb8c26e0d43e7db66a0a3a2c0d9ed937a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/598635 Reviewed-by: Keith Randall Reviewed-by: Keith Randall Reviewed-by: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI --- diff --git a/src/cmd/compile/internal/ssa/checkbce.go b/src/cmd/compile/internal/ssa/checkbce.go index 6a9ce2be0a..d7400b2ae9 100644 --- a/src/cmd/compile/internal/ssa/checkbce.go +++ b/src/cmd/compile/internal/ssa/checkbce.go @@ -16,6 +16,9 @@ func checkbce(f *Func) { } for _, b := range f.Blocks { + if b.Kind == BlockInvalid { + continue + } for _, v := range b.Values { if v.Op == OpIsInBounds || v.Op == OpIsSliceInBounds { if f.pass.debug > 0 { diff --git a/src/cmd/compile/internal/ssa/compile.go b/src/cmd/compile/internal/ssa/compile.go index 80ef53d085..3f46599a3e 100644 --- a/src/cmd/compile/internal/ssa/compile.go +++ b/src/cmd/compile/internal/ssa/compile.go @@ -477,9 +477,9 @@ var passes = [...]pass{ {name: "dead auto elim", fn: elimDeadAutosGeneric}, {name: "sccp", fn: sccp}, {name: "generic deadcode", fn: deadcode, required: true}, // remove dead stores, which otherwise mess up store chain - {name: "check bce", fn: checkbce}, {name: "branchelim", fn: branchelim}, {name: "late fuse", fn: fuseLate}, + {name: "check bce", fn: checkbce}, {name: "dse", fn: dse}, {name: "memcombine", fn: memcombine}, {name: "writebarrier", fn: writebarrier, required: true}, // expand write barrier ops diff --git a/test/fixedbugs/issue67329.go b/test/fixedbugs/issue67329.go new file mode 100644 index 0000000000..5595c31c8c --- /dev/null +++ b/test/fixedbugs/issue67329.go @@ -0,0 +1,27 @@ +// errorcheck -0 -d=ssa/check_bce/debug=1 + +// Copyright 2024 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 x + +func Found(x []string) string { + switch len(x) { + default: + return x[0] + case 0, 1: + return "" + } +} + +func NotFound(x []string) string { + switch len(x) { + default: + return x[0] + case 0: + return "" + case 1: + return "" + } +}