]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: handle multiple arches in asm build directives
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 21 Jul 2016 18:40:01 +0000 (11:40 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 22 Aug 2016 15:43:16 +0000 (15:43 +0000)
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 <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/vet/asmdecl.go

index 41faa035a66e9f92489a3692891c3caa3e4b8216..e228495071e37aa268875a2123a284cf10cc5bd2 100644 (file)
@@ -177,22 +177,35 @@ Files:
                        if arch == "" {
                                // Determine architecture from +build line if possible.
                                if m := asmPlusBuild.FindStringSubmatch(line); m != nil {
-                               Fields:
+                                       // There can be multiple architectures in a single +build line,
+                                       // so accumulate them all and then prefer the one that
+                                       // matches build.Default.GOARCH.
+                                       var archCandidates []*asmArch
                                        for _, fld := range strings.Fields(m[1]) {
                                                for _, a := range arches {
                                                        if a.name == fld {
-                                                               arch = a.name
-                                                               archDef = a
-                                                               break Fields
+                                                               archCandidates = append(archCandidates, a)
                                                        }
                                                }
                                        }
+                                       for _, a := range archCandidates {
+                                               if a.name == build.Default.GOARCH {
+                                                       archCandidates = []*asmArch{a}
+                                                       break
+                                               }
+                                       }
+                                       if len(archCandidates) > 0 {
+                                               arch = archCandidates[0].name
+                                               archDef = archCandidates[0]
+                                       }
                                }
                        }
 
                        if m := asmTEXT.FindStringSubmatch(line); m != nil {
                                flushRet()
                                if arch == "" {
+                                       // Arch not specified by filename or build tags.
+                                       // Fall back to build.Default.GOARCH.
                                        for _, a := range arches {
                                                if a.name == build.Default.GOARCH {
                                                        arch = a.name