From 48f8c5c0373886736d348acb1ce1601457da1d2e Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 10 May 2023 15:51:46 -0400 Subject: [PATCH] internal/bisect: copy parser changes from CL 494177 x/tools/cmd/bisect is changing to emit hex skips for robustness. Update this copy of internal/bisect to understand them. Change-Id: Ie9445714e8e9fb594e656db2f94dcde9b6ce82d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/494178 Reviewed-by: David Chase Run-TryBot: Russ Cox TryBot-Result: Gopher Robot --- .../compile/internal/loopvar/loopvar_test.go | 44 ++++++++++--------- src/internal/bisect/bisect.go | 23 +++++++++- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/cmd/compile/internal/loopvar/loopvar_test.go b/src/cmd/compile/internal/loopvar/loopvar_test.go index 3bfc802eb2d..d48b5ada7f9 100644 --- a/src/cmd/compile/internal/loopvar/loopvar_test.go +++ b/src/cmd/compile/internal/loopvar/loopvar_test.go @@ -191,30 +191,32 @@ func TestLoopVarHashes(t *testing.T) { return string(b) } - m := f("v001100110110110010100100") - t.Logf(m) + for _, arg := range []string{"v001100110110110010100100", "vx336ca4"} { + m := f(arg) + t.Logf(m) - mCount := strings.Count(m, "loopvarhash triggered cmd/compile/internal/loopvar/testdata/inlines/main.go:27:6 001100110110110010100100") - otherCount := strings.Count(m, "loopvarhash") - if mCount < 1 { - t.Errorf("did not see triggered main.go:27:6") - } - if mCount != otherCount { - t.Errorf("too many matches") - } + mCount := strings.Count(m, "loopvarhash triggered cmd/compile/internal/loopvar/testdata/inlines/main.go:27:6 001100110110110010100100") + otherCount := strings.Count(m, "loopvarhash") + if mCount < 1 { + t.Errorf("%s: did not see triggered main.go:27:6", arg) + } + if mCount != otherCount { + t.Errorf("%s: too many matches", arg) + } - mCount = strings.Count(m, "cmd/compile/internal/loopvar/testdata/inlines/main.go:27:6 [bisect-match 0x7802e115b9336ca4]") - otherCount = strings.Count(m, "[bisect-match ") - if mCount < 1 { - t.Errorf("did not see bisect-match for main.go:27:6") - } - if mCount != otherCount { - t.Errorf("too many matches") - } + mCount = strings.Count(m, "cmd/compile/internal/loopvar/testdata/inlines/main.go:27:6 [bisect-match 0x7802e115b9336ca4]") + otherCount = strings.Count(m, "[bisect-match ") + if mCount < 1 { + t.Errorf("%s: did not see bisect-match for main.go:27:6", arg) + } + if mCount != otherCount { + t.Errorf("%s: too many matches", arg) + } - // This next test carefully dodges a bug-to-be-fixed with inlined locations for ir.Names. - if !strings.Contains(m, ", 100, 100, 100, 100") { - t.Errorf("Did not see expected value of m run") + // This next test carefully dodges a bug-to-be-fixed with inlined locations for ir.Names. + if !strings.Contains(m, ", 100, 100, 100, 100") { + t.Errorf("%s: did not see expected value of m run", arg) + } } } diff --git a/src/internal/bisect/bisect.go b/src/internal/bisect/bisect.go index 21e825eab94..37f76a42718 100644 --- a/src/internal/bisect/bisect.go +++ b/src/internal/bisect/bisect.go @@ -229,17 +229,35 @@ func New(pattern string) (*Matcher, error) { result := true bits := uint64(0) start := 0 + wid := 1 // 1-bit (binary); sometimes 4-bit (hex) for i := 0; i <= len(p); i++ { // Imagine a trailing - at the end of the pattern to flush final suffix c := byte('-') if i < len(p) { c = p[i] } + if i == start && wid == 1 && c == 'x' { // leading x for hex + start = i + 1 + wid = 4 + continue + } switch c { default: return nil, &parseError{"invalid pattern syntax: " + pattern} + case '2', '3', '4', '5', '6', '7', '8', '9': + if wid != 4 { + return nil, &parseError{"invalid pattern syntax: " + pattern} + } + fallthrough case '0', '1': - bits = bits<<1 | uint64(c-'0') + bits <<= wid + bits |= uint64(c - '0') + case 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F': + if wid != 4 { + return nil, &parseError{"invalid pattern syntax: " + pattern} + } + bits <<= 4 + bits |= uint64(c&^0x20 - 'A' + 10) case 'y': if i+1 < len(p) && (p[i+1] == '0' || p[i+1] == '1') { return nil, &parseError{"invalid pattern syntax: " + pattern} @@ -251,7 +269,7 @@ func New(pattern string) (*Matcher, error) { return nil, &parseError{"invalid pattern syntax (+ after -): " + pattern} } if i > 0 { - n := i - start + n := (i - start) * wid if n > 64 { return nil, &parseError{"pattern bits too long: " + pattern} } @@ -270,6 +288,7 @@ func New(pattern string) (*Matcher, error) { bits = 0 result = c == '+' start = i + 1 + wid = 1 } } return m, nil