feat(lint): nonportable amd64 register name rule
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user