Debian Codegraph @

src/cmd/compile/internal/ssa/checkbce.go

raw
1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package ssa
6
7 import "cmd/compile/internal/logopt"
8
9 // checkbce prints all bounds checks that are present in the function.
10 // Useful to find regressions. checkbce is only activated when with
11 // corresponding debug options, so it's off by default.
12 // See test/checkbce.go
13 func checkbce(f *Func) {
14 if f.pass.debug <= 0 && !logopt.Enabled() {
15 return
16 }
17
18 for _, b := range f.Blocks {
19 if b.Kind == BlockInvalid {
20 continue
21 }
22 for _, v := range b.Values {
23 if v.Op == OpIsInBounds || v.Op == OpIsSliceInBounds {
24 if f.pass.debug > 0 {
25 f.Warnl(v.Pos, "Found %v", v.Op)
26 }
27 if logopt.Enabled() {
28 if v.Op == OpIsInBounds {
29 logopt.LogOpt(v.Pos, "isInBounds", "checkbce", f.Name)
30 }
31 if v.Op == OpIsSliceInBounds {
32 logopt.LogOpt(v.Pos, "isSliceInBounds", "checkbce", f.Name)
33 }
34 }
35 }
36 }
37 }
38 }