Skip to content

Commit 755363e

Browse files
committed
gopls: Update test cases.
Update test files for different types of reference relationships between asm and Go. Updates golang/go#71754
1 parent 139f5c3 commit 755363e

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

gopls/internal/goasm/references.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,15 @@ func References(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, p
9494
}
9595
}
9696

97-
if !includeDeclaration {
98-
return locations, nil
99-
}
10097
for _, asmFile := range pkg.AsmFiles() {
10198
for _, id := range asmFile.Idents {
102-
if id.Name == found.Name &&
103-
(id.Kind == asm.Data || id.Kind == asm.Ref) {
99+
if id.Name == found.Name {
100+
if !includeDeclaration && id.Kind == asm.Ref {
101+
continue
102+
}
103+
if id.Kind != asm.Data {
104+
continue
105+
}
104106
if loc, err := asmFile.IdentLocation(id); err == nil {
105107
locations = append(locations, loc)
106108
}

gopls/internal/golang/references.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"go/ast"
2020
"go/token"
2121
"go/types"
22+
"log"
2223
"sort"
2324
"strings"
2425
"sync"
@@ -36,7 +37,6 @@ import (
3637
"golang.org/x/tools/gopls/internal/util/morestrings"
3738
"golang.org/x/tools/gopls/internal/util/safetoken"
3839
"golang.org/x/tools/internal/event"
39-
"golang.org/x/tools/internal/typesinternal"
4040
)
4141

4242
// References returns a list of all references (sorted with
@@ -619,15 +619,17 @@ func localReferences(pkg *cache.Package, targets map[types.Object]bool, correspo
619619
if id.Kind != asm.Data && id.Kind != asm.Ref {
620620
continue
621621
}
622-
_, name, ok := morestrings.CutLast(id.Name, ".")
622+
pkgpath, name, ok := morestrings.CutLast(id.Name, ".")
623623
if !ok {
624624
continue
625625
}
626-
obj := pkg.Types().Scope().Lookup(name)
627-
if obj == nil {
626+
log.Printf("ignoring asm identifier %q in package %q: not in package %q", id.Name, pkgpath, pkg.Types().Path())
627+
if pkgpath != pkg.Types().Path() {
628+
log.Printf("ignoring asm identifier %q in package %q: not in package %q", id.Name, pkgpath, pkg.Types().Path())
628629
continue
629630
}
630-
if !typesinternal.IsPackageLevel(obj) {
631+
obj := pkg.Types().Scope().Lookup(name)
632+
if obj == nil {
631633
continue
632634
}
633635
if !matches(obj) {

gopls/internal/test/marker/testdata/references/asm_go.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,3 @@ TEXT ·CallSub(SB), $0-16
3939
MOVQ BX, b+8(FP)
4040
CALL ·Sub(SB) //@loc(callSubAsm, "·Sub")
4141
RET
42-
43-
// When defined in another package, it will not be processed.
44-
-- example/func.go --
45-
package example
46-
47-
func Add(a, b int) int
48-
func UseAdd() int {
49-
return Add(1, 2)
50-
}
51-
var myGlobal int64
52-
var _ = myGlobal
53-

0 commit comments

Comments
 (0)