feat(lint): add stack-imbalance rule

Assisted-by: MiMo V2.5 Pro
This commit is contained in:
2026-08-21 00:35:21 +02:00
parent ce5ec24fa8
commit ac02c83a86
2 changed files with 148 additions and 0 deletions
+27
View File
@@ -282,3 +282,30 @@ TEXT ·f(SB), NOSPLIT|NOFRAME|DUPOK, $0
t.Fatalf("valid flags must not be flagged: %+v", diags)
}
}
func TestStackImbalance(t *testing.T) {
// Function with frame size 16 but only SUB 8, SP — imbalance.
diags := lintSrc(t, `
#include "textflag.h"
TEXT ·f(SB), NOSPLIT, $16-0
SUBQ $8, SP
RET
`)
if codes(diags)[CodeStackImbalance] != 1 {
t.Fatalf("want one stack-imbalance, got %+v", diags)
}
}
func TestStackBalanced(t *testing.T) {
// Function with frame size 16 and matching SUB/ADD — balanced.
diags := lintSrc(t, `
#include "textflag.h"
TEXT ·f(SB), NOSPLIT, $16-0
SUBQ $16, SP
ADDQ $16, SP
RET
`)
if codes(diags)[CodeStackImbalance] != 0 {
t.Fatalf("balanced stack must not be flagged: %+v", diags)
}
}