feat(lint): add stack-imbalance rule
Assisted-by: MiMo V2.5 Pro
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user