fix(lint): trailing-label CFG guard and the goroutine alias
Assisted-by: GLM 5.3
This commit is contained in:
+17
-7
@@ -44,7 +44,7 @@ func checkFunCDATA(in *ast.Instr, cfg Config) []Diagnostic {
|
||||
Message: fmt.Sprintf("FUNCDATA expects 2 operands (index, symbol), got %d", len(in.Operands)),
|
||||
}}
|
||||
}
|
||||
out = append(out, checkIndex(in.Operands[0], "FUNCDATA")...)
|
||||
out = append(out, checkIndex(in.Operands[0], "FUNCDATA", maxFuncdataIndex)...)
|
||||
if sym := in.Operands[1].Addr.Sym; in.Operands[1].Kind != ast.OpAddr || sym == nil {
|
||||
out = append(out, Diagnostic{
|
||||
Pos: in.Operands[1].Pos, Severity: Warning, Code: CodeFuncdata,
|
||||
@@ -66,7 +66,7 @@ func checkPCDATA(in *ast.Instr, cfg Config) []Diagnostic {
|
||||
}}
|
||||
}
|
||||
var out []Diagnostic
|
||||
out = append(out, checkIndex(in.Operands[0], "PCDATA")...)
|
||||
out = append(out, checkIndex(in.Operands[0], "PCDATA", maxPcdataIndex)...)
|
||||
if in.Operands[1].Kind != ast.OpImmediate {
|
||||
out = append(out, Diagnostic{
|
||||
Pos: in.Operands[1].Pos, Severity: Warning, Code: CodeFuncdata,
|
||||
@@ -76,20 +76,30 @@ func checkPCDATA(in *ast.Instr, cfg Config) []Diagnostic {
|
||||
return out
|
||||
}
|
||||
|
||||
// checkIndex validates an immediate index operand. A literal index must lie in
|
||||
// the small range the runtime uses; a named constant (e.g. $PCDATA_StackMapIndex)
|
||||
// The largest literal FUNCDATA and PCDATA indices the Go 1.27 runtime
|
||||
// defines (internal/abi/symtab.go, which pkg/include/funcdata.h mirrors):
|
||||
// FUNCDATA_WrapInfo is 7 and PCDATA_PanicBounds is 4. A literal above them
|
||||
// addresses metadata no runtime reads, which in hand-written assembly is
|
||||
// near-certainly a typo.
|
||||
const (
|
||||
maxFuncdataIndex = 7
|
||||
maxPcdataIndex = 4
|
||||
)
|
||||
|
||||
// checkIndex validates an immediate index operand. A literal index must lie
|
||||
// in the range the runtime defines; a named constant (e.g. $PCDATA_StackMapIndex)
|
||||
// cannot be evaluated and is accepted without a range check.
|
||||
func checkIndex(op *ast.Operand, directive string) []Diagnostic {
|
||||
func checkIndex(op *ast.Operand, directive string, max int64) []Diagnostic {
|
||||
if op.Kind != ast.OpImmediate {
|
||||
return []Diagnostic{{
|
||||
Pos: op.Pos, Severity: Warning, Code: CodeFuncdata,
|
||||
Message: directive + " index must be an immediate",
|
||||
}}
|
||||
}
|
||||
if op.Imm.HasVal && (op.Imm.Val < 0 || op.Imm.Val > 10) {
|
||||
if op.Imm.HasVal && (op.Imm.Val < 0 || op.Imm.Val > max) {
|
||||
return []Diagnostic{{
|
||||
Pos: op.Pos, Severity: Warning, Code: CodeFuncdata,
|
||||
Message: fmt.Sprintf("%s index %d is outside the valid range 0-10", directive, op.Imm.Val),
|
||||
Message: fmt.Sprintf("%s index %d is outside the valid range 0-%d", directive, op.Imm.Val, max),
|
||||
}}
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user