Skip to content

Commit f410a66

Browse files
committed
cmd/vet: improve error message for cross-package assembly
bytes.Compare has its go prototype in package bytes, but its implementation in package runtime. vet used to complain that the prototype was missing. Now instead: runtime/asm_amd64.s:1483: [amd64] cannot check cross-package assembly function: Compare is in package bytes Updates #11041 Change-Id: Ied44fac10d0916d7a34e552c02d052e16fca0c8c Reviewed-on: https://go-review.googlesource.com/27153 Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rob Pike <[email protected]>
1 parent 0952a15 commit f410a66

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/cmd/vet/asmdecl.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (a *asmArch) maxAlign() int { return int(a.sizes.MaxAlign) }
9898
var (
9999
re = regexp.MustCompile
100100
asmPlusBuild = re(`//\s+\+build\s+([^\n]+)`)
101-
asmTEXT = re(`\bTEXT\b.*·([^\(]+)\(SB\)(?:\s*,\s*([0-9A-Z|+]+))?(?:\s*,\s*\$(-?[0-9]+)(?:-([0-9]+))?)?`)
101+
asmTEXT = re(`\bTEXT\b(.*)·([^\(]+)\(SB\)(?:\s*,\s*([0-9A-Z|+]+))?(?:\s*,\s*\$(-?[0-9]+)(?:-([0-9]+))?)?`)
102102
asmDATA = re(`\b(DATA|GLOBL)\b`)
103103
asmNamedFP = re(`([a-zA-Z0-9_\xFF-\x{10FFFF}]+)(?:\+([0-9]+))\(FP\)`)
104104
asmUnnamedFP = re(`[^+\-0-9](([0-9]+)\(FP\))`)
@@ -205,21 +205,32 @@ Files:
205205
continue Files
206206
}
207207
}
208-
fnName = m[1]
209-
fn = knownFunc[m[1]][arch]
208+
fnName = m[2]
209+
if pkgName := strings.TrimSpace(m[1]); pkgName != "" {
210+
pathParts := strings.Split(pkgName, "∕")
211+
pkgName = pathParts[len(pathParts)-1]
212+
if pkgName != f.pkg.path {
213+
f.Warnf(token.NoPos, "%s:%d: [%s] cannot check cross-package assembly function: %s is in package %s", f.name, lineno, arch, fnName, pkgName)
214+
fn = nil
215+
fnName = ""
216+
continue
217+
}
218+
}
219+
fn = knownFunc[fnName][arch]
210220
if fn != nil {
211-
size, _ := strconv.Atoi(m[4])
212-
if size != fn.size && (m[2] != "7" && !strings.Contains(m[2], "NOSPLIT") || size != 0) {
221+
size, _ := strconv.Atoi(m[5])
222+
flag := m[3]
223+
if size != fn.size && (flag != "7" && !strings.Contains(flag, "NOSPLIT") || size != 0) {
213224
badf("wrong argument size %d; expected $...-%d", size, fn.size)
214225
}
215226
}
216-
localSize, _ = strconv.Atoi(m[3])
227+
localSize, _ = strconv.Atoi(m[4])
217228
localSize += archDef.intSize()
218229
if archDef.lr {
219230
// Account for caller's saved LR
220231
localSize += archDef.intSize()
221232
}
222-
argSize, _ = strconv.Atoi(m[4])
233+
argSize, _ = strconv.Atoi(m[5])
223234
if fn == nil && !strings.Contains(fnName, "<>") {
224235
badf("function %s missing Go declaration", fnName)
225236
}

0 commit comments

Comments
 (0)