]> Cypherpunks repositories - gostls13.git/commitdiff
internal/bisect: copy parser changes from CL 494177
authorRuss Cox <rsc@golang.org>
Wed, 10 May 2023 19:51:46 +0000 (15:51 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 11 May 2023 01:52:24 +0000 (01:52 +0000)
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 <drchase@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/loopvar/loopvar_test.go
src/internal/bisect/bisect.go

index 3bfc802eb2dad98c073868e14f12cef5376e52f3..d48b5ada7f99a560ea123cf93931771a544675f5 100644 (file)
@@ -191,30 +191,32 @@ func TestLoopVarHashes(t *testing.T) {
                return string(b)
        }
 
-       m := f("v001100110110110010100100")
-       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")
-       }
+       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("%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)
+               }
        }
 }
 
index 21e825eab94b8586c1956b4c305d145fe3dd039f..37f76a42718496a7d66f7bfbc18824229a06cbdc 100644 (file)
@@ -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