diff options
| author | Keith Randall <khr@golang.org> | 2026-03-27 15:12:23 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2026-03-31 11:01:09 -0700 |
| commit | 1673075d4bd324e69cb4e6e58760316e2c84e604 (patch) | |
| tree | 0241cf5ff198bb149dec6843dfaef57dafb57c43 /src/cmd | |
| parent | 9387929d09490ae30a8da75c64d9c64e2c16936d (diff) | |
| download | go-1673075d4bd324e69cb4e6e58760316e2c84e604.tar.xz | |
test/codegen: fix broken syntax
A bunch of tests had broken yet undetected syntax errors
in their assembly output regexps. Things like mismatched quotes,
using ^ instead of - for negation, etc.
In addition, since CL 716060 using commas as separators between
regexps doesn't work, and ends up just silently dropping every
regexp after the comma.
Fix all these things, and add a test to make sure that we're not
silently dropping regexps on the floor.
After this CL I will do some cleanup to align with CL 716060, like
replacing commas and \s with spaces (which was the point of that CL,
but wasn't consistently rewritten everywhere).
Change-Id: I54f226120a311ead0c6c62eaf5d152ceed106034
Reviewed-on: https://go-review.googlesource.com/c/go/+/760521
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Paul Murphy <paumurph@redhat.com>
Auto-Submit: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd')
| -rw-r--r-- | src/cmd/internal/testdir/testdir_test.go | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/cmd/internal/testdir/testdir_test.go b/src/cmd/internal/testdir/testdir_test.go index c706089877..e4d5b5d70b 100644 --- a/src/cmd/internal/testdir/testdir_test.go +++ b/src/cmd/internal/testdir/testdir_test.go @@ -1394,10 +1394,11 @@ type wantedError struct { } var ( - errRx = regexp.MustCompile(`// (?:GC_)?ERROR (.*)`) - errAutoRx = regexp.MustCompile(`// (?:GC_)?ERRORAUTO (.*)`) - errQuotesRx = regexp.MustCompile(`"([^"]*)"`) - lineRx = regexp.MustCompile(`LINE(([+-])(\d+))?`) + errRx = regexp.MustCompile(`// (?:GC_)?ERROR (.*)`) + errAutoRx = regexp.MustCompile(`// (?:GC_)?ERRORAUTO (.*)`) + errQuotesRx = regexp.MustCompile(`"([^"]*)"`) + lineRx = regexp.MustCompile(`LINE(([+-])(\d+))?`) + possibleOpcodeRx = regexp.MustCompile(`([A-Z][A-Z]|[IF](32|64))`) // two caps, or a wasm prefix ) func (t test) wantedErrors(file, short string) (errs []wantedError) { @@ -1477,7 +1478,7 @@ var ( // followed by semi-colon, followed by a comma-separated list of opcode checks. // Extraneous spaces are ignored. // - // An example: arm64/v8.1 : -`ADD` , `SUB` + // An example: arm64/v8.1 : -`ADD` `SUB` // "(\w+)" matches "arm64" (architecture name) // "(/[\w.]+)?" matches "v8.1" (architecture version) // "(/\w*)?" doesn't match anything here (it's an optional part of the triplet) @@ -1485,10 +1486,11 @@ var ( // "(" starts a capturing group // first reMatchCheck matches "-`ADD`" // `(?:" starts a non-capturing group - // "\s*,\s*` matches " , " + // "[\s,]+" matches " " // second reMatchCheck matches "`SUB`" - // ")*)" closes started groups; "*" means that there might be other elements in the comma-separated list - rxAsmPlatform = regexp.MustCompile(`(\w+)(/[\w.]+)?(/\w*)?\s*:\s*(` + reMatchCheck + `(?:\s+` + reMatchCheck + `)*)`) + // ")*)" closes started groups; "*" means that there might be other elements in the space-separated list + // (TODO: remove allowance for comma-separation once the repo is all fixed.) + rxAsmPlatform = regexp.MustCompile(`(\w+)(/[\w.]+)?(/\w*)?\s*:\s*(` + reMatchCheck + `(?:[\s,]+` + reMatchCheck + `)*)`) // Regexp to extract a single opcoded check rxAsmCheck = regexp.MustCompile(reMatchCheck) @@ -1582,9 +1584,10 @@ func (t test) wantedAsmOpcodes(fn string) asmChecks { // Parse and extract any architecture check from comments, // made by one architecture name and multiple checks. lnum := fn + ":" + strconv.Itoa(i+1) + lastUsed := 0 for _, ac := range rxAsmPlatform.FindAllStringSubmatch(comment, -1) { archspec, allchecks := ac[1:4], ac[4] - + lastUsed = strings.LastIndex(comment, allchecks) + len(allchecks) var arch, subarch, os string switch { case archspec[2] != "": // 3 components: "linux/386/sse2" @@ -1670,6 +1673,18 @@ func (t test) wantedAsmOpcodes(fn string) asmChecks { } } } + if lastUsed > 0 { + // There was an asm spec in this comment. Check for possible syntax + // errors, which would leave some asm patterns unused. We want + // to allow some tail, for example for English comments. The + // hueristic we use here is we look for two consecutive capital + // letters (or a wasm prefix). Those are probably assembly mnemonics + // that weren't used. + tail := comment[lastUsed:] + if possibleOpcodeRx.MatchString(tail) { + t.Errorf("%s:%d: possible unused assembly pattern: %v", t.goFileName(), i+1, tail) + } + } comment = "" } |
