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

     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  		for _, v := range b.Values {
    20  			if v.Op == OpIsInBounds || v.Op == OpIsSliceInBounds {
    21  				if f.pass.debug > 0 {
    22  					f.Warnl(v.Pos, "Found %v", v.Op)
    23  				}
    24  				if logopt.Enabled() {
    25  					if v.Op == OpIsInBounds {
    26  						logopt.LogOpt(v.Pos, "isInBounds", "checkbce", f.Name)
    27  					}
    28  					if v.Op == OpIsSliceInBounds {
    29  						logopt.LogOpt(v.Pos, "isSliceInBounds", "checkbce", f.Name)
    30  					}
    31  				}
    32  			}
    33  		}
    34  	}
    35  }
    36  

View as plain text