Skip to content

Commit ef6fde2

Browse files
committed
cmd/vet: handle multiple arches in asm build directives
If a build directive contains multiple arches, try to match the build context. Updates #11041 Change-Id: I03b5d7bfb29d1ff6c7d36a9d7c7fabfcc1d871c1 Reviewed-on: https://go-review.googlesource.com/27158 Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rob Pike <[email protected]>
1 parent 863ca99 commit ef6fde2

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/cmd/vet/asmdecl.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,22 +177,35 @@ Files:
177177
if arch == "" {
178178
// Determine architecture from +build line if possible.
179179
if m := asmPlusBuild.FindStringSubmatch(line); m != nil {
180-
Fields:
180+
// There can be multiple architectures in a single +build line,
181+
// so accumulate them all and then prefer the one that
182+
// matches build.Default.GOARCH.
183+
var archCandidates []*asmArch
181184
for _, fld := range strings.Fields(m[1]) {
182185
for _, a := range arches {
183186
if a.name == fld {
184-
arch = a.name
185-
archDef = a
186-
break Fields
187+
archCandidates = append(archCandidates, a)
187188
}
188189
}
189190
}
191+
for _, a := range archCandidates {
192+
if a.name == build.Default.GOARCH {
193+
archCandidates = []*asmArch{a}
194+
break
195+
}
196+
}
197+
if len(archCandidates) > 0 {
198+
arch = archCandidates[0].name
199+
archDef = archCandidates[0]
200+
}
190201
}
191202
}
192203

193204
if m := asmTEXT.FindStringSubmatch(line); m != nil {
194205
flushRet()
195206
if arch == "" {
207+
// Arch not specified by filename or build tags.
208+
// Fall back to build.Default.GOARCH.
196209
for _, a := range arches {
197210
if a.name == build.Default.GOARCH {
198211
arch = a.name

0 commit comments

Comments
 (0)