Commit 46c9fd03 authored by David Chase's avatar David Chase

cmd/compile: enable optimizer logging for bounds checking

Change-Id: Ic1fc271589b7212e7f604ece93cfe34feff909b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/204160
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
parent 40ebcfaa
......@@ -20,12 +20,15 @@ type pair struct {a,b int}
func bar(y *pair) *int {
return &y.b
}
var a []int
func foo(w, z *pair) *int {
if *bar(w) > 0 {
return bar(z)
}
return nil
if a[1] > 0 {
a = a[:2]
}
return &a[0]
}
`
......@@ -102,6 +105,7 @@ func TestLogOpt(t *testing.T) {
t.Logf("%s", slogged)
// below shows proper inlining and nilcheck
want(t, slogged, `{"range":{"start":{"line":9,"character":13},"end":{"line":9,"character":13}},"severity":3,"code":"nilcheck","source":"go compiler","message":"","relatedInformation":[{"location":{"uri":"file://tmpdir/file.go","range":{"start":{"line":4,"character":11},"end":{"line":4,"character":11}}},"message":"inlineLoc"}]}`)
want(t, slogged, `{"range":{"start":{"line":11,"character":6},"end":{"line":11,"character":6}},"severity":3,"code":"isInBounds","source":"go compiler","message":""}`)
})
}
......
......@@ -4,20 +4,32 @@
package ssa
import "cmd/compile/internal/logopt"
// checkbce prints all bounds checks that are present in the function.
// Useful to find regressions. checkbce is only activated when with
// corresponding debug options, so it's off by default.
// See test/checkbce.go
func checkbce(f *Func) {
if f.pass.debug <= 0 {
if f.pass.debug <= 0 && !logopt.Enabled() {
return
}
for _, b := range f.Blocks {
for _, v := range b.Values {
if v.Op == OpIsInBounds || v.Op == OpIsSliceInBounds {
if f.pass.debug > 0 {
f.Warnl(v.Pos, "Found %v", v.Op)
}
if logopt.Enabled() {
if v.Op == OpIsInBounds {
logopt.LogOpt(v.Pos, "isInBounds", "checkbce", f.Name)
}
if v.Op == OpIsSliceInBounds {
logopt.LogOpt(v.Pos, "isSliceInBounds", "checkbce", f.Name)
}
}
}
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment