diff options
Diffstat (limited to 'src/cmd/internal/testdir/testdir_test.go')
| -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 = "" } |
