Source file src/cmd/compile/internal/ssacompile/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 ssacompile
     6  
     7  import (
     8  	"cmd/compile/internal/logopt"
     9  	"cmd/compile/internal/ssa"
    10  	"cmd/compile/internal/ssa/block"
    11  	"cmd/compile/internal/ssa/ssaop"
    12  )
    13  
    14  // checkbce prints all bounds checks that are present in the function.
    15  // Useful to find regressions. checkbce is only activated when with
    16  // corresponding debug options, so it's off by default.
    17  // See test/checkbce.go
    18  func checkbce(f *ssa.Func) {
    19  	if f.Pass.Debug <= 0 && !logopt.Enabled() {
    20  		return
    21  	}
    22  
    23  	for _, b := range f.Blocks {
    24  		if b.Kind == block.BlockInvalid {
    25  			continue
    26  		}
    27  		for _, v := range b.Values {
    28  			if v.Op == ssaop.OpIsInBounds || v.Op == ssaop.OpIsSliceInBounds {
    29  				if f.Pass.Debug > 0 {
    30  					f.Warnl(v.Pos, "Found %v", v.Op)
    31  				}
    32  				if logopt.Enabled() {
    33  					if v.Op == ssaop.OpIsInBounds {
    34  						logopt.LogOpt(v.Pos, "isInBounds", "checkbce", f.Name)
    35  					}
    36  					if v.Op == ssaop.OpIsSliceInBounds {
    37  						logopt.LogOpt(v.Pos, "isSliceInBounds", "checkbce", f.Name)
    38  					}
    39  				}
    40  			}
    41  		}
    42  	}
    43  }
    44  

View as plain text