fix(format): keep macro content behind a label on its line
The canonical form splits a label from the instruction that follows it, but an identifier naming a macro may expand into any token at all: moved to a line of its own it no longer parses, because the parser accepts a non-mnemonic first token only behind a label. The names #define'd in the file now hold such content back, conservatively across the whole file, and the crashing input joins the corpus. Assisted-by: GLM 5.3
This commit is contained in:
1 parent
f452b8a995
commit
b54d2b4520
3 files changed
+46
-14
No files matched your search
@@ -107,8 +107,22 @@ func TestFormatPreservesExpansionSemantics(t *testing.T) {
|
||||
"\tRET\n",
|
||||
},
|
||||
{
|
||||
// A use before the define: the name is not a macro yet at that
|
||||
// point of the file, so the label splits as any other does.
|
||||
// Content after a label that names a macro: the expansion may
|
||||
// start with any token, so the canonical form keeps it on the
|
||||
// label line, where the parser accepts a non-mnemonic first
|
||||
// token behind a label but not at the start of a line.
|
||||
name: "macro behind a label",
|
||||
src: "#define M 0\n" +
|
||||
"TEXT ·f(SB), $0\n" +
|
||||
"\tA: M\n" +
|
||||
"\tRET\n",
|
||||
},
|
||||
{
|
||||
// A use above its define: the name is not a macro at that point
|
||||
// of the file, so splitting would be safe; the whole-file set
|
||||
// the formatter keeps is deliberately conservative and leaves
|
||||
// the line whole, which preserves the expansion in both
|
||||
// directions alike.
|
||||
name: "label before the define of its name",
|
||||
src: "TEXT ·f(SB), $0\n" +
|
||||
"\tM: A00\n" +
|
||||
|
||||
Reference in new issue
Block a user