Skip to content

Commit d162461

Browse files
committed
go/analysis/passes/asmdecl: add support for ABI selector clauses
Accept ABI selector clauses for function definitions. The assembler allows these clauses when compiling the runtime, so the checker needs to be able to digest them as well. Updates golang/go#40724 Change-Id: I49ea4d87450c498bdfe10a8c441b48fcf70bea7c Reviewed-on: https://go-review.googlesource.com/c/tools/+/262197 Trust: Than McIntosh <[email protected]> Run-TryBot: Than McIntosh <[email protected]> Reviewed-by: Cherry Zhang <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 64a9e34 commit d162461

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

go/analysis/passes/asmdecl/asmdecl.go

+10
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ var (
137137
asmSP = re(`[^+\-0-9](([0-9]+)\(([A-Z0-9]+)\))`)
138138
asmOpcode = re(`^\s*(?:[A-Z0-9a-z_]+:)?\s*([A-Z]+)\s*([^,]*)(?:,\s*(.*))?`)
139139
ppc64Suff = re(`([BHWD])(ZU|Z|U|BR)?$`)
140+
abiSuff = re(`^(.+)<ABI.+>$`)
140141
)
141142

142143
func run(pass *analysis.Pass) (interface{}, error) {
@@ -200,6 +201,13 @@ Files:
200201
}
201202
retLine = nil
202203
}
204+
trimABI := func(fnName string) string {
205+
m := abiSuff.FindStringSubmatch(fnName)
206+
if m != nil {
207+
return m[1]
208+
}
209+
return fnName
210+
}
203211
for lineno, line := range lines {
204212
lineno++
205213

@@ -268,6 +276,8 @@ Files:
268276
continue
269277
}
270278
}
279+
// Trim off optional ABI selector.
280+
fnName := trimABI(fnName)
271281
flag := m[3]
272282
fn = knownFunc[fnName][arch]
273283
if fn != nil {

go/analysis/passes/asmdecl/testdata/src/a/asm.go

+4
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ func noframe1(x int32)
4747
func noframe2(x int32)
4848

4949
func fvariadic(int, ...int)
50+
51+
func pickStableABI(x int)
52+
func pickInternalABI(x int)
53+
func pickFutureABI(x int)

go/analysis/passes/asmdecl/testdata/src/a/asm1.s

+15
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,18 @@ TEXT ·f29318(SB), NOSPLIT, $32
330330
MOVQ x_0_1+8(FP), AX
331331
MOVQ x_1_1+24(FP), CX
332332
RET
333+
334+
// ABI selector
335+
TEXT ·pickStableABI<ABI0>(SB), NOSPLIT, $32
336+
MOVQ x+0(FP), AX
337+
RET
338+
339+
// ABI selector
340+
TEXT ·pickInternalABI<ABIInternal>(SB), NOSPLIT, $32
341+
MOVQ x+0(FP), AX
342+
RET
343+
344+
// ABI selector
345+
TEXT ·pickFutureABI<ABISomethingNotyetInvented>(SB), NOSPLIT, $32
346+
MOVQ x+0(FP), AX
347+
RET

0 commit comments

Comments
 (0)