]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: run checkbce after fuseLate pass
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 16 Jul 2024 16:56:56 +0000 (23:56 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 23 Jul 2024 23:50:30 +0000 (23:50 +0000)
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 <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/compile/internal/ssa/checkbce.go
src/cmd/compile/internal/ssa/compile.go
test/fixedbugs/issue67329.go [new file with mode: 0644]

index 6a9ce2be0aacab01ae33e81eef7bdf734a1d8446..d7400b2ae9c9ecd3e8f7eaffc21c4b18558d9703 100644 (file)
@@ -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 {
index 80ef53d085db6257f0df1e1bc69b2a92e1eebda8..3f46599a3e5756cbc97421aa84c9d46234f26de2 100644 (file)
@@ -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 (file)
index 0000000..5595c31
--- /dev/null
@@ -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 ""
+       }
+}