feat(lint): nonportable amd64 register name rule

This commit is contained in:
2026-08-29 13:39:22 +02:00
parent d75e6bcae6
commit c92e6bed3a
3 changed files with 119 additions and 0 deletions
+25
View File
@@ -411,3 +411,28 @@ TEXT ·f(SB), NOSPLIT, $0
t.Fatalf("byte register in L op must be flagged: %+v", diags)
}
}
func TestNonportableRegisterName(t *testing.T) {
diags := lintSrc(t, `
#include "textflag.h"
TEXT ·f(SB), NOSPLIT, $0
MOVQ RAX, RBX
MOVQ EAX, R9
RET
`)
// RAX and RBX (and EAX) are gasm aliases of AX/BX; R9 is canonical.
if got := codes(diags)[CodeNonportableRegister]; got != 3 {
t.Fatalf("want 3 nonportable-register-name, got %d: %+v", got, diags)
}
diags = lintSrc(t, `
#include "textflag.h"
TEXT ·f(SB), NOSPLIT, $0
MOVQ AX, BX
MOVQ (BX)(R9*4), R12
RET
`)
if codes(diags)[CodeNonportableRegister] != 0 {
t.Fatalf("canonical names must not be flagged: %+v", diags)
}
}