From 2afbb1cd5fd71d84600691f02ce813e584c460d9 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Fri, 1 Nov 2013 11:49:11 -0700 Subject: [PATCH] go.tools/cmd/vet: handle symbolic TEXT annotations The symbolic names such as NOSPLIT for annotations on the TEXT directive appeared after vet started checking .s files. This CL tweaks the regular expression to allow CAPITALS and the symbols | and + as well as digits in that field, and interprets NOSPLIT as equivalent to 7 in that field. All magic. Fixes golang/go#6695 R=golang-dev, rsc CC=golang-dev https://golang.org/cl/18700044 --- cmd/vet/asmdecl.go | 4 ++-- cmd/vet/testdata/asm.go | 7 +++++++ cmd/vet/testdata/asm4.s | 26 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 cmd/vet/testdata/asm4.s diff --git a/cmd/vet/asmdecl.go b/cmd/vet/asmdecl.go index c23514c2..a32f1d69 100644 --- a/cmd/vet/asmdecl.go +++ b/cmd/vet/asmdecl.go @@ -69,7 +69,7 @@ var ( var ( re = regexp.MustCompile asmPlusBuild = re(`//\s+\+build\s+([^\n]+)`) - asmTEXT = re(`\bTEXT\b.*·([^\(]+)\(SB\)(?:\s*,\s*([0-9]+))?(?:\s*,\s*\$([0-9]+)(?:-([0-9]+))?)?`) + asmTEXT = re(`\bTEXT\b.*·([^\(]+)\(SB\)(?:\s*,\s*([0-9A-Z|+]+))?(?:\s*,\s*\$([0-9]+)(?:-([0-9]+))?)?`) asmDATA = re(`\b(DATA|GLOBL)\b`) asmNamedFP = re(`([a-zA-Z0-9_\xFF-\x{10FFFF}]+)(?:\+([0-9]+))\(FP\)`) asmUnnamedFP = re(`[^+\-0-9]](([0-9]+)\(FP\))`) @@ -146,7 +146,7 @@ func asmCheck(pkg *Package) { fn = knownFunc[m[1]][arch] if fn != nil { size, _ := strconv.Atoi(m[4]) - if size != fn.size && (m[2] != "7" || size != 0) { + if size != fn.size && (m[2] != "7" && !strings.Contains(m[2], "NOSPLIT") || size != 0) { warnf("wrong argument size %d; expected $...-%d", size, fn.size) } } diff --git a/cmd/vet/testdata/asm.go b/cmd/vet/testdata/asm.go index 18254a40..d8df5aae 100644 --- a/cmd/vet/testdata/asm.go +++ b/cmd/vet/testdata/asm.go @@ -22,3 +22,10 @@ func argiface(x interface{}, y interface { func returnint() int func returnbyte(x int) byte func returnnamed(x byte) (r1 int, r2 int16, r3 string, r4 byte) + +func noprof(x int) +func dupok(x int) +func nosplit(x int) +func rodata(x int) +func noptr(x int) +func wrapper(x int) diff --git a/cmd/vet/testdata/asm4.s b/cmd/vet/testdata/asm4.s new file mode 100644 index 00000000..044b050b --- /dev/null +++ b/cmd/vet/testdata/asm4.s @@ -0,0 +1,26 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build amd64 +// +build vet_test + +// Test cases for symbolic NOSPLIT etc. on TEXT symbols. + +TEXT ·noprof(SB),NOPROF,$0-8 + RET + +TEXT ·dupok(SB),DUPOK,$0-8 + RET + +TEXT ·nosplit(SB),NOSPLIT,$0 + RET + +TEXT ·rodata(SB),RODATA,$0-8 + RET + +TEXT ·noptr(SB),NOPTR|NOSPLIT,$0 + RET + +TEXT ·wrapper(SB),WRAPPER,$0-8 + RET