fix(parser): diagnose GLOBL and DATA without a symbol name
A bare GLOBL or DATA parsed without a single diagnostic while leaving a nil Name in the tree, a pointer every downstream tool dereferences; TEXT keeps a placeholder beside its error for exactly that reason, and GLOBL and DATA now do the same. The crashing input enters the corpus. Assisted-by: GLM 5.3
This commit is contained in:
1 parent
05de774c0a
commit
bbe14dd1ab
3 files changed
+49
No files matched your search
@@ -383,6 +383,40 @@ func TestTextMissingSymbolKeepsDecl(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestGloblDataMissingSymbolKeepsDecl holds GLOBL and DATA to TEXT's
|
||||
// contract: a directive with no symbol name is a diagnostic, and the decl
|
||||
// stays in the tree with a non-nil placeholder, because downstream tools
|
||||
// dereference Name unconditionally. A bare "DATA" used to parse without a
|
||||
// single error while leaving Name nil behind, a landmine every consumer
|
||||
// stepped on.
|
||||
func TestGloblDataMissingSymbolKeepsDecl(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
src string
|
||||
kind string
|
||||
}{
|
||||
{"GLOBL , $8\n", "GLOBL"},
|
||||
{"DATA\n", "DATA"},
|
||||
{"DATA /4, $1\n", "DATA"},
|
||||
} {
|
||||
file, errs := Parse("t.s", tc.src)
|
||||
if len(errs) == 0 {
|
||||
t.Errorf("%s with no symbol: want a diagnostic", tc.kind)
|
||||
}
|
||||
var name *ast.Symbol
|
||||
switch d := file.Decls[0].(type) {
|
||||
case *ast.Globl:
|
||||
name = d.Name
|
||||
case *ast.Data:
|
||||
name = d.Name
|
||||
default:
|
||||
t.Fatalf("%s: decl is %T", tc.kind, d)
|
||||
}
|
||||
if name == nil {
|
||||
t.Errorf("%s: Name must never be nil: downstream tools dereference it", tc.kind)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestInt64MinimumImmediate covers $-0x8000000000000000: the digits overflow
|
||||
// int64 when parsed directly, but the negated magnitude is exactly the int64
|
||||
// minimum and must land in Val rather than the float fallback.
|
||||
|
||||
Reference in new issue
Block a user