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
@@ -299,6 +299,13 @@ func (p *state) parseGlobl(line []token.Token) *ast.Globl {
|
||||
g := &ast.Globl{Keyword: line[0]}
|
||||
rest := skipComma(line[1:])
|
||||
sym, n := parseSymbolPrefix(rest)
|
||||
if sym == nil {
|
||||
// A usable tree without a name cannot be had, and the linter and LSP
|
||||
// dereference Name on every parsed GLOBL, so the decl keeps a
|
||||
// placeholder beside its error, exactly as TEXT does.
|
||||
p.errorf(line[0].Pos, "GLOBL missing a symbol name")
|
||||
sym = &ast.Symbol{Pos: line[0].Pos, Raw: "?", Name: "?"}
|
||||
}
|
||||
g.Name = sym
|
||||
rest = skipComma(rest[n:])
|
||||
// Flags are identifiers (RODATA, DUPOK) or legacy numeric constants
|
||||
@@ -324,6 +331,12 @@ func (p *state) parseData(line []token.Token) *ast.Data {
|
||||
nameGroup, valuePart := splitFirstComma(rest)
|
||||
nameGroup, width := splitTrailingWidth(nameGroup)
|
||||
sym, _ := parseSymbolPrefix(nameGroup)
|
||||
if sym == nil {
|
||||
// Same contract as TEXT and GLOBL: the tree stays usable beside its
|
||||
// error, because downstream tools dereference Name unconditionally.
|
||||
p.errorf(line[0].Pos, "DATA missing a symbol name")
|
||||
sym = &ast.Symbol{Pos: line[0].Pos, Raw: "?", Name: "?"}
|
||||
}
|
||||
d.Name = sym
|
||||
d.Width = width
|
||||
if len(valuePart) > 0 {
|
||||
|
||||
Reference in new issue
Block a user